merge the formfield patch from ooo-build
[ooovba.git] / sw / source / filter / xml / xmlmeta.cxx
blob3bac5aa2b43a1096a17fd7d73c037ff0a4d316b3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlmeta.cxx,v $
10 * $Revision: 1.22 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <com/sun/star/frame/XModel.hpp>
37 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
38 #include <com/sun/star/text/XTextDocument.hpp>
39 #include <xmloff/xmlnmspe.hxx>
40 #include <xmloff/xmlmetai.hxx>
41 #include <xmloff/xmlmetae.hxx>
42 #include <svx/langitem.hxx>
43 #include <xmloff/xmluconv.hxx>
44 #include <xmloff/nmspmap.hxx>
45 #include "docstat.hxx"
46 #include "docsh.hxx"
47 #include <doc.hxx>
48 #include <unoobj.hxx>
49 #include "xmlimp.hxx"
50 #include "xmlexp.hxx"
53 using ::rtl::OUString;
54 using ::rtl::OUStringBuffer;
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::text;
60 using namespace ::xmloff::token;
62 // ---------------------------------------------------------------------
64 SvXMLImportContext *SwXMLImport::CreateMetaContext(
65 const OUString& rLocalName )
67 SvXMLImportContext *pContext = 0;
69 if( !(IsStylesOnlyMode() || IsInsertMode()) )
71 uno::Reference<xml::sax::XDocumentHandler> xDocBuilder(
72 mxServiceFactory->createInstance(::rtl::OUString::createFromAscii(
73 "com.sun.star.xml.dom.SAXDocumentBuilder")),
74 uno::UNO_QUERY_THROW);
75 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
76 GetModel(), UNO_QUERY_THROW);
77 pContext = new SvXMLMetaDocumentContext(*this,
78 XML_NAMESPACE_OFFICE, rLocalName,
79 xDPS->getDocumentProperties(), xDocBuilder);
82 if( !pContext )
83 pContext = new SvXMLImportContext( *this,
84 XML_NAMESPACE_OFFICE, rLocalName );
86 return pContext;
89 // ---------------------------------------------------------------------
91 enum SvXMLTokenMapAttrs
93 XML_TOK_META_STAT_TABLE = 1,
94 XML_TOK_META_STAT_IMAGE = 2,
95 XML_TOK_META_STAT_OLE = 4,
96 XML_TOK_META_STAT_PAGE = 8,
97 XML_TOK_META_STAT_PARA = 16,
98 XML_TOK_META_STAT_WORD = 32,
99 XML_TOK_META_STAT_CHAR = 64,
100 XML_TOK_META_STAT_END=XML_TOK_UNKNOWN
104 static __FAR_DATA SvXMLTokenMapEntry aMetaStatAttrTokenMap[] =
106 { XML_NAMESPACE_META, XML_TABLE_COUNT, XML_TOK_META_STAT_TABLE },
107 { XML_NAMESPACE_META, XML_IMAGE_COUNT, XML_TOK_META_STAT_IMAGE },
108 { XML_NAMESPACE_META, XML_OBJECT_COUNT, XML_TOK_META_STAT_OLE },
109 { XML_NAMESPACE_META, XML_PARAGRAPH_COUNT, XML_TOK_META_STAT_PARA },
110 { XML_NAMESPACE_META, XML_PAGE_COUNT, XML_TOK_META_STAT_PAGE },
111 { XML_NAMESPACE_META, XML_WORD_COUNT, XML_TOK_META_STAT_WORD },
112 { XML_NAMESPACE_META, XML_CHARACTER_COUNT, XML_TOK_META_STAT_CHAR },
113 XML_TOKEN_MAP_END
117 struct statistic {
118 SvXMLTokenMapAttrs token;
119 const char* name;
120 USHORT SwDocStat::* target16;
121 ULONG SwDocStat::* target32; /* or 64, on LP64 platforms */
124 static const struct statistic s_stats [] = {
125 { XML_TOK_META_STAT_TABLE, "TableCount", &SwDocStat::nTbl, 0 },
126 { XML_TOK_META_STAT_IMAGE, "ImageCount", &SwDocStat::nGrf, 0 },
127 { XML_TOK_META_STAT_OLE, "ObjectCount", &SwDocStat::nOLE, 0 },
128 { XML_TOK_META_STAT_PAGE, "PageCount", 0, &SwDocStat::nPage },
129 { XML_TOK_META_STAT_PARA, "ParagraphCount", 0, &SwDocStat::nPara },
130 { XML_TOK_META_STAT_WORD, "WordCount", 0, &SwDocStat::nWord },
131 { XML_TOK_META_STAT_CHAR, "CharacterCount", 0, &SwDocStat::nChar },
132 { XML_TOK_META_STAT_END, 0, 0, 0 }
135 void SwXMLImport::SetStatistics(
136 const Sequence< beans::NamedValue > & i_rStats)
138 if( IsStylesOnlyMode() || IsInsertMode() )
139 return;
141 SvXMLImport::SetStatistics(i_rStats);
143 SwDoc *pDoc = SwImport::GetDocFromXMLImport( *this );
144 SwDocStat aDocStat( pDoc->GetDocStat() );
146 sal_uInt32 nTokens = 0;
148 for (sal_Int32 i = 0; i < i_rStats.getLength(); ++i) {
149 for (struct statistic const* pStat = s_stats; pStat->name != 0;
150 ++pStat) {
151 if (i_rStats[i].Name.equalsAscii(pStat->name)) {
152 sal_Int32 val = 0;
153 if (i_rStats[i].Value >>= val) {
154 if (pStat->target16 != 0) {
155 aDocStat.*(pStat->target16)
156 = static_cast<sal_uInt16> (val);
157 } else {
158 aDocStat.*(pStat->target32)
159 = static_cast<sal_uInt32> (val);
161 nTokens |= pStat->token;
162 } else {
163 DBG_ERROR("SwXMLImport::SetStatistics: invalid entry");
169 if( 127 == nTokens )
170 aDocStat.bModified = sal_False;
171 if( nTokens )
172 pDoc->SetDocStat( aDocStat );
174 // set progress bar reference to #paragraphs. If not available,
175 // use #pages*10, or guesstimate 250 paragraphs. Additionally
176 // guesstimate PROGRESS_BAR_STEPS each for meta+settings, styles,
177 // and autostyles.
178 sal_Int32 nProgressReference = 250;
179 if( nTokens & XML_TOK_META_STAT_PARA )
180 nProgressReference = (sal_Int32)aDocStat.nPara;
181 else if ( nTokens & XML_TOK_META_STAT_PAGE )
182 nProgressReference = 10 * (sal_Int32)aDocStat.nPage;
183 ProgressBarHelper* pProgress = GetProgressBarHelper();
184 pProgress->SetReference( nProgressReference + 3*PROGRESS_BAR_STEP );
185 pProgress->SetValue( 0 );
188 // ---------------------------------------------------------------------
190 void SwXMLExport::_ExportMeta()
192 SvXMLExport::_ExportMeta();
194 if( !IsBlockMode() )
197 if( IsShowProgress() )
199 ProgressBarHelper *pProgress = GetProgressBarHelper();
200 pProgress->SetValue( pProgress->GetValue() + 2 );