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 "MetaExportComponent.hxx"
21 : #include <com/sun/star/frame/XModel.hpp>
22 : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
23 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 : #include <com/sun/star/uno/Sequence.hxx>
25 : #include <com/sun/star/uno/Reference.hxx>
26 : #include <com/sun/star/uno/Exception.hpp>
27 : #include <com/sun/star/util/MeasureUnit.hpp>
28 : #include <com/sun/star/beans/PropertyAttribute.hpp>
29 : #include <comphelper/genericpropertyset.hxx>
30 : #include <rtl/ustrbuf.hxx>
31 : #include "xmloff/xmlnmspe.hxx"
32 : #include <xmloff/nmspmap.hxx>
33 : #include <xmloff/xmltoken.hxx>
34 : #include <xmloff/xmlmetae.hxx>
35 : #include "PropertySetMerger.hxx"
36 :
37 : #include <unotools/docinfohelper.hxx>
38 :
39 :
40 : using namespace ::com::sun::star;
41 : using namespace ::xmloff::token;
42 :
43 0 : XMLMetaExportComponent::XMLMetaExportComponent(
44 : const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
45 : sal_uInt16 nFlags )
46 0 : : SvXMLExport( util::MeasureUnit::CM, xServiceFactory, XML_TEXT, nFlags )
47 : {
48 0 : }
49 :
50 0 : XMLMetaExportComponent::~XMLMetaExportComponent()
51 : {
52 0 : }
53 :
54 0 : void SAL_CALL XMLMetaExportComponent::setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException)
55 : {
56 : try
57 : {
58 0 : SvXMLExport::setSourceDocument( xDoc );
59 : }
60 0 : catch( lang::IllegalArgumentException& )
61 : {
62 : // allow to use document properties service without model access
63 : // this is required for document properties exporter
64 : mxDocProps =
65 0 : uno::Reference< document::XDocumentProperties >::query( xDoc );
66 0 : if( !mxDocProps.is() )
67 0 : throw lang::IllegalArgumentException();
68 : }
69 0 : }
70 :
71 0 : sal_uInt32 XMLMetaExportComponent::exportDoc( enum XMLTokenEnum )
72 : {
73 0 : uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler();
74 :
75 0 : if( (getExportFlags() & EXPORT_OASIS) == 0 )
76 : {
77 0 : uno::Reference< lang::XMultiServiceFactory > xFactory = getServiceFactory();
78 0 : if( xFactory.is() )
79 : {
80 : try
81 : {
82 : ::comphelper::PropertyMapEntry aInfoMap[] =
83 : {
84 : { "Class", sizeof("Class")-1, 0,
85 0 : &::getCppuType((::rtl::OUString*)0),
86 : beans::PropertyAttribute::MAYBEVOID, 0},
87 : { NULL, 0, 0, NULL, 0, 0 }
88 0 : };
89 : uno::Reference< beans::XPropertySet > xConvPropSet(
90 : ::comphelper::GenericPropertySet_CreateInstance(
91 0 : new ::comphelper::PropertySetInfo( aInfoMap ) ) );
92 :
93 0 : uno::Any aAny;
94 0 : aAny <<= GetXMLToken( XML_TEXT );
95 0 : xConvPropSet->setPropertyValue(
96 0 : ::rtl::OUString("Class"), aAny );
97 :
98 : uno::Reference< beans::XPropertySet > xPropSet =
99 0 : getExportInfo().is()
100 : ? PropertySetMerger_CreateInstance( getExportInfo(),
101 : xConvPropSet )
102 0 : : getExportInfo();
103 :
104 0 : uno::Sequence< uno::Any > aArgs( 3 );
105 0 : aArgs[0] <<= xDocHandler;
106 0 : aArgs[1] <<= xPropSet;
107 0 : aArgs[2] <<= GetModel();
108 :
109 : // get filter component
110 : xDocHandler = uno::Reference< xml::sax::XDocumentHandler >(
111 0 : xFactory->createInstanceWithArguments(
112 : ::rtl::OUString("com.sun.star.comp.Oasis2OOoTransformer"),
113 0 : aArgs),
114 0 : uno::UNO_QUERY_THROW );
115 :
116 0 : SetDocHandler( xDocHandler );
117 : }
118 0 : catch( com::sun::star::uno::Exception& )
119 : {
120 : OSL_FAIL( "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!\n");
121 : }
122 0 : }
123 : }
124 :
125 :
126 0 : xDocHandler->startDocument();
127 :
128 0 : addChaffWhenEncryptedStorage();
129 :
130 : {
131 :
132 0 : const SvXMLNamespaceMap& rMap = GetNamespaceMap();
133 0 : sal_uInt16 nPos = rMap.GetFirstKey();
134 0 : while( USHRT_MAX != nPos )
135 : {
136 0 : GetAttrList().AddAttribute( rMap.GetAttrNameByKey( nPos ), rMap.GetNameByKey( nPos ) );
137 0 : nPos = GetNamespaceMap().GetNextKey( nPos );
138 : }
139 :
140 0 : const sal_Char* pVersion = 0;
141 0 : switch( getDefaultVersion() )
142 : {
143 0 : case SvtSaveOptions::ODFVER_LATEST: pVersion = "1.2"; break;
144 0 : case SvtSaveOptions::ODFVER_012_EXT_COMPAT: pVersion = "1.2"; break;
145 0 : case SvtSaveOptions::ODFVER_012: pVersion = "1.2"; break;
146 0 : case SvtSaveOptions::ODFVER_011: pVersion = "1.1"; break;
147 0 : case SvtSaveOptions::ODFVER_010: break;
148 :
149 : default:
150 : OSL_FAIL("xmloff::XMLMetaExportComponent::exportDoc(), unexpected odf default version!");
151 : }
152 :
153 0 : if( pVersion )
154 : AddAttribute( XML_NAMESPACE_OFFICE, XML_VERSION,
155 0 : ::rtl::OUString::createFromAscii(pVersion) );
156 :
157 : SvXMLElementExport aDocElem( *this, XML_NAMESPACE_OFFICE, XML_DOCUMENT_META,
158 0 : sal_True, sal_True );
159 :
160 : // NB: office:meta is now written by _ExportMeta
161 0 : _ExportMeta();
162 : }
163 0 : xDocHandler->endDocument();
164 0 : return 0;
165 : }
166 :
167 0 : void XMLMetaExportComponent::_ExportMeta()
168 : {
169 0 : if (mxDocProps.is()) {
170 0 : ::rtl::OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
171 : // update generator here
172 0 : mxDocProps->setGenerator(generator);
173 0 : SvXMLMetaExport * pMeta = new SvXMLMetaExport(*this, mxDocProps);
174 0 : uno::Reference<xml::sax::XDocumentHandler> xMeta(pMeta);
175 0 : pMeta->Export();
176 : } else {
177 0 : SvXMLExport::_ExportMeta();
178 : }
179 0 : }
180 :
181 : // methods without content:
182 0 : void XMLMetaExportComponent::_ExportAutoStyles() {}
183 0 : void XMLMetaExportComponent::_ExportMasterStyles() {}
184 0 : void XMLMetaExportComponent::_ExportContent() {}
185 :
186 :
187 0 : uno::Sequence< rtl::OUString > SAL_CALL XMLMetaExportComponent_getSupportedServiceNames()
188 : throw()
189 : {
190 : const rtl::OUString aServiceName(
191 0 : "com.sun.star.document.XMLOasisMetaExporter" );
192 0 : const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
193 0 : return aSeq;
194 : }
195 :
196 2 : rtl::OUString SAL_CALL XMLMetaExportComponent_getImplementationName() throw()
197 : {
198 2 : return rtl::OUString( "XMLMetaExportComponent" );
199 : }
200 :
201 0 : uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportComponent_createInstance(
202 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
203 : throw( uno::Exception )
204 : {
205 0 : return (cppu::OWeakObject*)new XMLMetaExportComponent(rSMgr, EXPORT_META|EXPORT_OASIS);
206 : }
207 :
208 0 : uno::Sequence< rtl::OUString > SAL_CALL XMLMetaExportOOO_getSupportedServiceNames()
209 : throw()
210 : {
211 : const rtl::OUString aServiceName(
212 0 : "com.sun.star.document.XMLMetaExporter" );
213 0 : const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
214 0 : return aSeq;
215 : }
216 :
217 0 : rtl::OUString SAL_CALL XMLMetaExportOOO_getImplementationName() throw()
218 : {
219 0 : return rtl::OUString( "XMLMetaExportOOo" );
220 : }
221 :
222 0 : uno::Reference< uno::XInterface > SAL_CALL XMLMetaExportOOO_createInstance(
223 : const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
224 : throw( uno::Exception )
225 : {
226 0 : return (cppu::OWeakObject*)new XMLMetaExportComponent(rSMgr, EXPORT_META);
227 : }
228 :
229 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|