1*e1d5bd03SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*e1d5bd03SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*e1d5bd03SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*e1d5bd03SAndrew Rist * distributed with this work for additional information
6*e1d5bd03SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*e1d5bd03SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*e1d5bd03SAndrew Rist * "License"); you may not use this file except in compliance
9*e1d5bd03SAndrew Rist * with the License. You may obtain a copy of the License at
10*e1d5bd03SAndrew Rist *
11*e1d5bd03SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*e1d5bd03SAndrew Rist *
13*e1d5bd03SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*e1d5bd03SAndrew Rist * software distributed under the License is distributed on an
15*e1d5bd03SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*e1d5bd03SAndrew Rist * KIND, either express or implied. See the License for the
17*e1d5bd03SAndrew Rist * specific language governing permissions and limitations
18*e1d5bd03SAndrew Rist * under the License.
19*e1d5bd03SAndrew Rist *
20*e1d5bd03SAndrew Rist *************************************************************/
21*e1d5bd03SAndrew Rist
22*e1d5bd03SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmlscript.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <xmlscript/xmllib_imexp.hxx>
28cdf0e10cSrcweir #include <xmlscript/xml_helper.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir using namespace com::sun::star::uno;
31cdf0e10cSrcweir using namespace com::sun::star;
32cdf0e10cSrcweir using namespace rtl;
33cdf0e10cSrcweir
34cdf0e10cSrcweir namespace xmlscript
35cdf0e10cSrcweir {
36cdf0e10cSrcweir
37cdf0e10cSrcweir static OUString aTrueStr ( RTL_CONSTASCII_USTRINGPARAM("true") );
38cdf0e10cSrcweir static OUString aFalseStr( RTL_CONSTASCII_USTRINGPARAM("false") );
39cdf0e10cSrcweir
40cdf0e10cSrcweir //##################################################################################################
41cdf0e10cSrcweir
42cdf0e10cSrcweir
43cdf0e10cSrcweir //==================================================================================================
44cdf0e10cSrcweir
45cdf0e10cSrcweir void
exportLibraryContainer(Reference<xml::sax::XExtendedDocumentHandler> const & xOut,const LibDescriptorArray * pLibArray)46cdf0e10cSrcweir SAL_CALL exportLibraryContainer(
47cdf0e10cSrcweir Reference< xml::sax::XExtendedDocumentHandler > const & xOut,
48cdf0e10cSrcweir const LibDescriptorArray* pLibArray )
49cdf0e10cSrcweir SAL_THROW( (Exception) )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir xOut->startDocument();
52cdf0e10cSrcweir
53cdf0e10cSrcweir OUString aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM(
54cdf0e10cSrcweir "<!DOCTYPE library:libraries PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
55cdf0e10cSrcweir " \"libraries.dtd\">" ) );
56cdf0e10cSrcweir xOut->unknown( aDocTypeStr );
57cdf0e10cSrcweir xOut->ignorableWhitespace( OUString() );
58cdf0e10cSrcweir
59cdf0e10cSrcweir
60cdf0e10cSrcweir OUString aLibrariesName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":libraries") );
61cdf0e10cSrcweir XMLElement* pLibsElement = new XMLElement( aLibrariesName );
62cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xAttributes( pLibsElement );
63cdf0e10cSrcweir
64cdf0e10cSrcweir pLibsElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_LIBRARY_PREFIX) ),
65cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_URI) ) );
66cdf0e10cSrcweir pLibsElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_XLINK_PREFIX) ),
67cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_URI) ) );
68cdf0e10cSrcweir
69cdf0e10cSrcweir
70cdf0e10cSrcweir xOut->ignorableWhitespace( OUString() );
71cdf0e10cSrcweir xOut->startElement( aLibrariesName, xAttributes );
72cdf0e10cSrcweir
73cdf0e10cSrcweir int nLibCount = pLibArray->mnLibCount;
74cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir LibDescriptor& rLib = pLibArray->mpLibs[i];
77cdf0e10cSrcweir
78cdf0e10cSrcweir OUString aLibraryName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":library") );
79cdf0e10cSrcweir XMLElement* pLibElement = new XMLElement( aLibraryName );
80cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xLibElementAttribs;
81cdf0e10cSrcweir xLibElementAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement );
82cdf0e10cSrcweir
83cdf0e10cSrcweir pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":name") ),
84cdf0e10cSrcweir rLib.aName );
85cdf0e10cSrcweir
86cdf0e10cSrcweir
87cdf0e10cSrcweir if( rLib.aStorageURL.getLength() )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_PREFIX ":href") ),
90cdf0e10cSrcweir rLib.aStorageURL );
91cdf0e10cSrcweir pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_PREFIX ":type") ),
92cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("simple") ) );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":link") ),
96cdf0e10cSrcweir rLib.bLink ? aTrueStr : aFalseStr );
97cdf0e10cSrcweir
98cdf0e10cSrcweir if( rLib.bLink )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":readonly") ),
101cdf0e10cSrcweir rLib.bReadOnly ? aTrueStr : aFalseStr );
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
104cdf0e10cSrcweir pLibElement->dump( xOut.get() );
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
107cdf0e10cSrcweir xOut->ignorableWhitespace( OUString() );
108cdf0e10cSrcweir xOut->endElement( aLibrariesName );
109cdf0e10cSrcweir
110cdf0e10cSrcweir xOut->endDocument();
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir //==================================================================================================
114cdf0e10cSrcweir
115cdf0e10cSrcweir void
exportLibrary(::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XExtendedDocumentHandler> const & xOut,const LibDescriptor & rLib)116cdf0e10cSrcweir SAL_CALL exportLibrary(
117cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > const & xOut,
118cdf0e10cSrcweir const LibDescriptor& rLib )
119cdf0e10cSrcweir SAL_THROW( (::com::sun::star::uno::Exception) )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir xOut->startDocument();
122cdf0e10cSrcweir
123cdf0e10cSrcweir OUString aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM(
124cdf0e10cSrcweir "<!DOCTYPE library:library PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
125cdf0e10cSrcweir " \"library.dtd\">" ) );
126cdf0e10cSrcweir xOut->unknown( aDocTypeStr );
127cdf0e10cSrcweir xOut->ignorableWhitespace( OUString() );
128cdf0e10cSrcweir
129cdf0e10cSrcweir
130cdf0e10cSrcweir OUString aLibraryName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":library") );
131cdf0e10cSrcweir XMLElement* pLibElement = new XMLElement( aLibraryName );
132cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xAttributes( pLibElement );
133cdf0e10cSrcweir
134cdf0e10cSrcweir pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_LIBRARY_PREFIX) ),
135cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_URI) ) );
136cdf0e10cSrcweir
137cdf0e10cSrcweir pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":name") ),
138cdf0e10cSrcweir rLib.aName );
139cdf0e10cSrcweir
140cdf0e10cSrcweir pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":readonly") ),
141cdf0e10cSrcweir rLib.bReadOnly ? aTrueStr : aFalseStr );
142cdf0e10cSrcweir
143cdf0e10cSrcweir pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":passwordprotected") ),
144cdf0e10cSrcweir rLib.bPasswordProtected ? aTrueStr : aFalseStr );
145cdf0e10cSrcweir
146cdf0e10cSrcweir if( rLib.bPreload )
147cdf0e10cSrcweir pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":preload") ), aTrueStr );
148cdf0e10cSrcweir
149cdf0e10cSrcweir sal_Int32 nElementCount = rLib.aElementNames.getLength();
150cdf0e10cSrcweir if( nElementCount )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir const OUString* pElementNames = rLib.aElementNames.getConstArray();
153cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
154cdf0e10cSrcweir {
155cdf0e10cSrcweir XMLElement* pElement = new XMLElement( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":element" ) ) );
156cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xElementAttribs;
157cdf0e10cSrcweir xElementAttribs = static_cast< xml::sax::XAttributeList* >( pElement );
158cdf0e10cSrcweir
159cdf0e10cSrcweir pElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":name") ),
160cdf0e10cSrcweir pElementNames[i] );
161cdf0e10cSrcweir
162cdf0e10cSrcweir pLibElement->addSubElement( pElement );
163cdf0e10cSrcweir }
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
166cdf0e10cSrcweir pLibElement->dump( xOut.get() );
167cdf0e10cSrcweir
168cdf0e10cSrcweir xOut->endDocument();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
171cdf0e10cSrcweir }
172cdf0e10cSrcweir
173