merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / draw / layerimp.cxx
blobcf737b2080bfa01d6b69c6f9aef1a9afdf46d417
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: layerimp.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
34 #include <tools/debug.hxx>
35 #include <com/sun/star/drawing/XLayerManager.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/xml/sax/XAttributeList.hpp>
38 #include <com/sun/star/drawing/XLayerSupplier.hpp>
39 #include <comphelper/extract.hxx>
40 #include <xmloff/xmltoken.hxx>
41 #include <xmloff/xmlimp.hxx>
42 #include "xmlnmspe.hxx"
43 #include <xmloff/xmluconv.hxx>
44 #include <xmloff/nmspmap.hxx>
45 #include "layerimp.hxx"
47 using ::rtl::OUString;
48 using ::rtl::OUStringBuffer;
50 #include "XMLStringBufferImportContext.hxx"
52 using namespace ::std;
53 using namespace ::cppu;
54 using namespace ::xmloff::token;
55 using namespace ::com::sun::star;
56 using namespace ::com::sun::star::xml;
57 using namespace ::com::sun::star::xml::sax;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::drawing;
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::lang;
62 using namespace ::com::sun::star::container;
63 using ::xmloff::token::IsXMLToken;
65 class SdXMLLayerContext : public SvXMLImportContext
67 public:
68 SdXMLLayerContext( SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, const Reference< XNameAccess >& xLayerManager );
69 virtual ~SdXMLLayerContext();
71 virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix, const ::rtl::OUString& rLocalName, const Reference< XAttributeList >& xAttrList );
72 virtual void EndElement();
74 private:
75 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess > mxLayerManager;
76 ::rtl::OUString msName;
77 ::rtl::OUStringBuffer sDescriptionBuffer;
78 ::rtl::OUStringBuffer sTitleBuffer;
81 SdXMLLayerContext::SdXMLLayerContext( SvXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList, const Reference< XNameAccess >& xLayerManager )
82 : SvXMLImportContext(rImport, nPrefix, rLocalName)
83 , mxLayerManager( xLayerManager )
85 const OUString strName( RTL_CONSTASCII_USTRINGPARAM( "Name" ) );
87 OUString aName;
89 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
90 for(sal_Int16 i=0; i < nAttrCount; i++)
92 OUString aLocalName;
93 if( GetImport().GetNamespaceMap().GetKeyByAttrName( xAttrList->getNameByIndex( i ), &aLocalName ) == XML_NAMESPACE_DRAW )
95 const OUString sValue( xAttrList->getValueByIndex( i ) );
97 if( IsXMLToken( aLocalName, XML_NAME ) )
99 msName = sValue;
100 break; // no more attributes needed
107 SdXMLLayerContext::~SdXMLLayerContext()
111 SvXMLImportContext * SdXMLLayerContext::CreateChildContext( USHORT nPrefix, const ::rtl::OUString& rLocalName, const Reference< XAttributeList >& )
113 if( (XML_NAMESPACE_SVG == nPrefix) && IsXMLToken(rLocalName, XML_TITLE) )
115 return new XMLStringBufferImportContext( GetImport(), nPrefix, rLocalName, sTitleBuffer);
117 else if( (XML_NAMESPACE_SVG == nPrefix) && IsXMLToken(rLocalName, XML_DESC) )
119 return new XMLStringBufferImportContext( GetImport(), nPrefix, rLocalName, sDescriptionBuffer);
121 else
123 return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
127 void SdXMLLayerContext::EndElement()
129 DBG_ASSERT( msName.getLength(), "xmloff::SdXMLLayerContext::EndElement(), draw:layer element without draw:name!" );
130 if( msName.getLength() ) try
132 Reference< XPropertySet > xLayer;
134 if( mxLayerManager->hasByName( msName ) )
136 mxLayerManager->getByName( msName ) >>= xLayer;
137 DBG_ASSERT( xLayer.is(), "xmloff::SdXMLLayerContext::EndElement(), failed to get existing XLayer!" );
139 else
141 Reference< XLayerManager > xLayerManager( mxLayerManager, UNO_QUERY );
142 if( xLayerManager.is() )
143 xLayer = Reference< XPropertySet >::query( xLayerManager->insertNewByIndex( xLayerManager->getCount() ) );
144 DBG_ASSERT( xLayer.is(), "xmloff::SdXMLLayerContext::EndElement(), failed to create new XLayer!" );
146 if( xLayer.is() )
147 xLayer->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), Any( msName ) );
150 if( xLayer.is() )
152 xLayer->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Title") ), Any( sTitleBuffer.makeStringAndClear() ) );
153 xLayer->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM("Description") ), Any( sDescriptionBuffer.makeStringAndClear() ) );
156 catch( Exception& )
158 DBG_ERROR("SdXMLLayerContext::EndElement(), exception caught!");
163 TYPEINIT1( SdXMLLayerSetContext, SvXMLImportContext );
165 SdXMLLayerSetContext::SdXMLLayerSetContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName,
166 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>&)
167 : SvXMLImportContext(rImport, nPrfx, rLocalName)
169 Reference< XLayerSupplier > xLayerSupplier( rImport.GetModel(), UNO_QUERY );
170 DBG_ASSERT( xLayerSupplier.is(), "xmloff::SdXMLLayerSetContext::SdXMLLayerSetContext(), XModel is not supporting XLayerSupplier!" );
171 if( xLayerSupplier.is() )
172 mxLayerManager = xLayerSupplier->getLayerManager();
175 SdXMLLayerSetContext::~SdXMLLayerSetContext()
179 SvXMLImportContext * SdXMLLayerSetContext::CreateChildContext( USHORT nPrefix, const ::rtl::OUString& rLocalName,
180 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
182 return new SdXMLLayerContext( GetImport(), nPrefix, rLocalName, xAttrList, mxLayerManager );