summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@collabora.co.uk>2014-02-28 10:39:56 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2014-03-01 16:23:09 +0100
commit6ba394e6119fee2c5424b6c3b5eb3f4276cc2769 (patch)
tree8ababa0c1054d4ec9ec504ef4ae9a40b5418bdbc /oox
parenta143beb3a02dc23f5a256e64fb996a1329ce07c0 (diff)
handle OOXML strict namespaces
Change-Id: I198862388426161e3f054a5f128639c59f3c9d24
Diffstat (limited to 'oox')
-rw-r--r--oox/CustomTarget_generated.mk2
-rw-r--r--oox/source/core/fastparser.cxx19
-rw-r--r--oox/source/core/filterdetect.cxx3
-rw-r--r--oox/source/token/namespacemap.cxx12
-rw-r--r--oox/source/token/namespaces-strict.hxx.head27
-rw-r--r--oox/source/token/namespaces-strict.hxx.tail62
-rw-r--r--oox/source/token/namespaces-strict.pl70
-rw-r--r--oox/source/token/namespaces-strict.txt82
8 files changed, 273 insertions, 4 deletions
diff --git a/oox/CustomTarget_generated.mk b/oox/CustomTarget_generated.mk
index 92c8bf8196d8..89ac97d40f28 100644
--- a/oox/CustomTarget_generated.mk
+++ b/oox/CustomTarget_generated.mk
@@ -43,6 +43,7 @@ $(oox_GENHEADERPATH)/$(1).hxx : $(oox_SRC)/$(1).pl $(oox_SRC)/$(1).txt \
endef
$(eval $(call oox_GenTarget,namespaces,namespace,namespaces.txt))
+$(eval $(call oox_GenTarget,namespaces-strict,namespace-strict,namespaces-strict.txt))
$(eval $(call oox_GenTarget,properties,property,))
$(eval $(call oox_GenTarget,tokens,token,tokenhash.gperf))
@@ -54,6 +55,7 @@ $(call gb_CustomTarget_get_target,oox/generated) : \
$(oox_INC)/propertynames.inc \
$(oox_GENHEADERPATH)/tokens.hxx \
$(oox_GENHEADERPATH)/namespaces.hxx \
+ $(oox_GENHEADERPATH)/namespaces-strict.hxx \
$(oox_GENHEADERPATH)/properties.hxx \
$(oox_MISC)/namespaces.txt \
diff --git a/oox/source/core/fastparser.cxx b/oox/source/core/fastparser.cxx
index 6eeefb6e23f6..42306a9d15a2 100644
--- a/oox/source/core/fastparser.cxx
+++ b/oox/source/core/fastparser.cxx
@@ -94,11 +94,19 @@ void FastParser::registerNamespace( sal_Int32 nNamespaceId ) throw( IllegalArgum
if( !mxParser.is() )
throw RuntimeException();
- const OUString* pNamespaceUrl = ContainerHelper::getMapElement( mrNamespaceMap, nNamespaceId );
+ // add handling for OOXML strict here
+ const OUString* pNamespaceUrl = ContainerHelper::getMapElement( mrNamespaceMap.maTransitionalNamespaceMap, nNamespaceId );
if( !pNamespaceUrl )
throw IllegalArgumentException();
mxParser->registerNamespace( *pNamespaceUrl, nNamespaceId );
+
+ //also register the OOXML strict namespaces for the same id
+ const OUString* pNamespaceStrictUrl = ContainerHelper::getMapElement( mrNamespaceMap.maStrictNamespaceMap, nNamespaceId );
+ if(pNamespaceStrictUrl && (*pNamespaceUrl != *pNamespaceStrictUrl))
+ {
+ mxParser->registerNamespace( *pNamespaceStrictUrl, nNamespaceId );
+ }
}
void FastParser::setDocumentHandler( const Reference< XFastDocumentHandler >& rxDocHandler ) throw( RuntimeException )
@@ -150,9 +158,16 @@ bool FastParser::hasNamespaceURL( const OUString& rPrefix ) const
sal_Int32 FastParser::getNamespaceId( const OUString& rUrl )
{
- for( NamespaceMap::const_iterator aIt = mrNamespaceMap.begin(), aEnd = mrNamespaceMap.end(); aIt != aEnd; ++aIt )
+ for( NamespaceMap::const_iterator aIt = mrNamespaceMap.maTransitionalNamespaceMap.begin(),
+ aEnd = mrNamespaceMap.maTransitionalNamespaceMap.end(); aIt != aEnd; ++aIt )
if( rUrl == aIt->second )
return aIt->first;
+
+ for( NamespaceMap::const_iterator aIt = mrNamespaceMap.maStrictNamespaceMap.begin(),
+ aEnd = mrNamespaceMap.maStrictNamespaceMap.end(); aIt != aEnd; ++aIt )
+ if( rUrl == aIt->second )
+ return aIt->first;
+
return 0;
}
diff --git a/oox/source/core/filterdetect.cxx b/oox/source/core/filterdetect.cxx
index 3fd557810d79..6262071a49cd 100644
--- a/oox/source/core/filterdetect.cxx
+++ b/oox/source/core/filterdetect.cxx
@@ -155,7 +155,8 @@ void SAL_CALL FilterDetectDocHandler::processingInstruction(
void FilterDetectDocHandler::parseRelationship( const AttributeList& rAttribs )
{
OUString aType = rAttribs.getString( XML_Type, OUString() );
- if ( aType == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" )
+ if ( aType == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" // OOXML Transitional
+ || aType == "http://purl.oclc.org/ooxml/officeDocument/relationships/officeDocument" ) //OOXML strict
{
Reference<XUriReferenceFactory> xFactory = UriReferenceFactory::create( mxContext );
try
diff --git a/oox/source/token/namespacemap.cxx b/oox/source/token/namespacemap.cxx
index 4c4766b4f745..65487da70308 100644
--- a/oox/source/token/namespacemap.cxx
+++ b/oox/source/token/namespacemap.cxx
@@ -32,8 +32,18 @@ NamespaceMap::NamespaceMap()
{ -1, "" }
};
+ static const struct NamespaceStrictUrl { sal_Int32 mnId; const sal_Char* mpcUrl; } spNamespaceStrictUrls[] =
+ {
+// include auto-generated C array with namespace URLs as C strings
+#include "namespace-strictnames.inc"
+ { -1, "" }
+ };
+
for( const NamespaceUrl* pNamespaceUrl = spNamespaceUrls; pNamespaceUrl->mnId != -1; ++pNamespaceUrl )
- operator[]( pNamespaceUrl->mnId ) = OUString::createFromAscii( pNamespaceUrl->mpcUrl );
+ maTransitionalNamespaceMap[ pNamespaceUrl->mnId ] = OUString::createFromAscii( pNamespaceUrl->mpcUrl );
+
+ for( const NamespaceStrictUrl* pNamespaceUrl = spNamespaceStrictUrls; pNamespaceUrl->mnId != -1; ++pNamespaceUrl )
+ maStrictNamespaceMap[ pNamespaceUrl->mnId ] = OUString::createFromAscii( pNamespaceUrl->mpcUrl );
}
}
diff --git a/oox/source/token/namespaces-strict.hxx.head b/oox/source/token/namespaces-strict.hxx.head
new file mode 100644
index 000000000000..d00a3804a197
--- /dev/null
+++ b/oox/source/token/namespaces-strict.hxx.head
@@ -0,0 +1,27 @@
+/*
+ * 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 .
+ */
+
+#ifndef OOX_TOKEN_NAMESPACES_HXX
+#define OOX_TOKEN_NAMESPACES_HXX
+
+#include <sal/types.h>
+
+namespace oox {
+
+// ============================================================================
+
diff --git a/oox/source/token/namespaces-strict.hxx.tail b/oox/source/token/namespaces-strict.hxx.tail
new file mode 100644
index 000000000000..e0baeae0a315
--- /dev/null
+++ b/oox/source/token/namespaces-strict.hxx.tail
@@ -0,0 +1,62 @@
+/*
+ * 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 .
+ */
+
+// ============================================================================
+
+const sal_Int32 TOKEN_MASK = static_cast< sal_Int32 >( (1 << NMSP_SHIFT) - 1 );
+const sal_Int32 NMSP_MASK = static_cast< sal_Int32 >( SAL_MAX_INT32 & ~TOKEN_MASK );
+
+/** Returns the raw token identifier without namespace of the passed token. */
+inline sal_Int32 getBaseToken( sal_Int32 nToken ) { return nToken & TOKEN_MASK; }
+
+/** Returns the namespace without token identifier of the passed token. */
+inline sal_Int32 getNamespace( sal_Int32 nToken ) { return nToken & NMSP_MASK; }
+
+
+// defines for tokens with specific namespaces
+#define OOX_TOKEN( namespace, token ) (::oox::NMSP_##namespace | ::oox::XML_##token)
+
+#define A_TOKEN( token ) OOX_TOKEN( dml, token )
+#define AX_TOKEN( token ) OOX_TOKEN( ax, token )
+#define C_TOKEN( token ) OOX_TOKEN( dmlChart, token )
+#define CDR_TOKEN( token ) OOX_TOKEN( dmlChartDr, token )
+#define DGM_TOKEN( token ) OOX_TOKEN( dmlDiagram, token )
+#define MCE_TOKEN( token ) OOX_TOKEN( mce, token)
+#define O_TOKEN( token ) OOX_TOKEN( vmlOffice, token )
+#define PC_TOKEN( token ) OOX_TOKEN( packageContentTypes, token )
+#define PPT_TOKEN( token ) OOX_TOKEN( ppt, token )
+#define PR_TOKEN( token ) OOX_TOKEN( packageRel, token )
+#define R_TOKEN( token ) OOX_TOKEN( officeRel, token )
+#define VML_TOKEN( token ) OOX_TOKEN( vml, token )
+#define VMLX_TOKEN( token ) OOX_TOKEN( vmlExcel, token )
+#define XDR_TOKEN( token ) OOX_TOKEN( dmlSpreadDr, token )
+#define XLS_TOKEN( token ) OOX_TOKEN( xls, token )
+#define XLS_EXT_TOKEN( token ) OOX_TOKEN( xlsExtLst, token )
+#define XM_TOKEN( token ) OOX_TOKEN( xm, token )
+#define XML_TOKEN( token ) OOX_TOKEN( xml, token )
+#define VMLPPT_TOKEN( token ) OOX_TOKEN( vmlPowerpoint, token )
+#define DSP_TOKEN( token ) OOX_TOKEN( dsp, token )
+#define LC_TOKEN( token ) OOX_TOKEN( dmlLockedCanvas, token )
+#define WPS_TOKEN( token ) OOX_TOKEN( wps, token )
+#define WPG_TOKEN( token ) OOX_TOKEN( wpg, token )
+
+// ============================================================================
+
+} // namespace oox
+
+#endif
diff --git a/oox/source/token/namespaces-strict.pl b/oox/source/token/namespaces-strict.pl
new file mode 100644
index 000000000000..225b8f7f0ef2
--- /dev/null
+++ b/oox/source/token/namespaces-strict.pl
@@ -0,0 +1,70 @@
+#
+# 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 .
+#
+
+$ARGV0 = shift @ARGV;
+$ARGV1 = shift @ARGV;
+$ARGV2 = shift @ARGV;
+$ARGV3 = shift @ARGV;
+
+# parse input file
+
+open( INFILE, $ARGV0 ) or die "cannot open input file: $!";
+my %namespaces;
+while( <INFILE> )
+{
+ # trim newline
+ chomp( $_ );
+ # trim leading/trailing whitespace
+ $_ =~ s/^\s*//g;
+ $_ =~ s/\s*$//g;
+ # trim comments
+ $_ =~ s/^#.*//;
+ # skip empty lines
+ if( $_ )
+ {
+ # check for valid characters
+ $_ =~ /^([a-zA-Z][a-zA-Z0-9]*)\s+([a-zA-Z0-9-.:\/]+)\s*$/ or die "Error: invalid character in input data";
+ $namespaces{$1} = $2;
+ }
+}
+close( INFILE );
+
+# generate output files
+
+open( IDFILE, ">$ARGV1" ) or die "Error: cannot open output file: $!";
+open( NAMEFILE, ">$ARGV2" ) or die "Error: cannot open output file: $!";
+open( TXTFILE, ">$ARGV3" ) or die "Error: cannot open output file: $!";
+
+# number of bits to shift the namespace identifier
+$shift = 16;
+
+print ( IDFILE "const size_t NMSP_SHIFT = $shift;\n" );
+
+$i = 1;
+foreach( keys( %namespaces ) )
+{
+ print( IDFILE "const sal_Int32 NMSP_$_ = $i << NMSP_SHIFT;\n" );
+ $id = $i << $shift;
+ print( NAMEFILE "{ $id, \"$namespaces{$_}\" },\n" );
+ print( TXTFILE "$id $_ $namespaces{$_}\n" );
+ ++$i;
+}
+
+close( IDFILE );
+close( nameFILE );
+close( TXTFILE );
diff --git a/oox/source/token/namespaces-strict.txt b/oox/source/token/namespaces-strict.txt
new file mode 100644
index 000000000000..9549483ec280
--- /dev/null
+++ b/oox/source/token/namespaces-strict.txt
@@ -0,0 +1,82 @@
+#
+# 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 .
+#
+
+# generic XML -----------------------------------------------------------------
+
+xml http://www.w3.org/XML/1998/namespace
+schema http://purl.oclc.org/ooxml/schemaLibrary/main
+
+# package ---------------------------------------------------------------------
+
+packageContentTypes http://schemas.openxmlformats.org/package/2006/content-types
+packageMetaCorePr http://schemas.openxmlformats.org/package/2006/metadata/core-properties
+packageRel http://schemas.openxmlformats.org/package/2006/relationships
+
+# office shared ---------------------------------------------------------------
+
+officeCustomPr http://purl.oclc.org/ooxml/officeDocument/custom-properties
+officeDocPropsVT http://purl.oclc.org/ooxml/officeDocument/docPropsVTypes
+officeExtPr http://purl.oclc.org/ooxml/officeDocument/extended-properties
+officeMath http://purl.oclc.org/ooxml/officeDocument/math
+officeRel http://purl.oclc.org/ooxml/officeDocument/relationships
+officeRelTheme http://purl.oclc.org/ooxml/officeDocument/relationships/theme
+
+# applications ----------------------------------------------------------------
+
+doc http://purl.oclc.org/ooxml/wordprocessingml/main
+xls http://purl.oclc.org/ooxml/spreadsheetml/main
+ppt http://purl.oclc.org/ooxml/presentationml/main
+
+# drawing ---------------------------------------------------------------------
+
+dml http://purl.oclc.org/ooxml/drawingml/main
+dsp http://schemas.microsoft.com/office/drawing/2008/diagram
+dmlChart http://purl.oclc.org/ooxml/drawingml/chart
+dmlChartDr http://purl.oclc.org/ooxml/drawingml/chartDrawing
+dmlDiagram http://purl.oclc.org/ooxml/drawingml/diagram
+dmlLockedCanvas http://purl.oclc.org/ooxml/drawingml/lockedCanvas
+dmlPicture http://purl.oclc.org/ooxml/drawingml/picture
+dmlSpreadDr http://purl.oclc.org/ooxml/drawingml/spreadsheetDrawing
+dmlWordDr http://purl.oclc.org/ooxml/drawingml/wordprocessingDrawing
+
+# VML -------------------------------------------------------------------------
+
+vml urn:schemas-microsoft-com:vml
+vmlExcel urn:schemas-microsoft-com:office:excel
+vmlOffice urn:schemas-microsoft-com:office:office
+vmlPowerpoint urn:schemas-microsoft-com:office:powerpoint
+vmlWord urn:schemas-microsoft-com:office:word
+
+# other -----------------------------------------------------------------------
+
+ax http://schemas.microsoft.com/office/2006/activeX
+dc http://purl.org/dc/elements/1.1/
+dcTerms http://purl.org/dc/terms/
+xm http://schemas.microsoft.com/office/excel/2006/main
+sprm http://sprm
+mce http://schemas.openxmlformats.org/markup-compatibility/2006
+mceTest http://schemas.openxmlformats.org/spreadsheetml/2006/main/v2
+wps http://schemas.microsoft.com/office/word/2010/wordprocessingShape
+wpg http://schemas.microsoft.com/office/word/2010/wordprocessingGroup
+wp14 http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing
+w14 http://schemas.microsoft.com/office/word/2010/wordml
+
+# extlst namespaces
+
+# xlsExtLst for features introduced by excel 2010
+xlsExtLst http://schemas.microsoft.com/office/spreadsheetml/2009/9/main