1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_xmlscript.hxx" 30 31 #include <xmlscript/xmllib_imexp.hxx> 32 #include <xmlscript/xml_helper.hxx> 33 34 using namespace com::sun::star::uno; 35 using namespace com::sun::star; 36 using namespace rtl; 37 38 namespace xmlscript 39 { 40 41 static OUString aTrueStr ( RTL_CONSTASCII_USTRINGPARAM("true") ); 42 static OUString aFalseStr( RTL_CONSTASCII_USTRINGPARAM("false") ); 43 44 //################################################################################################## 45 46 47 //================================================================================================== 48 49 void 50 SAL_CALL exportLibraryContainer( 51 Reference< xml::sax::XExtendedDocumentHandler > const & xOut, 52 const LibDescriptorArray* pLibArray ) 53 SAL_THROW( (Exception) ) 54 { 55 xOut->startDocument(); 56 57 OUString aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM( 58 "<!DOCTYPE library:libraries PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\"" 59 " \"libraries.dtd\">" ) ); 60 xOut->unknown( aDocTypeStr ); 61 xOut->ignorableWhitespace( OUString() ); 62 63 64 OUString aLibrariesName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":libraries") ); 65 XMLElement* pLibsElement = new XMLElement( aLibrariesName ); 66 Reference< xml::sax::XAttributeList > xAttributes( pLibsElement ); 67 68 pLibsElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_LIBRARY_PREFIX) ), 69 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_URI) ) ); 70 pLibsElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_XLINK_PREFIX) ), 71 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_URI) ) ); 72 73 74 xOut->ignorableWhitespace( OUString() ); 75 xOut->startElement( aLibrariesName, xAttributes ); 76 77 int nLibCount = pLibArray->mnLibCount; 78 for( sal_Int32 i = 0 ; i < nLibCount ; i++ ) 79 { 80 LibDescriptor& rLib = pLibArray->mpLibs[i]; 81 82 OUString aLibraryName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":library") ); 83 XMLElement* pLibElement = new XMLElement( aLibraryName ); 84 Reference< xml::sax::XAttributeList > xLibElementAttribs; 85 xLibElementAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement ); 86 87 pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":name") ), 88 rLib.aName ); 89 90 91 if( rLib.aStorageURL.getLength() ) 92 { 93 pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_PREFIX ":href") ), 94 rLib.aStorageURL ); 95 pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_PREFIX ":type") ), 96 OUString( RTL_CONSTASCII_USTRINGPARAM("simple") ) ); 97 } 98 99 pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":link") ), 100 rLib.bLink ? aTrueStr : aFalseStr ); 101 102 if( rLib.bLink ) 103 { 104 pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":readonly") ), 105 rLib.bReadOnly ? aTrueStr : aFalseStr ); 106 } 107 108 pLibElement->dump( xOut.get() ); 109 } 110 111 xOut->ignorableWhitespace( OUString() ); 112 xOut->endElement( aLibrariesName ); 113 114 xOut->endDocument(); 115 } 116 117 //================================================================================================== 118 119 void 120 SAL_CALL exportLibrary( 121 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XExtendedDocumentHandler > const & xOut, 122 const LibDescriptor& rLib ) 123 SAL_THROW( (::com::sun::star::uno::Exception) ) 124 { 125 xOut->startDocument(); 126 127 OUString aDocTypeStr( RTL_CONSTASCII_USTRINGPARAM( 128 "<!DOCTYPE library:library PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\"" 129 " \"library.dtd\">" ) ); 130 xOut->unknown( aDocTypeStr ); 131 xOut->ignorableWhitespace( OUString() ); 132 133 134 OUString aLibraryName( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":library") ); 135 XMLElement* pLibElement = new XMLElement( aLibraryName ); 136 Reference< xml::sax::XAttributeList > xAttributes( pLibElement ); 137 138 pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_LIBRARY_PREFIX) ), 139 OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_URI) ) ); 140 141 pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":name") ), 142 rLib.aName ); 143 144 pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":readonly") ), 145 rLib.bReadOnly ? aTrueStr : aFalseStr ); 146 147 pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":passwordprotected") ), 148 rLib.bPasswordProtected ? aTrueStr : aFalseStr ); 149 150 if( rLib.bPreload ) 151 pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":preload") ), aTrueStr ); 152 153 sal_Int32 nElementCount = rLib.aElementNames.getLength(); 154 if( nElementCount ) 155 { 156 const OUString* pElementNames = rLib.aElementNames.getConstArray(); 157 for( sal_Int32 i = 0 ; i < nElementCount ; i++ ) 158 { 159 XMLElement* pElement = new XMLElement( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":element" ) ) ); 160 Reference< xml::sax::XAttributeList > xElementAttribs; 161 xElementAttribs = static_cast< xml::sax::XAttributeList* >( pElement ); 162 163 pElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":name") ), 164 pElementNames[i] ); 165 166 pLibElement->addSubElement( pElement ); 167 } 168 } 169 170 pLibElement->dump( xOut.get() ); 171 172 xOut->endDocument(); 173 } 174 175 } 176 177