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 throw(lang::IllegalArgumentException, uno::RuntimeException)
83 {
84 mxDocProps = uno::Reference< document::XDocumentProperties >::query( xDoc );
85 if( !mxDocProps.is() )
86 throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
87 "XMLMetaImportComponent::setTargetDocument: argument is no "
88 "XDocumentProperties"), uno::Reference<uno::XInterface>(*this), 0);
89 }
90
91 uno::Sequence< rtl::OUString > SAL_CALL
XMLMetaImportComponent_getSupportedServiceNames()92 XMLMetaImportComponent_getSupportedServiceNames()
93 throw()
94 {
95 const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM(
96 "com.sun.star.document.XMLOasisMetaImporter" ) );
97 const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
98 return aSeq;
99 }
100
XMLMetaImportComponent_getImplementationName()101 rtl::OUString SAL_CALL XMLMetaImportComponent_getImplementationName() throw()
102 {
103 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLMetaImportComponent" ) );
104 }
105
XMLMetaImportComponent_createInstance(const uno::Reference<lang::XMultiServiceFactory> & rSMgr)106 uno::Reference< uno::XInterface > SAL_CALL XMLMetaImportComponent_createInstance(
107 const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
108 throw( uno::Exception )
109 {
110 // #110680#
111 // return (cppu::OWeakObject*)new XMLMetaImportComponent;
112 return (cppu::OWeakObject*)new XMLMetaImportComponent(rSMgr);
113 }
114
115