LCOV - code coverage report
Current view: top level - filter/source/xsltdialog - typedetectionexport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 169 0.0 %
Date: 2012-08-25 Functions: 0 5 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      31                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      32                 :            : #include <com/sun/star/io/XActiveDataSource.hpp>
      33                 :            : #include <tools/urlobj.hxx>
      34                 :            : 
      35                 :            : #include "typedetectionexport.hxx"
      36                 :            : #include "xmlfiltersettingsdialog.hxx"
      37                 :            : 
      38                 :            : #include <comphelper/attributelist.hxx>
      39                 :            : 
      40                 :            : using namespace com::sun::star::beans;
      41                 :            : using namespace com::sun::star::uno;
      42                 :            : using namespace com::sun::star::io;
      43                 :            : using namespace com::sun::star::lang;
      44                 :            : using namespace com::sun::star::xml::sax;
      45                 :            : 
      46                 :            : using ::rtl::OUString;
      47                 :            : 
      48                 :          0 : TypeDetectionExporter::TypeDetectionExporter( Reference< XMultiServiceFactory >& xMSF )
      49                 :          0 : : mxMSF( xMSF )
      50                 :            : {
      51                 :          0 : }
      52                 :            : 
      53                 :          0 : static OUString createRelativeURL( const OUString& rFilterName, const OUString& rURL )
      54                 :            : {
      55                 :          0 :     if( !rURL.isEmpty() &&
      56                 :          0 :         (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("http:") ) != 0) &&
      57                 :          0 :         (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("shttp:") ) != 0) &&
      58                 :          0 :         (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("jar:") ) != 0) &&
      59                 :          0 :         (rURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("ftp:") ) != 0))
      60                 :            :     {
      61                 :          0 :         INetURLObject aURL( rURL );
      62                 :          0 :         OUString aName( aURL.GetName() );
      63                 :          0 :         if( aName.isEmpty() )
      64                 :            :         {
      65                 :          0 :             sal_Int32 nPos = rURL.lastIndexOf( sal_Unicode( '/' ) );
      66                 :          0 :             if( nPos == -1 )
      67                 :            :             {
      68                 :          0 :                 aName = rURL;
      69                 :            :             }
      70                 :            :             else
      71                 :            :             {
      72                 :          0 :                 aName = rURL.copy( nPos + 1 );
      73                 :            :             }
      74                 :            :         }
      75                 :            : 
      76                 :          0 :         OUString aRelURL( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package:" ) );
      77                 :          0 :         aRelURL += rFilterName;
      78                 :          0 :         aRelURL += OUString( sal_Unicode( '/' ) );
      79                 :          0 :         aRelURL += aName;
      80                 :          0 :         return aRelURL;
      81                 :            :     }
      82                 :            :     else
      83                 :            :     {
      84                 :          0 :         return rURL;
      85                 :            :     }
      86                 :            : }
      87                 :            : 
      88                 :          0 : void TypeDetectionExporter::doExport( Reference< XOutputStream > xOS,  const XMLFilterVector& rFilters )
      89                 :            : {
      90                 :            :     try
      91                 :            :     {
      92                 :          0 :         const OUString sComponentData       ( RTL_CONSTASCII_USTRINGPARAM ( "oor:component-data" ) );
      93                 :          0 :         const OUString sNode                ( RTL_CONSTASCII_USTRINGPARAM ( "node" ) );
      94                 :          0 :         const OUString sName                ( RTL_CONSTASCII_USTRINGPARAM ( "oor:name" ) );
      95                 :          0 :         const OUString sWhiteSpace          ( RTL_CONSTASCII_USTRINGPARAM ( " " ) );
      96                 :          0 :         const OUString sUIName              ( RTL_CONSTASCII_USTRINGPARAM ( "UIName" ) );
      97                 :          0 :         const OUString sComma               ( RTL_CONSTASCII_USTRINGPARAM ( "," ) );
      98                 :          0 :         const OUString sDelim               ( RTL_CONSTASCII_USTRINGPARAM ( ";" ) );
      99                 :          0 :         const OUString sData                ( RTL_CONSTASCII_USTRINGPARAM ( "Data" ) );
     100                 :          0 :         const OUString sDocTypePrefix       ( RTL_CONSTASCII_USTRINGPARAM ( "doctype:" ) );
     101                 :          0 :         const OUString sFilterAdaptorService( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.XmlFilterAdaptor" ) );
     102                 :          0 :         const OUString sXSLTFilterService   ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.documentconversion.XSLTFilter" ) );
     103                 :          0 :         const OUString sCdataAttribute      ( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) );
     104                 :            : 
     105                 :            : 
     106                 :            :         // set up sax writer and connect to given output stream
     107                 :          0 :         Reference< XDocumentHandler > xHandler( mxMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ) ) ), UNO_QUERY );
     108                 :          0 :         Reference< XActiveDataSource > xDocSrc( xHandler, UNO_QUERY );
     109                 :          0 :         xDocSrc->setOutputStream( xOS );
     110                 :            : 
     111                 :          0 :         ::comphelper::AttributeList * pAttrList = new ::comphelper::AttributeList;
     112                 :          0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "xmlns:oor" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "http://openoffice.org/2001/registry" )) );
     113                 :          0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "xmlns:xs" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "http://www.w3.org/2001/XMLSchema" )) );
     114                 :          0 :         pAttrList->AddAttribute ( sName, sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "TypeDetection" )) );
     115                 :          0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "oor:package" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Office" )) );
     116                 :          0 :         Reference < XAttributeList > xAttrList (pAttrList);
     117                 :            : 
     118                 :          0 :         xHandler->startDocument();
     119                 :          0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     120                 :          0 :         xHandler->startElement( sComponentData, xAttrList );
     121                 :            : 
     122                 :            :         // export types
     123                 :            :         {
     124                 :          0 :             xAttrList = pAttrList = new ::comphelper::AttributeList;
     125                 :          0 :             pAttrList->AddAttribute ( sName, sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "Types" )) );
     126                 :          0 :             xHandler->ignorableWhitespace ( sWhiteSpace );
     127                 :          0 :             xHandler->startElement( sNode, xAttrList );
     128                 :            : 
     129                 :          0 :             XMLFilterVector::const_iterator aIter( rFilters.begin() );
     130                 :          0 :             while( aIter != rFilters.end() )
     131                 :            :             {
     132                 :          0 :                 const filter_info_impl* pFilter = (*aIter);
     133                 :            : 
     134                 :          0 :                 xAttrList = pAttrList = new ::comphelper::AttributeList;
     135                 :          0 :                 pAttrList->AddAttribute( sName, sCdataAttribute, pFilter->maType );
     136                 :          0 :                 xHandler->ignorableWhitespace ( sWhiteSpace );
     137                 :          0 :                 xHandler->startElement( sNode, xAttrList );
     138                 :          0 :                 OUString sValue( sal_Unicode('0') );
     139                 :          0 :                 sValue += sComma;
     140                 :          0 :                 sValue += sComma;
     141                 :          0 :                 if( !pFilter->maDocType.isEmpty() )
     142                 :            :                 {
     143                 :          0 :                     sValue += sDocTypePrefix;
     144                 :          0 :                     sValue += pFilter->maDocType;
     145                 :            :                 }
     146                 :          0 :                 sValue += sComma;
     147                 :          0 :                 sValue += sComma;
     148                 :          0 :                 sValue += pFilter->maExtension;
     149                 :          0 :                 sValue += sComma;
     150                 :          0 :                 sValue += OUString::valueOf( pFilter->mnDocumentIconID );
     151                 :          0 :                 sValue += sComma;
     152                 :            : 
     153                 :          0 :                 addProperty( xHandler, sData, sValue );
     154                 :          0 :                 addLocaleProperty( xHandler, sUIName, pFilter->maInterfaceName );
     155                 :          0 :                 xHandler->ignorableWhitespace ( sWhiteSpace );
     156                 :          0 :                 xHandler->endElement( sNode );
     157                 :            : 
     158                 :          0 :                 ++aIter;
     159                 :          0 :             }
     160                 :            : 
     161                 :          0 :             xHandler->ignorableWhitespace ( sWhiteSpace );
     162                 :          0 :             xHandler->endElement( sNode );
     163                 :            :         }
     164                 :            : 
     165                 :            :         // export filters
     166                 :            :         {
     167                 :          0 :             xAttrList = pAttrList = new ::comphelper::AttributeList;
     168                 :          0 :             pAttrList->AddAttribute ( sName, sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "Filters" )) );
     169                 :          0 :             xHandler->ignorableWhitespace ( sWhiteSpace );
     170                 :          0 :             xHandler->startElement( sNode, xAttrList );
     171                 :            : 
     172                 :          0 :             XMLFilterVector::const_iterator aIter( rFilters.begin() );
     173                 :          0 :             while( aIter != rFilters.end() )
     174                 :            :             {
     175                 :          0 :                 const filter_info_impl* pFilter = (*aIter);
     176                 :            : 
     177                 :          0 :                 xAttrList = pAttrList = new ::comphelper::AttributeList;
     178                 :          0 :                 pAttrList->AddAttribute( sName, sCdataAttribute, pFilter->maFilterName );
     179                 :          0 :                 xHandler->ignorableWhitespace ( sWhiteSpace );
     180                 :          0 :                 xHandler->startElement( sNode, xAttrList );
     181                 :          0 :                 addLocaleProperty( xHandler, sUIName, pFilter->maInterfaceName );
     182                 :            : 
     183                 :          0 :                 OUString sValue( sal_Unicode('0') );
     184                 :          0 :                 sValue += sComma;
     185                 :          0 :                 sValue += pFilter->maType;
     186                 :            :                 sValue += sComma,
     187                 :          0 :                 sValue += pFilter->maDocumentService;
     188                 :            :                 sValue += sComma,
     189                 :          0 :                 sValue += sFilterAdaptorService;
     190                 :            :                 sValue += sComma,
     191                 :          0 :                 sValue += OUString::valueOf( pFilter->maFlags );
     192                 :          0 :                 sValue += sComma;
     193                 :          0 :                 sValue += sXSLTFilterService;
     194                 :          0 :                 sValue += sDelim;
     195                 :          0 :                 sValue += pFilter->maXSLTTransformerImpl;
     196                 :          0 :                 sValue += sDelim;
     197                 :            : 
     198                 :          0 :                 const application_info_impl* pAppInfo = getApplicationInfo( pFilter->maExportService );
     199                 :          0 :                 sValue += pAppInfo->maXMLImporter;
     200                 :          0 :                 sValue += sDelim;
     201                 :          0 :                 sValue += pAppInfo->maXMLExporter;
     202                 :          0 :                 sValue += sDelim;
     203                 :            : 
     204                 :          0 :                 sValue += createRelativeURL( pFilter->maFilterName, pFilter->maImportXSLT );
     205                 :          0 :                 sValue += sDelim;
     206                 :          0 :                 sValue += createRelativeURL( pFilter->maFilterName, pFilter->maExportXSLT );
     207                 :          0 :                 sValue += sDelim;
     208                 :          0 :                 sValue += createRelativeURL( pFilter->maFilterName, pFilter->maDTD );
     209                 :          0 :                 sValue += sDelim;
     210                 :          0 :                 sValue += pFilter->maComment;
     211                 :          0 :                 sValue += sComma;
     212                 :          0 :                 sValue += OUString( sal_Unicode('0') );
     213                 :          0 :                 sValue += sComma;
     214                 :          0 :                 sValue += createRelativeURL( pFilter->maFilterName, pFilter->maImportTemplate );
     215                 :          0 :                 addProperty( xHandler, sData, sValue );
     216                 :          0 :                 xHandler->ignorableWhitespace ( sWhiteSpace );
     217                 :          0 :                 xHandler->endElement( sNode );
     218                 :          0 :                 ++aIter;
     219                 :          0 :             }
     220                 :            : 
     221                 :          0 :             xHandler->endElement( sNode );
     222                 :            :         }
     223                 :            : 
     224                 :            :         // finish
     225                 :          0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     226                 :          0 :         xHandler->endElement( sComponentData );
     227                 :          0 :         xHandler->endDocument();
     228                 :            :     }
     229                 :          0 :     catch( const Exception& )
     230                 :            :     {
     231                 :            :         OSL_FAIL( "TypeDetectionExporter::doExport exception catched!" );
     232                 :            :     }
     233                 :          0 : }
     234                 :            : 
     235                 :          0 : void TypeDetectionExporter::addProperty( Reference< XDocumentHandler > xHandler, const OUString& rName, const OUString& rValue )
     236                 :            : {
     237                 :            :     try
     238                 :            :     {
     239                 :          0 :         const OUString sCdataAttribute( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) );
     240                 :          0 :         const OUString sProp( RTL_CONSTASCII_USTRINGPARAM( "prop" ) );
     241                 :          0 :         const OUString sValue( RTL_CONSTASCII_USTRINGPARAM( "value" ) );
     242                 :          0 :         const OUString sWhiteSpace          ( RTL_CONSTASCII_USTRINGPARAM ( " " ) );
     243                 :            : 
     244                 :          0 :         ::comphelper::AttributeList * pAttrList = new ::comphelper::AttributeList;
     245                 :          0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "oor:name" )), sCdataAttribute, rName );
     246                 :          0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "oor:type" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "xs:string" )) );
     247                 :          0 :         Reference < XAttributeList > xAttrList (pAttrList);
     248                 :            : 
     249                 :          0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     250                 :          0 :         xHandler->startElement( sProp, xAttrList );
     251                 :          0 :         xAttrList = NULL;
     252                 :          0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     253                 :          0 :         xHandler->startElement( sValue,xAttrList );
     254                 :          0 :         xHandler->characters( rValue );
     255                 :          0 :         xHandler->endElement( sValue );
     256                 :          0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     257                 :          0 :         xHandler->endElement( sProp );
     258                 :            :     }
     259                 :          0 :     catch( const Exception& )
     260                 :            :     {
     261                 :            :         OSL_FAIL( "TypeDetectionExporter::addProperty exception catched!" );
     262                 :            :     }
     263                 :          0 : }
     264                 :            : 
     265                 :          0 : void TypeDetectionExporter::addLocaleProperty( Reference< XDocumentHandler > xHandler, const OUString& rName, const OUString& rValue )
     266                 :            : {
     267                 :            :     try
     268                 :            :     {
     269                 :          0 :         const OUString sCdataAttribute( RTL_CONSTASCII_USTRINGPARAM( "CDATA" ) );
     270                 :          0 :         const OUString sProp( RTL_CONSTASCII_USTRINGPARAM( "prop" ) );
     271                 :          0 :         const OUString sValue( RTL_CONSTASCII_USTRINGPARAM( "value" ) );
     272                 :          0 :         const OUString sWhiteSpace          ( RTL_CONSTASCII_USTRINGPARAM ( " " ) );
     273                 :            : 
     274                 :          0 :         ::comphelper::AttributeList * pAttrList = new ::comphelper::AttributeList;
     275                 :          0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "oor:name" )), sCdataAttribute, rName );
     276                 :          0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "oor:type" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "xs:string" )) );
     277                 :          0 :         Reference < XAttributeList > xAttrList (pAttrList);
     278                 :            : 
     279                 :          0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     280                 :          0 :         xHandler->startElement( sProp, xAttrList );
     281                 :          0 :         xAttrList = pAttrList = new ::comphelper::AttributeList;
     282                 :          0 :         pAttrList->AddAttribute ( OUString( RTL_CONSTASCII_USTRINGPARAM( "xml:lang" )), sCdataAttribute, OUString( RTL_CONSTASCII_USTRINGPARAM( "en-US" )) );
     283                 :          0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     284                 :          0 :         xHandler->startElement( sValue, xAttrList );
     285                 :          0 :         xHandler->characters( rValue );
     286                 :          0 :         xHandler->endElement( sValue );
     287                 :          0 :         xHandler->ignorableWhitespace ( sWhiteSpace );
     288                 :          0 :         xHandler->endElement( sProp );
     289                 :            :     }
     290                 :          0 :     catch( const Exception& )
     291                 :            :     {
     292                 :            :         OSL_FAIL( "TypeDetectionExporter::addLocaleProperty exception catched!" );
     293                 :            :     }
     294                 :          0 : }
     295                 :            : 
     296                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10