poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r635253 - in /poi/branches/ooxml/src/ooxml: java/org/apache/poi/ java/org/apache/poi/xwpf/ java/org/apache/poi/xwpf/extractor/ java/org/apache/poi/xwpf/usermodel/ testcases/org/apache/poi/xslf/extractor/ testcases/org/apache/poi/xwpf/ testc...
Date Sun, 09 Mar 2008 14:39:39 GMT
Author: nick
Date: Sun Mar  9 07:39:36 2008
New Revision: 635253

URL: http://svn.apache.org/viewvc?rev=635253&view=rev
Log:
Update the word code to the new style ooxml stuff

Added:
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java
      - copied, changed from r635031, poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/HWPFXML.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java
      - copied, changed from r635031, poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/extractor/HXFWordExtractor.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java 
 (with props)
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java
      - copied, changed from r635243, poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestHXFPowerPointExtractor.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
      - copied, changed from r635031, poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/TestHWPFXML.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
      - copied, changed from r635031, poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestHXFWordExtractor.java
Removed:
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/HWPFXML.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/extractor/HXFWordExtractor.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/HWPFXMLDocument.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestHXFPowerPointExtractor.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/TestHWPFXML.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestHXFWordExtractor.java
Modified:
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java?rev=635253&r1=635252&r2=635253&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/POIXMLDocument.java Sun Mar  9 07:39:36
2008
@@ -123,6 +123,25 @@
 		PackageRelationship rel = rels.getRelationship(0);
 		return getTargetPart(rel);
 	}
+
+	/**
+	 * Retrieves all the PackageParts which are defined as
+	 *  relationships of the base document with the
+	 *  specified content type.
+	 */
+	protected PackagePart[] getRelatedByType(String contentType) throws InvalidFormatException
{
+		PackageRelationshipCollection partsC =
+			getCorePart().getRelationshipsByType(contentType);
+		
+		PackagePart[] parts = new PackagePart[partsC.size()];
+		int count = 0;
+		for (PackageRelationship rel : partsC) {
+			parts[count] = getTargetPart(rel);
+			count++;
+		}
+		return parts;
+	}
+
 	
     
     /**

Copied: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java (from r635031,
poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/HWPFXML.java)
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java?p2=poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java&p1=poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/HWPFXML.java&r1=635031&r2=635253&rev=635253&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/HWPFXML.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java Sun Mar  9 07:39:36
2008
@@ -14,11 +14,11 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-package org.apache.poi.hwpf;
+package org.apache.poi.xwpf;
 
 import java.io.IOException;
 
-import org.apache.poi.hxf.HXFDocument;
+import org.apache.poi.POIXMLDocument;
 import org.apache.xmlbeans.XmlException;
 import org.openxml4j.exceptions.InvalidFormatException;
 import org.openxml4j.exceptions.OpenXML4JException;
@@ -41,7 +41,7 @@
  *  
  * WARNING - APIs expected to change rapidly
  */
