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