diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-05-24 22:36:09 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-05-25 02:04:18 -0400 |
commit | a0b640bd1816bc464961c85eb2d1de405cd50d1c (patch) | |
tree | b13e360a6de9d00bb915940c94608721351caf5c /filter | |
parent | Patterns should precede extensions. (diff) | |
download | core-a0b640bd1816bc464961c85eb2d1de405cd50d1c.tar.gz core-a0b640bd1816bc464961c85eb2d1de405cd50d1c.zip |
Initial skeleton code for plain text filter detection service.
Right now it will always fail.
Change-Id: I50011bbf7ce59c3b299d23e688dd1af87bcafeb6
Diffstat (limited to 'filter')
-rw-r--r-- | filter/Module_filter.mk | 1 | ||||
-rw-r--r-- | filter/source/textfilterdetect/fdcomp.cxx | 72 | ||||
-rw-r--r-- | filter/source/textfilterdetect/filterdetect.cxx | 120 | ||||
-rw-r--r-- | filter/source/textfilterdetect/filterdetect.hxx | 83 | ||||
-rw-r--r-- | filter/source/textfilterdetect/textfd.component | 36 |
5 files changed, 312 insertions, 0 deletions
diff --git a/filter/Module_filter.mk b/filter/Module_filter.mk index 03f13e2379df..922d4f53e460 100644 --- a/filter/Module_filter.mk +++ b/filter/Module_filter.mk @@ -60,6 +60,7 @@ $(eval $(call gb_Module_add_targets,filter,\ Library_placeware \ Library_svgfilter \ Library_t602filter \ + Library_textfd \ Library_xmlfa \ Library_xmlfd \ Library_xsltdlg \ diff --git a/filter/source/textfilterdetect/fdcomp.cxx b/filter/source/textfilterdetect/fdcomp.cxx new file mode 100644 index 000000000000..6be78b323702 --- /dev/null +++ b/filter/source/textfilterdetect/fdcomp.cxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Kohei Yoshida <kohei.yoshida@suse.com> + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include <stdio.h> + +#include <osl/mutex.hxx> +#include <osl/thread.h> +#include <cppuhelper/factory.hxx> + +#include <com/sun/star/lang/XSingleServiceFactory.hpp> + +#include "filterdetect.hxx" + +using namespace ::cppu; +using namespace com::sun::star; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::registry; + +extern "C" { + +SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + const sal_Char* pImplName, void* pServiceManager, void* /* pRegistryKey */ ) +{ + void* pRet = NULL; + rtl::OUString implName = rtl::OUString::createFromAscii(pImplName); + if (pServiceManager && implName == PlainTextFilterDetect_getImplementationName()) + { + uno::Reference<lang::XSingleServiceFactory> xFactory( + createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + implName, + PlainTextFilterDetect_createInstance, PlainTextFilterDetect_getSupportedServiceNames())); + + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + } + + return pRet; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/textfilterdetect/filterdetect.cxx b/filter/source/textfilterdetect/filterdetect.cxx new file mode 100644 index 000000000000..55bfd0a5b223 --- /dev/null +++ b/filter/source/textfilterdetect/filterdetect.cxx @@ -0,0 +1,120 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Kohei Yoshida <kohei.yoshida@suse.com> + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include "filterdetect.hxx" +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +using namespace ::com::sun::star; + +PlainTextFilterDetect::PlainTextFilterDetect(const uno::Reference<lang::XMultiServiceFactory> &xMSF) : + mxMSF(xMSF) {} + +PlainTextFilterDetect::~PlainTextFilterDetect() {} + +rtl::OUString SAL_CALL PlainTextFilterDetect::detect(uno::Sequence<beans::PropertyValue>& aArguments) throw (uno::RuntimeException) +{ + return rtl::OUString(); +} + +// XInitialization + +void SAL_CALL PlainTextFilterDetect::initialize(const uno::Sequence<uno::Any>& aArguments) + throw (uno::Exception, uno::RuntimeException) +{ + uno::Sequence<beans::PropertyValue> aAnySeq; + sal_Int32 nLength = aArguments.getLength(); + if (nLength && (aArguments[0] >>= aAnySeq)) + { + const beans::PropertyValue * pValue = aAnySeq.getConstArray(); + for (sal_Int32 i = 0, n = aAnySeq.getLength(); i < n; ++i) + { + if (pValue[i].Name == "Type") + { + fprintf(stdout, "PlainTextFilterDetect::initialize: type = '%s'\n", + rtl::OUStringToOString(pValue[i].Value.get<rtl::OUString>(), RTL_TEXTENCODING_UTF8).getStr()); + } + else if (pValue[i].Name == "UserData") + { + fprintf(stdout, "PlainTextFilterDetect::initialize: user data = '%s'\n", + rtl::OUStringToOString(pValue[i].Value.get<rtl::OUString>(), RTL_TEXTENCODING_UTF8).getStr()); + } + else if (pValue[i].Name == "TemplateName") + { + fprintf(stdout, "PlainTextFilterDetect::initialize: template name = '%s'\n", + rtl::OUStringToOString(pValue[i].Value.get<rtl::OUString>(), RTL_TEXTENCODING_UTF8).getStr()); + } + } + } +} + +rtl::OUString PlainTextFilterDetect_getImplementationName() +{ + return rtl::OUString("com.sun.star.comp.filters.PlainTextFilterDetect"); +} + +sal_Bool PlainTextFilterDetect_supportsService(const rtl::OUString& ServiceName) +{ + return ServiceName == "com.sun.star.document.ExtendedTypeDetection" || + ServiceName == "com.sun.star.comp.filters.PlainTextFilterDetect"; +} + +uno::Sequence<rtl::OUString> PlainTextFilterDetect_getSupportedServiceNames() +{ + uno::Sequence<rtl::OUString> aRet(2); + rtl::OUString* pArray = aRet.getArray(); + pArray[0] = "com.sun.star.document.ExtendedTypeDetection"; + pArray[1] = "com.sun.star.comp.filters.PlainTextFilterDetect"; + return aRet; +} + +uno::Reference<uno::XInterface> PlainTextFilterDetect_createInstance( + const uno::Reference<lang::XMultiServiceFactory> & rSMgr) +{ + return (cppu::OWeakObject*) new PlainTextFilterDetect(rSMgr); +} + +// XServiceInfo +rtl::OUString SAL_CALL PlainTextFilterDetect::getImplementationName() + throw (uno::RuntimeException) +{ + return PlainTextFilterDetect_getImplementationName(); +} + +sal_Bool SAL_CALL PlainTextFilterDetect::supportsService(const rtl::OUString& rServiceName) + throw (uno::RuntimeException) +{ + return PlainTextFilterDetect_supportsService(rServiceName); +} + +uno::Sequence<rtl::OUString> SAL_CALL PlainTextFilterDetect::getSupportedServiceNames() + throw (uno::RuntimeException) +{ + return PlainTextFilterDetect_getSupportedServiceNames(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/textfilterdetect/filterdetect.hxx b/filter/source/textfilterdetect/filterdetect.hxx new file mode 100644 index 000000000000..7f3ad158e2ae --- /dev/null +++ b/filter/source/textfilterdetect/filterdetect.hxx @@ -0,0 +1,83 @@ +/* -*- 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 __FILTER_TEXTFILTERDETECT_FILTERDETECT_HXX__ +#define __FILTER_TEXTFILTERDETECT_FILTERDETECT_HXX__ + +#include <com/sun/star/document/XExtendedFilterDetection.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include <cppuhelper/implbase3.hxx> + +class PlainTextFilterDetect : public cppu::WeakImplHelper3< + com::sun::star::document::XExtendedFilterDetection, + com::sun::star::lang::XInitialization, + com::sun::star::lang::XServiceInfo> +{ + com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> mxMSF; + +public: + + PlainTextFilterDetect (const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> &xMSF); + virtual ~PlainTextFilterDetect(); + + // XExtendedFilterDetection + + virtual ::rtl::OUString SAL_CALL detect(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& lDescriptor) + throw( com::sun::star::uno::RuntimeException ); + + // XInitialization + + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence<com::sun::star::uno::Any>& aArguments) + throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException); + + // XServiceInfo + + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw (com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) + throw (com::sun::star::uno::RuntimeException); + + virtual com::sun::star::uno::Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames() + throw (com::sun::star::uno::RuntimeException); +}; + +rtl::OUString PlainTextFilterDetect_getImplementationName(); + +sal_Bool PlainTextFilterDetect_supportsService(const rtl::OUString& ServiceName); + +com::sun::star::uno::Sequence<rtl::OUString> PlainTextFilterDetect_getSupportedServiceNames(); + +com::sun::star::uno::Reference<com::sun::star::uno::XInterface> +PlainTextFilterDetect_createInstance(const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory>& rSMgr); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/textfilterdetect/textfd.component b/filter/source/textfilterdetect/textfd.component new file mode 100644 index 000000000000..e1708e772e72 --- /dev/null +++ b/filter/source/textfilterdetect/textfd.component @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--*********************************************************************** +* Version: MPL 1.1 / GPLv3+ / LGPLv3+ +* +* The contents of this file are subject to the Mozilla Public License Version +* 1.1 (the "License"); you may not use this file except in compliance with +* the License or as specified alternatively below. You may obtain a copy of +* the License at http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +* for the specific language governing rights and limitations under the +* License. +* +* The Initial Developer of the Original Code is +* Kohei Yoshida <kohei.yoshida@suse.com> (Initial Developer) +* Portions created by the Initial Developer are Copyright (C) 2011 the +* Initial Developer. All Rights Reserved. +* +* Major Contributor(s): +* +* For minor contributions see the git repository. +* +* Alternatively, the contents of this file may be used under the terms of +* either the GNU General Public License Version 3 or later (the "GPLv3+"), or +* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), +* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable +* instead of those above. +**************************************************************************--> + +<component loader="com.sun.star.loader.SharedLibrary" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.filters.PlainTextFilterDetect"> + <service name="com.sun.star.document.ExtendedTypeDetection"/> + </implementation> +</component> |