You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2009/01/29 13:44:35 UTC
svn commit: r738842 [5/7] - in /poi/trunk: ./ legal/ maven/
src/documentation/content/xdocs/ src/documentation/content/xdocs/oxml4j/
src/documentation/content/xdocs/spreadsheet/
src/examples/src/org/apache/poi/xssf/eventusermodel/examples/ src/ooxml/ja...
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,163 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.opc.internal;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
+import org.apache.poi.openxml4j.opc.ZipPackage;
+
+public final class ZipHelper {
+
+ /**
+ * Forward slash use to convert part name between OPC and zip item naming
+ * conventions.
+ */
+ private final static String FORWARD_SLASH = "/";
+
+ /**
+ * Buffer to read data from file. Use big buffer to improve performaces. the
+ * InputStream class is reading only 8192 bytes per read call (default value
+ * set by sun)
+ */
+ public static final int READ_WRITE_FILE_BUFFER_SIZE = 8192;
+
+ /**
+ * Prevent this class to be instancied.
+ */
+ private ZipHelper() {
+ // Do nothing
+ }
+
+ /**
+ * Retrieve the zip entry of the core properties part.
+ *
+ * @throws OpenXML4JException
+ * Throws if internal error occurs.
+ */
+ public static ZipEntry getCorePropertiesZipEntry(ZipPackage pkg)
+ throws OpenXML4JException {
+ PackageRelationship corePropsRel = pkg.getRelationshipsByType(
+ PackageRelationshipTypes.CORE_PROPERTIES).getRelationship(0);
+
+ if (corePropsRel == null)
+ return null;
+
+ return new ZipEntry(corePropsRel.getTargetURI().getPath());
+ }
+
+ /**
+ * Retrieve the Zip entry of the content types part.
+ */
+ public static ZipEntry getContentTypeZipEntry(ZipPackage pkg) {
+ Enumeration entries = pkg.getZipArchive().getEntries();
+ // Enumerate through the Zip entries until we find the one named
+ // '[Content_Types].xml'.
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = (ZipEntry) entries.nextElement();
+ if (entry.getName().equals(
+ ContentTypeManager.CONTENT_TYPES_PART_NAME))
+ return entry;
+ }
+ return null;
+ }
+
+ /**
+ * Convert a zip name into an OPC name by adding a leading forward slash to
+ * the specified item name.
+ *
+ * @param zipItemName
+ * Zip item name to convert.
+ * @return An OPC compliant name.
+ */
+ public static String getOPCNameFromZipItemName(String zipItemName) {
+ if (zipItemName == null)
+ throw new IllegalArgumentException("zipItemName");
+ if (zipItemName.startsWith(FORWARD_SLASH))
+ return zipItemName;
+ else
+ return FORWARD_SLASH + zipItemName;
+ }
+
+ /**
+ * Convert an OPC item name into a zip item name by removing any leading
+ * forward slash if it exist.
+ *
+ * @param opcItemName
+ * The OPC item name to convert.
+ * @return A zip item name without any leading slashes.
+ */
+ public static String getZipItemNameFromOPCName(String opcItemName) {
+ if (opcItemName == null)
+ throw new IllegalArgumentException("opcItemName");
+
+ String retVal = new String(opcItemName);
+ while (retVal.startsWith(FORWARD_SLASH))
+ retVal = retVal.substring(1);
+ return retVal;
+ }
+
+ /**
+ * Convert an OPC item name into a zip URI by removing any leading forward
+ * slash if it exist.
+ *
+ * @param opcItemName
+ * The OPC item name to convert.
+ * @return A zip URI without any leading slashes.
+ */
+ public static URI getZipURIFromOPCName(String opcItemName) {
+ if (opcItemName == null)
+ throw new IllegalArgumentException("opcItemName");
+
+ String retVal = new String(opcItemName);
+ while (retVal.startsWith(FORWARD_SLASH))
+ retVal = retVal.substring(1);
+ try {
+ return new URI(retVal);
+ } catch (URISyntaxException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Retrieve and open a zip file with the specified path.
+ *
+ * @param path
+ * The file path.
+ * @return The zip archive freshly open.
+ */
+ public static ZipFile openZipFile(String path) {
+ File f = new File(path);
+ try {
+ if (!f.exists()) {
+ return null;
+ }
+ return new ZipFile(f);
+ } catch (IOException ioe) {
+ return null;
+ }
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/DefaultMarshaller.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/DefaultMarshaller.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/DefaultMarshaller.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/DefaultMarshaller.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,45 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.opc.internal.marshallers;
+
+import java.io.OutputStream;
+
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
+
+/**
+ * Default marshaller that specified that the part is responsible to marshall its content.
+ *
+ * @author Julien Chable
+ * @version 1.0
+ * @see PartMarshaller
+ */
+public class DefaultMarshaller implements PartMarshaller {
+
+ /**
+ * Save part in the output stream by using the save() method of the part.
+ *
+ * @throws OpenXML4JException
+ * If any error occur.
+ */
+ public boolean marshall(PackagePart part, OutputStream out)
+ throws OpenXML4JException {
+ return part.save(out);
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/DefaultMarshaller.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,434 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.opc.internal.marshallers;
+
+import java.io.OutputStream;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
+import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
+
+/**
+ * Package properties marshaller.
+ *
+ * @author CDubet, Julien Chable
+ * @version 1.0
+ */
+public class PackagePropertiesMarshaller implements PartMarshaller {
+
+ private final static Namespace namespaceDC = new Namespace("dc",
+ PackagePropertiesPart.NAMESPACE_DC_URI);
+
+ private final static Namespace namespaceCoreProperties = new Namespace("",
+ PackagePropertiesPart.NAMESPACE_CP_URI);
+
+ private final static Namespace namespaceDcTerms = new Namespace("dcterms",
+ PackagePropertiesPart.NAMESPACE_DCTERMS_URI);
+
+ private final static Namespace namespaceXSI = new Namespace("xsi",
+ PackagePropertiesPart.NAMESPACE_XSI_URI);
+
+ protected static final String KEYWORD_CATEGORY = "category";
+
+ protected static final String KEYWORD_CONTENT_STATUS = "contentStatus";
+
+ protected static final String KEYWORD_CONTENT_TYPE = "contentType";
+
+ protected static final String KEYWORD_CREATED = "created";
+
+ protected static final String KEYWORD_CREATOR = "creator";
+
+ protected static final String KEYWORD_DESCRIPTION = "description";
+
+ protected static final String KEYWORD_IDENTIFIER = "identifier";
+
+ protected static final String KEYWORD_KEYWORDS = "keywords";
+
+ protected static final String KEYWORD_LANGUAGE = "language";
+
+ protected static final String KEYWORD_LAST_MODIFIED_BY = "lastModifiedBy";
+
+ protected static final String KEYWORD_LAST_PRINTED = "lastPrinted";
+
+ protected static final String KEYWORD_MODIFIED = "modified";
+
+ protected static final String KEYWORD_REVISION = "revision";
+
+ protected static final String KEYWORD_SUBJECT = "subject";
+
+ protected static final String KEYWORD_TITLE = "title";
+
+ protected static final String KEYWORD_VERSION = "version";
+
+ PackagePropertiesPart propsPart;
+
+ // The document
+ Document xmlDoc = null;
+
+ /**
+ * Marshall package core properties to an XML document. Always return
+ * <code>true</code>.
+ */
+ public boolean marshall(PackagePart part, OutputStream out)
+ throws OpenXML4JException {
+ if (!(part instanceof PackagePropertiesPart))
+ throw new IllegalArgumentException(
+ "'part' must be a PackagePropertiesPart instance.");
+ propsPart = (PackagePropertiesPart) part;
+
+ // Configure the document
+ xmlDoc = DocumentHelper.createDocument();
+ Element rootElem = xmlDoc.addElement(new QName("coreProperties",
+ namespaceCoreProperties));
+ rootElem.addNamespace("cp", PackagePropertiesPart.NAMESPACE_CP_URI);
+ rootElem.addNamespace("dc", PackagePropertiesPart.NAMESPACE_DC_URI);
+ rootElem.addNamespace("dcterms",
+ PackagePropertiesPart.NAMESPACE_DCTERMS_URI);
+ rootElem.addNamespace("xsi", PackagePropertiesPart.NAMESPACE_XSI_URI);
+
+ addCategory();
+ addContentStatus();
+ addContentType();
+ addCreated();
+ addCreator();
+ addDescription();
+ addIdentifier();
+ addKeywords();
+ addLanguage();
+ addLastModifiedBy();
+ addLastPrinted();
+ addModified();
+ addRevision();
+ addSubject();
+ addTitle();
+ addVersion();
+ return true;
+ }
+
+ /**
+ * Add category property element if needed.
+ */
+ private void addCategory() {
+ if (!propsPart.getCategoryProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_CATEGORY, namespaceCoreProperties));
+ if (elem == null) {
+ // Missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_CATEGORY, namespaceCoreProperties));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getCategoryProperty().getValue());
+ }
+
+ /**
+ * Add content status property element if needed.
+ */
+ private void addContentStatus() {
+ if (!propsPart.getContentStatusProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_CONTENT_STATUS, namespaceCoreProperties));
+ if (elem == null) {
+ // Missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_CONTENT_STATUS, namespaceCoreProperties));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getContentStatusProperty().getValue());
+ }
+
+ /**
+ * Add content type property element if needed.
+ */
+ private void addContentType() {
+ if (!propsPart.getContentTypeProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_CONTENT_TYPE, namespaceCoreProperties));
+ if (elem == null) {
+ // Missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_CONTENT_TYPE, namespaceCoreProperties));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getContentTypeProperty().getValue());
+ }
+
+ /**
+ * Add created property element if needed.
+ */
+ private void addCreated() {
+ if (!propsPart.getCreatedProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_CREATED, namespaceDcTerms));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_CREATED, namespaceDcTerms));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addAttribute(new QName("type", namespaceXSI), "dcterms:W3CDTF");
+ elem.addText(propsPart.getCreatedPropertyString());
+ }
+
+ /**
+ * Add creator property element if needed.
+ */
+ private void addCreator() {
+ if (!propsPart.getCreatorProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_CREATOR, namespaceDC));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_CREATOR, namespaceDC));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getCreatorProperty().getValue());
+ }
+
+ /**
+ * Add description property element if needed.
+ */
+ private void addDescription() {
+ if (!propsPart.getDescriptionProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_DESCRIPTION, namespaceDC));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_DESCRIPTION, namespaceDC));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getDescriptionProperty().getValue());
+ }
+
+ /**
+ * Add identifier property element if needed.
+ */
+ private void addIdentifier() {
+ if (!propsPart.getIdentifierProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_IDENTIFIER, namespaceDC));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_IDENTIFIER, namespaceDC));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getIdentifierProperty().getValue());
+ }
+
+ /**
+ * Add keywords property element if needed.
+ */
+ private void addKeywords() {
+ if (!propsPart.getKeywordsProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_KEYWORDS, namespaceCoreProperties));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_KEYWORDS, namespaceCoreProperties));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getKeywordsProperty().getValue());
+ }
+
+ /**
+ * Add language property element if needed.
+ */
+ private void addLanguage() {
+ if (!propsPart.getLanguageProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_LANGUAGE, namespaceDC));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_LANGUAGE, namespaceDC));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getLanguageProperty().getValue());
+ }
+
+ /**
+ * Add 'last modified by' property if needed.
+ */
+ private void addLastModifiedBy() {
+ if (!propsPart.getLastModifiedByProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_LAST_MODIFIED_BY, namespaceCoreProperties));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement()
+ .addElement(
+ new QName(KEYWORD_LAST_MODIFIED_BY,
+ namespaceCoreProperties));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getLastModifiedByProperty().getValue());
+ }
+
+ /**
+ * Add 'last printed' property if needed.
+ *
+ */
+ private void addLastPrinted() {
+ if (!propsPart.getLastPrintedProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_LAST_PRINTED, namespaceCoreProperties));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_LAST_PRINTED, namespaceCoreProperties));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getLastPrintedPropertyString());
+ }
+
+ /**
+ * Add modified property element if needed.
+ */
+ private void addModified() {
+ if (!propsPart.getModifiedProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_MODIFIED, namespaceDcTerms));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_MODIFIED, namespaceDcTerms));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addAttribute(new QName("type", namespaceXSI), "dcterms:W3CDTF");
+ elem.addText(propsPart.getModifiedPropertyString());
+ }
+
+ /**
+ * Add revision property if needed.
+ */
+ private void addRevision() {
+ if (!propsPart.getRevisionProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_REVISION, namespaceCoreProperties));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_REVISION, namespaceCoreProperties));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getRevisionProperty().getValue());
+ }
+
+ /**
+ * Add subject property if needed.
+ */
+ private void addSubject() {
+ if (!propsPart.getSubjectProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_SUBJECT, namespaceDC));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_SUBJECT, namespaceDC));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getSubjectProperty().getValue());
+ }
+
+ /**
+ * Add title property if needed.
+ */
+ private void addTitle() {
+ if (!propsPart.getTitleProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_TITLE, namespaceDC));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_TITLE, namespaceDC));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getTitleProperty().getValue());
+ }
+
+ private void addVersion() {
+ if (!propsPart.getVersionProperty().hasValue())
+ return;
+
+ Element elem = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_VERSION, namespaceCoreProperties));
+ if (elem == null) {
+ // missing, we add it
+ elem = xmlDoc.getRootElement().addElement(
+ new QName(KEYWORD_VERSION, namespaceCoreProperties));
+ } else {
+ elem.clearContent();// clear the old value
+ }
+ elem.addText(propsPart.getVersionProperty().getValue());
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/PackagePropertiesMarshaller.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPackagePropertiesMarshaller.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPackagePropertiesMarshaller.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPackagePropertiesMarshaller.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPackagePropertiesMarshaller.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,64 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.opc.internal.marshallers;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.StreamHelper;
+import org.apache.poi.openxml4j.opc.internal.ZipHelper;
+
+/**
+ * Package core properties marshaller specialized for zipped package.
+ *
+ * @author Julien Chable
+ * @version 1.0
+ */
+public class ZipPackagePropertiesMarshaller extends PackagePropertiesMarshaller {
+
+ @Override
+ public boolean marshall(PackagePart part, OutputStream out)
+ throws OpenXML4JException {
+ if (!(out instanceof ZipOutputStream)) {
+ throw new IllegalArgumentException("ZipOutputStream expected!");
+ }
+ ZipOutputStream zos = (ZipOutputStream) out;
+
+ // Saving the part in the zip file
+ ZipEntry ctEntry = new ZipEntry(ZipHelper
+ .getZipItemNameFromOPCName(part.getPartName().getURI()
+ .toString()));
+ try {
+ // Save in ZIP
+ zos.putNextEntry(ctEntry); // Add entry in ZIP
+ super.marshall(part, out); // Marshall the properties inside a XML
+ // Document
+ if (!StreamHelper.saveXmlInStream(xmlDoc, out)) {
+ return false;
+ }
+ zos.closeEntry();
+ } catch (IOException e) {
+ throw new OpenXML4JException(e.getLocalizedMessage());
+ }
+ return true;
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPackagePropertiesMarshaller.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,193 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.opc.internal.marshallers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.apache.log4j.Logger;
+import org.dom4j.Document;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+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.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.openxml4j.opc.StreamHelper;
+import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.openxml4j.opc.internal.PartMarshaller;
+import org.apache.poi.openxml4j.opc.internal.ZipHelper;
+
+/**
+ * Zip part marshaller. This marshaller is use to save any part in a zip stream.
+ *
+ * @author Julien Chable
+ * @version 0.1
+ */
+public class ZipPartMarshaller implements PartMarshaller {
+ private static Logger logger = Logger.getLogger("org.openxml4j");
+
+ /**
+ * Save the specified part.
+ *
+ * @throws OpenXML4JException
+ * Throws if an internal exception is thrown.
+ */
+ public boolean marshall(PackagePart part, OutputStream os)
+ throws OpenXML4JException {
+ if (!(os instanceof ZipOutputStream)) {
+ logger.error("Unexpected class " + os.getClass().getName());
+ throw new OpenXML4JException("ZipOutputStream expected !");
+ // Normally should happen only in developpement phase, so just throw
+ // exception
+ }
+
+ ZipOutputStream zos = (ZipOutputStream) os;
+ ZipEntry partEntry = new ZipEntry(ZipHelper
+ .getZipItemNameFromOPCName(part.getPartName().getURI()
+ .getPath()));
+ try {
+ // Create next zip entry
+ zos.putNextEntry(partEntry);
+
+ // Saving data in the ZIP file
+ InputStream ins = part.getInputStream();
+ byte[] buff = new byte[ZipHelper.READ_WRITE_FILE_BUFFER_SIZE];
+ while (ins.available() > 0) {
+ int resultRead = ins.read(buff);
+ if (resultRead == -1) {
+ // End of file reached
+ break;
+ } else {
+ zos.write(buff, 0, resultRead);
+ }
+ }
+ zos.closeEntry();
+ } catch (IOException ioe) {
+ logger.error("Cannot write: " + part.getPartName() + ": in ZIP",
+ ioe);
+ return false;
+ }
+
+ // Saving relationship part
+ if (part.hasRelationships()) {
+ PackagePartName relationshipPartName = PackagingURIHelper
+ .getRelationshipPartName(part.getPartName());
+
+ marshallRelationshipPart(part.getRelationships(),
+ relationshipPartName, zos);
+
+ }
+ return true;
+ }
+
+ /**
+ * Save relationships into the part.
+ *
+ * @param rels
+ * The relationships collection to marshall.
+ * @param relPartURI
+ * Part name of the relationship part to marshall.
+ * @param zos
+ * Zip output stream in which to save the XML content of the
+ * relationships serialization.
+ */
+ public static boolean marshallRelationshipPart(
+ PackageRelationshipCollection rels, PackagePartName relPartName,
+ ZipOutputStream zos) {
+ // Building xml
+ Document xmlOutDoc = DocumentHelper.createDocument();
+ // make something like <Relationships
+ // xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
+ Namespace dfNs = Namespace.get("", PackageNamespaces.RELATIONSHIPS);
+ Element root = xmlOutDoc.addElement(new QName(
+ PackageRelationship.RELATIONSHIPS_TAG_NAME, dfNs));
+
+ // <Relationship
+ // TargetMode="External"
+ // Id="rIdx"
+ // Target="http://www.custom.com/images/pic1.jpg"
+ // Type="http://www.custom.com/external-resource"/>
+
+ URI sourcePartURI = PackagingURIHelper
+ .getSourcePartUriFromRelationshipPartUri(relPartName.getURI());
+
+ for (PackageRelationship rel : rels) {
+ // L'�l�ment de la relation
+ Element relElem = root
+ .addElement(PackageRelationship.RELATIONSHIP_TAG_NAME);
+
+ // L'attribut ID
+ relElem.addAttribute(PackageRelationship.ID_ATTRIBUTE_NAME, rel
+ .getId());
+
+ // L'attribut Type
+ relElem.addAttribute(PackageRelationship.TYPE_ATTRIBUTE_NAME, rel
+ .getRelationshipType());
+
+ // L'attribut Target
+ String targetValue;
+ URI uri = rel.getTargetURI();
+ if (rel.getTargetMode() == TargetMode.EXTERNAL) {
+ // Save the target as-is - we don't need to validate it,
+ // alter it etc
+ targetValue = uri.toString();
+
+ // add TargetMode attribut (as it is external link external)
+ relElem.addAttribute(
+ PackageRelationship.TARGET_MODE_ATTRIBUTE_NAME,
+ "External");
+ } else {
+ targetValue = PackagingURIHelper.relativizeURI(
+ sourcePartURI, rel.getTargetURI()).getPath();
+ }
+ relElem.addAttribute(PackageRelationship.TARGET_ATTRIBUTE_NAME,
+ targetValue);
+ }
+
+ xmlOutDoc.normalize();
+
+ // String schemaFilename = Configuration.getPathForXmlSchema()+
+ // File.separator + "opc-relationships.xsd";
+
+ // Save part in zip
+ ZipEntry ctEntry = new ZipEntry(ZipHelper.getZipURIFromOPCName(
+ relPartName.getURI().toASCIIString()).getPath());
+ try {
+ // Cr�ation de l'entr�e dans le fichier ZIP
+ zos.putNextEntry(ctEntry);
+ if (!StreamHelper.saveXmlInStream(xmlOutDoc, zos)) {
+ return false;
+ }
+ zos.closeEntry();
+ } catch (IOException e) {
+ logger.error("Cannot create zip entry " + relPartName, e);
+ return false;
+ }
+ return true; // success
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/marshallers/ZipPartMarshaller.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalCertificatePart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalCertificatePart.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalCertificatePart.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalCertificatePart.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,79 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.opc.internal.signature;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.internal.ContentType;
+
+/**
+ * Digital certificate part.
+ *
+ * @author Julien Chable
+ * @version 0.1
+ */
+public final class DigitalCertificatePart extends PackagePart {
+
+ public DigitalCertificatePart() throws InvalidFormatException{
+ super(null, null, new ContentType(""));
+ // Review constructor
+ }
+
+ @Override
+ public void close() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void flush() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected InputStream getInputStreamImpl() throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected OutputStream getOutputStreamImpl() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean load(InputStream ios) throws InvalidFormatException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean save(OutputStream zos) throws OpenXML4JException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ // TODO Introduire le concept de partie typ�e d�s cette partie
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalCertificatePart.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalSignatureOriginPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalSignatureOriginPart.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalSignatureOriginPart.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalSignatureOriginPart.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,28 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.opc.internal.signature;
+
+/**
+ * Represents a digital signature origin part.
+ *
+ * @author Julien Chable
+ * @version 0.1
+ */
+public class DigitalSignatureOriginPart {
+
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/signature/DigitalSignatureOriginPart.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/PackagePropertiesUnmarshaller.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/PackagePropertiesUnmarshaller.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/PackagePropertiesUnmarshaller.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/PackagePropertiesUnmarshaller.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,390 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.opc.internal.unmarshallers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.zip.ZipEntry;
+
+import org.dom4j.Attribute;
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.Element;
+import org.dom4j.Namespace;
+import org.dom4j.QName;
+import org.dom4j.io.SAXReader;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackageNamespaces;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageProperties;
+import org.apache.poi.openxml4j.opc.ZipPackage;
+import org.apache.poi.openxml4j.opc.internal.PackagePropertiesPart;
+import org.apache.poi.openxml4j.opc.internal.PartUnmarshaller;
+import org.apache.poi.openxml4j.opc.internal.ZipHelper;
+
+/**
+ * Package properties unmarshaller.
+ *
+ * @author Julien Chable
+ * @version 1.0
+ */
+public class PackagePropertiesUnmarshaller implements PartUnmarshaller {
+
+ private final static Namespace namespaceDC = new Namespace("dc",
+ PackageProperties.NAMESPACE_DC);
+
+ private final static Namespace namespaceCP = new Namespace("cp",
+ PackageNamespaces.CORE_PROPERTIES);
+
+ private final static Namespace namespaceDcTerms = new Namespace("dcterms",
+ PackageProperties.NAMESPACE_DCTERMS);
+
+ private final static Namespace namespaceXML = new Namespace("xml",
+ "http://www.w3.org/XML/1998/namespace");
+
+ private final static Namespace namespaceXSI = new Namespace("xsi",
+ "http://www.w3.org/2001/XMLSchema-instance");
+
+ protected static final String KEYWORD_CATEGORY = "category";
+
+ protected static final String KEYWORD_CONTENT_STATUS = "contentStatus";
+
+ protected static final String KEYWORD_CONTENT_TYPE = "contentType";
+
+ protected static final String KEYWORD_CREATED = "created";
+
+ protected static final String KEYWORD_CREATOR = "creator";
+
+ protected static final String KEYWORD_DESCRIPTION = "description";
+
+ protected static final String KEYWORD_IDENTIFIER = "identifier";
+
+ protected static final String KEYWORD_KEYWORDS = "keywords";
+
+ protected static final String KEYWORD_LANGUAGE = "language";
+
+ protected static final String KEYWORD_LAST_MODIFIED_BY = "lastModifiedBy";
+
+ protected static final String KEYWORD_LAST_PRINTED = "lastPrinted";
+
+ protected static final String KEYWORD_MODIFIED = "modified";
+
+ protected static final String KEYWORD_REVISION = "revision";
+
+ protected static final String KEYWORD_SUBJECT = "subject";
+
+ protected static final String KEYWORD_TITLE = "title";
+
+ protected static final String KEYWORD_VERSION = "version";
+
+ // TODO Load element with XMLBeans or dynamic table
+ // TODO Check every element/namespace for compliance
+ public PackagePart unmarshall(UnmarshallContext context, InputStream in)
+ throws InvalidFormatException, IOException {
+ PackagePropertiesPart coreProps = new PackagePropertiesPart(context
+ .getPackage(), context.getPartName());
+
+ // If the input stream is null then we try to get it from the
+ // package.
+ if (in == null) {
+ if (context.getZipEntry() != null) {
+ in = ((ZipPackage) context.getPackage()).getZipArchive()
+ .getInputStream(context.getZipEntry());
+ } else if (context.getPackage() != null) {
+ // Try to retrieve the part inputstream from the URI
+ ZipEntry zipEntry;
+ try {
+ zipEntry = ZipHelper
+ .getCorePropertiesZipEntry((ZipPackage) context
+ .getPackage());
+ } catch (OpenXML4JException e) {
+ throw new IOException(
+ "Error while trying to get the part input stream.");
+ }
+ in = ((ZipPackage) context.getPackage()).getZipArchive()
+ .getInputStream(zipEntry);
+ } else
+ throw new IOException(
+ "Error while trying to get the part input stream.");
+ }
+
+ SAXReader xmlReader = new SAXReader();
+ Document xmlDoc;
+ try {
+ xmlDoc = xmlReader.read(in);
+
+ /* Check OPC compliance */
+
+ // Rule M4.2, M4.3, M4.4 and M4.5/
+ checkElementForOPCCompliance(xmlDoc.getRootElement());
+
+ /* End OPC compliance */
+
+ } catch (DocumentException e) {
+ throw new IOException(e.getMessage());
+ }
+
+ coreProps.setCategoryProperty(loadCategory(xmlDoc));
+ coreProps.setContentStatusProperty(loadContentStatus(xmlDoc));
+ coreProps.setContentTypeProperty(loadContentType(xmlDoc));
+ coreProps.setCreatedProperty(loadCreated(xmlDoc));
+ coreProps.setCreatorProperty(loadCreator(xmlDoc));
+ coreProps.setDescriptionProperty(loadDescription(xmlDoc));
+ coreProps.setIdentifierProperty(loadIdentifier(xmlDoc));
+ coreProps.setKeywordsProperty(loadKeywords(xmlDoc));
+ coreProps.setLanguageProperty(loadLanguage(xmlDoc));
+ coreProps.setLastModifiedByProperty(loadLastModifiedBy(xmlDoc));
+ coreProps.setLastPrintedProperty(loadLastPrinted(xmlDoc));
+ coreProps.setModifiedProperty(loadModified(xmlDoc));
+ coreProps.setRevisionProperty(loadRevision(xmlDoc));
+ coreProps.setSubjectProperty(loadSubject(xmlDoc));
+ coreProps.setTitleProperty(loadTitle(xmlDoc));
+ coreProps.setVersionProperty(loadVersion(xmlDoc));
+
+ return coreProps;
+ }
+
+ private String loadCategory(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_CATEGORY, namespaceCP));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadContentStatus(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_CONTENT_STATUS, namespaceCP));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadContentType(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_CONTENT_TYPE, namespaceCP));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadCreated(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_CREATED, namespaceDcTerms));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadCreator(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_CREATOR, namespaceDC));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadDescription(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_DESCRIPTION, namespaceDC));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadIdentifier(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_IDENTIFIER, namespaceDC));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadKeywords(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_KEYWORDS, namespaceCP));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadLanguage(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_LANGUAGE, namespaceDC));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadLastModifiedBy(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_LAST_MODIFIED_BY, namespaceCP));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadLastPrinted(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_LAST_PRINTED, namespaceCP));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadModified(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_MODIFIED, namespaceDcTerms));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadRevision(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_REVISION, namespaceCP));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadSubject(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_SUBJECT, namespaceDC));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadTitle(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_TITLE, namespaceDC));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ private String loadVersion(Document xmlDoc) {
+ Element el = xmlDoc.getRootElement().element(
+ new QName(KEYWORD_VERSION, namespaceCP));
+ if (el != null)
+ return el.getStringValue();
+ else
+ return null;
+ }
+
+ /* OPC Compliance methods */
+
+ /**
+ * Check the element for the following OPC compliance rules:
+ *
+ * Rule M4.2: A format consumer shall consider the use of the Markup
+ * Compatibility namespace to be an error.
+ *
+ * Rule M4.3: Producers shall not create a document element that contains
+ * refinements to the Dublin Core elements, except for the two specified in
+ * the schema: <dcterms:created> and <dcterms:modified> Consumers shall
+ * consider a document element that violates this constraint to be an error.
+ *
+ * Rule M4.4: Producers shall not create a document element that contains
+ * the xml:lang attribute. Consumers shall consider a document element that
+ * violates this constraint to be an error.
+ *
+ * Rule M4.5: Producers shall not create a document element that contains
+ * the xsi:type attribute, except for a <dcterms:created> or
+ * <dcterms:modified> element where the xsi:type attribute shall be present
+ * and shall hold the value dcterms:W3CDTF, where dcterms is the namespace
+ * prefix of the Dublin Core namespace. Consumers shall consider a document
+ * element that violates this constraint to be an error.
+ */
+ public void checkElementForOPCCompliance(Element el)
+ throws InvalidFormatException {
+ // Check the current element
+ List declaredNamespaces = el.declaredNamespaces();
+ Iterator itNS = declaredNamespaces.iterator();
+ while (itNS.hasNext()) {
+ Namespace ns = (Namespace) itNS.next();
+
+ // Rule M4.2
+ if (ns.getURI().equals(PackageNamespaces.MARKUP_COMPATIBILITY))
+ throw new InvalidFormatException(
+ "OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.");
+ }
+
+ // Rule M4.3
+ if (el.getNamespace().getURI().equals(
+ PackageProperties.NAMESPACE_DCTERMS)
+ && !(el.getName().equals(KEYWORD_CREATED) || el.getName()
+ .equals(KEYWORD_MODIFIED)))
+ throw new InvalidFormatException(
+ "OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.");
+
+ // Rule M4.4
+ if (el.attribute(new QName("lang", namespaceXML)) != null)
+ throw new InvalidFormatException(
+ "OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.");
+
+ // Rule M4.5
+ if (el.getNamespace().getURI().equals(
+ PackageProperties.NAMESPACE_DCTERMS)) {
+ // DCTerms namespace only use with 'created' and 'modified' elements
+ String elName = el.getName();
+ if (!(elName.equals(KEYWORD_CREATED) || elName
+ .equals(KEYWORD_MODIFIED)))
+ throw new InvalidFormatException("Namespace error : " + elName
+ + " shouldn't have the following naemspace -> "
+ + PackageProperties.NAMESPACE_DCTERMS);
+
+ // Check for the 'xsi:type' attribute
+ Attribute typeAtt = el.attribute(new QName("type", namespaceXSI));
+ if (typeAtt == null)
+ throw new InvalidFormatException("The element '" + elName
+ + "' must have the '" + namespaceXSI.getPrefix()
+ + ":type' attribute present !");
+
+ // Check for the attribute value => 'dcterms:W3CDTF'
+ if (!typeAtt.getValue().equals("dcterms:W3CDTF"))
+ throw new InvalidFormatException("The element '" + elName
+ + "' must have the '" + namespaceXSI.getPrefix()
+ + ":type' attribute with the value 'dcterms:W3CDTF' !");
+ }
+
+ // Check its children
+ Iterator itChildren = el.elementIterator();
+ while (itChildren.hasNext())
+ checkElementForOPCCompliance((Element) itChildren.next());
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/PackagePropertiesUnmarshaller.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/UnmarshallContext.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/UnmarshallContext.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/UnmarshallContext.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/UnmarshallContext.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,96 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.opc.internal.unmarshallers;
+
+import java.util.zip.ZipEntry;
+
+import org.apache.poi.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.opc.PackagePartName;
+
+/**
+ * Context needed for the unmarshall process of a part. This class is immutable.
+ *
+ * @author Julien Chable
+ * @version 1.0
+ */
+public final class UnmarshallContext {
+
+ private Package _package;
+
+ private PackagePartName partName;
+
+ private ZipEntry zipEntry;
+
+ /**
+ * Constructor.
+ *
+ * @param targetPackage
+ * Container.
+ * @param partName
+ * Name of the part to unmarshall.
+ */
+ public UnmarshallContext(Package targetPackage, PackagePartName partName) {
+ this._package = targetPackage;
+ this.partName = partName;
+ }
+
+ /**
+ * @return the container
+ */
+ Package getPackage() {
+ return _package;
+ }
+
+ /**
+ * @param container
+ * the container to set
+ */
+ public void setPackage(Package container) {
+ this._package = container;
+ }
+
+ /**
+ * @return the partName
+ */
+ PackagePartName getPartName() {
+ return partName;
+ }
+
+ /**
+ * @param partName
+ * the partName to set
+ */
+ public void setPartName(PackagePartName partName) {
+ this.partName = partName;
+ }
+
+ /**
+ * @return the zipEntry
+ */
+ ZipEntry getZipEntry() {
+ return zipEntry;
+ }
+
+ /**
+ * @param zipEntry
+ * the zipEntry to set
+ */
+ public void setZipEntry(ZipEntry zipEntry) {
+ this.zipEntry = zipEntry;
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/unmarshallers/UnmarshallContext.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignature.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignature.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignature.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignature.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,70 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.opc.signature;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.internal.ContentType;
+
+public class PackageDigitalSignature extends PackagePart {
+
+ public PackageDigitalSignature() throws InvalidFormatException {
+ super(null, null, new ContentType(""));
+ }
+
+ @Override
+ public void close() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void flush() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ protected InputStream getInputStreamImpl() throws IOException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected OutputStream getOutputStreamImpl() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean load(InputStream ios) throws InvalidFormatException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean save(OutputStream zos) throws OpenXML4JException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignature.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignatureManager.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignatureManager.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignatureManager.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignatureManager.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,22 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.opc.signature;
+
+public class PackageDigitalSignatureManager {
+
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/signature/PackageDigitalSignatureManager.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/Nullable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/Nullable.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/Nullable.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/Nullable.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,71 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.util;
+
+/**
+ * An immutable object that could be defined as null.
+ *
+ * @author Julien Chable
+ * @version 0.9
+ */
+public final class Nullable<E> {
+
+ private E value;
+
+ /**
+ * Constructor.
+ */
+ public Nullable() {
+ // Do nothing
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param value
+ * The value to set to this nullable.
+ */
+ public Nullable(E value) {
+ this.value = value;
+ }
+
+ /**
+ * Get the store value if any.
+ *
+ * @return
+ */
+ public E getValue() {
+ return value;
+ }
+
+ /**
+ * Get the status of this nullable.
+ *
+ * @return <b>true</b> if the nullable store a value (empty string is
+ * considered to be a value) else <b>false</>.
+ */
+ public boolean hasValue() {
+ return value != null;
+ }
+
+ /**
+ * Set the stored value to <i>null</i>.
+ */
+ public void nullify() {
+ value = null;
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/Nullable.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,48 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+
+/**
+ * An Interface to make getting the different bits
+ * of a Zip File easy.
+ * Allows you to get at the ZipEntries, without
+ * needing to worry about ZipFile vs ZipInputStream
+ * being annoyingly very different.
+ */
+public interface ZipEntrySource {
+ /**
+ * Returns an Enumeration of all the Entries
+ */
+ public Enumeration<? extends ZipEntry> getEntries();
+
+ /**
+ * Returns an InputStream of the decompressed
+ * data that makes up the entry
+ */
+ public InputStream getInputStream(ZipEntry entry) throws IOException;
+
+ /**
+ * Indicates we are done with reading, and
+ * resources may be freed
+ */
+ public void close() throws IOException;
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,48 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+/**
+ * A ZipEntrySource wrapper around a ZipFile.
+ * Should be as low in terms of memory as a
+ * normal ZipFile implementation is.
+ */
+public class ZipFileZipEntrySource implements ZipEntrySource {
+ private ZipFile zipArchive;
+ public ZipFileZipEntrySource(ZipFile zipFile) {
+ this.zipArchive = zipFile;
+ }
+
+ public void close() throws IOException {
+ zipArchive.close();
+ zipArchive = null;
+ }
+
+ public Enumeration<? extends ZipEntry> getEntries() {
+ return zipArchive.entries();
+ }
+
+ public InputStream getInputStream(ZipEntry entry) throws IOException {
+ return zipArchive.getInputStream(entry);
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java
------------------------------------------------------------------------------
svn:executable = *
Added: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java?rev=738842&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java Thu Jan 29 12:44:31 2009
@@ -0,0 +1,125 @@
+/* ====================================================================
+ 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.apache.poi.openxml4j.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * Provides a way to get at all the ZipEntries
+ * from a ZipInputStream, as many times as required.
+ * Allows a ZipInputStream to be treated much like
+ * a ZipFile, for a price in terms of memory.
+ * Be sure to call {@link #close()} as soon as you're
+ * done, to free up that memory!
+ */
+public class ZipInputStreamZipEntrySource implements ZipEntrySource {
+ private ArrayList<FakeZipEntry> zipEntries;
+
+ /**
+ * Reads all the entries from the ZipInputStream
+ * into memory, and closes the source stream.
+ * We'll then eat lots of memory, but be able to
+ * work with the entries at-will.
+ */
+ public ZipInputStreamZipEntrySource(ZipInputStream inp) throws IOException {
+ zipEntries = new ArrayList<FakeZipEntry>();
+
+ boolean going = true;
+ while(going) {
+ ZipEntry zipEntry = inp.getNextEntry();
+ if(zipEntry == null) {
+ going = false;
+ } else {
+ FakeZipEntry entry = new FakeZipEntry(zipEntry, inp);
+ inp.closeEntry();
+
+ zipEntries.add(entry);
+ }
+ }
+ inp.close();
+ }
+
+ public Enumeration<? extends ZipEntry> getEntries() {
+ return new EntryEnumerator();
+ }
+
+ public InputStream getInputStream(ZipEntry zipEntry) {
+ FakeZipEntry entry = (FakeZipEntry)zipEntry;
+ return entry.getInputStream();
+ }
+
+ public void close() {
+ // Free the memory
+ zipEntries = null;
+ }
+
+ /**
+ * Why oh why oh why are Iterator and Enumeration
+ * still not compatible?
+ */
+ private class EntryEnumerator implements Enumeration<ZipEntry> {
+ private Iterator<? extends ZipEntry> iterator;
+
+ private EntryEnumerator() {
+ iterator = zipEntries.iterator();
+ }
+
+ public boolean hasMoreElements() {
+ return iterator.hasNext();
+ }
+
+ public ZipEntry nextElement() {
+ return iterator.next();
+ }
+ }
+
+ /**
+ * So we can close the real zip entry and still
+ * effectively work with it.
+ * Holds the (decompressed!) data in memory, so
+ * close this as soon as you can!
+ */
+ public static class FakeZipEntry extends ZipEntry {
+ private byte[] data;
+
+ public FakeZipEntry(ZipEntry entry, ZipInputStream inp) throws IOException {
+ super(entry.getName());
+
+ // Grab the de-compressed contents for later
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] buffer = new byte[4096];
+ int read = 0;
+ while( (read = inp.read(buffer)) != -1 ) {
+ baos.write(buffer, 0, read);
+ }
+
+ data = baos.toByteArray();
+ }
+
+ public InputStream getInputStream() {
+ return new ByteArrayInputStream(data);
+ }
+ }
+}
Propchange: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
------------------------------------------------------------------------------
svn:executable = *
Modified: poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java Thu Jan 29 12:44:31 2009
@@ -24,7 +24,7 @@
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.opc.Package;
/**
* Factory for creating the appropriate kind of Workbook
Modified: poi/trunk/src/ooxml/java/org/apache/poi/util/PackageHelper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/util/PackageHelper.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/util/PackageHelper.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/util/PackageHelper.java Thu Jan 29 12:44:31 2009
@@ -16,16 +16,12 @@
==================================================================== */
package org.apache.poi.util;
-import org.openxml4j.opc.*;
-import org.openxml4j.opc.Package;
-import org.openxml4j.opc.internal.PackagePropertiesPart;
-import org.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller;
-import org.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.*;
+import org.apache.poi.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.util.IOUtils;
import java.io.*;
-import java.util.ArrayList;
-import java.lang.reflect.Method;
/**
* Provides handy methods to work with OOXML packages
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/XSLFSlideShow.java Thu Jan 29 12:44:31 2009
@@ -22,12 +22,12 @@
import org.apache.poi.POIXMLDocument;
import org.apache.xmlbeans.XmlException;
-import org.openxml4j.exceptions.InvalidFormatException;
-import org.openxml4j.exceptions.OpenXML4JException;
-import org.openxml4j.opc.Package;
-import org.openxml4j.opc.PackagePart;
-import org.openxml4j.opc.PackageRelationship;
-import org.openxml4j.opc.PackageRelationshipCollection;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
import org.openxmlformats.schemas.presentationml.x2006.main.CTCommentList;
import org.openxmlformats.schemas.presentationml.x2006.main.CTNotesSlide;
import org.openxmlformats.schemas.presentationml.x2006.main.CTPresentation;
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/extractor/XSLFPowerPointExtractor.java Thu Jan 29 12:44:31 2009
@@ -23,8 +23,8 @@
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFSlide;
import org.apache.xmlbeans.XmlException;
-import org.openxml4j.exceptions.OpenXML4JException;
-import org.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.Package;
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java Thu Jan 29 12:44:31 2009
@@ -25,14 +25,14 @@
import org.apache.poi.xssf.usermodel.XSSFRelation;
import org.apache.poi.POIXMLException;
import org.apache.xmlbeans.XmlException;
-import org.openxml4j.exceptions.InvalidFormatException;
-import org.openxml4j.exceptions.OpenXML4JException;
-import org.openxml4j.opc.Package;
-import org.openxml4j.opc.PackagePart;
-import org.openxml4j.opc.PackagePartName;
-import org.openxml4j.opc.PackageRelationship;
-import org.openxml4j.opc.PackageRelationshipTypes;
-import org.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackagePartName;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExcelExtractor.java Thu Jan 29 12:44:31 2009
@@ -29,8 +29,8 @@
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.xmlbeans.XmlException;
-import org.openxml4j.exceptions.OpenXML4JException;
-import org.openxml4j.opc.Package;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
+import org.apache.poi.openxml4j.opc.Package;
/**
* Helper class to extract text from an OOXML Excel file
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java Thu Jan 29 12:44:31 2009
@@ -29,8 +29,8 @@
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CommentsDocument;
-import org.openxml4j.opc.PackagePart;
-import org.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
public class CommentsTable extends POIXMLDocumentPart {
protected CTComments comments;
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java Thu Jan 29 12:44:31 2009
@@ -31,9 +31,8 @@
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSst;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.SstDocument;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
-import org.openxml4j.opc.PackagePart;
-import org.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
/**
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java Thu Jan 29 12:44:31 2009
@@ -48,8 +48,8 @@
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument;
-import org.openxml4j.opc.PackagePart;
-import org.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
/**
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/XSSFChildContainingModel.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/XSSFChildContainingModel.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/XSSFChildContainingModel.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/XSSFChildContainingModel.java Thu Jan 29 12:44:31 2009
@@ -17,7 +17,7 @@
package org.apache.poi.xssf.model;
import org.apache.poi.xssf.usermodel.XSSFRelation;
-import org.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackagePart;
/**
* Common interface for XSSF models, which have (typically
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFActiveXData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFActiveXData.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFActiveXData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFActiveXData.java Thu Jan 29 12:44:31 2009
@@ -7,7 +7,7 @@
import org.apache.poi.util.IOUtils;
import org.apache.poi.xssf.model.XSSFWritableModel;
import org.apache.poi.POIXMLException;
-import org.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackagePart;
public class XSSFActiveXData implements PictureData, XSSFWritableModel {
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java Thu Jan 29 12:44:31 2009
@@ -17,15 +17,8 @@
package org.apache.poi.xssf.usermodel;
-import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.POIXMLException;
-import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
-import org.openxml4j.opc.PackagePart;
-import org.openxml4j.opc.PackageRelationship;
-
-import java.io.IOException;
//YK: TODO: this is only a prototype
public class XSSFDialogsheet extends XSSFSheet implements Sheet{
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java Thu Jan 29 12:44:31 2009
@@ -21,7 +21,7 @@
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
-import org.openxml4j.opc.*;
+import org.apache.poi.openxml4j.opc.*;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java?rev=738842&r1=738841&r2=738842&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFactory.java Thu Jan 29 12:44:31 2009
@@ -22,8 +22,8 @@
import org.apache.poi.POIXMLRelation;
import org.apache.poi.util.POILogger;
import org.apache.poi.util.POILogFactory;
-import org.openxml4j.opc.PackageRelationship;
-import org.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackagePart;
import java.lang.reflect.Constructor;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org