Kaydet (Commit) 291e846d authored tarafından Matúš Kukan's avatar Matúš Kukan

sax: various clean up. Move _getFactory next to the implementation.

Use more anonymous namespaces, de-duplicate code, bin some comments.
Makes the library smaller.

Change-Id: Id0cefdcaa72a74741303fc27e36038488ef8b059
üst 562b2194
...@@ -52,9 +52,6 @@ public: ...@@ -52,9 +52,6 @@ public:
FastSaxParser(); FastSaxParser();
virtual ~FastSaxParser(); virtual ~FastSaxParser();
// The implementation details
static ::com::sun::star::uno::Sequence< OUString > getSupportedServiceNames_Static(void);
// XFastParser // XFastParser
virtual void SAL_CALL parseStream( const ::com::sun::star::xml::sax::InputSource& aInputSource ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL parseStream( const ::com::sun::star::xml::sax::InputSource& aInputSource ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setFastDocumentHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastDocumentHandler >& Handler ) throw (::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setFastDocumentHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastDocumentHandler >& Handler ) throw (::com::sun::star::uno::RuntimeException);
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
namespace sax_expatwrap {
Reference< XInterface > SAL_CALL SaxWriter_CreateInstance(
const Reference< XMultiServiceFactory > & rSMgr ) throw (Exception);
OUString SaxWriter_getServiceName() throw();
OUString SaxWriter_getImplementationName() throw();
Sequence< OUString > SaxWriter_getSupportedServiceNames(void) throw();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -46,12 +46,10 @@ using namespace ::com::sun::star::registry; ...@@ -46,12 +46,10 @@ using namespace ::com::sun::star::registry;
using namespace ::com::sun::star::xml::sax; using namespace ::com::sun::star::xml::sax;
using namespace ::com::sun::star::io; using namespace ::com::sun::star::io;
#include "factory.hxx"
#include "attrlistimpl.hxx" #include "attrlistimpl.hxx"
#include "xml2utf.hxx" #include "xml2utf.hxx"
#include <sax/fastparser.hxx>
namespace sax_expatwrap { namespace {
// Useful macros for correct String conversion depending on the choosen expat-mode // Useful macros for correct String conversion depending on the choosen expat-mode
#ifdef XML_UNICODE #ifdef XML_UNICODE
...@@ -128,11 +126,15 @@ OUString XmlChar2OUString( const XML_Char *p ) ...@@ -128,11 +126,15 @@ OUString XmlChar2OUString( const XML_Char *p )
}\ }\
((void)0) ((void)0)
#define IMPLEMENTATION_NAME "com.sun.star.comp.extensions.xml.sax.ParserExpat"
#define SERVICE_NAME "com.sun.star.xml.sax.Parser"
class SaxExpatParser_Impl; class SaxExpatParser_Impl;
static Sequence< OUString > SaxExpatParser_getSupportedServiceNames(void)
{
Sequence<OUString> seq(1);
seq[0] = OUString("com.sun.star.xml.sax.Parser");
return seq;
}
// This class implements the external Parser interface // This class implements the external Parser interface
class SaxExpatParser class SaxExpatParser
...@@ -145,12 +147,6 @@ public: ...@@ -145,12 +147,6 @@ public:
SaxExpatParser(); SaxExpatParser();
~SaxExpatParser(); ~SaxExpatParser();
public:
// The implementation details
static Sequence< OUString > getSupportedServiceNames_Static(void) throw ();
public:
// ::com::sun::star::lang::XInitialization: // ::com::sun::star::lang::XInitialization:
virtual void SAL_CALL initialize(Sequence<Any> const& rArguments) virtual void SAL_CALL initialize(Sequence<Any> const& rArguments)
throw (RuntimeException, Exception); throw (RuntimeException, Exception);
...@@ -183,45 +179,13 @@ private: ...@@ -183,45 +179,13 @@ private:
}; };
//--------------------------------------
// the extern interface
//---------------------------------------
Reference< XInterface > SAL_CALL SaxExpatParser_CreateInstance(
SAL_UNUSED_PARAMETER const Reference< XMultiServiceFactory > & )
throw(Exception)
{
SaxExpatParser *p = new SaxExpatParser;
return Reference< XInterface > ( (OWeakObject * ) p );
}
Reference< XInterface > SAL_CALL FastSaxParser_CreateInstance(
SAL_UNUSED_PARAMETER const Reference< XMultiServiceFactory > & )
throw(Exception)
{
::sax_fastparser::FastSaxParser *p = new ::sax_fastparser::FastSaxParser;
return Reference< XInterface > ( (OWeakObject * ) p );
}
Sequence< OUString > SaxExpatParser::getSupportedServiceNames_Static(void) throw ()
{
Sequence<OUString> aRet(1);
aRet[0] = SERVICE_NAME;
return aRet;
}
//---------------------------------------------
// the implementation part
//---------------------------------------------
// Entity binds all information neede for a single file // Entity binds all information neede for a single file
struct Entity struct Entity
{ {
InputSource structSource; InputSource structSource;
XML_Parser pParser; XML_Parser pParser;
XMLFile2UTFConverter converter; sax_expatwrap::XMLFile2UTFConverter converter;
}; };
...@@ -242,7 +206,7 @@ public: // module scope ...@@ -242,7 +206,7 @@ public: // module scope
Reference < XAttributeList > rAttrList; Reference < XAttributeList > rAttrList;
AttributeList *pAttrList; sax_expatwrap::AttributeList *pAttrList;
// External entity stack // External entity stack
vector<struct Entity> vecEntity; vector<struct Entity> vecEntity;
...@@ -450,7 +414,7 @@ SaxExpatParser::SaxExpatParser( ) ...@@ -450,7 +414,7 @@ SaxExpatParser::SaxExpatParser( )
// performance-improvement. Reference is needed when calling the startTag callback. // performance-improvement. Reference is needed when calling the startTag callback.
// Handing out the same object with every call is allowed (see sax-specification) // Handing out the same object with every call is allowed (see sax-specification)
m_pImpl->pAttrList = new AttributeList; m_pImpl->pAttrList = new sax_expatwrap::AttributeList;
m_pImpl->rAttrList = Reference< XAttributeList > ( m_pImpl->pAttrList ); m_pImpl->rAttrList = Reference< XAttributeList > ( m_pImpl->pAttrList );
m_pImpl->bExceptionWasThrown = false; m_pImpl->bExceptionWasThrown = false;
...@@ -630,7 +594,7 @@ void SaxExpatParser::setLocale( const Locale & locale ) throw (RuntimeException) ...@@ -630,7 +594,7 @@ void SaxExpatParser::setLocale( const Locale & locale ) throw (RuntimeException)
// XServiceInfo // XServiceInfo
OUString SaxExpatParser::getImplementationName() throw () OUString SaxExpatParser::getImplementationName() throw ()
{ {
return OUString( IMPLEMENTATION_NAME ); return OUString("com.sun.star.comp.extensions.xml.sax.ParserExpat");
} }
// XServiceInfo // XServiceInfo
...@@ -642,10 +606,7 @@ sal_Bool SaxExpatParser::supportsService(const OUString& ServiceName) throw () ...@@ -642,10 +606,7 @@ sal_Bool SaxExpatParser::supportsService(const OUString& ServiceName) throw ()
// XServiceInfo // XServiceInfo
Sequence< OUString > SaxExpatParser::getSupportedServiceNames(void) throw () Sequence< OUString > SaxExpatParser::getSupportedServiceNames(void) throw ()
{ {
return SaxExpatParser_getSupportedServiceNames();
Sequence<OUString> seq(1);
seq[0] = SERVICE_NAME;
return seq;
} }
...@@ -1058,56 +1019,29 @@ void SaxExpatParser_Impl::callbackEndCDATA( void *pvThis ) ...@@ -1058,56 +1019,29 @@ void SaxExpatParser_Impl::callbackEndCDATA( void *pvThis )
CALL_ELEMENT_HANDLER_AND_CARE_FOR_EXCEPTIONS(pImpl,rExtendedDocumentHandler->endCDATA() ); CALL_ELEMENT_HANDLER_AND_CARE_FOR_EXCEPTIONS(pImpl,rExtendedDocumentHandler->endCDATA() );
} }
} // namespace
static Reference< XInterface > SaxExpatParser_CreateInstance(
SAL_UNUSED_PARAMETER const Reference< XMultiServiceFactory > & )
throw(Exception)
{
SaxExpatParser *p = new SaxExpatParser;
return Reference< XInterface > ( (OWeakObject * ) p );
} }
static void * getSingleFactory( extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL
void *pServiceManager, com_sun_star_comp_extensions_xml_sax_ParserExpat_component_getFactory(
const OUString& sImplementation, const char * , void *pServiceManager, void * )
ComponentInstantiation pCreateFunction,
const Sequence< OUString > & rServiceNames)
{ {
Reference< XSingleServiceFactory > xFactory; Reference< XSingleServiceFactory > xFactory;
Reference< XMultiServiceFactory > xSMgr = Reference< XMultiServiceFactory > xSMgr =
reinterpret_cast< XMultiServiceFactory * >( pServiceManager ); reinterpret_cast< XMultiServiceFactory * >( pServiceManager );
xFactory = createSingleFactory( xSMgr, xFactory = createSingleFactory( xSMgr,
sImplementation, pCreateFunction, rServiceNames );
xFactory->acquire();
return xFactory.get();
}
using namespace sax_expatwrap;
extern "C"
{
SAL_DLLPUBLIC_EXPORT void * SAL_CALL com_sun_star_comp_extensions_xml_sax_ParserExpat_component_getFactory(
const char * , void *pServiceManager, void * )
{
return getSingleFactory( pServiceManager,
"com.sun.star.comp.extensions.xml.sax.ParserExpat", "com.sun.star.comp.extensions.xml.sax.ParserExpat",
SaxExpatParser_CreateInstance, SaxExpatParser_CreateInstance,
SaxExpatParser::getSupportedServiceNames_Static() ); SaxExpatParser_getSupportedServiceNames() );
} xFactory->acquire();
return xFactory.get();
SAL_DLLPUBLIC_EXPORT void * SAL_CALL com_sun_star_extensions_xml_sax_Writer_component_getFactory(
const char * , void *pServiceManager, void * )
{
return getSingleFactory( pServiceManager,
"com.sun.star.extensions.xml.sax.Writer",
SaxWriter_CreateInstance,
SaxWriter_getSupportedServiceNames() );
}
SAL_DLLPUBLIC_EXPORT void * SAL_CALL com_sun_star_comp_extensions_xml_sax_FastParser_component_getFactory(
const char * , void *pServiceManager, void * )
{
return getSingleFactory( pServiceManager,
"com.sun.star.comp.extensions.xml.sax.FastParser",
FastSaxParser_CreateInstance,
sax_fastparser::FastSaxParser::getSupportedServiceNames_Static() );
}
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -51,7 +51,6 @@ using namespace ::com::sun::star::xml::sax; ...@@ -51,7 +51,6 @@ using namespace ::com::sun::star::xml::sax;
using namespace ::com::sun::star::util; using namespace ::com::sun::star::util;
using namespace ::com::sun::star::io; using namespace ::com::sun::star::io;
#include "factory.hxx"
#include "xml2utf.hxx" #include "xml2utf.hxx"
#define LINEFEED 10 #define LINEFEED 10
...@@ -66,7 +65,7 @@ using namespace ::com::sun::star::io; ...@@ -66,7 +65,7 @@ using namespace ::com::sun::star::io;
* *
*****/ *****/
namespace sax_expatwrap { namespace {
enum SaxInvalidCharacterError enum SaxInvalidCharacterError
{ {
...@@ -868,6 +867,13 @@ static inline sal_Int32 getFirstLineBreak( const OUString & str ) throw () ...@@ -868,6 +867,13 @@ static inline sal_Int32 getFirstLineBreak( const OUString & str ) throw ()
return -1; return -1;
} }
static Sequence< OUString > SAXWriter_getSupportedServiceNames(void) throw ()
{
Sequence<OUString> seq(1);
seq.getArray()[0] = OUString("com.sun.star.xml.sax.Writer");
return seq;
}
class SAXWriter : class SAXWriter :
public WeakImplHelper2< public WeakImplHelper2<
XWriter, XWriter,
...@@ -965,36 +971,6 @@ private: ...@@ -965,36 +971,6 @@ private:
sal_Int32 m_nLevel; sal_Int32 m_nLevel;
}; };
//--------------------------------------
// the extern interface
//---------------------------------------
Reference < XInterface > SAL_CALL SaxWriter_CreateInstance(
SAL_UNUSED_PARAMETER const Reference < XMultiServiceFactory > & )
throw (Exception)
{
SAXWriter *p = new SAXWriter;
return Reference< XInterface > ( (static_cast< OWeakObject * >(p)) );
}
OUString SaxWriter_getServiceName() throw()
{
return OUString("com.sun.star.xml.sax.Writer");
}
OUString SaxWriter_getImplementationName() throw()
{
return OUString("com.sun.star.extensions.xml.sax.Writer");
}
Sequence< OUString > SaxWriter_getSupportedServiceNames(void) throw()
{
Sequence<OUString> aRet(1);
aRet.getArray()[0] = SaxWriter_getServiceName();
return aRet;
}
sal_Int32 SAXWriter::getIndentPrefixLength( sal_Int32 nFirstLineBreakOccurrence ) throw() sal_Int32 SAXWriter::getIndentPrefixLength( sal_Int32 nFirstLineBreakOccurrence ) throw()
{ {
sal_Int32 nLength =-1; sal_Int32 nLength =-1;
...@@ -1018,7 +994,7 @@ static inline sal_Bool isFirstCharWhitespace( const sal_Unicode *p ) throw() ...@@ -1018,7 +994,7 @@ static inline sal_Bool isFirstCharWhitespace( const sal_Unicode *p ) throw()
// XServiceInfo // XServiceInfo
OUString SAXWriter::getImplementationName() throw() OUString SAXWriter::getImplementationName() throw()
{ {
return SaxWriter_getImplementationName(); return OUString("com.sun.star.extensions.xml.sax.Writer");
} }
// XServiceInfo // XServiceInfo
...@@ -1030,9 +1006,7 @@ sal_Bool SAXWriter::supportsService(const OUString& ServiceName) throw() ...@@ -1030,9 +1006,7 @@ sal_Bool SAXWriter::supportsService(const OUString& ServiceName) throw()
// XServiceInfo // XServiceInfo
Sequence< OUString > SAXWriter::getSupportedServiceNames(void) throw () Sequence< OUString > SAXWriter::getSupportedServiceNames(void) throw ()
{ {
Sequence<OUString> seq(1); return SAXWriter_getSupportedServiceNames();
seq.getArray()[0] = SaxWriter_getServiceName();
return seq;
} }
void SAXWriter::startDocument() throw(SAXException, RuntimeException ) void SAXWriter::startDocument() throw(SAXException, RuntimeException )
...@@ -1398,6 +1372,29 @@ void SAXWriter::unknown(const OUString& sString) throw (SAXException, RuntimeExc ...@@ -1398,6 +1372,29 @@ void SAXWriter::unknown(const OUString& sString) throw (SAXException, RuntimeExc
} }
} }
} // namespace
static Reference < XInterface > SAXWriter_CreateInstance(
SAL_UNUSED_PARAMETER const Reference < XMultiServiceFactory > & )
throw (Exception)
{
SAXWriter *p = new SAXWriter;
return Reference< XInterface > ( (static_cast< OWeakObject * >(p)) );
}
extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL
com_sun_star_extensions_xml_sax_Writer_component_getFactory(
const char * , void *pServiceManager, void * )
{
Reference< XSingleServiceFactory > xFactory;
Reference< XMultiServiceFactory > xSMgr =
reinterpret_cast< XMultiServiceFactory * >( pServiceManager );
xFactory = createSingleFactory( xSMgr,
"com.sun.star.extensions.xml.sax.Writer",
SAXWriter_CreateInstance,
SAXWriter_getSupportedServiceNames() );
xFactory->acquire();
return xFactory.get();
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -42,8 +42,6 @@ using namespace ::com::sun::star::registry; ...@@ -42,8 +42,6 @@ using namespace ::com::sun::star::registry;
using namespace ::com::sun::star::io; using namespace ::com::sun::star::io;
using namespace ::com::sun::star::xml::sax; using namespace ::com::sun::star::xml::sax;
#include "factory.hxx"
// test szenarios // test szenarios
namespace sax_test { namespace sax_test {
......
...@@ -45,8 +45,6 @@ using namespace ::com::sun::star::registry; ...@@ -45,8 +45,6 @@ using namespace ::com::sun::star::registry;
using namespace ::com::sun::star::io; using namespace ::com::sun::star::io;
using namespace ::com::sun::star::xml::sax; using namespace ::com::sun::star::xml::sax;
#include "factory.hxx"
namespace sax_test { namespace sax_test {
class OFileWriter : class OFileWriter :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment