1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmllib_export.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlscript.hxx"
34 #include <xmlscript/xmllib_imexp.hxx>
35 #include <xmlscript/xml_helper.hxx>
37 using namespace com::sun::star::uno
;
38 using namespace com::sun::star
;
44 static OUString
aTrueStr ( RTL_CONSTASCII_USTRINGPARAM("true") );
45 static OUString
aFalseStr( RTL_CONSTASCII_USTRINGPARAM("false") );
47 //##################################################################################################
50 //==================================================================================================
53 SAL_CALL
exportLibraryContainer(
54 Reference
< xml::sax::XExtendedDocumentHandler
> const & xOut
,
55 const LibDescriptorArray
* pLibArray
)
56 SAL_THROW( (Exception
) )
58 xOut
->startDocument();
60 OUString
aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM(
61 "<!DOCTYPE library:libraries PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
62 " \"libraries.dtd\">" ) );
63 xOut
->unknown( aDocTypeStr
);
64 xOut
->ignorableWhitespace( OUString() );
67 OUString
aLibrariesName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":libraries") );
68 XMLElement
* pLibsElement
= new XMLElement( aLibrariesName
);
69 Reference
< xml::sax::XAttributeList
> xAttributes( pLibsElement
);
71 pLibsElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_LIBRARY_PREFIX
) ),
72 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_URI
) ) );
73 pLibsElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_XLINK_PREFIX
) ),
74 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_URI
) ) );
77 xOut
->ignorableWhitespace( OUString() );
78 xOut
->startElement( aLibrariesName
, xAttributes
);
80 int nLibCount
= pLibArray
->mnLibCount
;
81 for( sal_Int32 i
= 0 ; i
< nLibCount
; i
++ )
83 LibDescriptor
& rLib
= pLibArray
->mpLibs
[i
];
85 OUString
aLibraryName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":library") );
86 XMLElement
* pLibElement
= new XMLElement( aLibraryName
);
87 Reference
< xml::sax::XAttributeList
> xLibElementAttribs
;
88 xLibElementAttribs
= static_cast< xml::sax::XAttributeList
* >( pLibElement
);
90 pLibElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":name") ),
94 if( rLib
.aStorageURL
.getLength() )
96 pLibElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_PREFIX
":href") ),
98 pLibElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_PREFIX
":type") ),
99 OUString( RTL_CONSTASCII_USTRINGPARAM("simple") ) );
102 pLibElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":link") ),
103 rLib
.bLink
? aTrueStr
: aFalseStr
);
107 pLibElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":readonly") ),
108 rLib
.bReadOnly
? aTrueStr
: aFalseStr
);
111 pLibElement
->dump( xOut
.get() );
114 xOut
->ignorableWhitespace( OUString() );
115 xOut
->endElement( aLibrariesName
);
120 //==================================================================================================
123 SAL_CALL
exportLibrary(
124 ::com::sun::star::uno::Reference
< ::com::sun::star::xml::sax::XExtendedDocumentHandler
> const & xOut
,
125 const LibDescriptor
& rLib
)
126 SAL_THROW( (::com::sun::star::uno::Exception
) )
128 xOut
->startDocument();
130 OUString
aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM(
131 "<!DOCTYPE library:library PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
132 " \"library.dtd\">" ) );
133 xOut
->unknown( aDocTypeStr
);
134 xOut
->ignorableWhitespace( OUString() );
137 OUString
aLibraryName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":library") );
138 XMLElement
* pLibElement
= new XMLElement( aLibraryName
);
139 Reference
< xml::sax::XAttributeList
> xAttributes( pLibElement
);
141 pLibElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_LIBRARY_PREFIX
) ),
142 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_URI
) ) );
144 pLibElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":name") ),
147 pLibElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":readonly") ),
148 rLib
.bReadOnly
? aTrueStr
: aFalseStr
);
150 pLibElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":passwordprotected") ),
151 rLib
.bPasswordProtected
? aTrueStr
: aFalseStr
);
154 pLibElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":preload") ), aTrueStr
);
156 sal_Int32 nElementCount
= rLib
.aElementNames
.getLength();
159 const OUString
* pElementNames
= rLib
.aElementNames
.getConstArray();
160 for( sal_Int32 i
= 0 ; i
< nElementCount
; i
++ )
162 XMLElement
* pElement
= new XMLElement( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":element" ) ) );
163 Reference
< xml::sax::XAttributeList
> xElementAttribs
;
164 xElementAttribs
= static_cast< xml::sax::XAttributeList
* >( pElement
);
166 pElement
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX
":name") ),
169 pLibElement
->addSubElement( pElement
);
173 pLibElement
->dump( xOut
.get() );