1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26
27 #include "MetaImportComponent.hxx"
28 #include "xmloff/xmlnmspe.hxx"
29
30 #include <xmloff/xmltoken.hxx>
31 #include <xmloff/xmlmetai.hxx>
32 #include <xmloff/nmspmap.hxx>
33 #include <tools/string.hxx>
34
35
36 using namespace ::com::sun::star;
37 using namespace ::xmloff::token;
38
39
40 //===========================================================================
41
42 // #110680#
XMLMetaImportComponent(const uno::Reference<lang::XMultiServiceFactory> & xServiceFactory)43 XMLMetaImportComponent::XMLMetaImportComponent(
44 const uno::Reference< lang::XMultiServiceFactory >& xServiceFactory) throw()
45 : SvXMLImport(xServiceFactory), mxDocProps()
46 {
47 }
48
~XMLMetaImportComponent()49 XMLMetaImportComponent::~XMLMetaImportComponent() throw()
50 {
51 }
52
53
CreateContext(sal_uInt16 nPrefix,const rtl::OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)54 SvXMLImportContext* XMLMetaImportComponent::CreateContext(
55 sal_uInt16 nPrefix,
56 const rtl::OUString& rLocalName,
57 const uno::Reference<xml::sax::XAttributeList > & xAttrList )
58 {
59 if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
60 IsXMLToken(rLocalName, XML_DOCUMENT_META) )
61 {
62 if (!mxDocProps.is()) {
63 throw uno::RuntimeException(::rtl::OUString::createFromAscii(
64 "XMLMetaImportComponent::CreateContext: setTargetDocument "
65 "has not been called"), *this);
66 }
67 uno::Reference<xml::sax::XDocumentHandler> xDocBuilder(
68 mxServiceFactory->createInstance(::rtl::OUString::createFromAscii(
69 "com.sun.star.xml.dom.SAXDocumentBuilder")),
70 uno::UNO_QUERY_THROW);
71 return new SvXMLMetaDocumentContext(
72 *this, nPrefix, rLocalName, mxDocProps, xDocBuilder);
73 }
74 else
75 {
76 return SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
77 }
78 }
79
setTargetDocument(const uno::Reference<lang::XComponent> & xDoc)80 void SAL_CALL XMLMetaImportComponent::setTargetDocument(
81 const uno::Reference< lang::XComponent >& xDoc )
82 {
83 mxDocProps = uno::Reference< document::XDocumentProperties >::query( xDoc );
84 if( !mxDocProps.is() )
85 throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
86 "XMLMetaImportComponent::setTargetDocument: argument is no "
87 "XDocumentProperties"), uno::Reference<uno::XInterface>(*this), 0);
88 }
89
90 uno::Sequence< rtl::OUString > SAL_CALL
XMLMetaImportComponent_getSupportedServiceNames()91 XMLMetaImportComponent_getSupportedServiceNames()
92 throw()
93 {
94 const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM(
95 "com.sun.star.document.XMLOasisMetaImporter" ) );
96 const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
97 return aSeq;
98 }
99
XMLMetaImportComponent_getImplementationName()100 rtl::OUString SAL_CALL XMLMetaImportComponent_getImplementationName() throw()
101 {
102 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLMetaImportComponent" ) );
103 }
104
XMLMetaImportComponent_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)105 uno::Reference< uno::XInterface > SAL_CALL XMLMetaImportComponent_createInstance(
106 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
107 {
108 // #110680#
109 // return (cppu::OWeakObject*)new XMLMetaImportComponent;
110 return (cppu::OWeakObject*)new XMLMetaImportComponent(rSMgr);
111 }
112