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