Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / xmlscript / source / xmllib_imexp / xmllib_export.cxx
blobe2c73119a7d7605828784bd28e49fc4cbd678d0b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
24 using namespace com::sun::star::uno;
25 using namespace com::sun::star;
27 namespace xmlscript
30 const char aTrueStr[] = "true";
31 const char aFalseStr[] = "false";
33 void
34 exportLibraryContainer(
35 Reference< xml::sax::XWriter > const & xOut,
36 const LibDescriptorArray* pLibArray )
38 xOut->startDocument();
40 xOut->unknown(
41 "<!DOCTYPE library:libraries PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
42 " \"libraries.dtd\">" );
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 XMLElement* pLibElement = new XMLElement( XMLNS_LIBRARY_PREFIX ":library" );
64 Reference< xml::sax::XAttributeList > xLibElementAttribs;
65 xLibElementAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement );
67 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name", rLib.aName );
69 if( !rLib.aStorageURL.isEmpty() )
71 pLibElement->addAttribute( XMLNS_XLINK_PREFIX ":href", rLib.aStorageURL );
72 pLibElement->addAttribute( XMLNS_XLINK_PREFIX ":type", "simple" );
75 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":link", rLib.bLink ? sTrueStr : sFalseStr );
77 if( rLib.bLink )
79 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":readonly", rLib.bReadOnly ? sTrueStr : sFalseStr );
82 pLibElement->dump( xOut.get() );
85 xOut->ignorableWhitespace( OUString() );
86 xOut->endElement( aLibrariesName );
88 xOut->endDocument();
91 void
92 exportLibrary(
93 css::uno::Reference< css::xml::sax::XWriter > const & xOut,
94 const LibDescriptor& rLib )
96 xOut->startDocument();
98 xOut->unknown(
99 "<!DOCTYPE library:library PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
100 " \"library.dtd\">" );
101 xOut->ignorableWhitespace( OUString() );
103 rtl::Reference<XMLElement> pLibElement = new XMLElement( XMLNS_LIBRARY_PREFIX ":library" );
105 pLibElement->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX, XMLNS_LIBRARY_URI );
107 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name", rLib.aName );
109 OUString sTrueStr(aTrueStr);
110 OUString sFalseStr(aFalseStr);
112 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":readonly", rLib.bReadOnly ? sTrueStr : sFalseStr );
114 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":passwordprotected", rLib.bPasswordProtected ? sTrueStr : sFalseStr );
116 if( rLib.bPreload )
117 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":preload", sTrueStr );
119 sal_Int32 nElementCount = rLib.aElementNames.getLength();
120 if( nElementCount )
122 const OUString* pElementNames = rLib.aElementNames.getConstArray();
123 for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
125 XMLElement* pElement = new XMLElement( XMLNS_LIBRARY_PREFIX ":element" );
126 Reference< xml::sax::XAttributeList > xElementAttribs;
127 xElementAttribs = static_cast< xml::sax::XAttributeList* >( pElement );
129 pElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name",
130 pElementNames[i] );
132 pLibElement->addSubElement( pElement );
136 pLibElement->dump( xOut.get() );
138 xOut->endDocument();
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */