summaryrefslogtreecommitdiff
path: root/filter/source/textfilterdetect
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2013-03-05 22:51:22 -0500
committerKohei Yoshida <kohei.yoshida@gmail.com>2013-03-07 01:44:45 -0500
commit88ed1bf33789f1eaddc31e37b305cfb2daab4664 (patch)
treea754c9a5b484d2605c9e2564a59dd4ddf74f0abe /filter/source/textfilterdetect
parent8c31a6baf06e711d5e45d477abedfa6afb7ffe51 (diff)
Modernize the type detection service instantiation a bit.
Change-Id: If31092ecc2b746acbe5731bf9383560e93aa3a69
Diffstat (limited to 'filter/source/textfilterdetect')
-rw-r--r--filter/source/textfilterdetect/fdcomp.cxx49
-rw-r--r--filter/source/textfilterdetect/filterdetect.cxx49
-rw-r--r--filter/source/textfilterdetect/filterdetect.hxx7
3 files changed, 47 insertions, 58 deletions
diff --git a/filter/source/textfilterdetect/fdcomp.cxx b/filter/source/textfilterdetect/fdcomp.cxx
index 85b9f3b8362a..7e98cad43558 100644
--- a/filter/source/textfilterdetect/fdcomp.cxx
+++ b/filter/source/textfilterdetect/fdcomp.cxx
@@ -26,47 +26,30 @@
* instead of those above.
*/
-#include <stdio.h>
+#include "sal/config.h"
-#include <osl/mutex.hxx>
-#include <osl/thread.h>
-#include <cppuhelper/factory.hxx>
-
-#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include "cppuhelper/factory.hxx"
+#include "cppuhelper/implementationentry.hxx"
+#include "sal/types.h"
#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" {
+namespace {
-SAL_DLLPUBLIC_EXPORT void * SAL_CALL textfd_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()));
+static cppu::ImplementationEntry const services[] = {
+ { &PlainTextFilterDetect_createInstance, &PlainTextFilterDetect_getImplementationName,
+ &PlainTextFilterDetect_getSupportedServiceNames,
+ &cppu::createSingleComponentFactory, 0, 0 },
+ { 0, 0, 0, 0, 0, 0 }
+};
- if (xFactory.is())
- {
- xFactory->acquire();
- pRet = xFactory.get();
- }
- }
-
- return pRet;
}
+extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL textfd_component_getFactory(
+ char const * pImplName, void * pServiceManager, void * pRegistryKey)
+{
+ return cppu::component_getFactoryHelper(
+ pImplName, pServiceManager, pRegistryKey, services);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/source/textfilterdetect/filterdetect.cxx b/filter/source/textfilterdetect/filterdetect.cxx
index 7dd2ddd76cf0..e4bce81087c3 100644
--- a/filter/source/textfilterdetect/filterdetect.cxx
+++ b/filter/source/textfilterdetect/filterdetect.cxx
@@ -29,8 +29,10 @@
#include "filterdetect.hxx"
#include "tools/urlobj.hxx"
+#include "ucbhelper/content.hxx"
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
#define WRITER_TEXT_FILTER "Text"
#define CALC_TEXT_FILTER "Text - txt - csv (StarCalc)"
@@ -39,31 +41,33 @@ using namespace ::com::sun::star;
namespace {
-void setFilter(uno::Sequence<beans::PropertyValue>& rProps, sal_Int32 nPos, const rtl::OUString& rFilter)
+template<typename T>
+void setPropValue(uno::Sequence<beans::PropertyValue>& rProps, sal_Int32 nPos, const char* pName, const T& rValue)
{
if (nPos >= 0)
- rProps[nPos].Value <<= rFilter;
+ rProps[nPos].Value <<= rValue;
else
{
sal_Int32 n = rProps.getLength();
rProps.realloc(n+1);
- rProps[n].Name = "FilterName";
- rProps[n].Value <<= rFilter;
+ rProps[n].Name = OUString::createFromAscii(pName);
+ rProps[n].Value <<= rValue;
}
}
}
-PlainTextFilterDetect::PlainTextFilterDetect(const uno::Reference<lang::XMultiServiceFactory> &xMSF) :
- mxMSF(xMSF) {}
+PlainTextFilterDetect::PlainTextFilterDetect(const uno::Reference<uno::XComponentContext>& xCxt) :
+ mxCxt(xCxt) {}
PlainTextFilterDetect::~PlainTextFilterDetect() {}
rtl::OUString SAL_CALL PlainTextFilterDetect::detect(uno::Sequence<beans::PropertyValue>& lDescriptor) throw (uno::RuntimeException)
{
- rtl::OUString aType;
- rtl::OUString aDocService;
- rtl::OUString aExt;
+ OUString aType;
+ OUString aDocService;
+ OUString aExt;
+ OUString aUrl;
sal_Int32 nFilter = -1;
@@ -77,11 +81,10 @@ rtl::OUString SAL_CALL PlainTextFilterDetect::detect(uno::Sequence<beans::Proper
lDescriptor[i].Value >>= aDocService;
else if (lDescriptor[i].Name == "URL")
{
- rtl::OUString aURL;
- lDescriptor[i].Value >>= aURL;
+ lDescriptor[i].Value >>= aUrl;
// Get the file name extension.
- INetURLObject aParser(aURL);
+ INetURLObject aParser(aUrl);
aExt = aParser.getExtension(
INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET);
aExt = aExt.toAsciiLowerCase();
@@ -90,28 +93,30 @@ rtl::OUString SAL_CALL PlainTextFilterDetect::detect(uno::Sequence<beans::Proper
if (aType == "generic_Text")
{
- // Generic text type. Decide which filter to use based on the
- // document service first, then on extension if that's not available.
+ // Generic text type.
+
+ // Decide which filter to use based on the document service first,
+ // then on extension if that's not available.
if (aDocService == "com.sun.star.sheet.SpreadsheetDocument")
// Open it in Calc.
- setFilter(lDescriptor, nFilter, CALC_TEXT_FILTER);
+ setPropValue(lDescriptor, nFilter, "FilterName", OUString(CALC_TEXT_FILTER));
else if (aDocService == "com.sun.star.text.TextDocument")
// Open it in Writer.
- setFilter(lDescriptor, nFilter, WRITER_TEXT_FILTER);
+ setPropValue(lDescriptor, nFilter, "FilterName", OUString(WRITER_TEXT_FILTER));
else if (aExt == "csv")
- setFilter(lDescriptor, nFilter, CALC_TEXT_FILTER);
+ setPropValue(lDescriptor, nFilter, "FilterName", OUString(CALC_TEXT_FILTER));
else if (aExt == "txt")
- setFilter(lDescriptor, nFilter, WRITER_TEXT_FILTER);
+ setPropValue(lDescriptor, nFilter, "FilterName", OUString(WRITER_TEXT_FILTER));
else
// No clue. Open it in Writer by default.
- setFilter(lDescriptor, nFilter, WRITER_TEXT_FILTER);
+ setPropValue(lDescriptor, nFilter, "FilterName", OUString(WRITER_TEXT_FILTER));
return aType;
}
// failed!
- return rtl::OUString();
+ return OUString();
}
// XInitialization
@@ -142,9 +147,9 @@ uno::Sequence<rtl::OUString> PlainTextFilterDetect_getSupportedServiceNames()
}
uno::Reference<uno::XInterface> PlainTextFilterDetect_createInstance(
- const uno::Reference<lang::XMultiServiceFactory> & rSMgr)
+ const uno::Reference<uno::XComponentContext> & rCxt)
{
- return (cppu::OWeakObject*) new PlainTextFilterDetect(rSMgr);
+ return (cppu::OWeakObject*) new PlainTextFilterDetect(rCxt);
}
// XServiceInfo
diff --git a/filter/source/textfilterdetect/filterdetect.hxx b/filter/source/textfilterdetect/filterdetect.hxx
index b3b2790002c4..dd4aa639b8e1 100644
--- a/filter/source/textfilterdetect/filterdetect.hxx
+++ b/filter/source/textfilterdetect/filterdetect.hxx
@@ -23,6 +23,7 @@
#include <com/sun/star/document/XExtendedFilterDetection.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
#include <cppuhelper/implbase3.hxx>
@@ -31,11 +32,11 @@ class PlainTextFilterDetect : public cppu::WeakImplHelper3<
com::sun::star::lang::XInitialization,
com::sun::star::lang::XServiceInfo>
{
- com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> mxMSF;
+ com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> mxCxt;
public:
- PlainTextFilterDetect (const com::sun::star::uno::Reference<com::sun::star::lang::XMultiServiceFactory> &xMSF);
+ PlainTextFilterDetect (const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& xCxt);
virtual ~PlainTextFilterDetect();
// XExtendedFilterDetection
@@ -67,7 +68,7 @@ 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);
+PlainTextFilterDetect_createInstance(const com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>& rCxt);
#endif