incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liud...@apache.org
Subject svn commit: r1424353 [1/3] - in /incubator/odf/trunk: odfdom/src/main/java/org/odftoolkit/odfdom/pkg/ odfdom/src/main/java/org/odftoolkit/odfdom/pkg/manifest/ odfdom/src/test/java/org/odftoolkit/odfdom/doc/ odfdom/src/test/java/org/odftoolkit/odfdom/in...
Date Thu, 20 Dec 2012 07:33:34 GMT
Author: liudali
Date: Thu Dec 20 07:33:34 2012
New Revision: 1424353

URL: http://svn.apache.org/viewvc?rev=1424353&view=rev
Log:
ODFTOOLKIT-319 Add Document encryption support - developer:Devin Han,Rob Weir,Dali Liu

Added:
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfDecryptedException.java
Removed:
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/manifest/Algorithm.java
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/manifest/EncryptionData.java
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/manifest/KeyDerivation.java
Modified:
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfFileDom.java
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfManifestSaxHandler.java
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackage.java
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfPackageDocument.java
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfValidationException.java
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfXMLFactory.java
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/ZipHelper.java
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/manifest/OdfFileEntry.java
    incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/doc/DocumentTest.java
    incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/incubator/meta/OfficeMetaTest.java
    incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/PackageTest.java
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/Document.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/DocumentTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/SpreadsheetDocumentTest.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/meta/OfficeMetaTest.java
    incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFPackageValidator.java
    incubator/odf/trunk/validator/src/test/java/org/odftoolkit/odfvalidator/InvalidPackageTest.java

Added: incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfDecryptedException.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfDecryptedException.java?rev=1424353&view=auto
==============================================================================
--- incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfDecryptedException.java
(added)
+++ incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfDecryptedException.java
Thu Dec 20 07:33:34 2012
@@ -0,0 +1,37 @@
+/************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
+ *
+ * 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * 
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ************************************************************************/
+package org.odftoolkit.odfdom.pkg;
+
+/**
+ * This ODF document decryption exception.
+ * 
+ * @since 0.8.9
+ * 
+ */
+public class OdfDecryptedException extends RuntimeException {
+
+	private static final long serialVersionUID = 7657277144612220943L;
+
+	public OdfDecryptedException(String message) {
+		super(message);
+	}
+}

Modified: incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfFileDom.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfFileDom.java?rev=1424353&r1=1424352&r2=1424353&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfFileDom.java (original)
+++ incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfFileDom.java Thu
Dec 20 07:33:34 2012
@@ -83,20 +83,21 @@ public class OdfFileDom extends Document
 	protected Map<Node, Model> inCententMetadataCache;
 
 	protected JenaSink sink;
-	
-	/**
-	 * Creates the DOM representation of an XML file of an Odf document.
-	 *
-	 * @param packageDocument   the document the XML files belongs to
-	 * @param packagePath   the internal package path to the XML file
-	 */
-	protected OdfFileDom(OdfPackageDocument packageDocument, String packagePath) {
-		super(false);
-		if (packageDocument != null && packagePath != null) {
-
-			mPackageDocument = packageDocument;
-			mPackage = packageDocument.getPackage();
-			mPackagePath = packagePath;
+
+	/**
+	 * Creates the DOM representation of an XML file of an Odf document.
+	 * 
+	 * @param packageDocument
+	 *            the document the XML files belongs to
+	 * @param packagePath
+	 *            the internal package path to the XML file
+	 */
+	protected OdfFileDom(OdfPackageDocument packageDocument, String packagePath) {
+		super(false);
+		if (packageDocument != null && packagePath != null) {
+			mPackageDocument = packageDocument;
+			mPackage = packageDocument.getPackage();
+			mPackagePath = packagePath;
 			mUriByPrefix = new HashMap<String, String>();
 			mPrefixByUri = new HashMap<String, String>();
 			mDuplicatePrefixesByUri = new HashMap<String, Set<String>>();
@@ -104,7 +105,7 @@ public class OdfFileDom extends Document
 			initialize();
 			// Register every DOM to OdfPackage,
 			// so a package close might save this DOM (similar as OdfDocumentPackage)
-			this.addDomToCache(mPackageDocument.mPackage, packagePath);
+			this.addDomToCache(mPackage, packagePath);
 		} else {
 			throw new IllegalArgumentException("Arguments are not allowed to be NULL for OdfFileDom
constructor!");
 		}
@@ -157,12 +158,14 @@ public class OdfFileDom extends Document
 			} else if (packagePath.equals("styles.xml") || packagePath.endsWith("/styles.xml")) {
 				newFileDom = new OdfStylesDom((OdfSchemaDocument) packageDocument, packagePath);
 			} else if (packagePath.equals("meta.xml") || packagePath.endsWith("/meta.xml")) {
-				newFileDom = new OdfMetaDom((OdfSchemaDocument) packageDocument, packagePath);
-			} else if (packagePath.equals("settings.xml") || packagePath.endsWith("/settings.xml"))
{
-				newFileDom = new OdfSettingsDom((OdfSchemaDocument) packageDocument, packagePath);
-			} else {
-				newFileDom = new OdfFileDom(packageDocument, packagePath);
-			}
+				newFileDom = new OdfMetaDom((OdfSchemaDocument) packageDocument, packagePath);
+			} else if (packagePath.equals("settings.xml") || packagePath.endsWith("/settings.xml"))
{
+				newFileDom = new OdfSettingsDom((OdfSchemaDocument) packageDocument, packagePath);
+			} else if (packagePath.equals("META-INF/manifest.xml") || packagePath.endsWith("/META-INF/manifest.xml"))
{
+				newFileDom = new OdfManifestDom((OdfSchemaDocument) packageDocument, packagePath);
+			} else {
+				newFileDom = new OdfFileDom(packageDocument, packagePath);
+			}
 		} else {
 			if (existingDom instanceof OdfFileDom) {
 				newFileDom = (OdfFileDom) existingDom;
@@ -174,12 +177,36 @@ public class OdfFileDom extends Document
 			}
 
 		}
-		return newFileDom;
-	}
-
-	protected void initialize() {
-		InputStream fileStream = null;
-		try {
+		return newFileDom;
+	}
+
+	public static OdfFileDom newFileDom(OdfPackage pkg, String packagePath) {
+		OdfFileDom newFileDom = null;
+		// before creating a new dom, make sure that there no DOM opened for this file already
+		Document existingDom = pkg.getCachedDom(packagePath);
+		if (existingDom == null) {
+			if (packagePath.equals("META-INF/manifest.xml") || packagePath.endsWith("/META-INF/manifest.xml"))
{
+				newFileDom = new OdfManifestDom(pkg, packagePath);
+			} else {
+				newFileDom = new OdfFileDom(pkg, packagePath);
+			}
+		} else {
+			if (existingDom instanceof OdfFileDom) {
+				newFileDom = (OdfFileDom) existingDom;
+//ToDO: Issue 264 - Otherwise if NOT an OdfFileDom serialize old DOM AND CREATE A NEW ONE?!
+// Or shall we always reference to the dom, than we can not inherit from Document? Pro/Con?s
+//			}else{
+//				// Create an OdfFileDOM from an existing DOM
+//				newFileDom =
+			}
+
+		}
+		return newFileDom;
+	}
+	
+	protected void initialize() {
+		InputStream fileStream = null;
+		try {
 			fileStream = mPackage.getInputStream(mPackagePath);
 			if (fileStream != null) {
 				XMLReader xmlReader = mPackage.getXMLReader();
@@ -195,16 +222,16 @@ public class OdfFileDom extends Document
 				InputSource xmlSource = new InputSource(fileStream);
 				xmlReader.parse(xmlSource);
 			}
-		} catch (Exception ex) {
-			Logger.getLogger(OdfPackageDocument.class.getName()).log(Level.SEVERE, null, ex);
-		} finally {
-			try {
-				if (fileStream != null) {
-					fileStream.close();
-				}
-			} catch (IOException ex) {
-				Logger.getLogger(OdfPackageDocument.class.getName()).log(Level.SEVERE, null, ex);
-			}
+		} catch (Exception ex) {
+			Logger.getLogger(OdfFileDom.class.getName()).log(Level.SEVERE, null, ex);
+		} finally {
+			try {
+				if (fileStream != null) {
+					fileStream.close();
+				}
+			} catch (IOException ex) {
+				Logger.getLogger(OdfFileDom.class.getName()).log(Level.SEVERE, null, ex);
+			}
 		}
 	}
 

Modified: incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfManifestSaxHandler.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfManifestSaxHandler.java?rev=1424353&r1=1424352&r2=1424353&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfManifestSaxHandler.java
(original)
+++ incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfManifestSaxHandler.java
Thu Dec 20 07:33:34 2012
@@ -18,7 +18,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
- ************************************************************************/
+ ************************************************************************//*
 package org.odftoolkit.odfdom.pkg;
 
 import java.util.Map;
@@ -42,40 +42,40 @@ class OdfManifestSaxHandler implements C
 		mPackage = pkg;
 	}
 
