xref: /aoo41x/main/xmloff/source/draw/layerexp.cxx (revision 63bba73c)
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 <tools/debug.hxx>
28 #include <com/sun/star/drawing/XLayerSupplier.hpp>
29 #include <com/sun/star/container/XIndexAccess.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <xmloff/xmltoken.hxx>
32 #include "xmloff/xmlnmspe.hxx"
33 #include <xmloff/xmlexp.hxx>
34 #include <xmloff/xmlement.hxx>
35 #include <xmloff/nmspmap.hxx>
36 #include "layerexp.hxx"
37 
38 using ::rtl::OUString;
39 using ::rtl::OUStringBuffer;
40 using ::com::sun::star::uno::Reference;
41 
42 using namespace ::cppu;
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::uno;
45 using namespace ::com::sun::star::drawing;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::lang;
48 using namespace ::com::sun::star::container;
49 using namespace ::xmloff::token;
50 
exportLayer(SvXMLExport & rExport)51 void SdXMLayerExporter::exportLayer( SvXMLExport& rExport )
52 {
53 	Reference< XLayerSupplier > xLayerSupplier( rExport.GetModel(), UNO_QUERY );
54 	if( !xLayerSupplier.is() )
55 		return;
56 
57 	Reference< XIndexAccess > xLayerManager( xLayerSupplier->getLayerManager(), UNO_QUERY );
58 	if( !xLayerManager.is() )
59 		return;
60 
61 	const sal_Int32 nCount = xLayerManager->getCount();
62 	if( nCount == 0 )
63 		return;
64 
65 	const OUString strName( RTL_CONSTASCII_USTRINGPARAM( "Name" ) );
66 	const OUString strTitle( RTL_CONSTASCII_USTRINGPARAM( "Title" ) );
67 	const OUString strDescription( RTL_CONSTASCII_USTRINGPARAM( "Description" ) );
68 
69 	OUString sTmp;
70 
71 	SvXMLElementExport aElem( rExport, XML_NAMESPACE_DRAW, XML_LAYER_SET, sal_True, sal_True );
72 
73 	for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
74 	{
75 		try
76 		{
77 			Reference< XPropertySet> xLayer( xLayerManager->getByIndex( nIndex ), UNO_QUERY_THROW );
78 			xLayer->getPropertyValue( strName ) >>= sTmp;
79 			if(sTmp.getLength())
80 				rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, sTmp );
81 
82 			SvXMLElementExport aEle( rExport, XML_NAMESPACE_DRAW, XML_LAYER, sal_True, sal_True );
83 
84 			// title property (as <svg:title> element)
85 			xLayer->getPropertyValue(strTitle) >>= sTmp;
86 			if(sTmp.getLength())
87 			{
88 				SvXMLElementExport aEventElemt(rExport, XML_NAMESPACE_SVG, XML_TITLE, sal_True, sal_False);
89 				rExport.Characters(sTmp);
90 			}
91 
92 			// description property (as <svg:desc> element)
93 			xLayer->getPropertyValue(strDescription) >>= sTmp;
94 			if(sTmp.getLength() > 0)
95 			{
96 				SvXMLElementExport aDesc(rExport, XML_NAMESPACE_SVG, XML_DESC, sal_True, sal_False);
97 				rExport.Characters(sTmp);
98 			}
99 		}
100 		catch( Exception& )
101 		{
102 			DBG_ERROR("SdXMLayerExporter::exportLayer(), exception caught during export of one layer!");
103 		}
104 	}
105 }
106