]> source.dussan.org Git - poi.git/commitdiff
bug 61296: consolidate some of the ooxml namespace uri copy-paste in POI, prepare...
authorJaven O'Neal <onealj@apache.org>
Fri, 14 Jul 2017 03:14:30 +0000 (03:14 +0000)
committerJaven O'Neal <onealj@apache.org>
Fri, 14 Jul 2017 03:14:30 +0000 (03:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1801901 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/POIXMLTypeLoader.java
src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java
src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestRelationships.java

index f11b2d88b53c63a63f0624c69847833ed6da118b..ec829ce44e4a37cb76e798dfb36e498f26c71e45 100644 (file)
@@ -31,6 +31,7 @@ import java.util.Map;
 
 import javax.xml.stream.XMLStreamReader;
 
+import org.apache.poi.openxml4j.opc.PackageNamespaces;
 import org.apache.poi.util.DocumentHelper;
 import org.apache.xmlbeans.SchemaType;
 import org.apache.xmlbeans.SchemaTypeLoader;
@@ -49,6 +50,13 @@ import org.xml.sax.SAXException;
 public class POIXMLTypeLoader {
 
     private static ThreadLocal<ClassLoader> classLoader = new ThreadLocal<ClassLoader>();
+
+    // TODO: Do these have a good home like o.a.p.openxml4j.opc.PackageNamespaces and PackageRelationshipTypes?
+    // These constants should be common to all of POI and easy to use by other applications such as Tika
+    private static final String MS_OFFICE_URN = "urn:schemas-microsoft-com:office:office";
+    private static final String MS_EXCEL_URN = "urn:schemas-microsoft-com:office:excel";
+    private static final String MS_WORD_URN = "urn:schemas-microsoft-com:office:word";
+    private static final String MS_VML_URN = "urn:schemas-microsoft-com:vml";
     
     public static final XmlOptions DEFAULT_XML_OPTIONS;
     static {
@@ -66,17 +74,17 @@ public class POIXMLTypeLoader {
         map.put("http://schemas.openxmlformats.org/drawingml/2006/main", "a");
         map.put("http://schemas.openxmlformats.org/drawingml/2006/chart", "c");
         map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
-        map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
+        map.put(PackageNamespaces.MARKUP_COMPATIBILITY, "ve");
         map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
         map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
         map.put("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", "vt");
         map.put("http://schemas.openxmlformats.org/presentationml/2006/main", "p");
         map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
         map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne");
-        map.put("urn:schemas-microsoft-com:office:office", "o");
-        map.put("urn:schemas-microsoft-com:office:excel", "x");
-        map.put("urn:schemas-microsoft-com:office:word", "w10");
-        map.put("urn:schemas-microsoft-com:vml", "v");
+        map.put(MS_OFFICE_URN, "o");
+        map.put(MS_EXCEL_URN, "x");
+        map.put(MS_WORD_URN, "w10");
+        map.put(MS_VML_URN, "v");
         DEFAULT_XML_OPTIONS.setSaveSuggestedPrefixes(Collections.unmodifiableMap(map));
     }
     
index c315be51bfe0d3c702ada214147ee355a9aa6629..7e513e51c854f5e8c64abacfa42e927141070ec8 100644 (file)
@@ -30,6 +30,7 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
 import org.apache.poi.openxml4j.opc.ContentTypes;
 import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageNamespaces;
 import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.openxml4j.opc.PackagePartName;
 import org.apache.poi.openxml4j.opc.PackageProperties;
@@ -46,7 +47,7 @@ public final class PackagePropertiesPart extends PackagePart implements
 
        public final static String NAMESPACE_DC_URI = "http://purl.org/dc/elements/1.1/";
 
-       public final static String NAMESPACE_CP_URI = "http://schemas.openxmlformats.org/package/2006/metadata/core-properties";
+       public final static String NAMESPACE_CP_URI = PackageNamespaces.CORE_PROPERTIES;
 
        public final static String NAMESPACE_DCTERMS_URI = "http://purl.org/dc/terms/";
 
index cf485ed1f6d04e88bad9035613713b559ea59537..ebbc309ffa660d563e9c10651c30a733f2eb9a10 100644 (file)
@@ -260,7 +260,7 @@ public class TestRelationships extends TestCase {
                        partB.getRelationship("rId1").getTargetURI().toString());
        // Check core too
        assertEquals("/docProps/core.xml",
-                       pkg.getRelationshipsByType("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties").getRelationship(0).getTargetURI().toString());
+                       pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_PROPERTIES).getRelationship(0).getTargetURI().toString());
        
        
        // Add some more