Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <hintids.hxx>
21 : #include <com/sun/star/frame/XModel.hpp>
22 : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
23 : #include <com/sun/star/text/XTextDocument.hpp>
24 : #include <xmloff/xmlnmspe.hxx>
25 : #include <xmloff/xmlmetai.hxx>
26 : #include <xmloff/xmlmetae.hxx>
27 : #include <editeng/langitem.hxx>
28 : #include <xmloff/xmluconv.hxx>
29 : #include <xmloff/nmspmap.hxx>
30 : #include "docstat.hxx"
31 : #include "docsh.hxx"
32 : #include <doc.hxx>
33 : #include "xmlimp.hxx"
34 : #include "xmlexp.hxx"
35 :
36 : using namespace ::com::sun::star;
37 : using namespace ::com::sun::star::uno;
38 : using namespace ::com::sun::star::lang;
39 : using namespace ::com::sun::star::text;
40 : using namespace ::xmloff::token;
41 :
42 : uno::Reference<document::XDocumentProperties>
43 152 : SwXMLImport::GetDocumentProperties() const
44 : {
45 604 : if (IsOrganizerMode() || IsStylesOnlyMode() ||
46 452 : IsBlockMode() || IsInsertMode())
47 : {
48 39 : return 0;
49 : }
50 : uno::Reference<document::XDocumentPropertiesSupplier> const xDPS(
51 113 : GetModel(), UNO_QUERY_THROW);
52 113 : return xDPS->getDocumentProperties();
53 : }
54 :
55 115 : SvXMLImportContext *SwXMLImport::CreateMetaContext(
56 : const OUString& rLocalName )
57 : {
58 115 : SvXMLImportContext *pContext = 0;
59 :
60 115 : if (getImportFlags() & IMPORT_META)
61 : {
62 : uno::Reference<document::XDocumentProperties> const xDocProps(
63 115 : GetDocumentProperties());
64 230 : pContext = new SvXMLMetaDocumentContext(*this,
65 230 : XML_NAMESPACE_OFFICE, rLocalName, xDocProps);
66 : }
67 :
68 115 : if( !pContext )
69 : pContext = new SvXMLImportContext( *this,
70 0 : XML_NAMESPACE_OFFICE, rLocalName );
71 :
72 115 : return pContext;
73 : }
74 :
75 : enum SvXMLTokenMapAttrs
76 : {
77 : XML_TOK_META_STAT_TABLE = 1,
78 : XML_TOK_META_STAT_IMAGE = 2,
79 : XML_TOK_META_STAT_OLE = 4,
80 : XML_TOK_META_STAT_PAGE = 8,
81 : XML_TOK_META_STAT_PARA = 16,
82 : XML_TOK_META_STAT_WORD = 32,
83 : XML_TOK_META_STAT_CHAR = 64,
84 : XML_TOK_META_STAT_NON_WHITE_SPACE_CHAR = 128,
85 : XML_TOK_META_STAT_END=XML_TOK_UNKNOWN
86 : };
87 :
88 : struct statistic {
89 : SvXMLTokenMapAttrs token;
90 : const char* name;
91 : sal_uInt16 SwDocStat::* target16;
92 : sal_uLong SwDocStat::* target32; /* or 64, on LP64 platforms */
93 : };
94 :
95 : static const struct statistic s_stats [] = {
96 : { XML_TOK_META_STAT_TABLE, "TableCount", &SwDocStat::nTbl, 0 },
97 : { XML_TOK_META_STAT_IMAGE, "ImageCount", &SwDocStat::nGrf, 0 },
98 : { XML_TOK_META_STAT_OLE, "ObjectCount", &SwDocStat::nOLE, 0 },
99 : { XML_TOK_META_STAT_PAGE, "PageCount", 0, &SwDocStat::nPage },
100 : { XML_TOK_META_STAT_PARA, "ParagraphCount", 0, &SwDocStat::nPara },
101 : { XML_TOK_META_STAT_WORD, "WordCount", 0, &SwDocStat::nWord },
102 : { XML_TOK_META_STAT_CHAR, "CharacterCount", 0, &SwDocStat::nChar },
103 : { XML_TOK_META_STAT_NON_WHITE_SPACE_CHAR, "NonWhitespaceCharacterCount", 0, &SwDocStat::nCharExcludingSpaces },
104 : { XML_TOK_META_STAT_END, 0, 0, 0 }
105 : };
106 :
107 113 : void SwXMLImport::SetStatistics(
108 : const Sequence< beans::NamedValue > & i_rStats)
109 : {
110 113 : if( IsStylesOnlyMode() || IsInsertMode() )
111 113 : return;
112 :
113 113 : SvXMLImport::SetStatistics(i_rStats);
114 :
115 113 : SwDoc *pDoc = SwImport::GetDocFromXMLImport( *this );
116 113 : SwDocStat aDocStat( pDoc->GetDocStat() );
117 :
118 113 : sal_uInt32 nTokens = 0;
119 :
120 995 : for (sal_Int32 i = 0; i < i_rStats.getLength(); ++i) {
121 7938 : for (struct statistic const* pStat = s_stats; pStat->name != 0;
122 : ++pStat) {
123 7056 : if (i_rStats[i].Name.equalsAscii(pStat->name)) {
124 882 : sal_Int32 val = 0;
125 882 : if (i_rStats[i].Value >>= val) {
126 882 : if (pStat->target16 != 0) {
127 336 : aDocStat.*(pStat->target16)
128 336 : = static_cast<sal_uInt16> (val);
129 : } else {
130 546 : aDocStat.*(pStat->target32)
131 546 : = static_cast<sal_uInt32> (val);
132 : }
133 882 : nTokens |= pStat->token;
134 : } else {
135 : OSL_FAIL("SwXMLImport::SetStatistics: invalid entry");
136 : }
137 : }
138 : }
139 : }
140 :
141 113 : if( nTokens )
142 112 : pDoc->SetDocStat( aDocStat );
143 :
144 : // set progress bar reference to #paragraphs. If not available,
145 : // use #pages*10, or guesstimate 250 paragraphs. Additionally
146 : // guesstimate PROGRESS_BAR_STEPS each for meta+settings, styles,
147 : // and autostyles.
148 113 : sal_Int32 nProgressReference = 250;
149 113 : if( nTokens & XML_TOK_META_STAT_PARA )
150 112 : nProgressReference = (sal_Int32)aDocStat.nPara;
151 1 : else if ( nTokens & XML_TOK_META_STAT_PAGE )
152 0 : nProgressReference = 10 * (sal_Int32)aDocStat.nPage;
153 113 : ProgressBarHelper* pProgress = GetProgressBarHelper();
154 113 : pProgress->SetReference( nProgressReference + 3*PROGRESS_BAR_STEP );
155 113 : pProgress->SetValue( 0 );
156 : }
157 :
158 20 : void SwXMLExport::_ExportMeta()
159 : {
160 20 : SvXMLExport::_ExportMeta();
161 :
162 20 : if( !IsBlockMode() )
163 : {
164 :
165 20 : if( IsShowProgress() )
166 : {
167 20 : ProgressBarHelper *pProgress = GetProgressBarHelper();
168 20 : pProgress->SetValue( pProgress->GetValue() + 2 );
169 : }
170 : }
171 20 : }
172 :
173 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|