incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svanteschub...@apache.org
Subject svn commit: r1786676 - in /incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg: OdfPackageNamespace.java manifest/EncryptionDataElement.java
Date Mon, 13 Mar 2017 12:54:54 GMT
Author: svanteschubert
Date: Mon Mar 13 12:54:54 2017
New Revision: 1786676

URL: http://svn.apache.org/viewvc?rev=1786676&view=rev
Log:
ODFTOOLKIT-447 Encrypted documents invalid due to misordered manifest XML elements

Added:
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackageNamespace.java
      - copied, changed from r1786195, incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/dom/OdfDocumentNamespace.java
Modified:
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/manifest/EncryptionDataElement.java

Copied: incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackageNamespace.java
(from r1786195, incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/dom/OdfDocumentNamespace.java)
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackageNamespace.java?p2=incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackageNamespace.java&p1=incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/dom/OdfDocumentNamespace.java&r1=1786195&r2=1786676&rev=1786676&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/dom/OdfDocumentNamespace.java
(original)
+++ incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackageNamespace.java
Mon Mar 13 12:54:54 2017
@@ -2,8 +2,6 @@
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
  *
- * Copyright 2008, 2010 Oracle and/or its affiliates. All rights reserved.
- *
  * Use is subject to license terms.
  *
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -20,49 +18,24 @@
  *
  ************************************************************************/
 
-package org.odftoolkit.odfdom.dom;
-
-import org.odftoolkit.odfdom.pkg.NamespaceName;
+package org.odftoolkit.odfdom.pkg;
 
 /**
- * Namespaces of OpenDocument 1.2 XML Schema
+ * Namespaces of OpenDocument 1.2 XML Package Schema
  */
-public enum OdfDocumentNamespace implements NamespaceName {
+public enum OdfPackageNamespace implements NamespaceName {
+
 
-	ANIM("anim", "urn:oasis:names:tc:opendocument:xmlns:animation:1.0"),
-	CHART("chart", "urn:oasis:names:tc:opendocument:xmlns:chart:1.0"),
-	CONFIG("config", "urn:oasis:names:tc:opendocument:xmlns:config:1.0"),
-	DB("db", "urn:oasis:names:tc:opendocument:xmlns:database:1.0"),
-	DC("dc", "http://purl.org/dc/elements/1.1/"),
-	DR3D("dr3d", "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"),
-	DRAW("draw", "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"),
-	FO("fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"),
-	FORM("form", "urn:oasis:names:tc:opendocument:xmlns:form:1.0"),
-	GRDDL("grddl", "http://www.w3.org/2003/g/data-view#"),
-	MATH("math", "http://www.w3.org/1998/Math/MathML"),
-	META("meta", "urn:oasis:names:tc:opendocument:xmlns:meta:1.0"),
-	NUMBER("number", "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"),
-	OF("of", "urn:oasis:names:tc:opendocument:xmlns:of:1.2"),
-	OFFICE("office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0"),
-	PRESENTATION("presentation", "urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"),
-	SCRIPT("script", "urn:oasis:names:tc:opendocument:xmlns:script:1.0"),
-	SMIL("smil", "urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"),
-	STYLE("style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0"),
-	SVG("svg", "urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"),
-	TABLE("table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0"),
-	TEXT("text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0"),
-	XFORMS("xforms", "http://www.w3.org/2002/xforms"),
-	XHTML("xhtml", "http://www.w3.org/1999/xhtml"),
-	XLINK("xlink", "http://www.w3.org/1999/xlink"),
+	MANIFEST("chart", "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"),
 	XML("xml", "http://www.w3.org/XML/1998/namespace" );
-    	
+
 	private String mPrefix;
 	private String mUri;
-	
-	OdfDocumentNamespace(String prefix, String uri) {
+
+	OdfPackageNamespace(String prefix, String uri) {
 		mPrefix = prefix;
 		mUri = uri;
-	}    
+	}
 
 	/**
 	 * @return the prefix currently related to ODF Namespace.
@@ -72,9 +45,9 @@ public enum OdfDocumentNamespace impleme
 	}
 
 	/**
-	 * @return the URI identifiying the ODF Namespace.
+	 * @return the URI identifying the ODF Namespace.
 	 */
 	public String getUri() {
 		return mUri;
 	}
-} 
+}

Modified: incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/manifest/EncryptionDataElement.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/manifest/EncryptionDataElement.java?rev=1786676&r1=1786675&r2=1786676&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/manifest/EncryptionDataElement.java
(original)
+++ incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/manifest/EncryptionDataElement.java
Mon Mar 13 12:54:54 2017
@@ -1,9 +1,9 @@
 /************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
- * 
+ *
  * Use is subject to license terms.
- * 
+ *
  * 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.
@@ -31,6 +31,8 @@ package org.odftoolkit.odfdom.pkg.manife
 import org.odftoolkit.odfdom.pkg.OdfElement;
 import org.odftoolkit.odfdom.pkg.OdfFileDom;
 import org.odftoolkit.odfdom.pkg.OdfName;
+import org.odftoolkit.odfdom.pkg.OdfPackageNamespace;
+import org.w3c.dom.NodeList;
 /**
  * Manifest implementation of OpenDocument element  {@odf.element manifest:encryption-data}.
  *
@@ -124,7 +126,21 @@ public class EncryptionDataElement exten
 		AlgorithmElement algorithm = ((OdfFileDom) this.ownerDocument).newOdfElement(AlgorithmElement.class);
 		algorithm.setAlgorithmNameAttribute(algorithmNameValue);
 		algorithm.setInitialisationVectorAttribute(initialisationVectorValue);
-		this.appendChild(algorithm);
+        if(this.hasChildNodes()){
+            OdfElement precedingSibling = null;
+            NodeList nl = this.getElementsByTagNameNS(OdfPackageNamespace.MANIFEST.getUri(),
"start-key-generation");
+            if(nl.getLength() == 0){
+                nl = this.getElementsByTagNameNS(OdfPackageNamespace.MANIFEST.getUri(), "key-derivation");
+            }
+            if(nl.getLength() != 0){
+               precedingSibling = (OdfElement) nl.item(0);
+               this.insertBefore(algorithm, precedingSibling);
+            }else{
+                this.appendChild(algorithm);
+            }
+        }else{
+            this.appendChild(algorithm);
+        }
 		return algorithm;
 	}
 
@@ -160,8 +176,20 @@ public class EncryptionDataElement exten
 	 public StartKeyGenerationElement newStartKeyGenerationElement(String startKeyGenerationNameValue)
{
 		StartKeyGenerationElement startKeyGeneration = ((OdfFileDom) this.ownerDocument).newOdfElement(StartKeyGenerationElement.class);
 		startKeyGeneration.setStartKeyGenerationNameAttribute(startKeyGenerationNameValue);
-		this.appendChild(startKeyGeneration);
-		return startKeyGeneration;
+
+        if(this.hasChildNodes()){
+            OdfElement precedingSibling = null;
+            NodeList nl = this.getElementsByTagNameNS(OdfPackageNamespace.MANIFEST.getUri(),
"key-derivation");
+            if(nl.getLength() != 0){
+               precedingSibling = (OdfElement) nl.item(0);
+               this.insertBefore(startKeyGeneration, precedingSibling);
+            }else{
+                this.appendChild(startKeyGeneration);
+            }
+        }else{
+            this.appendChild(startKeyGeneration);
+        }
+        return startKeyGeneration;
 	}
 
 }



Mime
View raw message