-	/**
+	*//**
 	 * Receive an object for locating the origin of SAX document events.
-	 */
+	 *//*
 	public void setDocumentLocator(Locator locator) {
 	}
 
-	/**
+	*//**
 	 * Receive notification of the beginning of a document.
-	 */
+	 *//*
 	public void startDocument() throws SAXException {
 	}
 
-	/**
+	*//**
 	 * Receive notification of the end of a document.
-	 */
+	 *//*
 	public void endDocument() throws SAXException {
 	}
 
-	/**
+	*//**
 	 * Begin the scope of a prefix-URI Namespace mapping.
-	 */
+	 *//*
 	public void startPrefixMapping(String prefix, String uri)
 			throws SAXException {
 	}
 
-	/**
+	*//**
 	 * End the scope of a prefix-URI mapping.
-	 */
+	 *//*
 	public void endPrefixMapping(String prefix) throws SAXException {
 	}
 
-	/**
+	*//**
 	 * Receive notification of the beginning of an element.
-	 */
+	 *//*
 	public void startElement(String namespaceURI, String localName,
 			String qName, Attributes atts) throws SAXException {
 		Map<String, OdfFileEntry> entries = mPackage.getManifestEntries();
@@ -140,9 +140,9 @@ class OdfManifestSaxHandler implements C
 
 	}
 
-	/**
+	*//**
 	 * Receive notification of the end of an element.
-	 */
+	 *//*
 	public void endElement(String namespaceURI, String localName,
 			String qName) throws SAXException {
 		//ToDo Issue 263: Parsing of Manifest.xml specific part to be added to parser
@@ -151,30 +151,31 @@ class OdfManifestSaxHandler implements C
 		}
 	}
 
-	/**
+	*//**
 	 * Receive notification of character data.
-	 */
+	 *//*
 	public void characters(char[] ch, int start, int length)
 			throws SAXException {
 	}
 
-	/**
+	*//**
 	 * Receive notification of ignorable whitespace in element content.
-	 */
+	 *//*
 	public void ignorableWhitespace(char[] ch, int start, int length)
 			throws SAXException {
 	}
 
-	/**
+	*//**
 	 * Receive notification of a processing instruction.
-	 */
+	 *//*
 	public void processingInstruction(String target, String data)
 			throws SAXException {
 	}
 
-	/**
+	*//**
 	 * Receive notification of a skipped entity.
-	 */
+	 *//*
 	public void skippedEntity(String name) throws SAXException {
 	}
 }
+*/
\ No newline at end of file



Mime
View raw message