Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <hintids.hxx>
30 : : #include <com/sun/star/frame/XModel.hpp>
31 : : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
32 : : #include <com/sun/star/text/XTextDocument.hpp>
33 : : #include <xmloff/xmlnmspe.hxx>
34 : : #include <xmloff/xmlmetai.hxx>
35 : : #include <xmloff/xmlmetae.hxx>
36 : : #include <editeng/langitem.hxx>
37 : : #include <xmloff/xmluconv.hxx>
38 : : #include <xmloff/nmspmap.hxx>
39 : : #include "docstat.hxx"
40 : : #include "docsh.hxx"
41 : : #include <doc.hxx>
42 : : #include "xmlimp.hxx"
43 : : #include "xmlexp.hxx"
44 : :
45 : :
46 : : using ::rtl::OUString;
47 : : using ::rtl::OUStringBuffer;
48 : :
49 : : using namespace ::com::sun::star;
50 : : using namespace ::com::sun::star::uno;
51 : : using namespace ::com::sun::star::lang;
52 : : using namespace ::com::sun::star::text;
53 : : using namespace ::xmloff::token;
54 : :
55 : : // ---------------------------------------------------------------------
56 : :
57 : : uno::Reference<document::XDocumentProperties>
58 : 65 : SwXMLImport::GetDocumentProperties() const
59 : : {
60 [ + - ][ + - : 195 : if (IsOrganizerMode() || IsStylesOnlyMode() ||
+ - + + ]
[ + + ]
61 : 130 : IsBlockMode() || IsInsertMode())
62 : : {
63 [ + - ]: 2 : return 0;
64 : : }
65 : : uno::Reference<document::XDocumentPropertiesSupplier> const xDPS(
66 [ + - ]: 63 : GetModel(), UNO_QUERY_THROW);
67 [ + - ][ + - ]: 65 : return xDPS->getDocumentProperties();
68 : : }
69 : :
70 : 63 : SvXMLImportContext *SwXMLImport::CreateMetaContext(
71 : : const OUString& rLocalName )
72 : : {
73 : 63 : SvXMLImportContext *pContext = 0;
74 : :
75 [ + - ]: 63 : if (getImportFlags() & IMPORT_META)
76 : : {
77 : : uno::Reference<xml::sax::XDocumentHandler> const xDocBuilder(
78 [ + - ]: 63 : mxServiceFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
79 : 63 : "com.sun.star.xml.dom.SAXDocumentBuilder"))),
80 [ + - ][ + - ]: 63 : uno::UNO_QUERY_THROW);
[ + - ]
81 : : uno::Reference<document::XDocumentProperties> const xDocProps(
82 [ + - ]: 63 : GetDocumentProperties());
83 : : pContext = new SvXMLMetaDocumentContext(*this,
84 [ + - ][ + - ]: 63 : XML_NAMESPACE_OFFICE, rLocalName, xDocProps, xDocBuilder);
[ + - ]
85 : : }
86 : :
87 [ - + ]: 63 : if( !pContext )
88 : : pContext = new SvXMLImportContext( *this,
89 [ # # ]: 0 : XML_NAMESPACE_OFFICE, rLocalName );
90 : :
91 : 63 : return pContext;
92 : : }
93 : :
94 : : // ---------------------------------------------------------------------
95 : :
96 : : enum SvXMLTokenMapAttrs
97 : : {
98 : : XML_TOK_META_STAT_TABLE = 1,
99 : : XML_TOK_META_STAT_IMAGE = 2,
100 : : XML_TOK_META_STAT_OLE = 4,
101 : : XML_TOK_META_STAT_PAGE = 8,
102 : : XML_TOK_META_STAT_PARA = 16,
103 : : XML_TOK_META_STAT_WORD = 32,
104 : : XML_TOK_META_STAT_CHAR = 64,
105 : : XML_TOK_META_STAT_NON_WHITE_SPACE_CHAR = 128,
106 : : XML_TOK_META_STAT_END=XML_TOK_UNKNOWN
107 : : };
108 : :
109 : : struct statistic {
110 : : SvXMLTokenMapAttrs token;
111 : : const char* name;
112 : : sal_uInt16 SwDocStat::* target16;
113 : : sal_uLong SwDocStat::* target32; /* or 64, on LP64 platforms */
114 : : };
115 : :
116 : : static const struct statistic s_stats [] = {
117 : : { XML_TOK_META_STAT_TABLE, "TableCount", &SwDocStat::nTbl, 0 },
118 : : { XML_TOK_META_STAT_IMAGE, "ImageCount", &SwDocStat::nGrf, 0 },
119 : : { XML_TOK_META_STAT_OLE, "ObjectCount", &SwDocStat::nOLE, 0 },
120 : : { XML_TOK_META_STAT_PAGE, "PageCount", 0, &SwDocStat::nPage },
121 : : { XML_TOK_META_STAT_PARA, "ParagraphCount", 0, &SwDocStat::nPara },
122 : : { XML_TOK_META_STAT_WORD, "WordCount", 0, &SwDocStat::nWord },
123 : : { XML_TOK_META_STAT_CHAR, "CharacterCount", 0, &SwDocStat::nChar },
124 : : { XML_TOK_META_STAT_NON_WHITE_SPACE_CHAR, "NonWhitespaceCharacterCount", 0, &SwDocStat::nCharExcludingSpaces },
125 : : { XML_TOK_META_STAT_END, 0, 0, 0 }
126 : : };
127 : :
128 : 63 : void SwXMLImport::SetStatistics(
129 : : const Sequence< beans::NamedValue > & i_rStats)
130 : : {
131 [ + - ][ - + ]: 63 : if( IsStylesOnlyMode() || IsInsertMode() )
[ + - ]
132 : 63 : return;
133 : :
134 [ + - ]: 63 : SvXMLImport::SetStatistics(i_rStats);
135 : :
136 [ + - ]: 63 : SwDoc *pDoc = SwImport::GetDocFromXMLImport( *this );
137 [ + - ]: 63 : SwDocStat aDocStat( pDoc->GetDocStat() );
138 : :
139 : 63 : sal_uInt32 nTokens = 0;
140 : :
141 [ + + ]: 550 : for (sal_Int32 i = 0; i < i_rStats.getLength(); ++i) {
142 [ + + ]: 4383 : for (struct statistic const* pStat = s_stats; pStat->name != 0;
143 : : ++pStat) {
144 [ + + ]: 3896 : if (i_rStats[i].Name.equalsAscii(pStat->name)) {
145 : 487 : sal_Int32 val = 0;
146 [ + - ]: 487 : if (i_rStats[i].Value >>= val) {
147 [ + + ]: 487 : if (pStat->target16 != 0) {
148 : : aDocStat.*(pStat->target16)
149 : 189 : = static_cast<sal_uInt16> (val);
150 : : } else {
151 : : aDocStat.*(pStat->target32)
152 : 298 : = static_cast<sal_uInt32> (val);
153 : : }
154 : 487 : nTokens |= pStat->token;
155 : : } else {
156 : : OSL_FAIL("SwXMLImport::SetStatistics: invalid entry");
157 : : }
158 : : }
159 : : }
160 : : }
161 : :
162 [ + + ]: 63 : if( 255 == nTokens )
163 : 46 : aDocStat.bModified = sal_False;
164 [ + - ]: 63 : if( nTokens )
165 [ + - ]: 63 : pDoc->SetDocStat( aDocStat );
166 : :
167 : : // set progress bar reference to #paragraphs. If not available,
168 : : // use #pages*10, or guesstimate 250 paragraphs. Additionally
169 : : // guesstimate PROGRESS_BAR_STEPS each for meta+settings, styles,
170 : : // and autostyles.
171 : 63 : sal_Int32 nProgressReference = 250;
172 [ + - ]: 63 : if( nTokens & XML_TOK_META_STAT_PARA )
173 : 63 : nProgressReference = (sal_Int32)aDocStat.nPara;
174 [ # # ]: 0 : else if ( nTokens & XML_TOK_META_STAT_PAGE )
175 : 0 : nProgressReference = 10 * (sal_Int32)aDocStat.nPage;
176 [ + - ]: 63 : ProgressBarHelper* pProgress = GetProgressBarHelper();
177 : 63 : pProgress->SetReference( nProgressReference + 3*PROGRESS_BAR_STEP );
178 [ + - ]: 63 : pProgress->SetValue( 0 );
179 : : }
180 : :
181 : : // ---------------------------------------------------------------------
182 : :
183 : 19 : void SwXMLExport::_ExportMeta()
184 : : {
185 : 19 : SvXMLExport::_ExportMeta();
186 : :
187 [ + - ]: 19 : if( !IsBlockMode() )
188 : : {
189 : :
190 [ + - ]: 19 : if( IsShowProgress() )
191 : : {
192 : 19 : ProgressBarHelper *pProgress = GetProgressBarHelper();
193 : 19 : pProgress->SetValue( pProgress->GetValue() + 2 );
194 : : }
195 : : }
196 : 19 : }
197 : :
198 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|