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 <IDocumentStatistics.hxx>
34 : #include "xmlimp.hxx"
35 : #include "xmlexp.hxx"
36 :
37 : using namespace ::com::sun::star;
38 : using namespace ::com::sun::star::uno;
39 : using namespace ::com::sun::star::lang;
40 : using namespace ::com::sun::star::text;
41 : using namespace ::xmloff::token;
42 :
43 : uno::Reference<document::XDocumentProperties>
44 422 : SwXMLImport::GetDocumentProperties() const
45 : {
46 1676 : if (IsOrganizerMode() || IsStylesOnlyMode() ||
47 1254 : IsBlockMode() || IsInsertMode())
48 : {
49 110 : return 0;
50 : }
51 : uno::Reference<document::XDocumentPropertiesSupplier> const xDPS(
52 312 : GetModel(), UNO_QUERY_THROW);
53 312 : return xDPS->getDocumentProperties();
54 : }
55 :
56 316 : SvXMLImportContext *SwXMLImport::CreateMetaContext(
57 : const OUString& rLocalName )
58 : {
59 316 : SvXMLImportContext *pContext = 0;
60 :
61 316 : if (getImportFlags() & IMPORT_META)
62 : {
63 : uno::Reference<document::XDocumentProperties> const xDocProps(
64 316 : GetDocumentProperties());
65 632 : pContext = new SvXMLMetaDocumentContext(*this,
66 632 : XML_NAMESPACE_OFFICE, rLocalName, xDocProps);
67 : }
68 :
69 316 : if( !pContext )
70 : pContext = new SvXMLImportContext( *this,
71 0 : XML_NAMESPACE_OFFICE, rLocalName );
72 :
73 316 : return pContext;
74 : }
75 :
76 : enum SvXMLTokenMapAttrs
77 : {
78 : XML_TOK_META_STAT_TABLE = 1,
79 : XML_TOK_META_STAT_IMAGE = 2,
80 : XML_TOK_META_STAT_OLE = 4,
81 : XML_TOK_META_STAT_PAGE = 8,
82 : XML_TOK_META_STAT_PARA = 16,
83 : XML_TOK_META_STAT_WORD = 32,
84 : XML_TOK_META_STAT_CHAR = 64,
85 : XML_TOK_META_STAT_NON_WHITE_SPACE_CHAR = 128,
86 : XML_TOK_META_STAT_END=XML_TOK_UNKNOWN
87 : };
88 :
89 : struct statistic {
90 : SvXMLTokenMapAttrs token;
91 : const char* name;
92 : sal_uInt16 SwDocStat::* target16;
93 : sal_uLong SwDocStat::* target32; /* or 64, on LP64 platforms */
94 : };
95 :
96 : static const struct statistic s_stats [] = {
97 : { XML_TOK_META_STAT_TABLE, "TableCount", &SwDocStat::nTbl, 0 },
98 : { XML_TOK_META_STAT_IMAGE, "ImageCount", &SwDocStat::nGrf, 0 },
99 : { XML_TOK_META_STAT_OLE, "ObjectCount", &SwDocStat::nOLE, 0 },
100 : { XML_TOK_META_STAT_PAGE, "PageCount", 0, &SwDocStat::nPage },
101 : { XML_TOK_META_STAT_PARA, "ParagraphCount", 0, &SwDocStat::nPara },
102 : { XML_TOK_META_STAT_WORD, "WordCount", 0, &SwDocStat::nWord },
103 : { XML_TOK_META_STAT_CHAR, "CharacterCount", 0, &SwDocStat::nChar },
104 : { XML_TOK_META_STAT_NON_WHITE_SPACE_CHAR, "NonWhitespaceCharacterCount", 0, &SwDocStat::nCharExcludingSpaces },
105 : { XML_TOK_META_STAT_END, 0, 0, 0 }
106 : };
107 :
108 312 : void SwXMLImport::SetStatistics(
109 : const Sequence< beans::NamedValue > & i_rStats)
110 : {
111 312 : if( IsStylesOnlyMode() || IsInsertMode() )
112 312 : return;
113 :
114 312 : SvXMLImport::SetStatistics(i_rStats);
115 :
116 312 : SwDoc *pDoc = SwImport::GetDocFromXMLImport( *this );
117 312 : SwDocStat aDocStat( pDoc->getIDocumentStatistics().GetDocStat() );
118 :
119 312 : sal_uInt32 nTokens = 0;
120 :
121 2746 : for (sal_Int32 i = 0; i < i_rStats.getLength(); ++i) {
122 21906 : for (struct statistic const* pStat = s_stats; pStat->name != 0;
123 : ++pStat) {
124 19472 : if (i_rStats[i].Name.equalsAscii(pStat->name)) {
125 2434 : sal_Int32 val = 0;
126 2434 : if (i_rStats[i].Value >>= val) {
127 2434 : if (pStat->target16 != 0) {
128 924 : aDocStat.*(pStat->target16)
129 924 : = static_cast<sal_uInt16> (val);
130 : } else {
131 1510 : aDocStat.*(pStat->target32)
132 1510 : = static_cast<sal_uInt32> (val);
133 : }
134 2434 : nTokens |= pStat->token;
135 : } else {
136 : OSL_FAIL("SwXMLImport::SetStatistics: invalid entry");
137 : }
138 : }
139 : }
140 : }
141 :
142 312 : if( nTokens )
143 308 : pDoc->getIDocumentStatistics().SetDocStat( aDocStat );
144 :
145 : // set progress bar reference to #paragraphs. If not available,
146 : // use #pages*10, or guesstimate 250 paragraphs. Additionally
147 : // guesstimate PROGRESS_BAR_STEPS each for meta+settings, styles,
148 : // and autostyles.
149 312 : sal_Int32 nProgressReference = 250;
150 312 : if( nTokens & XML_TOK_META_STAT_PARA )
151 308 : nProgressReference = (sal_Int32)aDocStat.nPara;
152 4 : else if ( nTokens & XML_TOK_META_STAT_PAGE )
153 0 : nProgressReference = 10 * (sal_Int32)aDocStat.nPage;
154 312 : ProgressBarHelper* pProgress = GetProgressBarHelper();
155 312 : pProgress->SetReference( nProgressReference + 3*PROGRESS_BAR_STEP );
156 312 : pProgress->SetValue( 0 );
157 : }
158 :
159 52 : void SwXMLExport::_ExportMeta()
160 : {
161 52 : SvXMLExport::_ExportMeta();
162 :
163 52 : if( !IsBlockMode() )
164 : {
165 :
166 52 : if( IsShowProgress() )
167 : {
168 52 : ProgressBarHelper *pProgress = GetProgressBarHelper();
169 52 : pProgress->SetValue( pProgress->GetValue() + 2 );
170 : }
171 : }
172 322 : }
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|