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

Generated by: LCOV version 1.10