LibreOffice Module xmlscript (master) 1
xmllib_export.cxx
Go to the documentation of this file.
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#include <rtl/ref.hxx>
23#include <xmlscript/xmlns.h>
24#include <com/sun/star/xml/sax/XWriter.hpp>
25
26using namespace com::sun::star::uno;
27using namespace com::sun::star;
28
29namespace xmlscript
30{
31
32constexpr OUStringLiteral aTrueStr = u"true";
33constexpr OUStringLiteral aFalseStr = u"false";
34
35void
38 const LibDescriptorArray* pLibArray )
39{
40 xOut->startDocument();
41
42 xOut->unknown(
43 "<!DOCTYPE library:libraries PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
44 " \"libraries.dtd\">" );
45 xOut->ignorableWhitespace( OUString() );
46
47 OUString aLibrariesName( XMLNS_LIBRARY_PREFIX ":libraries" );
48 rtl::Reference<XMLElement> pLibsElement = new XMLElement( aLibrariesName );
49
50 pLibsElement->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX, XMLNS_LIBRARY_URI );
51 pLibsElement->addAttribute( "xmlns:" XMLNS_XLINK_PREFIX, XMLNS_XLINK_URI );
52
53 xOut->ignorableWhitespace( OUString() );
54 xOut->startElement( aLibrariesName, pLibsElement );
55
56 OUString sTrueStr(aTrueStr);
57 OUString sFalseStr(aFalseStr);
58
59 int nLibCount = pLibArray->mnLibCount;
60 for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
61 {
62 LibDescriptor& rLib = pLibArray->mpLibs[i];
63
64 rtl::Reference<XMLElement> pLibElement(new XMLElement( XMLNS_LIBRARY_PREFIX ":library" ));
65
66 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name", rLib.aName );
67
68 if( !rLib.aStorageURL.isEmpty() )
69 {
70 pLibElement->addAttribute( XMLNS_XLINK_PREFIX ":href", rLib.aStorageURL );
71 pLibElement->addAttribute( XMLNS_XLINK_PREFIX ":type", "simple" );
72 }
73
74 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":link", rLib.bLink ? sTrueStr : sFalseStr );
75
76 if( rLib.bLink )
77 {
78 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":readonly", rLib.bReadOnly ? sTrueStr : sFalseStr );
79 }
80
81 pLibElement->dump( xOut );
82 }
83
84 xOut->ignorableWhitespace( OUString() );
85 xOut->endElement( aLibrariesName );
86
87 xOut->endDocument();
88}
89
90void
92 css::uno::Reference< css::xml::sax::XWriter > const & xOut,
93 const LibDescriptor& rLib )
94{
95 xOut->startDocument();
96
97 xOut->unknown(
98 "<!DOCTYPE library:library PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
99 " \"library.dtd\">" );
100 xOut->ignorableWhitespace( OUString() );
101
102 rtl::Reference<XMLElement> pLibElement = new XMLElement( XMLNS_LIBRARY_PREFIX ":library" );
103
104 pLibElement->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX, XMLNS_LIBRARY_URI );
105
106 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name", rLib.aName );
107
108 OUString sTrueStr(aTrueStr);
109 OUString sFalseStr(aFalseStr);
110
111 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":readonly", rLib.bReadOnly ? sTrueStr : sFalseStr );
112
113 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":passwordprotected", rLib.bPasswordProtected ? sTrueStr : sFalseStr );
114
115 if( rLib.bPreload )
116 pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":preload", sTrueStr );
117
118 for( const auto& rElementName : rLib.aElementNames )
119 {
121
122 pElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name",
123 rElementName );
124
125 pLibElement->addSubElement( pElement );
126 }
127
128 pLibElement->dump( xOut );
129
130 xOut->endDocument();
131}
132
133}
134
135/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
float u
int i
constexpr OUStringLiteral aFalseStr
constexpr OUStringLiteral aTrueStr
void exportLibraryContainer(Reference< xml::sax::XWriter > const &xOut, const LibDescriptorArray *pLibArray)
void exportLibrary(css::uno::Reference< css::xml::sax::XWriter > const &xOut, const LibDescriptor &rLib)
std::unique_ptr< LibDescriptor[]> mpLibs
css::uno::Sequence< OUString > aElementNames
constexpr OUStringLiteral XMLNS_LIBRARY_URI
Definition: xmlns.h:32
constexpr OUStringLiteral XMLNS_XLINK_URI
Definition: xmlns.h:35
#define XMLNS_LIBRARY_PREFIX
Definition: xmlns.h:33
#define XMLNS_XLINK_PREFIX
Definition: xmlns.h:36