incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robw...@apache.org
Subject svn commit: r1359972 [1/3] - in /incubator/odf/trunk: odfdom/ 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/o...
Date Wed, 11 Jul 2012 01:03:24 GMT
Author: robweir
Date: Wed Jul 11 01:03:23 2012
New Revision: 1359972

URL: http://svn.apache.org/viewvc?rev=1359972&view=rev
Log:
Add document encryption (oassword protection) support
Patch by: devinhan
https://issues.apache.org/jira/browse/ODFTOOLKIT-319

Added:
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfDecryptedException.java
  (with props)
    incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/manifest/OdfManifestDom.java
  (with props)
Modified:
    incubator/odf/trunk/odfdom/pom.xml
    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/pkg/LoadSaveErrorTest.java
    incubator/odf/trunk/odfdom/src/test/java/org/odftoolkit/odfdom/pkg/OdfXMLHelper.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/text/FooterTest.java
    incubator/odf/trunk/validator/src/main/java/org/odftoolkit/odfvalidator/ODFFileValidator.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

Modified: incubator/odf/trunk/odfdom/pom.xml
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/odfdom/pom.xml?rev=1359972&r1=1359971&r2=1359972&view=diff
==============================================================================
--- incubator/odf/trunk/odfdom/pom.xml (original)
+++ incubator/odf/trunk/odfdom/pom.xml Wed Jul 11 01:03:23 2012
@@ -98,6 +98,8 @@
                 <!-- Explizit version required for fix on systemPropertyVariables -->
                 <version>2.6</version>
                 <configuration>
+                    <forkMode>pertest</forkMode>
+                    <argLine>-Xms512m -Xmx512m</argLine>
                     <systemPropertyVariables>
                         <odfdom.version>${project.version}</odfdom.version>
                         <odfdom.timestamp>${build.timestamp}</odfdom.timestamp>

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=1359972&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
Wed Jul 11 01:03:23 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);
+	}
+}

Propchange: incubator/odf/trunk/odfdom/src/main/java/org/odftoolkit/odfdom/pkg/OdfDecryptedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1359972&r1=1359971&r2=1359972&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 Wed
Jul 11 01:03:23 2012
@@ -43,6 +43,7 @@ import org.odftoolkit.odfdom.dom.OdfMeta
 import org.odftoolkit.odfdom.dom.OdfSchemaDocument;
 import org.odftoolkit.odfdom.dom.OdfSettingsDom;
 import org.odftoolkit.odfdom.dom.OdfStylesDom;
+import org.odftoolkit.odfdom.pkg.manifest.OdfManifestDom;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -50,7 +51,7 @@ import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 
 /**
- * The DOM repesentation of an XML file within the ODF document.
+ * The DOM representation of an XML file within the ODF document.
  */
 public class OdfFileDom extends DocumentImpl implements NamespaceContext {
 
@@ -67,14 +68,15 @@ public class OdfFileDom extends Document
 
 	/**
 	 * 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
+	 * 
+	 * @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;
@@ -84,14 +86,43 @@ 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!");
 		}
 	}
-
-	/** Adds the document to the pool of open documents of the package.
-	A document of a certain path is opened only once to avoid data duplication.
+	
+	/**
+	 * Creates the DOM representation of an XML file of an Odf document.
+	 * 
+	 * @param pkg
+	 *            the package the XML files belongs to
+	 * @param packagePath
+	 *            the internal package path to the XML file
+	 */
+	protected OdfFileDom(OdfPackage pkg, String packagePath) {
+		super(false);
+		if (pkg != null && packagePath != null) {
+			mPackageDocument = null;
+			mPackage = pkg;
+			mPackagePath = packagePath;
+			mUriByPrefix = new HashMap<String, String>();
+			mPrefixByUri = new HashMap<String, String>();
+			mDuplicatePrefixesByUri = new HashMap<String, Set<String>>();
+			initialize();
+			// Register every DOM to OdfPackage,
+			// so a package close might save this DOM (similar as
+			// OdfDocumentPackage)
+			addDomToCache(mPackage, packagePath);
+		} else {
+			throw new IllegalArgumentException(
+					"Arguments are not allowed to be NULL for OdfFileDom constructor!");
+		}
+	}
+	
+	/**
+	 * Adds the document to the pool of open documents of the package. A
+	 * document of a certain path is opened only once to avoid data duplication.
 	 */
 	private void addDomToCache(OdfPackage pkg, String internalPath) {
 		pkg.cacheDom(this, internalPath);
@@ -111,6 +142,8 @@ public class OdfFileDom extends Document
 				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);
 			}
@@ -128,6 +161,30 @@ public class OdfFileDom extends Document
 		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 {
@@ -140,14 +197,14 @@ public class OdfFileDom extends Document
 			}
 
 		} catch (Exception ex) {
-			Logger.getLogger(OdfPackageDocument.class.getName()).log(Level.SEVERE, null, ex);
+			Logger.getLogger(OdfFileDom.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);
+				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=1359972&r1=1359971&r2=1359972&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
Wed Jul 11 01:03:23 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 {
 	}
 }
+*/



Mime
View raw message