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 <rtl/ref.hxx>
21 #include <xmlscript/xmllib_imexp.hxx>
22 #include <xmlscript/xml_helper.hxx>
23 #include <xmlscript/xmlns.h>
24 #include <com/sun/star/xml/sax/XWriter.hpp>
26 using namespace com::sun::star::uno
;
27 using namespace com::sun::star
;
32 constexpr OUString aTrueStr
= u
"true"_ustr
;
33 constexpr OUString aFalseStr
= u
"false"_ustr
;
36 exportLibraryContainer(
37 Reference
< xml::sax::XWriter
> const & xOut
,
38 const LibDescriptorArray
* pLibArray
)
40 xOut
->startDocument();
43 "<!DOCTYPE library:libraries PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
44 " \"libraries.dtd\">" );
45 xOut
->ignorableWhitespace( OUString() );
47 OUString
aLibrariesName( XMLNS_LIBRARY_PREFIX
":libraries" );
48 rtl::Reference
<XMLElement
> pLibsElement
= new XMLElement( aLibrariesName
);
50 pLibsElement
->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX
, XMLNS_LIBRARY_URI
);
51 pLibsElement
->addAttribute( "xmlns:" XMLNS_XLINK_PREFIX
, XMLNS_XLINK_URI
);
53 xOut
->ignorableWhitespace( OUString() );
54 xOut
->startElement( aLibrariesName
, pLibsElement
);
56 OUString
sTrueStr(aTrueStr
);
57 OUString
sFalseStr(aFalseStr
);
59 int nLibCount
= pLibArray
->mnLibCount
;
60 for( sal_Int32 i
= 0 ; i
< nLibCount
; i
++ )
62 LibDescriptor
& rLib
= pLibArray
->mpLibs
[i
];
64 rtl::Reference
<XMLElement
> pLibElement(new XMLElement( XMLNS_LIBRARY_PREFIX
":library" ));
66 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":name", rLib
.aName
);
68 if( !rLib
.aStorageURL
.isEmpty() )
70 pLibElement
->addAttribute( XMLNS_XLINK_PREFIX
":href", rLib
.aStorageURL
);
71 pLibElement
->addAttribute( XMLNS_XLINK_PREFIX
":type", "simple" );
74 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":link", rLib
.bLink
? sTrueStr
: sFalseStr
);
78 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":readonly", rLib
.bReadOnly
? sTrueStr
: sFalseStr
);
81 pLibElement
->dump( xOut
);
84 xOut
->ignorableWhitespace( OUString() );
85 xOut
->endElement( aLibrariesName
);
92 css::uno::Reference
< css::xml::sax::XWriter
> const & xOut
,
93 const LibDescriptor
& rLib
)
95 xOut
->startDocument();
98 "<!DOCTYPE library:library PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
99 " \"library.dtd\">" );
100 xOut
->ignorableWhitespace( OUString() );
102 rtl::Reference
<XMLElement
> pLibElement
= new XMLElement( XMLNS_LIBRARY_PREFIX
":library" );
104 pLibElement
->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX
, XMLNS_LIBRARY_URI
);
106 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":name", rLib
.aName
);
108 OUString
sTrueStr(aTrueStr
);
109 OUString
sFalseStr(aFalseStr
);
111 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":readonly", rLib
.bReadOnly
? sTrueStr
: sFalseStr
);
113 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":passwordprotected", rLib
.bPasswordProtected
? sTrueStr
: sFalseStr
);
116 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":preload", sTrueStr
);
118 for( const auto& rElementName
: rLib
.aElementNames
)
120 rtl::Reference
<XMLElement
> pElement(new XMLElement( XMLNS_LIBRARY_PREFIX
":element" ));
122 pElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":name",
125 pLibElement
->addSubElement( pElement
);
128 pLibElement
->dump( xOut
);
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */