You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2007/12/27 10:12:58 UTC

svn commit: r607024 - in /poi/trunk: ./ src/scratchpad/ooxml-src/org/apache/poi/ src/scratchpad/ooxml-src/org/apache/poi/hssf/ src/scratchpad/ooxml-src/org/apache/poi/hxf/ src/scratchpad/ooxml-src/org/apache/poi/hxf/dev/ src/scratchpad/ooxml-testcases/...

Author: nick
Date: Thu Dec 27 01:12:57 2007
New Revision: 607024

URL: http://svn.apache.org/viewvc?rev=607024&view=rev
Log:
Shuffle a few ooxml bits about, improve the ant tasks for it, and add in a ooxml container lister

Added:
    poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/
    poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/HXFDocument.java
      - copied, changed from r606923, poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/HXFDocument.java
    poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/dev/
    poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/dev/HXFLister.java   (with props)
Removed:
    poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/HXFDocument.java
Modified:
    poi/trunk/build.xml
    poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hssf/HSSFXML.java
    poi/trunk/src/scratchpad/ooxml-testcases/org/apache/poi/hssf/TestHSSFXML.java

Modified: poi/trunk/build.xml
URL: http://svn.apache.org/viewvc/poi/trunk/build.xml?rev=607024&r1=607023&r2=607024&view=diff
==============================================================================
--- poi/trunk/build.xml (original)
+++ poi/trunk/build.xml Thu Dec 27 01:12:57 2007
@@ -145,6 +145,7 @@
   <property name="ooxml.xsds.ozip" location="${ooxml.lib}/OfficeOpenXML-Part4.zip"/>
   <property name="ooxml.xsds.izip" location="${ooxml.lib}/OfficeOpenXML-XMLSchema.zip"/>
   <property name="ooxml.xsds.url" value="http://www.ecma-international.org/publications/files/ECMA-ST/Office%20Open%20XML%20Part%204%20(DOCX).zip" />
+  <property name="ooxml.xsds.jar" location="${ooxml.lib}/ooxml-schemas.jar"/>
 
   <property name="build.site" location="build/tmp/site/build/site"/>
   <property name="build.site.src" location="build/tmp/site"/>
@@ -262,9 +263,11 @@
         <mkdir dir="${scratchpad.output.dir}"/>
         <mkdir dir="${contrib.output.dir}"/>
         <mkdir dir="${examples.output.dir}"/>
+        <mkdir dir="${ooxml.output.dir}"/>
         <mkdir dir="${main.output.test.dir}"/>
         <mkdir dir="${contrib.output.test.dir}"/>
         <mkdir dir="${scratchpad.output.test.dir}"/>
+        <mkdir dir="${ooxml.output.test.dir}"/>
         <mkdir dir="${main.reports.test}"/>
         <mkdir dir="${scratchpad.reports.test}"/>
         <mkdir dir="${contrib.reports.test}"/>
@@ -348,7 +351,18 @@
 			</patternset>
 		</unzip>
 	</target>
-	<target name="compile-ooxml-xsds" depends="check-jars,fetch-jars,check-ooxml-xsds,fetch-ooxml-xsds"
+	<target name="check-compiled-ooxml-xsds">
+        <condition property="ooxml-compiled-xsds.present">
+            <or>
+                <and>
+                    <available file="${ooxml.xsds.jar}"/>
+                </and>
+                <isset property="disconnected"/>
+            </or>
+        </condition>
+	</target>
+	<target name="compile-ooxml-xsds" unless="ooxml-compiled-xsds.present"
+	 depends="check-jars,fetch-jars,check-ooxml-xsds,fetch-ooxml-xsds,check-compiled-ooxml-xsds"
 	 description="Unpacks the OOXML xsd files, and compiles them into XmlBeans">
 		<taskdef name="xmlbean"
 			classname="org.apache.xmlbeans.impl.tool.XMLBean"
@@ -361,7 +375,7 @@
 		-->
 		<xmlbean
 			schema="build/ooxml-xsds/"
-			destfile="${ooxml.lib}/ooxml-schemas.jar"
+			destfile="${ooxml.xsds.jar}"
 			javasource="1.4"
 			failonerror="false"
 		>
@@ -452,7 +466,8 @@
   </target>
 
   <target name="compile-ooxml" depends="init, check-ooxml-xsds, fetch-ooxml-xsds, compile-ooxml-xsds, compile-main">
-    <javac target="${jdk.version.class}" source="${jdk.version.source}"
+	<!-- openxml4j requires java 1.5, so so must we, for now -->
+    <javac target="1.5" source="1.5"
       destdir="${ooxml.output.dir}" debug="on" srcdir="${ooxml.src}">
       <classpath refid="ooxml.classpath"/>
     </javac>

Modified: poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hssf/HSSFXML.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hssf/HSSFXML.java?rev=607024&r1=607023&r2=607024&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hssf/HSSFXML.java (original)
+++ poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hssf/HSSFXML.java Thu Dec 27 01:12:57 2007
@@ -18,7 +18,7 @@
 
 import java.io.IOException;
 
-import org.apache.poi.HXFDocument;
+import org.apache.poi.hxf.HXFDocument;
 import org.apache.xmlbeans.XmlException;
 import org.openxml4j.exceptions.OpenXML4JException;
 import org.openxml4j.opc.Package;

Copied: poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/HXFDocument.java (from r606923, poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/HXFDocument.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/HXFDocument.java?p2=poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/HXFDocument.java&p1=poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/HXFDocument.java&r1=606923&r2=607024&rev=607024&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/HXFDocument.java (original)
+++ poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/HXFDocument.java Thu Dec 27 01:12:57 2007
@@ -14,12 +14,13 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-package org.apache.poi;
+package org.apache.poi.hxf;
 
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 
+import org.apache.poi.POIXMLDocument;
 import org.dom4j.Document;
 import org.dom4j.DocumentException;
 import org.dom4j.io.SAXReader;

Added: poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/dev/HXFLister.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/dev/HXFLister.java?rev=607024&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/dev/HXFLister.java (added)
+++ poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/dev/HXFLister.java Thu Dec 27 01:12:57 2007
@@ -0,0 +1,126 @@
+/* ====================================================================
+   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.hxf.dev;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+
+import org.openxml4j.opc.Package;
+import org.openxml4j.opc.PackageAccess;
+import org.openxml4j.opc.PackagePart;
+import org.openxml4j.opc.PackageRelationship;
+import org.openxml4j.opc.PackageRelationshipCollection;
+
+/**
+ * Prints out the contents of a HXF (ooxml) container.
+ * Useful for seeing what parts are defined, and how
+ *  they're all related to each other.
+ */
+public class HXFLister {
+	private Package container;
+	private PrintStream disp;
+	
+	public HXFLister(Package container) {
+		this(container, System.out);
+	}
+	public HXFLister(Package container, PrintStream disp) {
+		this.container = container;
+		this.disp = disp;
+	}
+	
+	/**
+	 * Figures out how big a given PackagePart is.
+	 */
+	public static long getSize(PackagePart part) throws IOException {
+		InputStream in = part.getInputStream();
+		byte[] b = new byte[8192];
+		long size = 0;
+		int read = 0;
+		
+		while(read > -1) {
+			read = in.read(b);
+			if(read > 0) {
+				size += read;
+			}
+		}
+		
+		return size;
+	}
+	
+	/**
+	 * Displays information on all the different
+	 *  parts of the OOXML file container.
+	 */
+	public void displayParts() throws Exception {
+		ArrayList<PackagePart> parts = container.getParts();
+		for (PackagePart part : parts) {
+			disp.println(part.getPartName());
+			disp.println("\t" + part.getContentType());
+			
+			if(! part.getPartName().toString().equals("/docProps/core.xml")) {
+				disp.println("\t" + getSize(part) + " bytes");
+			}
+			
+			if(! part.isRelationshipPart()) {
+				disp.println("\t" + part.getRelationships().size() + " relations");
+			}
+		}
+	}
+	/**
+	 * Displays information on all the different
+	 *  relationships between different parts
+	 *  of the OOXML file container.
+	 */
+	public void displayRelations() throws Exception {
+		PackageRelationshipCollection rels = 
+			container.getRelationships();
+		for (PackageRelationship rel : rels) {
+			disp.println("Relationship:");
+			disp.println("\tFrom: "+ rel.getSourceURI());
+			disp.println("\tTo:   " + rel.getTargetURI());
+			disp.println("\tMode: " + rel.getTargetMode());
+			disp.println("\tType: " + rel.getRelationshipType());
+		}
+	}
+	
+	public static void main(String[] args) throws Exception {
+		if(args.length == 0) {
+			System.err.println("Use:");
+			System.err.println("\tjava HXFLister <filename>");
+			System.exit(1);
+		}
+		
+		File f = new File(args[0]);
+		if(! f.exists()) {
+			System.err.println("Error, file not found!");
+			System.err.println("\t" + f.toString());
+			System.exit(2);
+		}
+		
+		HXFLister lister = new HXFLister(
+				Package.open(f.toString(), PackageAccess.READ)
+		);
+		
+		lister.disp.println(f.toString() + "\n");
+		lister.displayParts();
+		lister.disp.println();
+		lister.displayRelations();
+	}
+}

Propchange: poi/trunk/src/scratchpad/ooxml-src/org/apache/poi/hxf/dev/HXFLister.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: poi/trunk/src/scratchpad/ooxml-testcases/org/apache/poi/hssf/TestHSSFXML.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/ooxml-testcases/org/apache/poi/hssf/TestHSSFXML.java?rev=607024&r1=607023&r2=607024&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/ooxml-testcases/org/apache/poi/hssf/TestHSSFXML.java (original)
+++ poi/trunk/src/scratchpad/ooxml-testcases/org/apache/poi/hssf/TestHSSFXML.java Thu Dec 27 01:12:57 2007
@@ -2,7 +2,7 @@
 
 import java.io.File;
 
-import org.apache.poi.HXFDocument;
+import org.apache.poi.hxf.HXFDocument;
 import org.openxml4j.opc.Package;
 import org.openxml4j.opc.PackagePart;
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org