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