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