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 .
21 #include <xmlscript/xmllib_imexp.hxx>
22 #include <xmlscript/xml_helper.hxx>
24 using namespace com::sun::star::uno
;
25 using namespace com::sun::star
;
27 using ::rtl::OUString
;
32 const char aTrueStr
[] = "true";
33 const char aFalseStr
[] = "false";
35 //##################################################################################################
38 //==================================================================================================
41 SAL_CALL
exportLibraryContainer(
42 Reference
< xml::sax::XWriter
> const & xOut
,
43 const LibDescriptorArray
* pLibArray
)
44 SAL_THROW( (Exception
) )
46 xOut
->startDocument();
49 "<!DOCTYPE library:libraries PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
50 " \"libraries.dtd\">" );
51 xOut
->unknown( aDocTypeStr
);
52 xOut
->ignorableWhitespace( OUString() );
55 OUString
aLibrariesName( XMLNS_LIBRARY_PREFIX
":libraries" );
56 XMLElement
* pLibsElement
= new XMLElement( aLibrariesName
);
57 Reference
< xml::sax::XAttributeList
> xAttributes( pLibsElement
);
59 pLibsElement
->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX
, XMLNS_LIBRARY_URI
);
60 pLibsElement
->addAttribute( "xmlns:" XMLNS_XLINK_PREFIX
, XMLNS_XLINK_URI
);
63 xOut
->ignorableWhitespace( OUString() );
64 xOut
->startElement( aLibrariesName
, xAttributes
);
66 OUString
sTrueStr(aTrueStr
);
67 OUString
sFalseStr(aFalseStr
);
69 int nLibCount
= pLibArray
->mnLibCount
;
70 for( sal_Int32 i
= 0 ; i
< nLibCount
; i
++ )
72 LibDescriptor
& rLib
= pLibArray
->mpLibs
[i
];
74 OUString
aLibraryName( XMLNS_LIBRARY_PREFIX
":library" );
75 XMLElement
* pLibElement
= new XMLElement( aLibraryName
);
76 Reference
< xml::sax::XAttributeList
> xLibElementAttribs
;
77 xLibElementAttribs
= static_cast< xml::sax::XAttributeList
* >( pLibElement
);
79 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":name", rLib
.aName
);
82 if( !rLib
.aStorageURL
.isEmpty() )
84 pLibElement
->addAttribute( XMLNS_XLINK_PREFIX
":href", rLib
.aStorageURL
);
85 pLibElement
->addAttribute( XMLNS_XLINK_PREFIX
":type", "simple" );
88 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":link", rLib
.bLink
? sTrueStr
: sFalseStr
);
92 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":readonly", rLib
.bReadOnly
? sTrueStr
: sFalseStr
);
95 pLibElement
->dump( xOut
.get() );
98 xOut
->ignorableWhitespace( OUString() );
99 xOut
->endElement( aLibrariesName
);
104 //==================================================================================================
107 SAL_CALL
exportLibrary(
108 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XWriter
> const & xOut
,
109 const LibDescriptor
& rLib
)
110 SAL_THROW( (::com::sun::star::uno::Exception
) )
112 xOut
->startDocument();
114 OUString
aDocTypeStr(
115 "<!DOCTYPE library:library PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
116 " \"library.dtd\">" );
117 xOut
->unknown( aDocTypeStr
);
118 xOut
->ignorableWhitespace( OUString() );
121 OUString
aLibraryName( XMLNS_LIBRARY_PREFIX
":library" );
122 XMLElement
* pLibElement
= new XMLElement( aLibraryName
);
123 Reference
< xml::sax::XAttributeList
> xAttributes( pLibElement
);
125 pLibElement
->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX
, XMLNS_LIBRARY_URI
);
127 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":name", rLib
.aName
);
129 OUString
sTrueStr(aTrueStr
);
130 OUString
sFalseStr(aFalseStr
);
132 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":readonly", rLib
.bReadOnly
? sTrueStr
: sFalseStr
);
134 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":passwordprotected", rLib
.bPasswordProtected
? sTrueStr
: sFalseStr
);
137 pLibElement
->addAttribute( XMLNS_LIBRARY_PREFIX
":preload", sTrueStr
);
139 sal_Int32 nElementCount
= rLib
.aElementNames
.getLength();
142 const OUString
* pElementNames
= rLib
.aElementNames
.getConstArray();
143 for( sal_Int32 i
= 0 ; i
< nElementCount
; i
++ )
145 XMLElement
* pElement
= new XMLElement( XMLNS_LIBRARY_PREFIX
":element" );
146 Reference
< xml::sax::XAttributeList
> xElementAttribs
;
147 xElementAttribs
= static_cast< xml::sax::XAttributeList
* >( pElement
);
149 pElement
->addAttribute( OUString( XMLNS_LIBRARY_PREFIX
":name" ),
152 pLibElement
->addSubElement( pElement
);
156 pLibElement
->dump( xOut
.get() );
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */