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

Generated by: LCOV version 1.11