-public class HWPFXML extends HXFDocument {
+public class XWPFDocument extends POIXMLDocument {
 	public static final String MAIN_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
 	public static final String FOOTER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml";
 	public static final String HEADER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml";
@@ -50,11 +50,11 @@
 	
 	private DocumentDocument wordDoc;
 	
-	public HWPFXML(Package container) throws OpenXML4JException, IOException, XmlException {
-		super(container, MAIN_CONTENT_TYPE);
+	public XWPFDocument(Package container) throws OpenXML4JException, IOException, XmlException
{
+		super(container);
 		
 		wordDoc =
-			DocumentDocument.Factory.parse(basePart.getInputStream());
+			DocumentDocument.Factory.parse(getCorePart().getInputStream());
 	}
 	
 	/**

Copied: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java
(from r635031, poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/extractor/HXFWordExtractor.java)
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java?p2=poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java&p1=poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/extractor/HXFWordExtractor.java&r1=635031&r2=635253&rev=635253&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/extractor/HXFWordExtractor.java
(original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java
Sun Mar  9 07:39:36 2008
@@ -14,15 +14,14 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-package org.apache.poi.hwpf.extractor;
+package org.apache.poi.xwpf.extractor;
 
 import java.io.File;
 import java.io.IOException;
 
+import org.apache.poi.POIXMLDocument;
 import org.apache.poi.POIXMLTextExtractor;
-import org.apache.poi.hwpf.HWPFXML;
-import org.apache.poi.hwpf.usermodel.HWPFXMLDocument;
-import org.apache.poi.hxf.HXFDocument;
+import org.apache.poi.xwpf.XWPFDocument;
 import org.apache.xmlbeans.XmlException;
 import org.openxml4j.exceptions.OpenXML4JException;
 import org.openxml4j.opc.Package;
@@ -34,15 +33,13 @@
 /**
  * Helper class to extract text from an OOXML Word file
  */
-public class HXFWordExtractor extends POIXMLTextExtractor {
-	private HWPFXMLDocument document;
+public class XWPFWordExtractor extends POIXMLTextExtractor {
+	private XWPFDocument document;
 	
-	public HXFWordExtractor(Package container) throws XmlException, OpenXML4JException, IOException
{
-		this(new HWPFXMLDocument(
-				new HWPFXML(container)
-		));
+	public XWPFWordExtractor(Package container) throws XmlException, OpenXML4JException, IOException
{
+		this(new XWPFDocument(container));
 	}
-	public HXFWordExtractor(HWPFXMLDocument document) {
+	public XWPFWordExtractor(XWPFDocument document) {
 		super(document);
 		this.document = document;
 	}
@@ -54,14 +51,14 @@
 			System.exit(1);
 		}
 		POIXMLTextExtractor extractor = 
-			new HXFWordExtractor(HXFDocument.openPackage(
-					new File(args[0])
+			new XWPFWordExtractor(POIXMLDocument.openPackage(
+					args[0]
 			));
 		System.out.println(extractor.getText());
 	}
 
 	public String getText() {
-		CTBody body = document._getHWPFXML().getDocumentBody();
+		CTBody body = document.getDocumentBody();
 		StringBuffer text = new StringBuffer();
 		
 		// Loop over paragraphs

Added: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java?rev=635253&view=auto
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java (added)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java Sun
Mar  9 07:39:36 2008
@@ -0,0 +1,34 @@
+/* ====================================================================
+   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.xwpf.usermodel;
+
+import org.apache.poi.xwpf.XWPFDocument;
+
+/**
+ * High level representation of a ooxml text document.
+ */
+public class XMLWordDocument {
+	private XWPFDocument xwpfXML;
+	
+	public XMLWordDocument(XWPFDocument xml) {
+		this.xwpfXML = xml;
+	}
+	
+	public XWPFDocument _getXWPFXML() {
+		return xwpfXML;
+	}
+}

Propchange: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java
(from r635243, poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestHXFPowerPointExtractor.java)
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java?p2=poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java&p1=poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestHXFPowerPointExtractor.java&r1=635243&r2=635253&rev=635253&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestHXFPowerPointExtractor.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xslf/extractor/TestXSLFPowerPointExtractor.java
Sun Mar  9 07:39:36 2008
@@ -14,45 +14,47 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-package org.apache.poi.hslf.extractor;
+package org.apache.poi.xslf.extractor;
 
 import java.io.File;
 
-import org.apache.poi.hslf.HSLFXML;
-import org.apache.poi.hslf.usermodel.HSLFXMLSlideShow;
-import org.apache.poi.hxf.HXFDocument;
+import org.apache.poi.POIXMLDocument;
+import org.apache.poi.xslf.XSLFSlideShow;
 
 import junit.framework.TestCase;
 
 /**
  * Tests for HXFPowerPointExtractor
  */
-public class TestHXFPowerPointExtractor extends TestCase {
+public class TestXSLFPowerPointExtractor extends TestCase {
 	/**
 	 * A simple file
 	 */
-	private HSLFXML xmlA;
+	private XSLFSlideShow xmlA;
+	private File fileA;
 
 	protected void setUp() throws Exception {
 		super.setUp();
 		
-		File fileA = new File(
+		fileA = new File(
 				System.getProperty("HSLF.testdata.path") +
 				File.separator + "sample.pptx"
 		);
+		assertTrue(fileA.exists());
 		
-		xmlA = new HSLFXML(HXFDocument.openPackage(fileA));
+		xmlA = new XSLFSlideShow(fileA.toString());
 	}
 
 	/**
 	 * Get text out of the simple file
 	 */
 	public void testGetSimpleText() throws Exception {
-		new HXFPowerPointExtractor(xmlA.getPackage());
-		new HXFPowerPointExtractor(new XMLSlideShow(xmlA));
+		new XSLFPowerPointExtractor(xmlA);
+		new XSLFPowerPointExtractor(
+				POIXMLDocument.openPackage(fileA.toString()));
 		
-		HXFPowerPointExtractor extractor = 
-			new HXFPowerPointExtractor(xmlA.getPackage());
+		XSLFPowerPointExtractor extractor = 
+			new XSLFPowerPointExtractor(xmlA);
 		extractor.getText();
 		
 		String text = extractor.getText();

Copied: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java (from
r635031, poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/TestHWPFXML.java)
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java?p2=poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java&p1=poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/TestHWPFXML.java&r1=635031&r2=635253&rev=635253&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/TestHWPFXML.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java Sun Mar
 9 07:39:36 2008
@@ -14,17 +14,17 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-package org.apache.poi.hwpf;
+package org.apache.poi.xwpf;
 
 import java.io.File;
 
-import org.apache.poi.hxf.HXFDocument;
+import org.apache.poi.POIXMLDocument;
 import org.openxml4j.opc.Package;
 import org.openxml4j.opc.PackagePart;
 
 import junit.framework.TestCase;
 
-public class TestHWPFXML extends TestCase {
+public class TestXWPFDocument extends TestCase {
 	private File sampleFile;
 	private File complexFile;
 
@@ -39,14 +39,17 @@
 				System.getProperty("HWPF.testdata.path") +
 				File.separator + "IllustrativeCases.docx"
 		);
+		
+		assertTrue(sampleFile.exists());
+		assertTrue(complexFile.exists());
 	}
 
 	public void testContainsMainContentType() throws Exception {
-		Package pack = HXFDocument.openPackage(sampleFile);
+		Package pack = POIXMLDocument.openPackage(sampleFile.toString());
 		
 		boolean found = false;
 		for(PackagePart part : pack.getParts()) {
-			if(part.getContentType().equals(HWPFXML.MAIN_CONTENT_TYPE)) {
+			if(part.getContentType().equals(XWPFDocument.MAIN_CONTENT_TYPE)) {
 				found = true;
 			}
 			System.out.println(part);
@@ -55,14 +58,21 @@
 	}
 
 	public void testOpen() throws Exception {
-		HXFDocument.openPackage(sampleFile);
-		HXFDocument.openPackage(complexFile);
+		POIXMLDocument.openPackage(sampleFile.toString());
+		POIXMLDocument.openPackage(complexFile.toString());
+		
+		new XWPFDocument(
+				POIXMLDocument.openPackage(sampleFile.toString())
+		);
+		new XWPFDocument(
+				POIXMLDocument.openPackage(complexFile.toString())
+		);
 		
-		HWPFXML xml;
+		XWPFDocument xml;
 		
 		// Simple file
-		xml = new HWPFXML(
-				HXFDocument.openPackage(sampleFile)
+		xml = new XWPFDocument(
+				POIXMLDocument.openPackage(sampleFile.toString())
 		);
 		// Check it has key parts
 		assertNotNull(xml.getDocument());
@@ -70,8 +80,8 @@
 		assertNotNull(xml.getStyle());
 		
 		// Complex file
-		xml = new HWPFXML(
-				HXFDocument.openPackage(complexFile)
+		xml = new XWPFDocument(
+				POIXMLDocument.openPackage(complexFile.toString())
 		);
 		assertNotNull(xml.getDocument());
 		assertNotNull(xml.getDocumentBody());
@@ -79,8 +89,8 @@
 	}
 	
 	public void testMetadataBasics() throws Exception {
-		HWPFXML xml = new HWPFXML(
-				HXFDocument.openPackage(sampleFile)
+		XWPFDocument xml = new XWPFDocument(
+				POIXMLDocument.openPackage(sampleFile.toString())
 		);
 		assertNotNull(xml.getCoreProperties());
 		assertNotNull(xml.getExtendedProperties());
@@ -94,8 +104,8 @@
 	}
 	
 	public void testMetadataComplex() throws Exception {
-		HWPFXML xml = new HWPFXML(
-				HXFDocument.openPackage(complexFile)
+		XWPFDocument xml = new XWPFDocument(
+				POIXMLDocument.openPackage(complexFile.toString())
 		);
 		assertNotNull(xml.getCoreProperties());
 		assertNotNull(xml.getExtendedProperties());

Copied: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
(from r635031, poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestHXFWordExtractor.java)
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java?p2=poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java&p1=poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestHXFWordExtractor.java&r1=635031&r2=635253&rev=635253&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestHXFWordExtractor.java
(original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
Sun Mar  9 07:39:36 2008
@@ -14,54 +14,57 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-package org.apache.poi.hwpf.extractor;
+package org.apache.poi.xwpf.extractor;
 
 import java.io.File;
 
-import org.apache.poi.hwpf.HWPFXML;
-import org.apache.poi.hwpf.usermodel.HWPFXMLDocument;
-import org.apache.poi.hxf.HXFDocument;
+import org.apache.poi.POIXMLDocument;
+import org.apache.poi.xwpf.XWPFDocument;
 
 import junit.framework.TestCase;
 
 /**
  * Tests for HXFWordExtractor
  */
-public class TestHXFWordExtractor extends TestCase {
+public class TestXWPFWordExtractor extends TestCase {
 	/**
 	 * A very simple file
 	 */
-	private HWPFXML xmlA;
+	private XWPFDocument xmlA;
+	private File fileA;
 	/**
 	 * A fairly complex file
 	 */
-	private HWPFXML xmlB;
+	private XWPFDocument xmlB;
+	private File fileB;
 
 	protected void setUp() throws Exception {
 		super.setUp();
 		
-		File fileA = new File(
+		fileA = new File(
 				System.getProperty("HWPF.testdata.path") +
 				File.separator + "sample.docx"
 		);
-		File fileB = new File(
+		fileB = new File(
 				System.getProperty("HWPF.testdata.path") +
 				File.separator + "IllustrativeCases.docx"
 		);
+		assertTrue(fileA.exists());
+		assertTrue(fileB.exists());
 		
-		xmlA = new HWPFXML(HXFDocument.openPackage(fileA));
-		xmlB = new HWPFXML(HXFDocument.openPackage(fileB));
+		xmlA = new XWPFDocument(POIXMLDocument.openPackage(fileA.toString()));
+		xmlB = new XWPFDocument(POIXMLDocument.openPackage(fileB.toString()));
 	}
 
 	/**
 	 * Get text out of the simple file
 	 */
 	public void testGetSimpleText() throws Exception {
-		new HXFWordExtractor(xmlA.getPackage());
-		new HXFWordExtractor(new HWPFXMLDocument(xmlA));
+		new XWPFWordExtractor(xmlA);
+		new XWPFWordExtractor(POIXMLDocument.openPackage(fileA.toString()));
 		
-		HXFWordExtractor extractor = 
-			new HXFWordExtractor(xmlA.getPackage());
+		XWPFWordExtractor extractor = 
+			new XWPFWordExtractor(xmlA);
 		extractor.getText();
 		
 		String text = extractor.getText();
@@ -88,8 +91,8 @@
 	 * Tests getting the text out of a complex file
 	 */
 	public void testGetComplexText() throws Exception {
-		HXFWordExtractor extractor = 
-			new HXFWordExtractor(xmlB.getPackage());
+		XWPFWordExtractor extractor = 
+			new XWPFWordExtractor(xmlB);
 		extractor.getText();
 		
 		String text = extractor.getText();



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


Mime
View raw message