LCOV - code coverage report
Current view: top level - writerfilter/unocomponent/debugservices/ooxml - OOXMLAnalyzeService.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 101 0.0 %
Date: 2012-08-25 Functions: 0 12 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                 :            :  * 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 <comphelper/processfactory.hxx>
      21                 :            : 
      22                 :            : #include "OOXMLAnalyzeService.hxx"
      23                 :            : #include <stdio.h>
      24                 :            : #include <wchar.h>
      25                 :            : #include <com/sun/star/io/XStream.hpp>
      26                 :            : #include <com/sun/star/io/XInputStream.hpp>
      27                 :            : #include <com/sun/star/io/XSeekable.hpp>
      28                 :            : #include <com/sun/star/io/XTruncate.hpp>
      29                 :            : #include <com/sun/star/task/XStatusIndicator.hpp>
      30                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      31                 :            : #include <ucbhelper/contentbroker.hxx>
      32                 :            : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
      33                 :            : #include <com/sun/star/ucb/XSimpleFileAccess2.hpp>
      34                 :            : #include <osl/process.h>
      35                 :            : #include <rtl/string.hxx>
      36                 :            : #include <boost/unordered_set.hpp>
      37                 :            : #include <assert.h>
      38                 :            : #include <cppuhelper/implbase2.hxx>
      39                 :            : #include <com/sun/star/embed/XTransactedObject.hpp>
      40                 :            : #include <com/sun/star/embed/XStorage.hpp>
      41                 :            : #include <com/sun/star/util/XCloseable.hpp>
      42                 :            : #include <comphelper/storagehelper.hxx>
      43                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      44                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      45                 :            : #include <comphelper/seqstream.hxx>
      46                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      47                 :            : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      48                 :            : #include <com/sun/star/uno/Any.hxx>
      49                 :            : #include <resourcemodel/WW8ResourceModel.hxx>
      50                 :            : #include <ooxml/OOXMLDocument.hxx>
      51                 :            : 
      52                 :            : #include <ctype.h>
      53                 :            : 
      54                 :            : using namespace ::com::sun::star;
      55                 :            : 
      56                 :            : namespace writerfilter { namespace ooxmltest  {
      57                 :            : 
      58                 :            : const sal_Char AnalyzeService::SERVICE_NAME[40] = "debugservices.ooxml.AnalyzeService";
      59                 :            : const sal_Char AnalyzeService::IMPLEMENTATION_NAME[40] = "debugservices.ooxml.AnalyzeService";
      60                 :            : 
      61                 :          0 : class URLLister
      62                 :            : {
      63                 :            :     uno::Reference<io::XInputStream> xInputStream;
      64                 :            :     OUString mString;
      65                 :            :     OUString mCRLF;
      66                 :            :     OUString mLF;
      67                 :            : 
      68                 :          0 :     sal_uInt32 getEOLIndex()
      69                 :            :     {
      70                 :          0 :         sal_Int32 nIndex = mString.indexOf(mCRLF);
      71                 :            : 
      72                 :          0 :         if (nIndex == -1)
      73                 :            :         {
      74                 :          0 :             nIndex = mString.indexOf(mLF);
      75                 :            :         }
      76                 :            : 
      77                 :          0 :         return nIndex;
      78                 :            :     }
      79                 :            : 
      80                 :            : public:
      81                 :          0 :     URLLister(uno::Reference<com::sun::star::uno::XComponentContext> xContext,
      82                 :            :               OUString absFileUrl)
      83                 :          0 :     {
      84                 :          0 :         uno::Reference<ucb::XSimpleFileAccess2> xFileAccess(ucb::SimpleFileAccess::create(xContext));
      85                 :          0 :         xInputStream = xFileAccess->openFileRead(absFileUrl) ;
      86                 :            : 
      87                 :          0 :         mLF = OUString("\n");
      88                 :          0 :         mCRLF = OUString("\r\n");
      89                 :          0 :     }
      90                 :            : 
      91                 :          0 :     OUString getURL()
      92                 :            :     {
      93                 :          0 :         OUString aResult;
      94                 :            : 
      95                 :          0 :         sal_Int32 nIndex = getEOLIndex();
      96                 :            : 
      97                 :          0 :         while (nIndex == -1)
      98                 :            :         {
      99                 :          0 :             uno::Sequence<sal_Int8> aSeq;
     100                 :          0 :             sal_uInt32 nCount = xInputStream->readBytes(aSeq, 1024);
     101                 :            : 
     102                 :          0 :             if (nCount > 0)
     103                 :            :             {
     104                 :          0 :                 rtl_String * pNew = 0;
     105                 :            :                 rtl_string_newFromStr_WithLength
     106                 :          0 :                     (&pNew, reinterpret_cast<const sal_Char *>(&aSeq[0]),
     107                 :          0 :                      nCount);
     108                 :            : 
     109                 :          0 :                 OString aTmp(pNew);
     110                 :            :                 OUString aTail(OStringToOUString
     111                 :          0 :                                     (aTmp, RTL_TEXTENCODING_ASCII_US));
     112                 :          0 :                 mString = mString.concat(aTail);
     113                 :            :             }
     114                 :            : 
     115                 :          0 :             nIndex = getEOLIndex();
     116                 :            : 
     117                 :          0 :             if (nCount != 1024)
     118                 :            :                 break;
     119                 :          0 :         }
     120                 :            : 
     121                 :          0 :         if (nIndex > 0)
     122                 :            :         {
     123                 :          0 :             aResult = mString.copy(0, nIndex);
     124                 :            : 
     125                 :          0 :             if (mString.match(mCRLF, nIndex))
     126                 :          0 :                 mString = mString.copy(nIndex + 2);
     127                 :            :             else
     128                 :          0 :                 mString = mString.copy(nIndex + 1);
     129                 :            :         }
     130                 :            : 
     131                 :          0 :         return aResult;
     132                 :            :     }
     133                 :            : };
     134                 :            : 
     135                 :          0 : AnalyzeService::AnalyzeService(const uno::Reference< uno::XComponentContext > &xContext_) :
     136                 :          0 : xContext( xContext_ )
     137                 :            : {
     138                 :          0 : }
     139                 :            : 
     140                 :          0 : sal_Int32 SAL_CALL AnalyzeService::run
     141                 :            : ( const uno::Sequence< OUString >& aArguments )
     142                 :            :     throw (uno::RuntimeException)
     143                 :            : {
     144                 :          0 :     uno::Sequence<uno::Any> aUcbInitSequence(2);
     145                 :          0 :     aUcbInitSequence[0] <<= OUString("Local");
     146                 :          0 :     aUcbInitSequence[1] <<= OUString("Office");
     147                 :            :     uno::Reference<lang::XMultiServiceFactory>
     148                 :          0 :         xServiceFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW);
     149                 :            :     uno::Reference<lang::XMultiComponentFactory>
     150                 :          0 :         xFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW );
     151                 :            : 
     152                 :          0 :     if (::ucbhelper::ContentBroker::initialize(xServiceFactory, aUcbInitSequence))
     153                 :            :     {
     154                 :          0 :         ::comphelper::setProcessServiceFactory(xServiceFactory);
     155                 :            : 
     156                 :          0 :         OUString arg=aArguments[0];
     157                 :            : 
     158                 :          0 :         rtl_uString *dir=NULL;
     159                 :          0 :         osl_getProcessWorkingDir(&dir);
     160                 :            : 
     161                 :          0 :         OUString absFileUrlUrls;
     162                 :          0 :         osl_getAbsoluteFileURL(dir, arg.pData, &absFileUrlUrls.pData);
     163                 :            : 
     164                 :          0 :         URLLister aLister(xContext, absFileUrlUrls);
     165                 :            : 
     166                 :          0 :         fprintf(stdout, "<analyze>\n");
     167                 :            : 
     168                 :          0 :         writerfilter::analyzerIds();
     169                 :            : 
     170                 :          0 :         OUString aURL = aLister.getURL();
     171                 :            : 
     172                 :          0 :         while (!aURL.isEmpty())
     173                 :            :         {
     174                 :          0 :             uno::Reference<ucb::XSimpleFileAccess2> xFileAccess(ucb::SimpleFileAccess::create(xContext));
     175                 :            : 
     176                 :          0 :             OString aStr;
     177                 :            :             aURL.convertToString(&aStr, RTL_TEXTENCODING_ASCII_US,
     178                 :          0 :                                  OUSTRING_TO_OSTRING_CVTFLAGS);
     179                 :            : 
     180                 :          0 :             fprintf(stdout, "<file><name>%s</name>\n", aStr.getStr());
     181                 :          0 :             fprintf(stderr, "%s\n", aStr.getStr());
     182                 :          0 :             fflush(stderr);
     183                 :            : 
     184                 :          0 :             bool bStatus = true;
     185                 :            :             try
     186                 :            :             {
     187                 :            :                 uno::Reference<io::XInputStream> xInputStream =
     188                 :          0 :                     xFileAccess->openFileRead(aURL);
     189                 :            : 
     190                 :          0 :                 if (xInputStream.is())
     191                 :            :                 {
     192                 :            :                     ooxml::OOXMLStream::Pointer_t pDocStream =
     193                 :            :                         ooxml::OOXMLDocumentFactory::createStream
     194                 :          0 :                         (xContext, xInputStream);
     195                 :            : 
     196                 :          0 :                     if (pDocStream.get() != NULL)
     197                 :            :                     {
     198                 :            :                         ooxml::OOXMLDocument::Pointer_t pDocument
     199                 :            :                             (ooxml::OOXMLDocumentFactory::createDocument
     200                 :          0 :                              (pDocStream));
     201                 :            : 
     202                 :            :                         Stream::Pointer_t pAnalyzer =
     203                 :          0 :                             writerfilter::createAnalyzer();
     204                 :          0 :                         pDocument->resolve(*pAnalyzer);
     205                 :            :                     }
     206                 :            :                     else
     207                 :            :                     {
     208                 :            :                         fprintf(stdout,
     209                 :          0 :                                 "<exception>file open failed</exception>\n");
     210                 :          0 :                         bStatus = false;
     211                 :            :                     }
     212                 :          0 :                     fprintf(stderr, "done\n");
     213                 :            :                 }
     214                 :            : 
     215                 :          0 :                 xInputStream->closeInput();
     216                 :            :             }
     217                 :          0 :             catch (...)
     218                 :            :             {
     219                 :          0 :                 fprintf(stdout, "<exception>unknown</exception>\n");
     220                 :          0 :                 bStatus = false;
     221                 :            :             }
     222                 :            : 
     223                 :          0 :             if (bStatus)
     224                 :          0 :                 fprintf(stdout, "<status>ok</status>\n");
     225                 :            :             else
     226                 :          0 :                 fprintf(stdout, "<status>failed</status>\n");
     227                 :            : 
     228                 :          0 :             aURL = aLister.getURL();
     229                 :            : 
     230                 :          0 :             fprintf(stdout, "</file>\n");
     231                 :          0 :             fflush(stdout);
     232                 :          0 :         }
     233                 :            : 
     234                 :          0 :         fprintf(stdout, "</analyze>\n");
     235                 :            : 
     236                 :          0 :         rtl_uString_release(dir);
     237                 :          0 :         ::ucbhelper::ContentBroker::deinitialize();
     238                 :            : 
     239                 :            : 
     240                 :            :     }
     241                 :            :     else
     242                 :            :     {
     243                 :          0 :         fprintf(stdout, "can't initialize UCB");
     244                 :            :     }
     245                 :          0 :     return 0;
     246                 :            : }
     247                 :            : 
     248                 :          0 : OUString AnalyzeService_getImplementationName ()
     249                 :            : {
     250                 :          0 :     return OUString(AnalyzeService::IMPLEMENTATION_NAME );
     251                 :            : }
     252                 :            : 
     253                 :          0 : sal_Bool SAL_CALL AnalyzeService_supportsService( const OUString& ServiceName )
     254                 :            : {
     255                 :          0 :     return ServiceName == AnalyzeService::SERVICE_NAME;
     256                 :            : }
     257                 :          0 : uno::Sequence< OUString > SAL_CALL AnalyzeService_getSupportedServiceNames(  ) throw (uno::RuntimeException)
     258                 :            : {
     259                 :          0 :     uno::Sequence < OUString > aRet(1);
     260                 :          0 :     OUString* pArray = aRet.getArray();
     261                 :          0 :     pArray[0] =  OUString(AnalyzeService::SERVICE_NAME );
     262                 :          0 :     return aRet;
     263                 :            : }
     264                 :            : 
     265                 :          0 : uno::Reference< uno::XInterface > SAL_CALL AnalyzeService_createInstance( const uno::Reference< uno::XComponentContext > & xContext) throw( uno::Exception )
     266                 :            : {
     267                 :          0 :     return (cppu::OWeakObject*) new AnalyzeService( xContext );
     268                 :            : }
     269                 :            : 
     270                 :          0 : } } /* end namespace writerfilter::doctok */
     271                 :            : 
     272                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10