1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 #include "MetaImportComponent.hxx"
32 #include "xmloff/xmlnmspe.hxx"
33 
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmlmetai.hxx>
36 #include <xmloff/nmspmap.hxx>
37 #include <tools/string.hxx>
38 
39 
40 using namespace ::com::sun::star;
41 using namespace ::xmloff::token;
42 
43 
44 //===========================================================================
45 
46 // #110680#
47 XMLMetaImportComponent::XMLMetaImportComponent(
48     const uno::Reference< lang::XMultiServiceFactory >& xServiceFactory) throw()
49     :   SvXMLImport(xServiceFactory), mxDocProps()
50 {
51 }
52 
53 XMLMetaImportComponent::~XMLMetaImportComponent() throw()
54 {
55 }
56 
57 
58 SvXMLImportContext* XMLMetaImportComponent::CreateContext(
59     sal_uInt16 nPrefix,
60     const rtl::OUString& rLocalName,
61     const uno::Reference<xml::sax::XAttributeList > & xAttrList )
62 {
63     if (  (XML_NAMESPACE_OFFICE == nPrefix) &&
64          IsXMLToken(rLocalName, XML_DOCUMENT_META) )
65     {
66         if (!mxDocProps.is()) {
67             throw uno::RuntimeException(::rtl::OUString::createFromAscii(
68                 "XMLMetaImportComponent::CreateContext: setTargetDocument "
69                 "has not been called"), *this);
70         }
71         uno::Reference<xml::sax::XDocumentHandler> xDocBuilder(
72             mxServiceFactory->createInstance(::rtl::OUString::createFromAscii(
73                     "com.sun.star.xml.dom.SAXDocumentBuilder")),
74                  uno::UNO_QUERY_THROW);
75         return new SvXMLMetaDocumentContext(
76                         *this, nPrefix, rLocalName, mxDocProps, xDocBuilder);
77     }
78     else
79     {
80         return SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
81     }
82 }
83 
84 void SAL_CALL XMLMetaImportComponent::setTargetDocument(
85     const uno::Reference< lang::XComponent >& xDoc )
86     throw(lang::IllegalArgumentException, uno::RuntimeException)
87 {
88     mxDocProps = uno::Reference< document::XDocumentProperties >::query( xDoc );
89     if( !mxDocProps.is() )
90         throw lang::IllegalArgumentException(::rtl::OUString::createFromAscii(
91             "XMLMetaImportComponent::setTargetDocument: argument is no "
92             "XDocumentProperties"), uno::Reference<uno::XInterface>(*this), 0);
93 }
94 
95 uno::Sequence< rtl::OUString > SAL_CALL
96     XMLMetaImportComponent_getSupportedServiceNames()
97         throw()
98 {
99     const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM(
100         "com.sun.star.document.XMLOasisMetaImporter" ) );
101     const uno::Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
102     return aSeq;
103 }
104 
105 rtl::OUString SAL_CALL XMLMetaImportComponent_getImplementationName() throw()
106 {
107     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLMetaImportComponent" ) );
108 }
109 
110 uno::Reference< uno::XInterface > SAL_CALL XMLMetaImportComponent_createInstance(
111         const uno::Reference< lang::XMultiServiceFactory > & rSMgr)
112     throw( uno::Exception )
113 {
114     // #110680#
115     // return (cppu::OWeakObject*)new XMLMetaImportComponent;
116     return (cppu::OWeakObject*)new XMLMetaImportComponent(rSMgr);
117 }
118 
119