LibreOffice Module xmloff (master) 1
MetaExportComponent.cxx
Go to the documentation of this file.
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
21#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
22#include <com/sun/star/uno/Sequence.hxx>
23#include <com/sun/star/uno/Reference.hxx>
24#include <com/sun/star/uno/Exception.hpp>
25#include <com/sun/star/util/MeasureUnit.hpp>
26#include <com/sun/star/beans/PropertyAttribute.hpp>
27#include <com/sun/star/frame/XModel.hpp>
28#include <com/sun/star/uno/XComponentContext.hpp>
31#include <osl/diagnose.h>
34#include <xmloff/xmltoken.hxx>
35#include <xmloff/xmlmetae.hxx>
36#include <PropertySetMerger.hxx>
37
39
40
41using namespace ::com::sun::star;
42using namespace ::xmloff::token;
43
45 const css::uno::Reference< css::uno::XComponentContext >& xContext,
46 OUString const & implementationName, SvXMLExportFlags nFlags )
47: SvXMLExport( xContext, implementationName, util::MeasureUnit::CM, XML_TEXT, nFlags )
48{
49}
50
52{
53}
54
55void SAL_CALL XMLMetaExportComponent::setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
56{
57 try
58 {
60 }
61 catch( lang::IllegalArgumentException& )
62 {
63 // allow to use document properties service without model access
64 // this is required for document properties exporter
66 uno::Reference< document::XDocumentProperties >::query( xDoc );
67 if( !mxDocProps.is() )
68 throw lang::IllegalArgumentException();
69 }
70}
71
73{
74 uno::Reference< xml::sax::XDocumentHandler > xDocHandler = GetDocHandler();
75
77 {
78 uno::Reference< uno::XComponentContext > xContext = getComponentContext();
79 try
80 {
81 static const ::comphelper::PropertyMapEntry aInfoMap[] =
82 {
83 { OUString("Class"), 0,
85 beans::PropertyAttribute::MAYBEVOID, 0},
86 };
87 uno::Reference< beans::XPropertySet > xConvPropSet(
88 ::comphelper::GenericPropertySet_CreateInstance(
89 new ::comphelper::PropertySetInfo( aInfoMap ) ) );
90
91 xConvPropSet->setPropertyValue("Class", uno::Any(GetXMLToken( XML_TEXT )) );
92
93 uno::Reference< beans::XPropertySet > xPropSet =
94 getExportInfo().is()
96 xConvPropSet )
97 : getExportInfo();
98
99 uno::Sequence< uno::Any > aArgs{ uno::Any(xDocHandler), uno::Any(xPropSet),
100 uno::Any(GetModel()) };
101
102 // get filter component
103 xDocHandler.set(
104 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
105 "com.sun.star.comp.Oasis2OOoTransformer", aArgs, xContext),
106 uno::UNO_QUERY_THROW );
107
108 SetDocHandler( xDocHandler );
109 }
110 catch( css::uno::Exception& )
111 {
112 OSL_FAIL( "Cannot instantiate com.sun.star.comp.Oasis2OOoTransformer!");
113 }
114 }
115
116
117 xDocHandler->startDocument();
118
120
121 {
122
123 const SvXMLNamespaceMap& rMap = GetNamespaceMap();
124 sal_uInt16 nPos = rMap.GetFirstKey();
125 while( USHRT_MAX != nPos )
126 {
129 }
130
131 const char*const pVersion = GetODFVersionAttributeValue();
132
133 if( pVersion )
135 OUString::createFromAscii(pVersion) );
136
138 true, true );
139
140 // NB: office:meta is now written by _ExportMeta
141 ExportMeta_();
142 }
143 xDocHandler->endDocument();
144 return ERRCODE_NONE;
145}
146
148{
149 if (mxDocProps.is()) {
150 OUString generator( ::utl::DocInfoHelper::GetGeneratorString() );
151 // update generator here
152 mxDocProps->setGenerator(generator);
154 pMeta->Export();
155 } else {
157 }
158}
159
160// methods without content:
164
165extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
167 css::uno::XComponentContext *context,
168 css::uno::Sequence<css::uno::Any> const &)
169{
170 return cppu::acquire(new XMLMetaExportComponent(context, "XMLMetaExportComponent", SvXMLExportFlags::META|SvXMLExportFlags::OASIS));
171}
172
173extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
174XMLMetaExportOOo_get_implementation(css::uno::XComponentContext* context,
175 css::uno::Sequence<css::uno::Any> const&)
176{
177 return cppu::acquire(
178 new XMLMetaExportComponent(context, "XMLMetaExportOOo", SvXMLExportFlags::META));
179}
180
181/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * XMLMetaExportComponent_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * XMLMetaExportOOo_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Reference< XPropertySet > PropertySetMerger_CreateInstance(const Reference< XPropertySet > &rPropSet1, const Reference< XPropertySet > &rPropSet2) noexcept
const SvXMLNamespaceMap & GetNamespaceMap() const
Definition: xmlexp.hxx:385
char const * GetODFVersionAttributeValue() const
returns value of ODF version attribute
Definition: xmlexp.cxx:1195
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
Definition: xmlexp.cxx:907
SvXMLExportFlags getExportFlags() const
Definition: xmlexp.hxx:473
const css::uno::Reference< css::frame::XModel > & GetModel() const
Definition: xmlexp.hxx:411
virtual void ExportMeta_()
Override this method to export the content of <office:meta>.
Definition: xmlexp.cxx:1416
void addChaffWhenEncryptedStorage()
Definition: xmlexp.cxx:1185
const css::uno::Reference< css::xml::sax::XDocumentHandler > & GetDocHandler() const
Definition: xmlexp.hxx:379
virtual void SAL_CALL setSourceDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
Definition: xmlexp.cxx:573
void SetDocHandler(const css::uno::Reference< css::xml::sax::XDocumentHandler > &rHandler)
Definition: xmlexp.cxx:285
const css::uno::Reference< css::beans::XPropertySet > & getExportInfo() const
Definition: xmlexp.hxx:446
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
Definition: xmlexp.hxx:517
comphelper::AttributeList & GetAttrList()
Definition: xmlexp.hxx:374
export meta data from an XDocumentProperties instance.
Definition: xmlmetae.hxx:51
const OUString & GetNameByKey(sal_uInt16 nKey) const
sal_uInt16 GetFirstKey() const
OUString GetAttrNameByKey(sal_uInt16 nKey) const
sal_uInt16 GetNextKey(sal_uInt16 nOldKey) const
virtual ErrCode exportDoc(enum ::xmloff::token::XMLTokenEnum eClass=xmloff::token::XML_TOKEN_INVALID) override
virtual void ExportAutoStyles_() override
Override this method to export the contents of <style:auto-styles>.
XMLMetaExportComponent(const css::uno::Reference< css::uno::XComponentContext > &xContext, OUString const &implementationName, SvXMLExportFlags nFlags)
css::uno::Reference< css::document::XDocumentProperties > mxDocProps
virtual void SAL_CALL setSourceDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
virtual ~XMLMetaExportComponent() override
virtual void ExportMasterStyles_() override
Override this method to export the contents of <style:master-styles>.
virtual void ExportMeta_() override
Override this method to export the content of <office:meta>.
virtual void ExportContent_() override
Override this method to export the content of <office:body>.
void AddAttribute(const OUString &sName, const OUString &sValue)
css::uno::Type const & get()
static OUString GetGeneratorString()
#define ERRCODE_NONE
sal_uInt16 nPos
constexpr OUStringLiteral implementationName
Handling of tokens in XML:
XMLTokenEnum
The enumeration of all XML tokens.
Definition: xmltoken.hxx:50
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
SvXMLExportFlags
Definition: xmlexp.hxx:90
constexpr sal_uInt16 XML_NAMESPACE_OFFICE