Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <tools/debug.hxx>
31 : : #include <com/sun/star/drawing/XLayerManager.hpp>
32 : : #include <com/sun/star/beans/XPropertySet.hpp>
33 : : #include <com/sun/star/xml/sax/XAttributeList.hpp>
34 : : #include <com/sun/star/drawing/XLayerSupplier.hpp>
35 : : #include <comphelper/extract.hxx>
36 : : #include <xmloff/xmltoken.hxx>
37 : : #include <xmloff/xmlimp.hxx>
38 : : #include "xmloff/xmlnmspe.hxx"
39 : : #include <xmloff/xmluconv.hxx>
40 : : #include <xmloff/nmspmap.hxx>
41 : : #include "layerimp.hxx"
42 : :
43 : : using ::rtl::OUString;
44 : : using ::rtl::OUStringBuffer;
45 : :
46 : : #include "XMLStringBufferImportContext.hxx"
47 : :
48 : : using namespace ::std;
49 : : using namespace ::cppu;
50 : : using namespace ::xmloff::token;
51 : : using namespace ::com::sun::star;
52 : : using namespace ::com::sun::star::xml;
53 : : using namespace ::com::sun::star::xml::sax;
54 : : using namespace ::com::sun::star::uno;
55 : : using namespace ::com::sun::star::drawing;
56 : : using namespace ::com::sun::star::beans;
57 : : using namespace ::com::sun::star::lang;
58 : : using namespace ::com::sun::star::container;
59 : : using ::xmloff::token::IsXMLToken;
60 : :
61 : : class SdXMLLayerContext : public SvXMLImportContext
62 : : {
63 : : public:
64 : : SdXMLLayerContext( SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, const Reference< XNameAccess >& xLayerManager );
65 : : virtual ~SdXMLLayerContext();
66 : :
67 : : virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
68 : : virtual void EndElement();
69 : :
70 : : private:
71 : : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > mxLayerManager;
72 : : ::rtl::OUString msName;
73 : : ::rtl::OUStringBuffer sDescriptionBuffer;
74 : : ::rtl::OUStringBuffer sTitleBuffer;
75 : : };
76 : :
77 : 55 : SdXMLLayerContext::SdXMLLayerContext( SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, const Reference< XNameAccess >& xLayerManager )
78 : : : SvXMLImportContext(rImport, nPrefix, rLocalName)
79 : 55 : , mxLayerManager( xLayerManager )
80 : : {
81 [ + - ][ + - ]: 55 : const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + - ]
82 [ + - ]: 110 : for(sal_Int16 i=0; i < nAttrCount; i++)
83 : : {
84 : 55 : OUString aLocalName;
85 [ + - ][ + - ]: 55 : if( GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( i ), &aLocalName ) == XML_NAMESPACE_DRAW )
[ + - ][ + - ]
86 : : {
87 [ + - ][ + - ]: 55 : const OUString sValue( xAttrList->getValueByIndex( i ) );
88 : :
89 [ + - ][ + - ]: 55 : if( IsXMLToken( aLocalName, XML_NAME ) )
90 : : {
91 : 55 : msName = sValue;
92 : : break; // no more attributes needed
93 [ - + ]: 55 : }
94 : : }
95 [ - + ]: 55 : }
96 : :
97 : 55 : }
98 : :
99 : 55 : SdXMLLayerContext::~SdXMLLayerContext()
100 : : {
101 [ - + ]: 110 : }
102 : :
103 : 0 : SvXMLImportContext * SdXMLLayerContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const Reference< XAttributeList >& )
104 : : {
105 [ # # ][ # # ]: 0 : if( (XML_NAMESPACE_SVG == nPrefix) && IsXMLToken(rLocalName, XML_TITLE) )
[ # # ]
106 : : {
107 [ # # ]: 0 : return new XMLStringBufferImportContext( GetImport(), nPrefix, rLocalName, sTitleBuffer);
108 : : }
109 [ # # ][ # # ]: 0 : else if( (XML_NAMESPACE_SVG == nPrefix) && IsXMLToken(rLocalName, XML_DESC) )
[ # # ]
110 : : {
111 [ # # ]: 0 : return new XMLStringBufferImportContext( GetImport(), nPrefix, rLocalName, sDescriptionBuffer);
112 : : }
113 : : else
114 : : {
115 [ # # ]: 0 : return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
116 : : }
117 : : }
118 : :
119 : 55 : void SdXMLLayerContext::EndElement()
120 : : {
121 : : DBG_ASSERT( !msName.isEmpty(), "xmloff::SdXMLLayerContext::EndElement(), draw:layer element without draw:name!" );
122 [ + - ]: 55 : if( !msName.isEmpty() ) try
123 : : {
124 : 55 : Reference< XPropertySet > xLayer;
125 : :
126 [ + - ][ + - ]: 55 : if( mxLayerManager->hasByName( msName ) )
[ + - ]
127 : : {
128 [ + - ][ + - ]: 55 : mxLayerManager->getByName( msName ) >>= xLayer;
[ + - ]
129 : : DBG_ASSERT( xLayer.is(), "xmloff::SdXMLLayerContext::EndElement(), failed to get existing XLayer!" );
130 : : }
131 : : else
132 : : {
133 [ # # ]: 0 : Reference< XLayerManager > xLayerManager( mxLayerManager, UNO_QUERY );
134 [ # # ]: 0 : if( xLayerManager.is() )
135 [ # # ][ # # ]: 0 : xLayer = Reference< XPropertySet >::query( xLayerManager->insertNewByIndex( xLayerManager->getCount() ) );
[ # # ][ # # ]
[ # # ][ # # ]
136 : : DBG_ASSERT( xLayer.is(), "xmloff::SdXMLLayerContext::EndElement(), failed to create new XLayer!" );
137 : :
138 [ # # ]: 0 : if( xLayer.is() )
139 [ # # ][ # # ]: 0 : xLayer->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( msName ) );
[ # # ][ # # ]
140 : : }
141 : :
142 [ + - ]: 55 : if( xLayer.is() )
143 : : {
144 [ + - ][ + - ]: 55 : xLayer->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Title") ), Any( sTitleBuffer.makeStringAndClear() ) );
[ + - ][ + - ]
[ + - ]
145 [ + - ][ + - ]: 55 : xLayer->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Description") ), Any( sDescriptionBuffer.makeStringAndClear() ) );
[ + - ][ + - ]
[ + - ]
146 [ # # ]: 55 : }
147 : : }
148 : 0 : catch( Exception& )
149 : : {
150 : : OSL_FAIL("SdXMLLayerContext::EndElement(), exception caught!");
151 : : }
152 : 55 : }
153 : :
154 : :
155 [ # # ][ # # ]: 0 : TYPEINIT1( SdXMLLayerSetContext, SvXMLImportContext );
156 : :
157 : 11 : SdXMLLayerSetContext::SdXMLLayerSetContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName,
158 : : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>&)
159 : 11 : : SvXMLImportContext(rImport, nPrfx, rLocalName)
160 : : {
161 [ + - ]: 11 : Reference< XLayerSupplier > xLayerSupplier( rImport.GetModel(), UNO_QUERY );
162 : : DBG_ASSERT( xLayerSupplier.is(), "xmloff::SdXMLLayerSetContext::SdXMLLayerSetContext(), XModel is not supporting XLayerSupplier!" );
163 [ + - ]: 11 : if( xLayerSupplier.is() )
164 [ + - ][ + - ]: 11 : mxLayerManager = xLayerSupplier->getLayerManager();
[ + - ]
165 : 11 : }
166 : :
167 : 11 : SdXMLLayerSetContext::~SdXMLLayerSetContext()
168 : : {
169 [ - + ]: 22 : }
170 : :
171 : 55 : SvXMLImportContext * SdXMLLayerSetContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
172 : : const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
173 : : {
174 [ + - ]: 55 : return new SdXMLLayerContext( GetImport(), nPrefix, rLocalName, xAttrList, mxLayerManager );
175 : : }
176 : :
177 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|