1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <xmlscript/xmllib_imexp.hxx>
21 #include <xmlscript/xml_helper.hxx>
23 using namespace com::sun::star::uno
;
24 using namespace com::sun::star
;
29 const char aTrueStr
[] = "true";
30 const char aFalseStr
[] = "false";
33 SAL_CALL
exportLibraryContainer(
34 Reference
< xml::sax::XWriter
> const & xOut
,
35 const LibDescriptorArray
* pLibArray
)
37 xOut
->startDocument();
40 "<!DOCTYPE library:libraries PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
41 " \"libraries.dtd\">" );
42 xOut
->unknown( aDocTypeStr
);
43 xOut
->ignorableWhitespace( OUString() );
45 OUString
aLibrariesName( XMLNS_LIBRARY_PREFIX
":libraries" );
46 XMLElement
* pLibsElement
= new XMLElement( aLibrariesName
);
47 Reference
< xml::sax::XAttributeList
> xAttributes( pLibsElement
);
49 pLibsElement
->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX
, XMLNS_LIBRARY_URI
);
50 pLibsElement
->addAttribute( "xmlns:" XMLNS_XLINK_PREFIX
, XMLNS_XLINK_URI
);
52 xOut
->ignorableWhitespace( OUString() );
53 xOut
->startElement( aLibrariesName
, xAttributes
);
55 OUString
sTrueStr(aTrueStr
);
56 OUString
sFalseStr(aFalseStr
);
58 int nLibCount
= pLibArray
->mnLibCount
;
59 for( sal_Int32 i
= 0 ; i
< nLibCount
; i
++ )
61 LibDescriptor
& rLib
= pLibArray
->mpLibs
[i
];
63 OUString
aLibraryName( XMLNS_LIBRARY_PREFIX
":library" );
64 XMLElement
* pLibElement
= new XMLElement( aLibraryName
);
65 Reference
< xml::sax::XAttributeList
> xLibElementAttribs
;
66 xLibElementAttribs
= static_cast< xml::sax::XAttributeList
* >( pLibElement
);
68 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":name", rLib
.aName
);
70 if( !rLib
.aStorageURL
.isEmpty() )
72 pLibElement
->addAttribute( XMLNS_XLINK_PREFIX
":href", rLib
.aStorageURL
);
73 pLibElement
->addAttribute( XMLNS_XLINK_PREFIX
":type", "simple" );
76 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":link", rLib
.bLink
? sTrueStr
: sFalseStr
);
80 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":readonly", rLib
.bReadOnly
? sTrueStr
: sFalseStr
);
83 pLibElement
->dump( xOut
.get() );
86 xOut
->ignorableWhitespace( OUString() );
87 xOut
->endElement( aLibrariesName
);
93 SAL_CALL
exportLibrary(
94 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XWriter
> const & xOut
,
95 const LibDescriptor
& rLib
)
97 xOut
->startDocument();
100 "<!DOCTYPE library:library PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
101 " \"library.dtd\">" );
102 xOut
->unknown( aDocTypeStr
);
103 xOut
->ignorableWhitespace( OUString() );
105 OUString
aLibraryName( XMLNS_LIBRARY_PREFIX
":library" );
106 XMLElement
* pLibElement
= new XMLElement( aLibraryName
);
107 Reference
< xml::sax::XAttributeList
> xAttributes( pLibElement
);
109 pLibElement
->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX
, XMLNS_LIBRARY_URI
);
111 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":name", rLib
.aName
);
113 OUString
sTrueStr(aTrueStr
);
114 OUString
sFalseStr(aFalseStr
);
116 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":readonly", rLib
.bReadOnly
? sTrueStr
: sFalseStr
);
118 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":passwordprotected", rLib
.bPasswordProtected
? sTrueStr
: sFalseStr
);
121 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":preload", sTrueStr
);
123 sal_Int32 nElementCount
= rLib
.aElementNames
.getLength();
126 const OUString
* pElementNames
= rLib
.aElementNames
.getConstArray();
127 for( sal_Int32 i
= 0 ; i
< nElementCount
; i
++ )
129 XMLElement
* pElement
= new XMLElement( XMLNS_LIBRARY_PREFIX
":element" );
130 Reference
< xml::sax::XAttributeList
> xElementAttribs
;
131 xElementAttribs
= static_cast< xml::sax::XAttributeList
* >( pElement
);
133 pElement
->addAttribute( OUString( XMLNS_LIBRARY_PREFIX
":name" ),
136 pLibElement
->addSubElement( pElement
);
140 pLibElement
->dump( xOut
.get() );
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */