diff options
Diffstat (limited to 'writerfilter/unocomponent/debugservices')
15 files changed, 2277 insertions, 0 deletions
diff --git a/writerfilter/unocomponent/debugservices/doctok/DocTokAnalyzeService.cxx b/writerfilter/unocomponent/debugservices/doctok/DocTokAnalyzeService.cxx new file mode 100644 index 000000000000..5ba20a706547 --- /dev/null +++ b/writerfilter/unocomponent/debugservices/doctok/DocTokAnalyzeService.cxx @@ -0,0 +1,296 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "DocTokAnalyzeService.hxx" +#include <stdio.h> +#include <wchar.h> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/task/XStatusIndicator.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <ucbhelper/contentbroker.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <osl/process.h> +#include <rtl/string.hxx> +#include <boost/unordered_set.hpp> +#include <assert.h> +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <comphelper/storagehelper.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <comphelper/seqstream.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/container/XNameContainer.hpp> +#include <resourcemodel/WW8ResourceModel.hxx> +#include <resourcemodel/exceptions.hxx> +#include <doctok/WW8Document.hxx> + +#include <ctype.h> + +using namespace ::com::sun::star; + +namespace writerfilter { namespace doctoktest { + +const sal_Char AnalyzeService::SERVICE_NAME[40] = "debugservices.doctok.AnalyzeService"; +const sal_Char AnalyzeService::IMPLEMENTATION_NAME[40] = "debugservices.doctok.AnalyzeService"; + +class URLLister +{ + uno::Reference<io::XInputStream> xInputStream; + rtl::OUString mString; + rtl::OUString mCRLF; + rtl::OUString mLF; + + sal_uInt32 getEOLIndex() + { + sal_Int32 nIndex = mString.indexOf(mCRLF); + + if (nIndex == -1) + { + nIndex = mString.indexOf(mLF); + } + + return nIndex; + } + +public: + URLLister(uno::Reference<com::sun::star::uno::XComponentContext> xContext, + uno::Reference<lang::XMultiComponentFactory> xFactory, + rtl::OUString absFileUrl) + { + uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess + (xFactory->createInstanceWithContext + (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM + ("com.sun.star.ucb.SimpleFileAccess")), + xContext), uno::UNO_QUERY_THROW); + xInputStream = xFileAccess->openFileRead(absFileUrl) ; + + mLF = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n")); + mCRLF = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\r\n")); + } + + rtl::OUString getURL() + { + rtl::OUString aResult; + + sal_Int32 nIndex = getEOLIndex(); + + while (nIndex == -1) + { + uno::Sequence<sal_Int8> aSeq; + sal_uInt32 nCount = xInputStream->readBytes(aSeq, 1024); + + if (nCount > 0) + { + rtl_String * pNew = 0; + rtl_string_newFromStr_WithLength + (&pNew, reinterpret_cast<const sal_Char *>(&aSeq[0]), + nCount); + + rtl::OString aTmp(pNew); + rtl::OUString aTail(rtl::OStringToOUString + (aTmp, RTL_TEXTENCODING_ASCII_US)); + mString = mString.concat(aTail); + } + + nIndex = getEOLIndex(); + + if (nCount != 1024) + break; + } + + if (nIndex > 0) + { + aResult = mString.copy(0, nIndex); + + if (mString.match(mCRLF, nIndex)) + mString = mString.copy(nIndex + 2); + else + mString = mString.copy(nIndex + 1); + } + + return aResult; + } +}; + +AnalyzeService::AnalyzeService(const uno::Reference< uno::XComponentContext > &xContext_) : +xContext( xContext_ ) +{ +} + +sal_Int32 SAL_CALL AnalyzeService::run +( const uno::Sequence< rtl::OUString >& aArguments ) + throw (uno::RuntimeException) +{ + uno::Sequence<uno::Any> aUcbInitSequence(2); + aUcbInitSequence[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local")); + aUcbInitSequence[1] <<= + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office")); + uno::Reference<lang::XMultiServiceFactory> + xServiceFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW); + uno::Reference<lang::XMultiComponentFactory> + xFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + + if (::ucbhelper::ContentBroker::initialize(xServiceFactory, aUcbInitSequence)) + { + rtl::OUString arg=aArguments[0]; + + rtl_uString *dir=NULL; + osl_getProcessWorkingDir(&dir); + + rtl::OUString absFileUrlUrls; + osl_getAbsoluteFileURL(dir, arg.pData, &absFileUrlUrls.pData); + + URLLister aLister(xContext, xFactory, absFileUrlUrls); + + fprintf(stdout, "<analyze>\n"); + + rtl::OUString aURL = aLister.getURL(); + + while (aURL.getLength() > 0) + { + uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess + (xFactory->createInstanceWithContext + (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM + ("com.sun.star.ucb.SimpleFileAccess")), + xContext), uno::UNO_QUERY_THROW ); + + rtl::OString aStr; + aURL.convertToString(&aStr, RTL_TEXTENCODING_ASCII_US, + OUSTRING_TO_OSTRING_CVTFLAGS); + + fprintf(stdout, "<file><name>%s</name>\n", aStr.getStr()); + fprintf(stderr, "%s\n", aStr.getStr()); + fflush(stderr); + + bool bStatus = true; + try + { + try + { + uno::Reference<io::XInputStream> xInputStream = + xFileAccess->openFileRead(aURL); + { + doctok::WW8Stream::Pointer_t pDocStream = + doctok::WW8DocumentFactory::createStream + (xContext, xInputStream); + + if (pDocStream.get() != NULL) + { + doctok::WW8Document::Pointer_t pDocument + (doctok::WW8DocumentFactory::createDocument + (pDocStream)); + + Stream::Pointer_t pAnalyzer = + writerfilter::createAnalyzer(); + pDocument->resolve(*pAnalyzer); + } + else + { + fprintf(stdout, + "<exception>file open failed</exception>\n"); + bStatus = false; + } + fprintf(stderr, "done\n"); + } + + xInputStream->closeInput(); + } + catch (Exception e) + { + fprintf(stdout, "<exception>%s</exception>\n", + e.getText().c_str()); + bStatus = false; + } + } + catch (...) + { + fprintf(stdout, "<exception>unknown</exception>\n"); + bStatus = false; + } + + if (bStatus) + fprintf(stdout, "<status>ok</status>\n"); + else + fprintf(stdout, "<status>failed</status>\n"); + + aURL = aLister.getURL(); + + fprintf(stdout, "</file>\n"); + fflush(stdout); + } + + fprintf(stdout, "</analyze>\n"); + + rtl_uString_release(dir); + ::ucbhelper::ContentBroker::deinitialize(); + + + } + else + { + fprintf(stdout, "can't initialize UCB"); + } + return 0; +} + +::rtl::OUString AnalyzeService_getImplementationName () +{ + return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( AnalyzeService::IMPLEMENTATION_NAME )); +} + +sal_Bool SAL_CALL AnalyzeService_supportsService( const ::rtl::OUString& ServiceName ) +{ + return ServiceName.equals( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( AnalyzeService::SERVICE_NAME )) ); +} +uno::Sequence< rtl::OUString > SAL_CALL AnalyzeService_getSupportedServiceNames( ) throw (uno::RuntimeException) +{ + uno::Sequence < rtl::OUString > aRet(1); + rtl::OUString* pArray = aRet.getArray(); + pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( AnalyzeService::SERVICE_NAME )); + return aRet; +} + +uno::Reference< uno::XInterface > SAL_CALL AnalyzeService_createInstance( const uno::Reference< uno::XComponentContext > & xContext) throw( uno::Exception ) +{ + return (cppu::OWeakObject*) new AnalyzeService( xContext ); +} + +} } /* end namespace writerfilter::doctok */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/doctok/DocTokAnalyzeService.hxx b/writerfilter/unocomponent/debugservices/doctok/DocTokAnalyzeService.hxx new file mode 100644 index 000000000000..eb471b85a221 --- /dev/null +++ b/writerfilter/unocomponent/debugservices/doctok/DocTokAnalyzeService.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_DOCTOK_ANALYZESERVICE_HXX +#define INCLUDED_DOCTOK_ANALYZESERVICE_HXX + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/lang/XMain.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +namespace writerfilter { namespace doctoktest { + +class AnalyzeService : public cppu::WeakImplHelper1 < ::com::sun::star::lang::XMain > +{ +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext; + +public: + AnalyzeService(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext); + + virtual ::sal_Int32 SAL_CALL run( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aArguments ) throw (::com::sun::star::uno::RuntimeException); + +public: + const static sal_Char SERVICE_NAME[40]; + const static sal_Char IMPLEMENTATION_NAME[40]; + +}; + +::rtl::OUString AnalyzeService_getImplementationName (); +sal_Bool SAL_CALL AnalyzeService_supportsService( const ::rtl::OUString& ServiceName ); +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL AnalyzeService_getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL AnalyzeService_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext) throw( ::com::sun::star::uno::Exception ); + +} } /* end namespace writerfilter::rtftok */ + +#define DOCTOK_ANALYZESERVICE_COMPONENT_ENTRY \ +{\ + writerfilter::doctoktest::AnalyzeService_createInstance,\ + writerfilter::doctoktest::AnalyzeService_getImplementationName,\ + writerfilter::doctoktest::AnalyzeService_getSupportedServiceNames,\ + ::cppu::createSingleComponentFactory,\ + 0, 0\ +} + + +#endif /* INCLUDED_RTFTOK_ANALYZESERVICE_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/doctok/DocTokTestService.cxx b/writerfilter/unocomponent/debugservices/doctok/DocTokTestService.cxx new file mode 100644 index 000000000000..926a9dcf9c8a --- /dev/null +++ b/writerfilter/unocomponent/debugservices/doctok/DocTokTestService.cxx @@ -0,0 +1,152 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "DocTokTestService.hxx" +#include <stdio.h> +#include <wchar.h> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/task/XStatusIndicator.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <ucbhelper/contentbroker.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <osl/process.h> +#include <rtl/string.hxx> +#include <boost/unordered_set.hpp> +#include <assert.h> +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <comphelper/storagehelper.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <comphelper/seqstream.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/container/XNameContainer.hpp> +#include <resourcemodel/WW8ResourceModel.hxx> +#include <resourcemodel/exceptions.hxx> +#include <doctok/WW8Document.hxx> + +#include <ctype.h> + +using namespace ::com::sun::star; + +namespace writerfilter { namespace doctoktest { + +const sal_Char ScannerTestService::SERVICE_NAME[40] = "debugservices.doctok.ScannerTestService"; +const sal_Char ScannerTestService::IMPLEMENTATION_NAME[40] = "debugservices.doctok.ScannerTestService"; + + + + +ScannerTestService::ScannerTestService(const uno::Reference< uno::XComponentContext > &xContext_) : +xContext( xContext_ ) +{ +} + +sal_Int32 SAL_CALL ScannerTestService::run( const uno::Sequence< rtl::OUString >& aArguments ) throw (uno::RuntimeException) +{ + uno::Sequence<uno::Any> aUcbInitSequence(2); + aUcbInitSequence[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local")); + aUcbInitSequence[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office")); + uno::Reference<lang::XMultiServiceFactory> xServiceFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW); + uno::Reference<lang::XMultiComponentFactory> xFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + if (::ucbhelper::ContentBroker::initialize(xServiceFactory, aUcbInitSequence)) + { + rtl::OUString arg=aArguments[0]; + + uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess( + xFactory->createInstanceWithContext( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess")), + xContext), uno::UNO_QUERY_THROW ); + + rtl_uString *dir=NULL; + osl_getProcessWorkingDir(&dir); + rtl::OUString absFileUrl; + osl_getAbsoluteFileURL(dir, arg.pData, &absFileUrl.pData); + rtl_uString_release(dir); + + uno::Reference<io::XInputStream> xInputStream = xFileAccess->openFileRead(absFileUrl); + doctok::WW8Stream::Pointer_t pDocStream = doctok::WW8DocumentFactory::createStream(xContext, xInputStream); + + doctok::WW8Document::Pointer_t pDocument(doctok::WW8DocumentFactory::createDocument(pDocStream)); + +#if 0 + TimeValue t1; osl_getSystemTime(&t1); +#endif + + Stream::Pointer_t pStream = createStreamHandler(); + pDocument->resolve(*pStream); + +#if 0 + TimeValue t2; osl_getSystemTime(&t2); + printf("time=%is\n", t2.Seconds-t1.Seconds); +#endif + + ::ucbhelper::ContentBroker::deinitialize(); + } + else + { + fprintf(stderr, "can't initialize UCB"); + } + return 0; +} + +::rtl::OUString ScannerTestService_getImplementationName () +{ + return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( ScannerTestService::IMPLEMENTATION_NAME )); +} + +sal_Bool SAL_CALL ScannerTestService_supportsService( const ::rtl::OUString& ServiceName ) +{ + return ServiceName.equals( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ScannerTestService::SERVICE_NAME )) ); +} +uno::Sequence< rtl::OUString > SAL_CALL ScannerTestService_getSupportedServiceNames( ) throw (uno::RuntimeException) +{ + uno::Sequence < rtl::OUString > aRet(1); + rtl::OUString* pArray = aRet.getArray(); + pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( ScannerTestService::SERVICE_NAME )); + return aRet; +} + +uno::Reference< uno::XInterface > SAL_CALL ScannerTestService_createInstance( const uno::Reference< uno::XComponentContext > & xContext) throw( uno::Exception ) +{ + return (cppu::OWeakObject*) new ScannerTestService( xContext ); +} + +} } /* end namespace writerfilter::doctok */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/doctok/DocTokTestService.hxx b/writerfilter/unocomponent/debugservices/doctok/DocTokTestService.hxx new file mode 100644 index 000000000000..cbdc8b46d6bd --- /dev/null +++ b/writerfilter/unocomponent/debugservices/doctok/DocTokTestService.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_DOCTOK_SCANNERTESTSERVICE_HXX +#define INCLUDED_DOCTOK_SCANNERTESTSERVICE_HXX + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/lang/XMain.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +namespace writerfilter { namespace doctoktest { + +class ScannerTestService : public cppu::WeakImplHelper1 < ::com::sun::star::lang::XMain > +{ +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext; + +public: + ScannerTestService(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext); + + virtual ::sal_Int32 SAL_CALL run( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aArguments ) throw (::com::sun::star::uno::RuntimeException); + +public: + const static sal_Char SERVICE_NAME[40]; + const static sal_Char IMPLEMENTATION_NAME[40]; + +}; + +::rtl::OUString ScannerTestService_getImplementationName (); +sal_Bool SAL_CALL ScannerTestService_supportsService( const ::rtl::OUString& ServiceName ); +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL ScannerTestService_getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL ScannerTestService_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext) throw( ::com::sun::star::uno::Exception ); + +} } /* end namespace writerfilter::rtftok */ + +#define DOCTOK_SCANNERTESTSERVICE_COMPONENT_ENTRY \ +{\ + writerfilter::doctoktest::ScannerTestService_createInstance,\ + writerfilter::doctoktest::ScannerTestService_getImplementationName,\ + writerfilter::doctoktest::ScannerTestService_getSupportedServiceNames,\ + ::cppu::createSingleComponentFactory,\ + 0, 0\ +} + + +#endif /* INCLUDED_RTFTOK_SCANNERTESTSERVICE_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/doctok/makefile.mk b/writerfilter/unocomponent/debugservices/doctok/makefile.mk new file mode 100644 index 000000000000..989be1baa3de --- /dev/null +++ b/writerfilter/unocomponent/debugservices/doctok/makefile.mk @@ -0,0 +1,44 @@ +#************************************************************************ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +# ***********************************************************************/ +PRJ=..$/..$/.. +PRJNAME=writerfilter +TARGET=debugservices_doctok +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/DocTokTestService.obj \ + $(SLO)$/DocTokAnalyzeService.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/writerfilter/unocomponent/debugservices/ooxml/OOXMLAnalyzeService.cxx b/writerfilter/unocomponent/debugservices/ooxml/OOXMLAnalyzeService.cxx new file mode 100644 index 000000000000..d002ff39ddad --- /dev/null +++ b/writerfilter/unocomponent/debugservices/ooxml/OOXMLAnalyzeService.cxx @@ -0,0 +1,294 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <comphelper/processfactory.hxx> + +#include "OOXMLAnalyzeService.hxx" +#include <stdio.h> +#include <wchar.h> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/task/XStatusIndicator.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <ucbhelper/contentbroker.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <osl/process.h> +#include <rtl/string.hxx> +#include <boost/unordered_set.hpp> +#include <assert.h> +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <comphelper/storagehelper.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <comphelper/seqstream.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/container/XNameContainer.hpp> +#include <resourcemodel/WW8ResourceModel.hxx> +#include <ooxml/OOXMLDocument.hxx> + +#include <ctype.h> + +using namespace ::com::sun::star; + +namespace writerfilter { namespace ooxmltest { + +const sal_Char AnalyzeService::SERVICE_NAME[40] = "debugservices.ooxml.AnalyzeService"; +const sal_Char AnalyzeService::IMPLEMENTATION_NAME[40] = "debugservices.ooxml.AnalyzeService"; + +class URLLister +{ + uno::Reference<io::XInputStream> xInputStream; + rtl::OUString mString; + rtl::OUString mCRLF; + rtl::OUString mLF; + + sal_uInt32 getEOLIndex() + { + sal_Int32 nIndex = mString.indexOf(mCRLF); + + if (nIndex == -1) + { + nIndex = mString.indexOf(mLF); + } + + return nIndex; + } + +public: + URLLister(uno::Reference<com::sun::star::uno::XComponentContext> xContext, + uno::Reference<lang::XMultiComponentFactory> xFactory, + rtl::OUString absFileUrl) + { + uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess + (xFactory->createInstanceWithContext + (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM + ("com.sun.star.ucb.SimpleFileAccess")), + xContext), uno::UNO_QUERY_THROW); + xInputStream = xFileAccess->openFileRead(absFileUrl) ; + + mLF = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n")); + mCRLF = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\r\n")); + } + + rtl::OUString getURL() + { + rtl::OUString aResult; + + sal_Int32 nIndex = getEOLIndex(); + + while (nIndex == -1) + { + uno::Sequence<sal_Int8> aSeq; + sal_uInt32 nCount = xInputStream->readBytes(aSeq, 1024); + + if (nCount > 0) + { + rtl_String * pNew = 0; + rtl_string_newFromStr_WithLength + (&pNew, reinterpret_cast<const sal_Char *>(&aSeq[0]), + nCount); + + rtl::OString aTmp(pNew); + rtl::OUString aTail(rtl::OStringToOUString + (aTmp, RTL_TEXTENCODING_ASCII_US)); + mString = mString.concat(aTail); + } + + nIndex = getEOLIndex(); + + if (nCount != 1024) + break; + } + + if (nIndex > 0) + { + aResult = mString.copy(0, nIndex); + + if (mString.match(mCRLF, nIndex)) + mString = mString.copy(nIndex + 2); + else + mString = mString.copy(nIndex + 1); + } + + return aResult; + } +}; + +AnalyzeService::AnalyzeService(const uno::Reference< uno::XComponentContext > &xContext_) : +xContext( xContext_ ) +{ +} + +sal_Int32 SAL_CALL AnalyzeService::run +( const uno::Sequence< rtl::OUString >& aArguments ) + throw (uno::RuntimeException) +{ + uno::Sequence<uno::Any> aUcbInitSequence(2); + aUcbInitSequence[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local")); + aUcbInitSequence[1] <<= + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office")); + uno::Reference<lang::XMultiServiceFactory> + xServiceFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW); + uno::Reference<lang::XMultiComponentFactory> + xFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + + if (::ucbhelper::ContentBroker::initialize(xServiceFactory, aUcbInitSequence)) + { + ::comphelper::setProcessServiceFactory(xServiceFactory); + + rtl::OUString arg=aArguments[0]; + + rtl_uString *dir=NULL; + osl_getProcessWorkingDir(&dir); + + rtl::OUString absFileUrlUrls; + osl_getAbsoluteFileURL(dir, arg.pData, &absFileUrlUrls.pData); + + URLLister aLister(xContext, xFactory, absFileUrlUrls); + + fprintf(stdout, "<analyze>\n"); + + writerfilter::analyzerIds(); + + rtl::OUString aURL = aLister.getURL(); + + while (aURL.getLength() > 0) + { + uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess + (xFactory->createInstanceWithContext + (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM + ("com.sun.star.ucb.SimpleFileAccess")), + xContext), uno::UNO_QUERY_THROW ); + + rtl::OString aStr; + aURL.convertToString(&aStr, RTL_TEXTENCODING_ASCII_US, + OUSTRING_TO_OSTRING_CVTFLAGS); + + fprintf(stdout, "<file><name>%s</name>\n", aStr.getStr()); + fprintf(stderr, "%s\n", aStr.getStr()); + fflush(stderr); + + bool bStatus = true; + try + { + uno::Reference<io::XInputStream> xInputStream = + xFileAccess->openFileRead(aURL); + + if (xInputStream.is()) + { + ooxml::OOXMLStream::Pointer_t pDocStream = + ooxml::OOXMLDocumentFactory::createStream + (xContext, xInputStream); + + if (pDocStream.get() != NULL) + { + ooxml::OOXMLDocument::Pointer_t pDocument + (ooxml::OOXMLDocumentFactory::createDocument + (pDocStream)); + + Stream::Pointer_t pAnalyzer = + writerfilter::createAnalyzer(); + pDocument->resolve(*pAnalyzer); + } + else + { + fprintf(stdout, + "<exception>file open failed</exception>\n"); + bStatus = false; + } + fprintf(stderr, "done\n"); + } + + xInputStream->closeInput(); + } + catch (...) + { + fprintf(stdout, "<exception>unknown</exception>\n"); + bStatus = false; + } + + if (bStatus) + fprintf(stdout, "<status>ok</status>\n"); + else + fprintf(stdout, "<status>failed</status>\n"); + + aURL = aLister.getURL(); + + fprintf(stdout, "</file>\n"); + fflush(stdout); + } + + fprintf(stdout, "</analyze>\n"); + + rtl_uString_release(dir); + ::ucbhelper::ContentBroker::deinitialize(); + + + } + else + { + fprintf(stdout, "can't initialize UCB"); + } + return 0; +} + +::rtl::OUString AnalyzeService_getImplementationName () +{ + return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( AnalyzeService::IMPLEMENTATION_NAME )); +} + +sal_Bool SAL_CALL AnalyzeService_supportsService( const ::rtl::OUString& ServiceName ) +{ + return ServiceName.equals( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( AnalyzeService::SERVICE_NAME )) ); +} +uno::Sequence< rtl::OUString > SAL_CALL AnalyzeService_getSupportedServiceNames( ) throw (uno::RuntimeException) +{ + uno::Sequence < rtl::OUString > aRet(1); + rtl::OUString* pArray = aRet.getArray(); + pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( AnalyzeService::SERVICE_NAME )); + return aRet; +} + +uno::Reference< uno::XInterface > SAL_CALL AnalyzeService_createInstance( const uno::Reference< uno::XComponentContext > & xContext) throw( uno::Exception ) +{ + return (cppu::OWeakObject*) new AnalyzeService( xContext ); +} + +} } /* end namespace writerfilter::doctok */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/ooxml/OOXMLAnalyzeService.hxx b/writerfilter/unocomponent/debugservices/ooxml/OOXMLAnalyzeService.hxx new file mode 100644 index 000000000000..055a0571b357 --- /dev/null +++ b/writerfilter/unocomponent/debugservices/ooxml/OOXMLAnalyzeService.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_OOXML_ANALYZE_SERVICE_HXX +#define INCLUDED_OOXML_ANALYZE_SERVICE_HXX + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/lang/XMain.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +namespace writerfilter { namespace ooxmltest { + +class AnalyzeService : public cppu::WeakImplHelper1 < ::com::sun::star::lang::XMain > +{ +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext; + +public: + AnalyzeService(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext); + + virtual ::sal_Int32 SAL_CALL run( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aArguments ) throw (::com::sun::star::uno::RuntimeException); + +public: + const static sal_Char SERVICE_NAME[40]; + const static sal_Char IMPLEMENTATION_NAME[40]; + +}; + +::rtl::OUString AnalyzeService_getImplementationName (); +sal_Bool SAL_CALL AnalyzeService_supportsService( const ::rtl::OUString& ServiceName ); +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL AnalyzeService_getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL AnalyzeService_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext) throw( ::com::sun::star::uno::Exception ); + +} } /* end namespace writerfilter::rtftok */ + +#define OOXML_ANALYZESERVICE_COMPONENT_ENTRY \ +{\ + writerfilter::ooxmltest::AnalyzeService_createInstance,\ + writerfilter::ooxmltest::AnalyzeService_getImplementationName,\ + writerfilter::ooxmltest::AnalyzeService_getSupportedServiceNames,\ + ::cppu::createSingleComponentFactory,\ + 0, 0\ +} + + +#endif /* INCLUDED_OOXML_ANALYZE_SERVICE_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/ooxml/OOXMLTestService.cxx b/writerfilter/unocomponent/debugservices/ooxml/OOXMLTestService.cxx new file mode 100644 index 000000000000..45d3fe86abd1 --- /dev/null +++ b/writerfilter/unocomponent/debugservices/ooxml/OOXMLTestService.cxx @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/lang/XMain.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <comphelper/processfactory.hxx> + +#include "OOXMLTestService.hxx" +#include <stdio.h> +#include <wchar.h> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/task/XStatusIndicator.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <ucbhelper/contentbroker.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <osl/process.h> +#include <rtl/string.hxx> +#include <boost/unordered_set.hpp> +#include <assert.h> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/bootstrap.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <comphelper/storagehelper.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <comphelper/seqstream.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <ooxml/OOXMLDocument.hxx> +#include <resourcemodel/TagLogger.hxx> + +#include <ctype.h> + +using namespace ::com::sun::star; + +namespace writerfilter { namespace ooxmltest { + +const sal_Char ScannerTestService::SERVICE_NAME[40] = "debugservices.ooxml.ScannerTestService"; +const sal_Char ScannerTestService::IMPLEMENTATION_NAME[40] = "debugservices.ooxml.ScannerTestService"; + + + + +ScannerTestService::ScannerTestService(const uno::Reference< uno::XComponentContext > &xContext_) : +xContext( xContext_ ) +{ +} + +sal_Int32 SAL_CALL ScannerTestService::run( const uno::Sequence< rtl::OUString >& aArguments ) throw (uno::RuntimeException) +{ + uno::Sequence<uno::Any> aUcbInitSequence(2); + aUcbInitSequence[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local")); + aUcbInitSequence[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office")); + uno::Reference<lang::XMultiServiceFactory> xServiceFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW); + uno::Reference<lang::XMultiComponentFactory> xFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + if (::ucbhelper::ContentBroker::initialize(xServiceFactory, aUcbInitSequence)) + { +#ifdef DEBUG_ELEMENT + writerfilter::TagLogger::Pointer_t debugLogger + (writerfilter::TagLogger::getInstance("DEBUG")); + debugLogger->startDocument(); +#endif + + rtl::OUString arg=aArguments[0]; + + ::comphelper::setProcessServiceFactory(xServiceFactory); + + uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess + (xFactory->createInstanceWithContext + (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM + ("com.sun.star.ucb.SimpleFileAccess")), + xContext), uno::UNO_QUERY_THROW ); + + rtl_uString *dir=NULL; + osl_getProcessWorkingDir(&dir); + rtl::OUString absFileUrl; + osl_getAbsoluteFileURL(dir, arg.pData, &absFileUrl.pData); + rtl_uString_release(dir); + + uno::Reference<io::XInputStream> xInputStream = + xFileAccess->openFileRead(absFileUrl); + ooxml::OOXMLStream::Pointer_t pDocStream = + ooxml::OOXMLDocumentFactory::createStream(xContext, xInputStream); + + ooxml::OOXMLDocument::Pointer_t pDocument + (ooxml::OOXMLDocumentFactory::createDocument(pDocStream)); + +#if 0 + uno::Reference<text::XTextDocument> xDocument + (xFactory->createInstanceWithContext + (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM + ("com.sun.star.text.TextDocument")), + xContext), uno::UNO_QUERY_THROW ); + uno::Reference<frame::XModel> xModel + (xDocument, uno::UNO_QUERY_THROW); + + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier + (xDocument, uno::UNO_QUERY_THROW); + uno::Reference<drawing::XShapes> xShapes + (xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW); + + pDocument->setModel(xModel); + pDocument->setShapes(xShapes); +#endif + + Stream::Pointer_t pStream = createStreamHandler(); + pDocument->resolve(*pStream); + +#ifdef DEBUG_ELEMENT + debugLogger->endDocument(); +#endif + + ::ucbhelper::ContentBroker::deinitialize(); + } + else + { + fprintf(stderr, "can't initialize UCB"); + } + return 0; +} + +::rtl::OUString ScannerTestService_getImplementationName () +{ + return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( ScannerTestService::IMPLEMENTATION_NAME )); +} + +sal_Bool SAL_CALL ScannerTestService_supportsService( const ::rtl::OUString& ServiceName ) +{ + return ServiceName.equals( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ScannerTestService::SERVICE_NAME )) ); +} +uno::Sequence< rtl::OUString > SAL_CALL ScannerTestService_getSupportedServiceNames( ) throw (uno::RuntimeException) +{ + uno::Sequence < rtl::OUString > aRet(1); + rtl::OUString* pArray = aRet.getArray(); + pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( ScannerTestService::SERVICE_NAME )); + return aRet; +} + +uno::Reference< uno::XInterface > SAL_CALL ScannerTestService_createInstance( const uno::Reference< uno::XComponentContext > & xContext) throw( uno::Exception ) +{ + return (cppu::OWeakObject*) new ScannerTestService( xContext ); +} + +} } /* end namespace writerfilter::ooxml */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/ooxml/OOXMLTestService.hxx b/writerfilter/unocomponent/debugservices/ooxml/OOXMLTestService.hxx new file mode 100644 index 000000000000..ef4fe4506fd6 --- /dev/null +++ b/writerfilter/unocomponent/debugservices/ooxml/OOXMLTestService.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_OOXML_SCANNERTESTSERVICE_HXX +#define INCLUDED_OOXML_SCANNERTESTSERVICE_HXX + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/lang/XMain.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +namespace writerfilter { namespace ooxmltest { + +class ScannerTestService : public cppu::WeakImplHelper1 < ::com::sun::star::lang::XMain > +{ +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext; + +public: + ScannerTestService(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext); + + virtual ::sal_Int32 SAL_CALL run( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aArguments ) throw (::com::sun::star::uno::RuntimeException); + +public: + const static sal_Char SERVICE_NAME[40]; + const static sal_Char IMPLEMENTATION_NAME[40]; + +}; + +::rtl::OUString ScannerTestService_getImplementationName (); +sal_Bool SAL_CALL ScannerTestService_supportsService( const ::rtl::OUString& ServiceName ); +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL ScannerTestService_getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL ScannerTestService_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext) throw( ::com::sun::star::uno::Exception ); + +} } /* end namespace writerfilter::ooxml */ + +#define OOXML_SCANNERTESTSERVICE_COMPONENT_ENTRY \ +{\ + writerfilter::ooxmltest::ScannerTestService_createInstance,\ + writerfilter::ooxmltest::ScannerTestService_getImplementationName,\ + writerfilter::ooxmltest::ScannerTestService_getSupportedServiceNames,\ + ::cppu::createSingleComponentFactory,\ + 0, 0\ +} + + +#endif /* INCLUDED_OOXML_SCANNERTESTSERVICE_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/ooxml/makefile.mk b/writerfilter/unocomponent/debugservices/ooxml/makefile.mk new file mode 100644 index 000000000000..f7de799334f9 --- /dev/null +++ b/writerfilter/unocomponent/debugservices/ooxml/makefile.mk @@ -0,0 +1,59 @@ +#************************************************************************ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +# ***********************************************************************/ +PRJ=..$/..$/.. +PRJNAME=writerfilter +TARGET=debugservices_ooxml +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/inc$/writerfilter.mk + +.IF "$(GUI)"=="UNX" || "$(GUI)"=="MAC" +RESSOUREMODELLIB=-lresourcemodel +.ELIF "$(GUI)"=="WNT" +.IF "$(COM)"=="GCC" +RESOURCEMODELLIB=-lresourcemodel +.ELSE +RESOURCEMODELLIB=$(LB)$/iresourcemodel.lib +.ENDIF +.ENDIF + +SHL1STDLIBS= \ + $(COMPHELPERLIB) \ + $(RESOURCEMODELLIB) + +# --- Files -------------------------------------------------------- + +SLOFILES= \ + $(SLO)$/OOXMLTestService.obj \ + $(SLO)$/OOXMLAnalyzeService.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk diff --git a/writerfilter/unocomponent/debugservices/rtftok/ScannerTestService.cxx b/writerfilter/unocomponent/debugservices/rtftok/ScannerTestService.cxx new file mode 100644 index 000000000000..b4c977943935 --- /dev/null +++ b/writerfilter/unocomponent/debugservices/rtftok/ScannerTestService.cxx @@ -0,0 +1,429 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "ScannerTestService.hxx" +#include <stdio.h> +#include <string.h> +#include <wchar.h> +#include <rtftok/RTFScanner.hxx> +#include <rtftok/RTFScannerHandler.hxx> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/task/XStatusIndicator.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <ucbhelper/contentbroker.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <osl/process.h> +#include <rtl/string.hxx> +#include <boost/unordered_set.hpp> +#include <assert.h> +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <comphelper/storagehelper.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <comphelper/seqstream.hxx> + +#include <ctype.h> + +using namespace ::com::sun::star; + +namespace writerfilter { namespace rtftok { + +const sal_Char ScannerTestService::SERVICE_NAME[40] = "debugservices.rtftok.ScannerTestService"; +const sal_Char ScannerTestService::IMPLEMENTATION_NAME[40] = "debugservices.rtftok.ScannerTestService"; + +struct ScannerTestServiceHelper +{ + size_t operator()(const rtl::OString &str) const + { + return str.hashCode(); + } + bool operator()(const rtl::OString &str1, const rtl::OString &str2) const + { + return str1.compareTo(str2)==0; + } +}; + +typedef ::boost::unordered_set< ::rtl::OString, ScannerTestServiceHelper, ScannerTestServiceHelper > ScannerTestServiceTokenMap; + +class MyRtfScannerHandler : public writerfilter::rtftok::RTFScannerHandler +{ + ScannerTestServiceTokenMap destMap; + ScannerTestServiceTokenMap ctrlMap; + std::vector<unsigned char> binBuffer; + int objDataLevel; + int numOfOLEs; + unsigned char hb; + int numOfOLEChars; + uno::Reference<lang::XMultiServiceFactory> xServiceFactory; + uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess; + uno::Reference<embed::XStorage> xStorage; + + void dest(char* token, char* /*value*/) + { + destMap.insert(rtl::OString(token)); + if (strcmp(token, "objdata")==0) + { + binBuffer.clear(); + objDataLevel=1; + numOfOLEChars=0; + } + } + void ctrl(char*token, char* /*value*/) + { + ctrlMap.insert(rtl::OString(token)); + } + void lbrace(void) + { + } + void rbrace(void) + { +#ifndef LINUX + unsigned char * binBufferStr = ((unsigned char*)&(*binBuffer.begin())); + + if (objDataLevel) + { + int o=0; + unsigned int type=((unsigned int)binBuffer[o]) | ((unsigned int)binBuffer[o+1])<<8 | ((unsigned int)binBuffer[o+2])<<16 | ((unsigned int)binBuffer[o+3]<<24); o+=4; + unsigned int recType=((unsigned int)binBuffer[o]) | ((unsigned int)binBuffer[o+1])<<8 | ((unsigned int)binBuffer[o+2])<<16 | ((unsigned int)binBuffer[o+3]<<24); o+=4; + unsigned int strLen=((unsigned int)binBuffer[o]) | ((unsigned int)binBuffer[o+1])<<8 | ((unsigned int)binBuffer[o+2])<<16 | ((unsigned int)binBuffer[o+3]<<24); o+=4; + unsigned char *str=binBufferStr+o; + o+=strLen; + o+=4; // dummy1 + o+=4; // dummy2 + unsigned int binLen=((unsigned int)binBuffer[o]) | ((unsigned int)binBuffer[o+1])<<8 | ((unsigned int)binBuffer[o+2])<<16 | ((unsigned int)binBuffer[o+3]<<24); o+=4; + printf("OLE%i \"%s\" type=%i recType=%i binBuffer.size()=%u len=%u\n", numOfOLEs, str, type, recType, (unsigned int)(binBuffer.size()), o+binLen); + char buf[100]; + sprintf(buf, "ole%02i.ole", numOfOLEs); + + comphelper::ByteSequence seq(binLen); + unsigned char *data0=binBufferStr; + memcpy(seq.getArray(), data0+o, binLen); + uno::Reference<io::XInputStream> myStream=new comphelper::SequenceInputStream(seq); + uno::Sequence< uno::Any > aArgs0( 1 ); + aArgs0[0] <<= myStream; + uno::Reference< container::XNameContainer > xNameContainer( + xServiceFactory->createInstanceWithArguments( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.OLESimpleStorage")), + aArgs0 ), + uno::UNO_QUERY_THROW ); + try { + printf("TRY\n"); + ::com::sun::star::uno::Sequence< ::rtl::OUString > names=xNameContainer->getElementNames(); + printf("OK\n"); + + for(int i=0;i<names.getLength();i++) + { + rtl::OUString &name=names[i]; + wprintf(L"name=%s\n", name.getStr()); + } + { + uno::Reference< io::XStream > xContentStream = xStorage->openStreamElement( + rtl::OUString::createFromAscii(buf), embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); + uno::Reference<beans::XPropertySet> xContentStreamPropSet(xContentStream, uno::UNO_QUERY_THROW); + xContentStreamPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType")), uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.oleobject")))); + uno::Reference<io::XOutputStream> myOutStream=xContentStream->getOutputStream(); + uno::Sequence< ::sal_Int8 > seq1(binLen); + unsigned char *data1=binBufferStr; + memcpy(seq1.getArray(), data1+o, binLen); + myOutStream->writeBytes(seq1); + myOutStream->closeOutput(); + } + + } catch(com::sun::star::uno::RuntimeException &) + { + printf("NOT OK\n"); + comphelper::ByteSequence seq2(4+binLen); + seq2[0]= sal::static_int_cast<sal_Int8>(binLen&0xFF); + seq2[1]= sal::static_int_cast<sal_Int8>((binLen>>8)&0xFF); + seq2[2]= sal::static_int_cast<sal_Int8>((binLen>>16)&0xFF); + seq2[3]= sal::static_int_cast<sal_Int8>((binLen>>24)&0xFF); + unsigned char *data2=binBufferStr; + memcpy(seq2.getArray()+4, data2+o, binLen); + uno::Reference<io::XInputStream> myInStream=new comphelper::SequenceInputStream(seq2); + printf("SEQ OK\n"); + + uno::Reference< io::XStream > xContentStream = xStorage->openStreamElement( + rtl::OUString::createFromAscii(buf), embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); + uno::Reference<beans::XPropertySet> xContentStreamPropSet(xContentStream, uno::UNO_QUERY_THROW); + xContentStreamPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType")), uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("application/vnd.sun.star.oleobject")))); + printf("CONTENT STREAM OK\n"); + + uno::Sequence< uno::Any > aArgs1( 1 ); + aArgs1[0] <<= xContentStream; + uno::Reference< container::XNameContainer > xNameContainer2( + xServiceFactory->createInstanceWithArguments( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.OLESimpleStorage")), + aArgs1 ), + uno::UNO_QUERY_THROW ); + printf("OLE STORAGE OK\n"); + + uno::Any anyStream; + anyStream <<= myInStream; + xNameContainer2->insertByName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\1Ole10Native")), anyStream); + printf("INSERT OK\n"); + + uno::Reference<embed::XTransactedObject> xTransact(xNameContainer2, uno::UNO_QUERY); + xTransact->commit(); + } + objDataLevel--; + numOfOLEs++; + } +#endif + } + void addSpaces(int /*count*/) + { + } + void addBinData(unsigned char /*data*/) + { + } + void addChar(char ch) + { + if (objDataLevel) + { + if (numOfOLEChars%2==0) + { + char c=sal::static_int_cast<char>(toupper(ch)); + assert((c<='F' && c>='A') || (c<='9' && c>='0')); + if(c>='A') hb=(unsigned char)(c-'A'+10); else hb=(unsigned char)(c-'0'); + } + else + { + unsigned char lb; + char c=sal::static_int_cast<char>(toupper(ch)); + assert((c<='F' && c>='A') || (c<='9' && c>='0')); + if(c>='A') lb=(unsigned char)(c-'A'+10); else lb=(unsigned char)(c-'0'); + unsigned char r=(hb<<4)|lb; + binBuffer.push_back(r); + } + numOfOLEChars++; + } + } + void addCharU(sal_Unicode /*ch*/) + { + } + void addHexChar(char* /*hexch*/) + { + } + + +public: + MyRtfScannerHandler(uno::Reference<lang::XMultiServiceFactory> &xServiceFactory_, uno::Reference<com::sun::star::ucb::XSimpleFileAccess> &xFileAccess_, uno::Reference<embed::XStorage> &xStorage_) : + objDataLevel(0), numOfOLEs(0), + xServiceFactory(xServiceFactory_), + xFileAccess(xFileAccess_), + xStorage(xStorage_) + { + } + + virtual ~MyRtfScannerHandler() {} + + void dump() + { + printf("Destinations:\n"); + for(ScannerTestServiceTokenMap::iterator i=destMap.begin();i!=destMap.end();i++) + { + printf(" %s\n", i->getStr()); + } + printf("Ctrls:\n"); + for(ScannerTestServiceTokenMap::iterator i=ctrlMap.begin();i!=ctrlMap.end();i++) + { + printf(" %s\n", i->getStr()); + } + } +}; + +class RtfInputSourceImpl : public rtftok::RTFInputSource +{ +private: + uno::Reference< io::XInputStream > xInputStream; + uno::Reference< io::XSeekable > xSeekable; + uno::Reference< task::XStatusIndicator > xStatusIndicator; + sal_Int64 bytesTotal; + sal_Int64 bytesRead; +public: + RtfInputSourceImpl(uno::Reference< io::XInputStream > &xInputStream_, uno::Reference< task::XStatusIndicator > &xStatusIndicator_) : + xInputStream(xInputStream_), + xStatusIndicator(xStatusIndicator_), + bytesRead(0) + { + xSeekable=uno::Reference< io::XSeekable >(xInputStream, uno::UNO_QUERY); + if (xSeekable.is()) + bytesTotal=xSeekable->getLength(); + if (xStatusIndicator.is() && xSeekable.is()) + { + xStatusIndicator->start(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Converting")), 100); + } + } + + virtual ~RtfInputSourceImpl() {} + + int read(void *buf, int maxlen) + { + uno::Sequence< sal_Int8 > buffer; + int len=xInputStream->readSomeBytes(buffer,maxlen); + if (len>0) + { + sal_Int8 *_buffer=buffer.getArray(); + memcpy(buf, _buffer, len); + bytesRead+=len; + if (xStatusIndicator.is()) + { + if (xSeekable.is()) + { + xStatusIndicator->setValue((int)(bytesRead*100/bytesTotal)); + } + else + { + char buf1[100]; + sprintf(buf1, "Converted %" SAL_PRIdINT64 " KB", bytesRead/1024); + xStatusIndicator->start(::rtl::OUString::createFromAscii(buf1), 0); + } + } + return len; + } + else + { + if (xStatusIndicator.is()) + { + xStatusIndicator->end(); + } + return 0; + } + } +}; + +ScannerTestService::ScannerTestService(const uno::Reference< uno::XComponentContext > &xContext_) : +xContext( xContext_ ) +{ +} + +sal_Int32 SAL_CALL ScannerTestService::run( const uno::Sequence< rtl::OUString >& aArguments ) throw (uno::RuntimeException) +{ + + printf("TEST\n"); + + uno::Sequence<uno::Any> aUcbInitSequence(2); + aUcbInitSequence[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local")); + aUcbInitSequence[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office")); + uno::Reference<lang::XMultiServiceFactory> xServiceFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW); + printf("A\n"); + uno::Reference<lang::XMultiComponentFactory> xFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + printf("B\n"); + if (::ucbhelper::ContentBroker::initialize(xServiceFactory, aUcbInitSequence)) + { + printf("C\n"); + rtl::OUString arg=aArguments[0]; + + uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess( + xFactory->createInstanceWithContext( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess")), + xContext), uno::UNO_QUERY_THROW ); + + rtl_uString *dir=NULL; + osl_getProcessWorkingDir(&dir); + rtl::OUString absFileUrl; + osl_getAbsoluteFileURL(dir, arg.pData, &absFileUrl.pData); + rtl_uString_release(dir); + + uno::Reference <lang::XSingleServiceFactory> xStorageFactory( + xServiceFactory->createInstance (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.StorageFactory"))), uno::UNO_QUERY_THROW); + + rtl::OUString outFileUrl; + { + rtl_uString *dir1=NULL; + osl_getProcessWorkingDir(&dir1); + osl_getAbsoluteFileURL(dir1, aArguments[1].pData, &outFileUrl.pData); + rtl_uString_release(dir1); + } + + uno::Sequence< uno::Any > aArgs2( 2 ); + aArgs2[0] <<= outFileUrl; + aArgs2[1] <<= embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE; + uno::Reference<embed::XStorage> xStorage(xStorageFactory->createInstanceWithArguments(aArgs2), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xStorage, uno::UNO_QUERY_THROW); + xPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType")), uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("application/vnd.oasis.opendocument.text")))); + uno::Reference<io::XInputStream> xInputStream = xFileAccess->openFileRead(absFileUrl); + uno::Reference< task::XStatusIndicator > xStatusIndicator; + + TimeValue t1; osl_getSystemTime(&t1); + + RtfInputSourceImpl rtfInputSource(xInputStream, xStatusIndicator); + MyRtfScannerHandler eventHandler(xServiceFactory, xFileAccess, xStorage); + writerfilter::rtftok::RTFScanner *rtfScanner=writerfilter::rtftok::RTFScanner::createRTFScanner(rtfInputSource, eventHandler); + + rtfScanner->yylex(); + delete rtfScanner; + + TimeValue t2; osl_getSystemTime(&t2); + printf("time=%" SAL_PRIuUINT32 "s\n", t2.Seconds-t1.Seconds); + + uno::Reference<embed::XTransactedObject> xTransact(xStorage, uno::UNO_QUERY); + xTransact->commit(); + + + ::ucbhelper::ContentBroker::deinitialize(); + } + else + { + fprintf(stderr, "can't initialize UCB"); + } + return 0; +} + +::rtl::OUString ScannerTestService_getImplementationName () +{ + return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( ScannerTestService::IMPLEMENTATION_NAME )); +} + +sal_Bool SAL_CALL ScannerTestService_supportsService( const ::rtl::OUString& ServiceName ) +{ + return ServiceName.equals( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ScannerTestService::SERVICE_NAME )) ); +} +uno::Sequence< rtl::OUString > SAL_CALL ScannerTestService_getSupportedServiceNames( ) throw (uno::RuntimeException) +{ + uno::Sequence < rtl::OUString > aRet(1); + rtl::OUString* pArray = aRet.getArray(); + pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( ScannerTestService::SERVICE_NAME )); + return aRet; +} + +uno::Reference< uno::XInterface > SAL_CALL ScannerTestService_createInstance( const uno::Reference< uno::XComponentContext > & xContext) throw( uno::Exception ) +{ + return (cppu::OWeakObject*) new ScannerTestService( xContext ); +} + +} } /* end namespace writerfilter::rtftok */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/rtftok/ScannerTestService.hxx b/writerfilter/unocomponent/debugservices/rtftok/ScannerTestService.hxx new file mode 100644 index 000000000000..ab9c35ba4d3d --- /dev/null +++ b/writerfilter/unocomponent/debugservices/rtftok/ScannerTestService.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_RTFTOK_SCANNERTESTSERVICE_HXX +#define INCLUDED_RTFTOK_SCANNERTESTSERVICE_HXX + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/lang/XMain.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +namespace writerfilter { namespace rtftok { + +class ScannerTestService : public cppu::WeakImplHelper1 < ::com::sun::star::lang::XMain > +{ +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext; + +public: + ScannerTestService(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext); + + virtual ::sal_Int32 SAL_CALL run( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aArguments ) throw (::com::sun::star::uno::RuntimeException); + +public: + const static sal_Char SERVICE_NAME[40]; + const static sal_Char IMPLEMENTATION_NAME[40]; + +}; + +::rtl::OUString ScannerTestService_getImplementationName (); +sal_Bool SAL_CALL ScannerTestService_supportsService( const ::rtl::OUString& ServiceName ); +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL ScannerTestService_getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL ScannerTestService_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext) throw( ::com::sun::star::uno::Exception ); + +} } /* end namespace writerfilter::rtftok */ + +#define RTFTOK_SCANNERTESTSERVICE_COMPONENT_ENTRY \ +{\ + writerfilter::rtftok::ScannerTestService_createInstance,\ + writerfilter::rtftok::ScannerTestService_getImplementationName,\ + writerfilter::rtftok::ScannerTestService_getSupportedServiceNames,\ + ::cppu::createSingleComponentFactory,\ + 0, 0\ +} + + +#endif /* INCLUDED_RTFTOK_SCANNERTESTSERVICE_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/rtftok/XMLScanner.cxx b/writerfilter/unocomponent/debugservices/rtftok/XMLScanner.cxx new file mode 100644 index 000000000000..8214dc240ffa --- /dev/null +++ b/writerfilter/unocomponent/debugservices/rtftok/XMLScanner.cxx @@ -0,0 +1,336 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "XMLScanner.hxx" +#include <stdio.h> +#include <string.h> +#include <wchar.h> +#include <rtftok/RTFScanner.hxx> +#include <rtftok/RTFScannerHandler.hxx> +#include <com/sun/star/io/XStream.hpp> +#include <com/sun/star/io/XInputStream.hpp> +#include <com/sun/star/io/XSeekable.hpp> +#include <com/sun/star/io/XTruncate.hpp> +#include <com/sun/star/task/XStatusIndicator.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <ucbhelper/contentbroker.hxx> +#include <com/sun/star/ucb/XSimpleFileAccess.hpp> +#include <osl/process.h> +#include <rtl/string.hxx> +#include <boost/unordered_set.hpp> +#include <assert.h> +#include <string> +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <comphelper/storagehelper.hxx> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <comphelper/seqstream.hxx> + +#include <ctype.h> +#include <iostream> + +using namespace ::com::sun::star; +using namespace ::std; + +namespace writerfilter { namespace rtftok { + +const sal_Char XMLScanner::SERVICE_NAME[40] = "debugservices.rtftok.XMLScanner"; +const sal_Char XMLScanner::IMPLEMENTATION_NAME[40] = "debugservices.rtftok.XMLScanner"; + +class XmlRtfScannerHandler : public writerfilter::rtftok::RTFScannerHandler +{ + std::vector<unsigned char> binBuffer; + int objDataLevel; + int numOfOLEs; + unsigned char hb; + int numOfOLEChars; + uno::Reference<lang::XMultiServiceFactory> xServiceFactory; + uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess; + string charBuffer; + string ucharBuffer; + vector<string> vCloseTags; + + void xmlout(const string & str) + { + for (size_t n = 0; n < str.length(); ++n) + { + char c = str[n]; + + switch (c) + { + case '<': cout << "<"; break; + case '>': cout << ">"; break; + case '&': cout << "&"; break; + default: + cout << c; + + break; + } + } + } + + void clearBuffers() + { + if (charBuffer.length() > 0) + { + cout << "<text>"; + xmlout(charBuffer); + cout << "</text>" << endl; + } + + charBuffer = ""; + + if (ucharBuffer.length() > 0) + { + cout << "<utext>"; + xmlout(ucharBuffer); + cout << ucharBuffer << "</utext>" << endl; + } + + ucharBuffer = ""; + } + + void dest(char* token, char* value) + { + clearBuffers(); + cout << "<dest name=\"" << token << "\" value=\""<< value << "\">" << endl; + vCloseTags.push_back("</dest>"); + } + void ctrl(char*token, char* value) + { + clearBuffers(); + cout << "<" << token << ">" << value << "</" << token << ">" + << endl; + } + void lbrace(void) + { + clearBuffers(); + cout << "<brace>" << endl; + vCloseTags.push_back("</brace>"); + } + void rbrace(void) + { + clearBuffers(); + cout << vCloseTags.back() << endl; + vCloseTags.pop_back(); + } + void addSpaces(int count) + { + clearBuffers(); + cout << "<spaces count=\"" << count << "\"/>" << endl; + } + void addBinData(unsigned char /*data*/) + { + clearBuffers(); + cout << "<bindata/>" << endl; + } + void addChar(char ch) + { + charBuffer += ch; + } + void addCharU(sal_Unicode ch) + { + ucharBuffer += sal_Char(ch < 128 ? ch : '.'); + } + void addHexChar(char* hexch) + { + clearBuffers(); + cout << "<hexchar value=\"" << hexch << "\"/>" << endl; + } + +public: + XmlRtfScannerHandler(uno::Reference<lang::XMultiServiceFactory> &xServiceFactory_, uno::Reference<com::sun::star::ucb::XSimpleFileAccess> &xFileAccess_) : + objDataLevel(0), numOfOLEs(0), + xServiceFactory(xServiceFactory_), + xFileAccess(xFileAccess_) + { + } + + virtual ~XmlRtfScannerHandler() {} + + void dump() + { + } +}; + +class RtfInputSourceImpl : public rtftok::RTFInputSource +{ +private: + uno::Reference< io::XInputStream > xInputStream; + uno::Reference< io::XSeekable > xSeekable; + uno::Reference< task::XStatusIndicator > xStatusIndicator; + sal_Int64 bytesTotal; + sal_Int64 bytesRead; +public: + RtfInputSourceImpl(uno::Reference< io::XInputStream > &xInputStream_, uno::Reference< task::XStatusIndicator > &xStatusIndicator_) : + xInputStream(xInputStream_), + xStatusIndicator(xStatusIndicator_), + bytesRead(0) + { + xSeekable=uno::Reference< io::XSeekable >(xInputStream, uno::UNO_QUERY); + if (xSeekable.is()) + bytesTotal=xSeekable->getLength(); + if (xStatusIndicator.is() && xSeekable.is()) + { + xStatusIndicator->start(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Converting")), 100); + } + } + + virtual ~RtfInputSourceImpl() {} + + int read(void *buf, int maxlen) + { + uno::Sequence< sal_Int8 > buffer; + int len=xInputStream->readSomeBytes(buffer,maxlen); + if (len>0) + { + sal_Int8 *_buffer=buffer.getArray(); + memcpy(buf, _buffer, len); + bytesRead+=len; + if (xStatusIndicator.is()) + { + if (xSeekable.is()) + { + xStatusIndicator->setValue((int)(bytesRead*100/bytesTotal)); + } + else + { + char buf1[100]; + sprintf(buf1, "Converted %" SAL_PRIdINT64 " KB", bytesRead/1024); + xStatusIndicator->start(::rtl::OUString::createFromAscii(buf1), 0); + } + } + return len; + } + else + { + if (xStatusIndicator.is()) + { + xStatusIndicator->end(); + } + return 0; + } + } +}; + +XMLScanner::XMLScanner(const uno::Reference< uno::XComponentContext > &xContext_) : +xContext( xContext_ ) +{ +} + +sal_Int32 SAL_CALL XMLScanner::run( const uno::Sequence< rtl::OUString >& aArguments ) throw (uno::RuntimeException) +{ + uno::Sequence<uno::Any> aUcbInitSequence(2); + aUcbInitSequence[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local")); + aUcbInitSequence[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office")); + uno::Reference<lang::XMultiServiceFactory> xServiceFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW); + uno::Reference<lang::XMultiComponentFactory> xFactory(xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + if (::ucbhelper::ContentBroker::initialize(xServiceFactory, aUcbInitSequence)) + { + rtl::OUString arg=aArguments[0]; + + uno::Reference<com::sun::star::ucb::XSimpleFileAccess> xFileAccess( + xFactory->createInstanceWithContext( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess")), + xContext), uno::UNO_QUERY_THROW ); + + rtl_uString *dir=NULL; + osl_getProcessWorkingDir(&dir); + rtl::OUString absFileUrl; + osl_getAbsoluteFileURL(dir, arg.pData, &absFileUrl.pData); + rtl_uString_release(dir); + + uno::Reference <lang::XSingleServiceFactory> xStorageFactory( + xServiceFactory->createInstance (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.StorageFactory"))), uno::UNO_QUERY_THROW); + +#if 0 + rtl::OUString outFileUrl; + { + rtl_uString *dir1=NULL; + osl_getProcessWorkingDir(&dir1); + osl_getAbsoluteFileURL(dir1, aArguments[1].pData, &outFileUrl.pData); + rtl_uString_release(dir1); + } + + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[0] <<= outFileUrl; + aArgs[1] <<= embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE; + uno::Reference<embed::XStorage> xStorage(xStorageFactory->createInstanceWithArguments(aArgs), uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xStorage, uno::UNO_QUERY_THROW); + xPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType")), uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("application/vnd.oasis.opendocument.text")))); +#endif + uno::Reference<io::XInputStream> xInputStream = xFileAccess->openFileRead(absFileUrl); + uno::Reference< task::XStatusIndicator > xStatusIndicator; + + RtfInputSourceImpl rtfInputSource(xInputStream, xStatusIndicator); + XmlRtfScannerHandler eventHandler(xServiceFactory, xFileAccess); + writerfilter::rtftok::RTFScanner *rtfScanner=writerfilter::rtftok::RTFScanner::createRTFScanner(rtfInputSource, eventHandler); + + cout << "<out>" << endl; + rtfScanner->yylex(); + cout << "</out>" << endl; + delete rtfScanner; + + ::ucbhelper::ContentBroker::deinitialize(); + } + else + { + fprintf(stderr, "can't initialize UCB"); + } + return 0; +} + +::rtl::OUString XMLScanner_getImplementationName () +{ + return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( XMLScanner::IMPLEMENTATION_NAME )); +} + +sal_Bool SAL_CALL XMLScanner_supportsService( const ::rtl::OUString& ServiceName ) +{ + return ServiceName.equals( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( XMLScanner::SERVICE_NAME )) ); +} +uno::Sequence< rtl::OUString > SAL_CALL XMLScanner_getSupportedServiceNames( ) throw (uno::RuntimeException) +{ + uno::Sequence < rtl::OUString > aRet(1); + rtl::OUString* pArray = aRet.getArray(); + pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM ( XMLScanner::SERVICE_NAME )); + return aRet; +} + +uno::Reference< uno::XInterface > SAL_CALL XMLScanner_createInstance( const uno::Reference< uno::XComponentContext > & xContext) throw( uno::Exception ) +{ + return (cppu::OWeakObject*) new XMLScanner( xContext ); +} + +} } /* end namespace writerfilter::rtftok */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/rtftok/XMLScanner.hxx b/writerfilter/unocomponent/debugservices/rtftok/XMLScanner.hxx new file mode 100644 index 000000000000..3da1c69d3828 --- /dev/null +++ b/writerfilter/unocomponent/debugservices/rtftok/XMLScanner.hxx @@ -0,0 +1,73 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_RTFTOK_XMLSCANNER_HXX +#define INCLUDED_RTFTOK_XMLSCANNER_HXX + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/lang/XMain.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +namespace writerfilter { namespace rtftok { + +class XMLScanner : public cppu::WeakImplHelper1 < ::com::sun::star::lang::XMain > +{ +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext; + +public: + XMLScanner(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext); + + virtual ::sal_Int32 SAL_CALL run( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aArguments ) throw (::com::sun::star::uno::RuntimeException); + +public: + const static sal_Char SERVICE_NAME[40]; + const static sal_Char IMPLEMENTATION_NAME[40]; + +}; + +::rtl::OUString XMLScanner_getImplementationName (); +sal_Bool SAL_CALL XMLScanner_supportsService( const ::rtl::OUString& ServiceName ); +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL XMLScanner_getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException); +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL XMLScanner_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > &xContext) throw( ::com::sun::star::uno::Exception ); + +} } /* end namespace writerfilter::rtftok */ + +#define RTFTOK_XMLSCANNER_COMPONENT_ENTRY \ +{\ + writerfilter::rtftok::XMLScanner_createInstance,\ + writerfilter::rtftok::XMLScanner_getImplementationName,\ + writerfilter::rtftok::XMLScanner_getSupportedServiceNames,\ + ::cppu::createSingleComponentFactory,\ + 0, 0\ +} + + +#endif /* INCLUDED_RTFTOK_SCANNERTESTSERVICE_HXX */ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/unocomponent/debugservices/rtftok/makefile.mk b/writerfilter/unocomponent/debugservices/rtftok/makefile.mk new file mode 100644 index 000000000000..66c54a8707cd --- /dev/null +++ b/writerfilter/unocomponent/debugservices/rtftok/makefile.mk @@ -0,0 +1,45 @@ +#************************************************************************ +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +# ***********************************************************************/ +PRJ=..$/..$/.. +PRJNAME=writerfilter +TARGET=debugservices_rtftok +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# --- Files -------------------------------------------------------- + +SLOFILES=\ + $(SLO)$/ScannerTestService.obj \ + $(SLO)$/XMLScanner.obj +#$(SLO)$/TestService.obj $(SLO)$/ResolverTestService.obj $(SLO)$/XmlParserTestService.obj $(SLO)$/RngService.obj + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk |