summaryrefslogtreecommitdiff
path: root/oox
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 /oox
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
Diffstat (limited to 'oox')
-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
4 files changed, 28 insertions, 1 deletions
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 );