summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@collabora.com>2013-12-02 19:20:59 -0500
committerKohei Yoshida <kohei.yoshida@collabora.com>2013-12-02 19:32:28 -0500
commit532b2f48185c9ee3f389f1a3fbdfffcf113c15c0 (patch)
tree896dc46717b963601188efd001830c7a130e0249
parent2130fd9d610bf12b09fe29bafd46a673b21e064d (diff)
Add a means to check if a namespace exists.
Useful when we just need to check if the stream has a certain namespace defined. Calling getNamespaceURL() may throw SAXException in such case. Change-Id: Ib2b7b202492390158270d87bab95d1793c9d8a70
-rw-r--r--include/oox/core/fastparser.hxx6
-rw-r--r--include/oox/core/xmlfilterbase.hxx2
-rw-r--r--include/sax/fastparser.hxx3
-rw-r--r--oox/Library_oox.mk1
-rw-r--r--oox/source/core/fastparser.cxx17
-rw-r--r--oox/source/core/fragmenthandler2.cxx6
-rw-r--r--oox/source/core/xmlfilterbase.cxx5
-rw-r--r--sax/source/fastparser/fastparser.cxx23
8 files changed, 60 insertions, 3 deletions
diff --git a/include/oox/core/fastparser.hxx b/include/oox/core/fastparser.hxx
index fd982413329c..a673217c0eab 100644
--- a/include/oox/core/fastparser.hxx
+++ b/include/oox/core/fastparser.hxx
@@ -75,10 +75,12 @@ public:
void parseStream( StorageBase& rStorage, const OUString& rStreamName, bool bCloseStream = false )
throw( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException );
- OUString getNamespaceURL( const OUString& rPrefix )
+ OUString getNamespaceURL( const OUString& rPrefix )
throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
- sal_Int32 getNamespaceId( const OUString& aUrl );
+ bool hasNamespaceURL( const OUString& rPrefix ) const;
+
+ sal_Int32 getNamespaceId( const OUString& aUrl );
::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler >
getTokenHandler() const { return mxTokenHandler; }
diff --git a/include/oox/core/xmlfilterbase.hxx b/include/oox/core/xmlfilterbase.hxx
index 76eb091b3f2e..604f220c4a1d 100644
--- a/include/oox/core/xmlfilterbase.hxx
+++ b/include/oox/core/xmlfilterbase.hxx
@@ -227,6 +227,8 @@ public:
OUString getNamespaceURL( const OUString& rPrefix );
+ bool hasNamespaceURL( const OUString& rPrefix ) const;
+
sal_Int32 getNamespaceId( const OUString& rUrl );
void importDocumentProperties();
diff --git a/include/sax/fastparser.hxx b/include/sax/fastparser.hxx
index 3a8ae5302073..217893c47362 100644
--- a/include/sax/fastparser.hxx
+++ b/include/sax/fastparser.hxx
@@ -140,9 +140,12 @@ public:
void pushEntity( const Entity& rEntity );
void popEntity();
Entity& getEntity();
+ const Entity& getEntity() const;
void parse();
void produce( CallbackType aType );
+ bool hasNamespaceURL( const OUString& rPrefix ) const;
+
private:
bool consume(EventList *);
void deleteUsedEvents();
diff --git a/oox/Library_oox.mk b/oox/Library_oox.mk
index b7e763c6f575..0a4fc04e0360 100644
--- a/oox/Library_oox.mk
+++ b/oox/Library_oox.mk
@@ -40,6 +40,7 @@ $(eval $(call gb_Library_use_libraries,oox,\
cppuhelper \
editeng \
drawinglayer \
+ fastsax \
msfilter \
sal \
i18nlangtag \
diff --git a/oox/source/core/fastparser.cxx b/oox/source/core/fastparser.cxx
index 03fd60a7481e..70e12a896098 100644
--- a/oox/source/core/fastparser.cxx
+++ b/oox/source/core/fastparser.cxx
@@ -25,6 +25,8 @@
#include "oox/helper/storagebase.hxx"
#include "oox/token/namespacemap.hxx"
+#include "sax/fastparser.hxx"
+
namespace oox {
namespace core {
@@ -66,11 +68,13 @@ InputStreamCloseGuard::~InputStreamCloseGuard()
// ============================================================================
FastParser::FastParser( const Reference< XComponentContext >& rxContext ) throw( RuntimeException ) :
- mrNamespaceMap( StaticNamespaceMap::get() )
+ mrNamespaceMap( StaticNamespaceMap::get() ),
+ mpParser(NULL)
{
// create a fast parser instance
Reference< XMultiComponentFactory > xFactory( rxContext->getServiceManager(), UNO_SET_THROW );
mxParser.set( xFactory->createInstanceWithContext( "com.sun.star.xml.sax.FastParser", rxContext ), UNO_QUERY_THROW );
+ mpParser = dynamic_cast<sax_fastparser::FastSaxParser*>(mxParser.get());
// create the fast tokenhandler
mxTokenHandler.set( new FastTokenHandler );
@@ -131,6 +135,17 @@ OUString FastParser::getNamespaceURL( const OUString& rPrefix ) throw( IllegalAr
return mxParser->getNamespaceURL( rPrefix );
}
+bool FastParser::hasNamespaceURL( const OUString& rPrefix ) const
+{
+ if (!mxParser.is())
+ throw RuntimeException();
+
+ if (!mpParser)
+ return false;
+
+ return mpParser->hasNamespaceURL(rPrefix);
+}
+
sal_Int32 FastParser::getNamespaceId( const OUString& rUrl )
{
for( NamespaceMap::const_iterator aIt = mrNamespaceMap.begin(), aEnd = mrNamespaceMap.end(); aIt != aEnd; ++aIt )
diff --git a/oox/source/core/fragmenthandler2.cxx b/oox/source/core/fragmenthandler2.cxx
index 668eb7fbee49..8133b7382133 100644
--- a/oox/source/core/fragmenthandler2.cxx
+++ b/oox/source/core/fragmenthandler2.cxx
@@ -67,6 +67,12 @@ bool FragmentHandler2::prepareMceContext( sal_Int32 nElement, const AttributeLis
case MCE_TOKEN( Choice ):
{
OUString aRequires = rAttribs.getString( ( XML_Requires ), OUString("none") );
+ if (!getFilter().hasNamespaceURL(aRequires))
+ // Check to see if we have this namespace defined first,
+ // because calling getNamespaceURL() would throw if the
+ // namespace doesn't exist.
+ return false;
+
aRequires = getFilter().getNamespaceURL( aRequires );
if( getFilter().getNamespaceId( aRequires ) > 0 && !aMceState.empty() && aMceState.back() == MCE_STARTED )
aMceState.back() = MCE_FOUND_CHOICE;
diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx
index 30f384898ce9..ea2cc07f86f0 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -300,6 +300,11 @@ OUString XmlFilterBase::getNamespaceURL( const OUString& rPrefix )
return mxImpl->maFastParser.getNamespaceURL( rPrefix );
}
+bool XmlFilterBase::hasNamespaceURL( const OUString& rPrefix ) const
+{
+ return mxImpl->maFastParser.hasNamespaceURL(rPrefix);
+}
+
sal_Int32 XmlFilterBase::getNamespaceId( const OUString& rUrl )
{
return mxImpl->maFastParser.getNamespaceId( rUrl );
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 9f60b72c2d5c..9535902f92d2 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -859,6 +859,24 @@ void FastSaxParser::produce( CallbackType aType )
}
}
+bool FastSaxParser::hasNamespaceURL( const OUString& rPrefix ) const
+{
+ const Entity& rEntity = getEntity();
+
+ if (rEntity.maNamespaceCount.empty())
+ return false;
+
+ OString aPrefix = OUStringToOString(rPrefix, RTL_TEXTENCODING_UTF8);
+ sal_uInt32 nNamespace = rEntity.maNamespaceCount.top();
+ while (nNamespace--)
+ {
+ if (rEntity.maNamespaceDefines[nNamespace]->maPrefix == aPrefix)
+ return true;
+ }
+
+ return false;
+}
+
bool FastSaxParser::consume(EventList *pEventList)
{
Entity& rEntity = getEntity();
@@ -924,6 +942,11 @@ Entity& FastSaxParser::getEntity()
return maEntities.top();
}
+const Entity& FastSaxParser::getEntity() const
+{
+ return maEntities.top();
+}
+
// starts parsing with actual parser !
void FastSaxParser::parse()
{