xref: /trunk/main/xmlscript/source/xmllib_imexp/xmllib_export.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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_xmlscript.hxx"
26 
27 #include <xmlscript/xmllib_imexp.hxx>
28 #include <xmlscript/xml_helper.hxx>
29 
30 using namespace com::sun::star::uno;
31 using namespace com::sun::star;
32 using namespace rtl;
33 
34 namespace xmlscript
35 {
36 
37 static OUString aTrueStr ( RTL_CONSTASCII_USTRINGPARAM("true") );
38 static OUString aFalseStr( RTL_CONSTASCII_USTRINGPARAM("false") );
39 
40 //##################################################################################################
41 
42 
43 //==================================================================================================
44 
45 void
exportLibraryContainer(Reference<xml::sax::XExtendedDocumentHandler> const & xOut,const LibDescriptorArray * pLibArray)46 SAL_CALL exportLibraryContainer(
47     Reference< xml::sax::XExtendedDocumentHandler > const & xOut,
48     const LibDescriptorArray* pLibArray )
49 {
50     xOut->startDocument();
51 
52     OUString aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM(
53         "<!DOCTYPE library:libraries PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
54         " \"libraries.dtd\">" ) );
55     xOut->unknown( aDocTypeStr );
56     xOut->ignorableWhitespace( OUString() );
57 
58 
59     OUString aLibrariesName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":libraries") );
60     XMLElement* pLibsElement = new XMLElement( aLibrariesName );
61     Reference< xml::sax::XAttributeList > xAttributes( pLibsElement );
62 
63     pLibsElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_LIBRARY_PREFIX) ),
64                                 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_URI) ) );
65     pLibsElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_XLINK_PREFIX) ),
66                                 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_URI) ) );
67 
68 
69     xOut->ignorableWhitespace( OUString() );
70     xOut->startElement( aLibrariesName, xAttributes );
71 
72     int nLibCount = pLibArray->mnLibCount;
73     for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
74     {
75         LibDescriptor& rLib = pLibArray->mpLibs[i];
76 
77         OUString aLibraryName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":library") );
78         XMLElement* pLibElement = new XMLElement( aLibraryName );
79         Reference< xml::sax::XAttributeList > xLibElementAttribs;
80         xLibElementAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement );
81 
82         pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":name") ),
83                                     rLib.aName );
84 
85 
86         if( rLib.aStorageURL.getLength() )
87         {
88             pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_PREFIX ":href") ),
89                                         rLib.aStorageURL );
90             pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_PREFIX ":type") ),
91                                         OUString( RTL_CONSTASCII_USTRINGPARAM("simple") ) );
92         }
93 
94         pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":link") ),
95                                     rLib.bLink ? aTrueStr : aFalseStr );
96 
97         if( rLib.bLink )
98         {
99             pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":readonly") ),
100                                         rLib.bReadOnly ? aTrueStr : aFalseStr );
101         }
102 
103         pLibElement->dump( xOut.get() );
104     }
105 
106     xOut->ignorableWhitespace( OUString() );
107     xOut->endElement( aLibrariesName );
108 
109     xOut->endDocument();
110 }
111 
112 //==================================================================================================
113 
114 void
exportLibrary(::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XExtendedDocumentHandler> const & xOut,const LibDescriptor & rLib)115 SAL_CALL exportLibrary(
116     ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > const & xOut,
117     const LibDescriptor& rLib )
118 {
119     xOut->startDocument();
120 
121     OUString aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM(
122         "<!DOCTYPE library:library PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
123         " \"library.dtd\">" ) );
124     xOut->unknown( aDocTypeStr );
125     xOut->ignorableWhitespace( OUString() );
126 
127 
128     OUString aLibraryName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":library") );
129     XMLElement* pLibElement = new XMLElement( aLibraryName );
130     Reference< xml::sax::XAttributeList > xAttributes( pLibElement );
131 
132     pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_LIBRARY_PREFIX) ),
133                                 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_URI) ) );
134 
135     pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":name") ),
136                                 rLib.aName );
137 
138     pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":readonly") ),
139                                 rLib.bReadOnly ? aTrueStr : aFalseStr );
140 
141     pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":passwordprotected") ),
142                                 rLib.bPasswordProtected ? aTrueStr : aFalseStr );
143 
144     if( rLib.bPreload )
145         pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":preload") ), aTrueStr );
146 
147     sal_Int32 nElementCount = rLib.aElementNames.getLength();
148     if( nElementCount )
149     {
150         const OUString* pElementNames = rLib.aElementNames.getConstArray();
151         for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
152         {
153             XMLElement* pElement = new XMLElement( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":element" ) ) );
154             Reference< xml::sax::XAttributeList > xElementAttribs;
155             xElementAttribs = static_cast< xml::sax::XAttributeList* >( pElement );
156 
157             pElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":name") ),
158                                         pElementNames[i] );
159 
160             pLibElement->addSubElement( pElement );
161         }
162     }
163 
164     pLibElement->dump( xOut.get() );
165 
166     xOut->endDocument();
167 }
168 
169 }
170