LCOV - code coverage report
Current view: top level - xmlscript/source/xmllib_imexp - xmllib_export.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 59 63 93.7 %
Date: 2014-04-11 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 <xmlscript/xmllib_imexp.hxx>
      21             : #include <xmlscript/xml_helper.hxx>
      22             : 
      23             : using namespace com::sun::star::uno;
      24             : using namespace com::sun::star;
      25             : 
      26             : namespace xmlscript
      27             : {
      28             : 
      29             : const char aTrueStr[] = "true";
      30             : const char aFalseStr[] = "false";
      31             : 
      32             : void
      33           2 : SAL_CALL exportLibraryContainer(
      34             :     Reference< xml::sax::XWriter > const & xOut,
      35             :     const LibDescriptorArray* pLibArray )
      36             :         SAL_THROW( (Exception) )
      37             : {
      38           2 :     xOut->startDocument();
      39             : 
      40             :     OUString aDocTypeStr(
      41             :         "<!DOCTYPE library:libraries PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
      42           2 :         " \"libraries.dtd\">" );
      43           2 :     xOut->unknown( aDocTypeStr );
      44           2 :     xOut->ignorableWhitespace( OUString() );
      45             : 
      46           4 :     OUString aLibrariesName( XMLNS_LIBRARY_PREFIX ":libraries" );
      47           2 :     XMLElement* pLibsElement = new XMLElement( aLibrariesName );
      48           4 :     Reference< xml::sax::XAttributeList > xAttributes( pLibsElement );
      49             : 
      50           2 :     pLibsElement->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX, XMLNS_LIBRARY_URI );
      51           2 :     pLibsElement->addAttribute( "xmlns:" XMLNS_XLINK_PREFIX, XMLNS_XLINK_URI );
      52             : 
      53           2 :     xOut->ignorableWhitespace( OUString() );
      54           2 :     xOut->startElement( aLibrariesName, xAttributes );
      55             : 
      56           4 :     OUString sTrueStr(aTrueStr);
      57           4 :     OUString sFalseStr(aFalseStr);
      58             : 
      59           2 :     int nLibCount = pLibArray->mnLibCount;
      60           4 :     for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
      61             :     {
      62           2 :         LibDescriptor& rLib = pLibArray->mpLibs[i];
      63             : 
      64           2 :         OUString aLibraryName( XMLNS_LIBRARY_PREFIX ":library" );
      65           2 :         XMLElement* pLibElement = new XMLElement( aLibraryName );
      66           4 :         Reference< xml::sax::XAttributeList > xLibElementAttribs;
      67           2 :         xLibElementAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement );
      68             : 
      69           2 :         pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name", rLib.aName );
      70             : 
      71           2 :         if( !rLib.aStorageURL.isEmpty() )
      72             :         {
      73           0 :             pLibElement->addAttribute( XMLNS_XLINK_PREFIX ":href", rLib.aStorageURL );
      74           0 :             pLibElement->addAttribute( XMLNS_XLINK_PREFIX ":type", "simple" );
      75             :         }
      76             : 
      77           2 :         pLibElement->addAttribute(  XMLNS_LIBRARY_PREFIX ":link", rLib.bLink ? sTrueStr : sFalseStr );
      78             : 
      79           2 :         if( rLib.bLink )
      80             :         {
      81           0 :             pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":readonly", rLib.bReadOnly ? sTrueStr : sFalseStr );
      82             :         }
      83             : 
      84           2 :         pLibElement->dump( xOut.get() );
      85           2 :     }
      86             : 
      87           2 :     xOut->ignorableWhitespace( OUString() );
      88           2 :     xOut->endElement( aLibrariesName );
      89             : 
      90           4 :     xOut->endDocument();
      91           2 : }
      92             : 
      93             : void
      94           2 : SAL_CALL exportLibrary(
      95             :     ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XWriter > const & xOut,
      96             :     const LibDescriptor& rLib )
      97             :         SAL_THROW( (::com::sun::star::uno::Exception) )
      98             : {
      99           2 :     xOut->startDocument();
     100             : 
     101             :     OUString aDocTypeStr(
     102             :         "<!DOCTYPE library:library PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\""
     103           2 :         " \"library.dtd\">" );
     104           2 :     xOut->unknown( aDocTypeStr );
     105           2 :     xOut->ignorableWhitespace( OUString() );
     106             : 
     107           4 :     OUString aLibraryName( XMLNS_LIBRARY_PREFIX ":library" );
     108           2 :     XMLElement* pLibElement = new XMLElement( aLibraryName );
     109           4 :     Reference< xml::sax::XAttributeList > xAttributes( pLibElement );
     110             : 
     111           2 :     pLibElement->addAttribute( "xmlns:" XMLNS_LIBRARY_PREFIX, XMLNS_LIBRARY_URI );
     112             : 
     113           2 :     pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":name", rLib.aName );
     114             : 
     115           4 :     OUString sTrueStr(aTrueStr);
     116           4 :     OUString sFalseStr(aFalseStr);
     117             : 
     118           2 :     pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":readonly", rLib.bReadOnly ? sTrueStr : sFalseStr );
     119             : 
     120           2 :     pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":passwordprotected", rLib.bPasswordProtected ? sTrueStr : sFalseStr );
     121             : 
     122           2 :     if( rLib.bPreload )
     123           0 :         pLibElement->addAttribute( XMLNS_LIBRARY_PREFIX ":preload", sTrueStr );
     124             : 
     125           2 :     sal_Int32 nElementCount = rLib.aElementNames.getLength();
     126           2 :     if( nElementCount )
     127             :     {
     128           2 :         const OUString* pElementNames = rLib.aElementNames.getConstArray();
     129           4 :         for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
     130             :         {
     131           2 :             XMLElement* pElement = new XMLElement( XMLNS_LIBRARY_PREFIX ":element" );
     132           2 :             Reference< xml::sax::XAttributeList > xElementAttribs;
     133           2 :             xElementAttribs = static_cast< xml::sax::XAttributeList* >( pElement );
     134             : 
     135             :             pElement->addAttribute( OUString( XMLNS_LIBRARY_PREFIX ":name" ),
     136           2 :                                         pElementNames[i] );
     137             : 
     138           2 :             pLibElement->addSubElement( pElement );
     139           2 :         }
     140             :     }
     141             : 
     142           2 :     pLibElement->dump( xOut.get() );
     143             : 
     144           4 :     xOut->endDocument();
     145           2 : }
     146             : 
     147             : }
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10