LCOV - code coverage report
Current view: top level - libreoffice/filter/source/xsltdialog - typedetectionexport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 167 0.0 %
Date: 2012-12-17 Functions: 0 7 0.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             : 
      21             : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      22             : #include <com/sun/star/xml/sax/Writer.hpp>
      23             : #include <com/sun/star/beans/PropertyValue.hpp>
      24             : #include <com/sun/star/io/XActiveDataSource.hpp>
      25             : #include <tools/urlobj.hxx>
      26             : 
      27             : #include "typedetectionexport.hxx"
      28             : #include "xmlfiltersettingsdialog.hxx"
      29             : 
      30             : #include <comphelper/attributelist.hxx>
      31             : 
      32             : using namespace com::sun::star::beans;
      33             : using namespace com::sun::star::uno;
      34             : using namespace com::sun::star::io;
      35             : using namespace com::sun::star::lang;
      36             : using namespace com::sun::star::xml::sax;
      37             : 
      38             : using ::rtl::OUString;
      39             : 
      40           0 : TypeDetectionExporter::TypeDetectionExporter( Reference< XComponentContext >& xContext )
      41           0 : : mxContext( xContext )
      42             : {
      43           0 : }
      44             : 
      45           0 : static OUString createRelativeURL( const OUString& rFilterName, const OUString& rURL )
      46             : {
      47           0 :     if( !rURL.isEmpty() &&
      48           0 :         (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("http:") ) != 0) &&
      49           0 :         (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("shttp:") ) != 0) &&
      50           0 :         (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("jar:") ) != 0) &&
      51           0 :         (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("ftp:") ) != 0))
      52             :     {
      53           0 :         INetURLObject aURL( rURL );
      54           0 :         OUString aName( aURL.GetName() );
      55           0 :         if( aName.isEmpty() )
      56             :         {
      57           0 :             sal_Int32 nPos = rURL.lastIndexOf( sal_Unicode( '/' ) );
      58           0 :             if( nPos == -1 )
      59             :             {
      60           0 :                 aName = rURL;
      61             :             }
      62             :             else
      63             :             {
      64           0 :                 aName = rURL.copy( nPos + 1 );
      65             :             }
      66             :         }
      67             : 
      68           0 :         OUString aRelURL( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package:" ) );
      69           0 :         aRelURL += rFilterName;
      70           0 :         aRelURL += OUString( sal_Unicode( '/' ) );
      71           0 :         aRelURL += aName;
      72           0 :         return aRelURL;
      73             :     }
      74             :     else
      75             :     {
      76           0 :         return rURL;
      77             :     }
      78             : }
      79             : 
      80           0 : void TypeDetectionExporter::doExport( Reference< XOutputStream > xOS,  const XMLFilterVector& rFilters )
      81             : {
      82             :     try
      83             :     {
      84           0 :         const OUString sComponentData       ( RTL_CONSTASCII_USTRINGPARAM ( "oor:component-data" ) );
      85           0 :         const OUString sNode                ( RTL_CONSTASCII_USTRINGPARAM ( "node" ) );
      86           0 :         const OUString sName                ( RTL_CONSTASCII_USTRINGPARAM ( "oor:name" ) );
      87           0 :         const OUString sWhiteSpace          ( RTL_CONSTASCII_USTRINGPARAM ( " " ) );
      88           0 :         const OUString sUIName              ( RTL_CONSTASCII_USTRINGPARAM ( "UIName" ) );
      89           0 :         const OUString sComma               ( RTL_CONSTASCII_USTRINGPARAM ( "," ) );
      90           0 :         const OUString sDelim               ( RTL_CONSTASCII_USTRINGPARAM ( ";" ) );
      91           0 :         const OUString sData                ( RTL_CONSTASCII_USTRINGPARAM ( "Data" ) );
      92           0 :         const OUString sDocTypePrefix       ( RTL_CONSTASCII_USTRINGPARAM ( "doctype:" ) );
      93           0 :         const OUString sFilterAdaptorService( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.XmlFilterAdaptor" ) );
      94           0 :         const OUString sXSLTFilterService   ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.documentconversion.XSLTFilter" ) );
      95           0 :         const OUString sCdataAttribute      ( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) );
      96             : 
      97             : 
      98             :         // set up sax writer and connect to given output stream
      99           0 :         Reference< XWriter > xHandler = Writer::create( mxContext );
     100           0 :         xHandler->setOutputStream( xOS );
     101             : 
     102           0 :         ::comphelper::AttributeList * pAttrList = new ::comphelper::AttributeList;
     103           0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "xmlns:oor" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "http://openoffice.org/2001/registry" )) );
     104           0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "xmlns:xs" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "http://www.w3.org/2001/XMLSchema" )) );
     105           0 :         pAttrList->AddAttribute ( sName, sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "TypeDetection" )) );
     106           0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "oor:package" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Office" )) );
     107           0 :         Reference < XAttributeList > xAttrList (pAttrList);
     108             : 
     109           0 :         xHandler->startDocument();
     110           0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     111           0 :         xHandler->startElement( sComponentData, xAttrList );
     112             : 
     113             :         // export types
     114             :         {
     115           0 :             xAttrList = pAttrList = new ::comphelper::AttributeList;
     116           0 :             pAttrList->AddAttribute ( sName, sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "Types" )) );
     117           0 :             xHandler->ignorableWhitespace ( sWhiteSpace );
     118           0 :             xHandler->startElement( sNode, xAttrList );
     119             : 
     120           0 :             XMLFilterVector::const_iterator aIter( rFilters.begin() );
     121           0 :             while( aIter != rFilters.end() )
     122             :             {
     123           0 :                 const filter_info_impl* pFilter = (*aIter);
     124             : 
     125           0 :                 xAttrList = pAttrList = new ::comphelper::AttributeList;
     126           0 :                 pAttrList->AddAttribute( sName, sCdataAttribute, pFilter->maType );
     127           0 :                 xHandler->ignorableWhitespace ( sWhiteSpace );
     128           0 :                 xHandler->startElement( sNode, xAttrList );
     129           0 :                 OUString sValue( sal_Unicode('0') );
     130           0 :                 sValue += sComma;
     131           0 :                 sValue += sComma;
     132           0 :                 if( !pFilter->maDocType.isEmpty() )
     133             :                 {
     134           0 :                     sValue += sDocTypePrefix;
     135           0 :                     sValue += pFilter->maDocType;
     136             :                 }
     137           0 :                 sValue += sComma;
     138           0 :                 sValue += sComma;
     139           0 :                 sValue += pFilter->maExtension;
     140           0 :                 sValue += sComma;
     141           0 :                 sValue += OUString::valueOf( pFilter->mnDocumentIconID );
     142           0 :                 sValue += sComma;
     143             : 
     144           0 :                 addProperty( xHandler, sData, sValue );
     145           0 :                 addLocaleProperty( xHandler, sUIName, pFilter->maInterfaceName );
     146           0 :                 xHandler->ignorableWhitespace ( sWhiteSpace );
     147           0 :                 xHandler->endElement( sNode );
     148             : 
     149           0 :                 ++aIter;
     150           0 :             }
     151             : 
     152           0 :             xHandler->ignorableWhitespace ( sWhiteSpace );
     153           0 :             xHandler->endElement( sNode );
     154             :         }
     155             : 
     156             :         // export filters
     157             :         {
     158           0 :             xAttrList = pAttrList = new ::comphelper::AttributeList;
     159           0 :             pAttrList->AddAttribute ( sName, sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "Filters" )) );
     160           0 :             xHandler->ignorableWhitespace ( sWhiteSpace );
     161           0 :             xHandler->startElement( sNode, xAttrList );
     162             : 
     163           0 :             XMLFilterVector::const_iterator aIter( rFilters.begin() );
     164           0 :             while( aIter != rFilters.end() )
     165             :             {
     166           0 :                 const filter_info_impl* pFilter = (*aIter);
     167             : 
     168           0 :                 xAttrList = pAttrList = new ::comphelper::AttributeList;
     169           0 :                 pAttrList->AddAttribute( sName, sCdataAttribute, pFilter->maFilterName );
     170           0 :                 xHandler->ignorableWhitespace ( sWhiteSpace );
     171           0 :                 xHandler->startElement( sNode, xAttrList );
     172           0 :                 addLocaleProperty( xHandler, sUIName, pFilter->maInterfaceName );
     173             : 
     174           0 :                 OUString sValue( sal_Unicode('0') );
     175           0 :                 sValue += sComma;
     176           0 :                 sValue += pFilter->maType;
     177             :                 sValue += sComma,
     178           0 :                 sValue += pFilter->maDocumentService;
     179             :                 sValue += sComma,
     180           0 :                 sValue += sFilterAdaptorService;
     181             :                 sValue += sComma,
     182           0 :                 sValue += OUString::valueOf( pFilter->maFlags );
     183           0 :                 sValue += sComma;
     184           0 :                 sValue += sXSLTFilterService;
     185           0 :                 sValue += sDelim;
     186           0 :                 sValue += OUString::valueOf( pFilter->mbNeedsXSLT2 );
     187           0 :                 sValue += sDelim;
     188             : 
     189           0 :                 const application_info_impl* pAppInfo = getApplicationInfo( pFilter->maExportService );
     190           0 :                 sValue += pAppInfo->maXMLImporter;
     191           0 :                 sValue += sDelim;
     192           0 :                 sValue += pAppInfo->maXMLExporter;
     193           0 :                 sValue += sDelim;
     194             : 
     195           0 :                 sValue += createRelativeURL( pFilter->maFilterName, pFilter->maImportXSLT );
     196           0 :                 sValue += sDelim;
     197           0 :                 sValue += createRelativeURL( pFilter->maFilterName, pFilter->maExportXSLT );
     198           0 :                 sValue += sDelim;
     199             :                 // entry DTD obsolete and removed, but delimiter kept
     200           0 :                 sValue += sDelim;
     201           0 :                 sValue += pFilter->maComment;
     202           0 :                 sValue += sComma;
     203           0 :                 sValue += OUString( sal_Unicode('0') );
     204           0 :                 sValue += sComma;
     205           0 :                 sValue += createRelativeURL( pFilter->maFilterName, pFilter->maImportTemplate );
     206           0 :                 addProperty( xHandler, sData, sValue );
     207           0 :                 xHandler->ignorableWhitespace ( sWhiteSpace );
     208           0 :                 xHandler->endElement( sNode );
     209           0 :                 ++aIter;
     210           0 :             }
     211             : 
     212           0 :             xHandler->endElement( sNode );
     213             :         }
     214             : 
     215             :         // finish
     216           0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     217           0 :         xHandler->endElement( sComponentData );
     218           0 :         xHandler->endDocument();
     219             :     }
     220           0 :     catch( const Exception& )
     221             :     {
     222             :         OSL_FAIL( "TypeDetectionExporter::doExport exception catched!" );
     223             :     }
     224           0 : }
     225             : 
     226           0 : void TypeDetectionExporter::addProperty( Reference< XWriter > xHandler, const OUString& rName, const OUString& rValue )
     227             : {
     228             :     try
     229             :     {
     230           0 :         const OUString sCdataAttribute( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) );
     231           0 :         const OUString sProp( RTL_CONSTASCII_USTRINGPARAM( "prop" ) );
     232           0 :         const OUString sValue( RTL_CONSTASCII_USTRINGPARAM( "value" ) );
     233           0 :         const OUString sWhiteSpace          ( RTL_CONSTASCII_USTRINGPARAM ( " " ) );
     234             : 
     235           0 :         ::comphelper::AttributeList * pAttrList = new ::comphelper::AttributeList;
     236           0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "oor:name" )), sCdataAttribute, rName );
     237           0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "oor:type" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "xs:string" )) );
     238           0 :         Reference < XAttributeList > xAttrList (pAttrList);
     239             : 
     240           0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     241           0 :         xHandler->startElement( sProp, xAttrList );
     242           0 :         xAttrList = NULL;
     243           0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     244           0 :         xHandler->startElement( sValue,xAttrList );
     245           0 :         xHandler->characters( rValue );
     246           0 :         xHandler->endElement( sValue );
     247           0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     248           0 :         xHandler->endElement( sProp );
     249             :     }
     250           0 :     catch( const Exception& )
     251             :     {
     252             :         OSL_FAIL( "TypeDetectionExporter::addProperty exception catched!" );
     253             :     }
     254           0 : }
     255             : 
     256           0 : void TypeDetectionExporter::addLocaleProperty( Reference< XWriter > xHandler, const OUString& rName, const OUString& rValue )
     257             : {
     258             :     try
     259             :     {
     260           0 :         const OUString sCdataAttribute( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) );
     261           0 :         const OUString sProp( RTL_CONSTASCII_USTRINGPARAM( "prop" ) );
     262           0 :         const OUString sValue( RTL_CONSTASCII_USTRINGPARAM( "value" ) );
     263           0 :         const OUString sWhiteSpace          ( RTL_CONSTASCII_USTRINGPARAM ( " " ) );
     264             : 
     265           0 :         ::comphelper::AttributeList * pAttrList = new ::comphelper::AttributeList;
     266           0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "oor:name" )), sCdataAttribute, rName );
     267           0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "oor:type" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "xs:string" )) );
     268           0 :         Reference < XAttributeList > xAttrList (pAttrList);
     269             : 
     270           0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     271           0 :         xHandler->startElement( sProp, xAttrList );
     272           0 :         xAttrList = pAttrList = new ::comphelper::AttributeList;
     273           0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "xml:lang" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "en-US" )) );
     274           0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     275           0 :         xHandler->startElement( sValue, xAttrList );
     276           0 :         xHandler->characters( rValue );
     277           0 :         xHandler->endElement( sValue );
     278           0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     279           0 :         xHandler->endElement( sProp );
     280             :     }
     281           0 :     catch( const Exception& )
     282             :     {
     283             :         OSL_FAIL( "TypeDetectionExporter::addLocaleProperty exception catched!" );
     284             :     }
     285           0 : }
     286             : 
     287             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10