Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <xmlscript/xmllib_imexp.hxx>
21 : #include <xmlscript/xml_helper.hxx>
22 :
23 : using namespace com::sun::star::uno;
24 : using namespace com::sun::star;
25 :
26 : namespace xmlscript
27 : {
28 :
29 : const char aTrueStr[] = "true";
30 : const char aFalseStr[] = "false";
31 :
32 : void
33 8 : SAL_CALL exportLibraryContainer(
34 : Reference< xml::sax::XWriter > const & xOut,
35 : const LibDescriptorArray* pLibArray )
36 : {
37 8 : xOut->startDocument();
38 :
39 : OUString aDocTypeStr(
40 : "<!DOCTYPE library:libraries PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
41 8 : " \"libraries.dtd\">" );
42 8 : xOut->unknown( aDocTypeStr );
43 8 : xOut->ignorableWhitespace( OUString() );
44 :
45 16 : OUString aLibrariesName( XMLNS_LIBRARY_PREFIX ":libraries" );
46 8 : XMLElement* pLibsElement = new XMLElement( aLibrariesName );
47 16 : Reference< xml::sax::XAttributeList > xAttributes( pLibsElement );
48 :
49 8 : pLibsElement->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX, XMLNS_LIBRARY_URI );
50 8 : pLibsElement->addAttribute( "xmlns:" XMLNS_XLINK_PREFIX, XMLNS_XLINK_URI );
51 :
52 8 : xOut->ignorableWhitespace( OUString() );
53 8 : xOut->startElement( aLibrariesName, xAttributes );
54 :
55 16 : OUString sTrueStr(aTrueStr);
56 16 : OUString sFalseStr(aFalseStr);
57 :
58 8 : int nLibCount = pLibArray->mnLibCount;
59 20 : for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
60 : {
61 12 : LibDescriptor& rLib = pLibArray->mpLibs[i];
62 :
63 12 : OUString aLibraryName( XMLNS_LIBRARY_PREFIX ":library" );
64 12 : XMLElement* pLibElement = new XMLElement( aLibraryName );
65 24 : Reference< xml::sax::XAttributeList > xLibElementAttribs;
66 12 : xLibElementAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement );
67 :
68 12 : pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name", rLib.aName );
69 :
70 12 : if( !rLib.aStorageURL.isEmpty() )
71 : {
72 0 : pLibElement->addAttribute( XMLNS_XLINK_PREFIX ":href", rLib.aStorageURL );
73 0 : pLibElement->addAttribute( XMLNS_XLINK_PREFIX ":type", "simple" );
74 : }
75 :
76 12 : pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":link", rLib.bLink ? sTrueStr : sFalseStr );
77 :
78 12 : if( rLib.bLink )
79 : {
80 0 : pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":readonly", rLib.bReadOnly ? sTrueStr : sFalseStr );
81 : }
82 :
83 12 : pLibElement->dump( xOut.get() );
84 12 : }
85 :
86 8 : xOut->ignorableWhitespace( OUString() );
87 8 : xOut->endElement( aLibrariesName );
88 :
89 16 : xOut->endDocument();
90 8 : }
91 :
92 : void
93 4 : SAL_CALL exportLibrary(
94 : ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XWriter > const & xOut,
95 : const LibDescriptor& rLib )
96 : {
97 4 : xOut->startDocument();
98 :
99 : OUString aDocTypeStr(
100 : "<!DOCTYPE library:library PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
101 4 : " \"library.dtd\">" );
102 4 : xOut->unknown( aDocTypeStr );
103 4 : xOut->ignorableWhitespace( OUString() );
104 :
105 8 : OUString aLibraryName( XMLNS_LIBRARY_PREFIX ":library" );
106 4 : XMLElement* pLibElement = new XMLElement( aLibraryName );
107 8 : Reference< xml::sax::XAttributeList > xAttributes( pLibElement );
108 :
109 4 : pLibElement->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX, XMLNS_LIBRARY_URI );
110 :
111 4 : pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name", rLib.aName );
112 :
113 8 : OUString sTrueStr(aTrueStr);
114 8 : OUString sFalseStr(aFalseStr);
115 :
116 4 : pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":readonly", rLib.bReadOnly ? sTrueStr : sFalseStr );
117 :
118 4 : pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":passwordprotected", rLib.bPasswordProtected ? sTrueStr : sFalseStr );
119 :
120 4 : if( rLib.bPreload )
121 0 : pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":preload", sTrueStr );
122 :
123 4 : sal_Int32 nElementCount = rLib.aElementNames.getLength();
124 4 : if( nElementCount )
125 : {
126 2 : const OUString* pElementNames = rLib.aElementNames.getConstArray();
127 4 : for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
128 : {
129 2 : XMLElement* pElement = new XMLElement( XMLNS_LIBRARY_PREFIX ":element" );
130 2 : Reference< xml::sax::XAttributeList > xElementAttribs;
131 2 : xElementAttribs = static_cast< xml::sax::XAttributeList* >( pElement );
132 :
133 : pElement->addAttribute( OUString( XMLNS_LIBRARY_PREFIX ":name" ),
134 2 : pElementNames[i] );
135 :
136 2 : pLibElement->addSubElement( pElement );
137 2 : }
138 : }
139 :
140 4 : pLibElement->dump( xOut.get() );
141 :
142 8 : xOut->endDocument();
143 4 : }
144 :
145 : }
146 :
147 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|