poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r712508 - in /poi/trunk/src: examples/src/org/apache/poi/xwpf/ examples/src/org/apache/poi/xwpf/usermodel/ ooxml/interfaces-jdk14/ ooxml/java/org/apache/poi/ ooxml/java/org/apache/poi/extractor/ ooxml/java/org/apache/poi/xssf/usermodel/ oox...
Date Sun, 09 Nov 2008 16:18:47 GMT
Author: yegor
Date: Sun Nov  9 08:18:46 2008
New Revision: 712508

URL: http://svn.apache.org/viewvc?rev=712508&view=rev
Log:
1. removed interfaces-jdk14, they are now obsolete2. started paving the way for XWPF

Added:
    poi/trunk/src/examples/src/org/apache/poi/xwpf/
    poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/
    poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocument.java   (with props)
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java   (with props)
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
      - copied, changed from r712506, poi/trunk/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java   (with props)
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java   (with props)
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java   (with props)
Removed:
    poi/trunk/src/ooxml/interfaces-jdk14/
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XMLWordDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraphText.java
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFCommentsDecorator.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHyperlinkDecorator.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFComment.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/TestEmbeded.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java

Added: poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocument.java?rev=712508&view=auto
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocument.java (added)
+++ poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocument.java Sun Nov  9 08:18:46 2008
@@ -0,0 +1,50 @@
+/* ====================================================================
+   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 java.io.FileOutputStream;
+
+/**
+ * A simple WOrdprocessingML document created by POI XWPF API
+ *
+ * @author Yegor Kozlov
+ */
+public class SimpleDocument {
+
+    public static void main(String[] args) throws Exception {
+        XWPFDocument doc = new XWPFDocument();
+
+        XWPFParagraph p1 = doc.createParagraph();
+        p1.setAlignment(ParagraphAlignment.CENTER);
+
+        XWPFRun r1 = p1.createRun();
+        r1.setBold(true);
+        r1.setText("The quick brown fox");
+
+        XWPFParagraph p2 = doc.createParagraph();
+        p2.setAlignment(ParagraphAlignment.RIGHT);
+
+        XWPFRun r2 = p2.createRun();
+        r2.setBold(false);
+        r2.setText("jumped over the lazy dog");
+
+        FileOutputStream out = new FileOutputStream("simple.docx");
+        doc.write(out);
+        out.close();
+
+    }
+}

Propchange: poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/SimpleDocument.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java Sun Nov  9 08:18:46 2008
@@ -21,6 +21,7 @@
 
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.util.IOUtils;
+import org.apache.poi.util.PackageHelper;
 import org.apache.xmlbeans.XmlException;
 import org.openxml4j.exceptions.InvalidFormatException;
 import org.openxml4j.exceptions.OpenXML4JException;
@@ -169,4 +170,35 @@
      */
     public abstract List<PackagePart> getAllEmbedds() throws OpenXML4JException;
 
+    /**
+     * YK: current implementation of OpenXML4J is funny.
+     * Packages opened by Package.open(InputStream is) are read-only,
+     * there is no way to change or even save such an instance in a OutputStream.
+     * The workaround is to create a copy via a temp file
+     */
+    protected static Package ensureWriteAccess(Package pkg) throws IOException {
+        if(pkg.getPackageAccess() == PackageAccess.READ){
+            try {
+                return PackageHelper.clone(pkg);
+            } catch (OpenXML4JException e){
+                throw new POIXMLException(e);
+            }
+        }
+        return pkg;
+    }
+
+    /**
+     * Write out this document to an Outputstream.
+     *
+     * @param stream - the java OutputStream you wish to write the XLS to
+     *
+     * @exception IOException if anything can't be written.
+     */
+    public final void write(OutputStream stream) throws IOException {
+        //force all children to commit their changes into the underlying OOXML Package
+        onSave();
+
+        getPackage().save(stream);
+    }
+
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/extractor/ExtractorFactory.java Sun Nov  9 08:18:46 2008
@@ -41,7 +41,8 @@
 import org.apache.poi.xslf.extractor.XSLFPowerPointExtractor;
 import org.apache.poi.xssf.extractor.XSSFExcelExtractor;
 import org.apache.poi.xssf.usermodel.XSSFRelation;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFRelation;
 import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
 import org.apache.xmlbeans.XmlException;
 import org.openxml4j.exceptions.InvalidFormatException;
@@ -99,7 +100,7 @@
 		if(corePart.getContentType().equals(XSSFRelation.WORKBOOK.getContentType())) {
 			return new XSSFExcelExtractor(pkg);
 		}
-		if(corePart.getContentType().equals(XWPFDocument.MAIN_CONTENT_TYPE)) {
+		if(corePart.getContentType().equals(XWPFRelation.MAIN_CONTENT_TYPE)) {
 			return new XWPFWordExtractor(pkg);
 		}
 		if(corePart.getContentType().equals(XSLFSlideShow.MAIN_CONTENT_TYPE)) {

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Sun Nov  9 08:18:46 2008
@@ -137,23 +137,6 @@
         this(openPackage(path));
     }
 
-    /**
-     * YK: current implementation of OpenXML4J is funny.
-     * Packages opened by Package.open(InputStream is) are read-only,
-     * there is no way to change or even save such an instance in a OutputStream.
-     * The workaround is to create a copy via a temp file
-     */
-    private static Package ensureWriteAccess(Package pkg) throws IOException {
-        if(pkg.getPackageAccess() == PackageAccess.READ){
-            try {
-                return PackageHelper.clone(pkg);
-            } catch (OpenXML4JException e){
-                throw new POIXMLException(e);
-            }
-        }
-        return pkg;
-    }
-
     @Override
     protected void onDocumentRead() throws IOException {
         try {
@@ -1058,20 +1041,6 @@
     }
 
     /**
-     * Write out this workbook to an Outputstream.
-     *
-     * @param stream - the java OutputStream you wish to write the XLS to
-     *
-     * @exception IOException if anything can't be written.
-     */
-    public void write(OutputStream stream) throws IOException {
-        //force all children to commit their changes into the underlying OOXML Package
-        onSave();
-
-        getPackage().save(stream);
-    }
-
-    /**
      * Returns SharedStringsTable - tha cache of string for this workbook
      *
      * @return the shared string table

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java Sun Nov  9 08:18:46 2008
@@ -21,7 +21,7 @@
 
 import org.apache.poi.POIXMLDocument;
 import org.apache.poi.POIXMLTextExtractor;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.apache.poi.xwpf.model.XWPFCommentsDecorator;
 import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
 import org.apache.poi.xwpf.model.XWPFHyperlinkDecorator;

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFCommentsDecorator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFCommentsDecorator.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFCommentsDecorator.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFCommentsDecorator.java Sun Nov  9 08:18:46 2008
@@ -41,7 +41,7 @@
 
 		for(CTMarkupRange anchor : paragraph.getCTP().getCommentRangeStartArray())
 		{
-			if((comment = paragraph.getDocRef().getCommentByID(anchor.getId().toString())) != null)
+			if((comment = paragraph.getDocument().getCommentByID(anchor.getId().toString())) != null)
 				commentText.append("\tComment by " + comment.getAuthor()+": "+comment.getText());
 		}
 	}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java Sun Nov  9 08:18:46 2008
@@ -18,7 +18,7 @@
 
 import java.io.IOException;
 
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.apache.poi.xwpf.usermodel.XWPFFooter;
 import org.apache.poi.xwpf.usermodel.XWPFHeader;
 import org.apache.xmlbeans.XmlException;
@@ -57,7 +57,7 @@
 		// For now, we don't care about different ranges, as it
 		//  doesn't seem that .docx properly supports that
 		//  feature of the file format yet
-		CTSectPr sectPr = doc.getDocumentBody().getSectPr();
+		CTSectPr sectPr = doc.getDocument().getBody().getSectPr();
 		for(int i=0; i<sectPr.sizeOfHeaderReferenceArray(); i++) {
 			// Get the header
 			CTHdrFtrRef ref = sectPr.getHeaderReferenceArray(i);

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHyperlinkDecorator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHyperlinkDecorator.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHyperlinkDecorator.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHyperlinkDecorator.java Sun Nov  9 08:18:46 2008
@@ -56,8 +56,8 @@
 					hyperlinkText.append(text.getStringValue());
 				}
 			}
-			if(outputHyperlinkUrls && paragraph.getDocRef().getHyperlinkByID(link.getId()) != null) {
-				hyperlinkText.append(" <"+paragraph.getDocRef().getHyperlinkByID(link.getId()).getURL()+">");
+			if(outputHyperlinkUrls && paragraph.getDocument().getHyperlinkByID(link.getId()) != null) {
+				hyperlinkText.append(" <"+paragraph.getDocument().getHyperlinkByID(link.getId()).getURL()+">");
 			}
 		}
 	}

Added: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java?rev=712508&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java Sun Nov  9 08:18:46 2008
@@ -0,0 +1,65 @@
+/* ====================================================================
+   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 java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Specifies all types of alignment which are available to be applied to objects in a
+ * WordprocessingML document
+ *
+ * @author Yegor Kozlov
+ */
+public enum ParagraphAlignment {
+    //YK: TODO document each alignment option
+
+    LEFT(1),
+    CENTER(2),
+    RIGHT(3),
+    BOTH(4),
+    MEDIUM_KASHIDA(5),
+    DISTRIBUTE(6),
+    NUM_TAB(7),
+    HIGH_KASHIDA(8),
+    LOW_KASHIDA(9),
+    THAI_DISTRIBUTE(10);
+
+    private final int value;
+
+    private ParagraphAlignment(int val){
+        value = val;
+    }
+
+    public int getValue(){
+        return value;
+    }
+
+    private static Map<Integer, ParagraphAlignment> imap = new HashMap<Integer, ParagraphAlignment>();
+    static{
+        for (ParagraphAlignment p : values()) {
+            imap.put(p.getValue(), p);
+        }
+    }
+
+    public static ParagraphAlignment valueOf(int type){
+        ParagraphAlignment err = imap.get(type);
+        if(err == null) throw new IllegalArgumentException("Unknown paragraph alignment: " + type);
+        return err;
+    }
+
+}

Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/ParagraphAlignment.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFComment.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFComment.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFComment.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFComment.java Sun Nov  9 08:18:46 2008
@@ -39,7 +39,7 @@
         
         for(CTP ctp : comment.getPArray())
         {
-            XWPFParagraph p = new XWPFParagraph(ctp);
+            XWPFParagraph p = new XWPFParagraph(ctp, null);
             text.append(p.getText());
         }
     }

Copied: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (from r712506, poi/trunk/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java)
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java?p2=poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java&p1=poi/trunk/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java&r1=712506&r2=712508&rev=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/XWPFDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java Sun Nov  9 08:18:46 2008
@@ -14,26 +14,23 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-package org.apache.poi.xwpf;
+package org.apache.poi.xwpf.usermodel;
 
 import java.io.IOException;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
+import java.io.OutputStream;
+import java.util.*;
 
 import org.apache.poi.POIXMLDocument;
+import org.apache.poi.POIXMLException;
+import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.util.PackageHelper;
 import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
-import org.apache.poi.xwpf.usermodel.XWPFComment;
-import org.apache.poi.xwpf.usermodel.XWPFHyperlink;
-import org.apache.poi.xwpf.usermodel.XWPFParagraph;
-import org.apache.poi.xwpf.usermodel.XWPFTable;
 import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlOptions;
 import org.openxml4j.exceptions.InvalidFormatException;
 import org.openxml4j.exceptions.OpenXML4JException;
+import org.openxml4j.opc.*;
 import org.openxml4j.opc.Package;
-import org.openxml4j.opc.PackagePart;
-import org.openxml4j.opc.PackageRelationship;
-import org.openxml4j.opc.PackageRelationshipCollection;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
@@ -44,212 +41,282 @@
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
 
+import javax.xml.namespace.QName;
+
 /**
  * Experimental class to do low level processing
  *  of docx files.
- * 
+ *
  * If you are using these low level classes, then you
  *  will almost certainly need to refer to the OOXML
  *  specifications from
  *  http://www.ecma-international.org/publications/standards/Ecma-376.htm
- *  
+ *
  * WARNING - APIs expected to change rapidly
  */
 public class XWPFDocument extends POIXMLDocument {
-	public static final String MAIN_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
-	public static final String HEADER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml";
-	public static final String HEADER_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
-	public static final String FOOTER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml";
-	public static final String FOOTER_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer";
-	public static final String STYLES_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml";
-	public static final String STYLES_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
-	public static final String HYPERLINK_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
-	public static final String COMMENT_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
-	
-	private DocumentDocument wordDoc;
-	protected List<XWPFComment> comments;
-	protected List<XWPFHyperlink> hyperlinks;
-	protected List<XWPFParagraph> paragraphs;
-	protected List<XWPFTable> tables;
-    /**
-     * The embedded OLE2 files in the OPC package
-     */
-    private List<PackagePart> embedds;
-
-	/** Handles the joy of different headers/footers for different pages */
-	private XWPFHeaderFooterPolicy headerFooterPolicy;
-	
-	public XWPFDocument(Package container) throws OpenXML4JException, IOException, XmlException {
-		super(container);
-
-		hyperlinks = new LinkedList<XWPFHyperlink>();
-		comments = new LinkedList<XWPFComment>();
-		paragraphs = new LinkedList<XWPFParagraph>();
-		tables= new LinkedList<XWPFTable>();
-		
-		wordDoc =
-			DocumentDocument.Factory.parse(getCorePart().getInputStream());
-		
-		// filling paragraph list
-		for (CTP p : getDocumentBody().getPArray())	{
-			paragraphs.add(new XWPFParagraph(p, this));
-		}
-
-		// Get the hyperlinks 
-		// TODO: make me optional/separated in private function
-		try	{
-			Iterator <PackageRelationship> relIter = 
-				getCorePart().getRelationshipsByType(HYPERLINK_RELATION_TYPE).iterator();
-			while(relIter.hasNext()) {
-				PackageRelationship rel = relIter.next();
-				hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString()));
-			}
-		} catch(Exception e) {
-			throw new OpenXML4JException(e.getLocalizedMessage());
-		}
-
-		// Get the comments, if there are any
-		PackageRelationshipCollection commentsRel = getCmntRelations();
-		if(commentsRel != null && commentsRel.size() > 0) {
-			PackagePart commentsPart = getTargetPart(commentsRel.getRelationship(0));
-			CommentsDocument cmntdoc = CommentsDocument.Factory.parse(commentsPart.getInputStream());
-			for(CTComment ctcomment : cmntdoc.getComments().getCommentArray()) {
-				comments.add(new XWPFComment(ctcomment));
-			}
-		}
-		
-		// Get any tables
-		for(CTTbl table : getDocumentBody().getTblArray()) {
-			tables.add(new XWPFTable(table));
-		}
-		
-		/// Process embedded document parts
-        this.embedds = new LinkedList<PackagePart>();
-        for(PackageRelationship rel : getCorePart().getRelationshipsByType(OLE_OBJECT_REL_TYPE)) {
-            embedds.add(getTargetPart(rel));
+
+    private CTDocument1 ctDocument;
+    protected List<XWPFComment> comments;
+    protected List<XWPFHyperlink> hyperlinks;
+    protected List<XWPFParagraph> paragraphs;
+    protected List<XWPFTable> tables;
+
+    /** Handles the joy of different headers/footers for different pages */
+    private XWPFHeaderFooterPolicy headerFooterPolicy;
+
+    public XWPFDocument(Package pkg) throws IOException {
+        super(ensureWriteAccess(pkg));
+
+        //build a tree of POIXMLDocumentParts, this document being the root
+        try {
+            read(XWPFFactory.getInstance());
+        } catch (OpenXML4JException e){
+            throw new POIXMLException(e);
         }
-        for(PackageRelationship rel : getCorePart().getRelationshipsByType(PACK_OBJECT_REL_TYPE)) {
-            embedds.add(getTargetPart(rel));
+        onDocumentRead();
+    }
+
+    public XWPFDocument(){
+        super(newPackage());
+        onDocumentCreate();
+    }
+
+    @Override
+    protected void onDocumentRead() throws IOException {
+        hyperlinks = new ArrayList<XWPFHyperlink>();
+        comments = new ArrayList<XWPFComment>();
+        paragraphs = new ArrayList<XWPFParagraph>();
+        tables= new ArrayList<XWPFTable>();
+
+        try {
+            DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
+            ctDocument = doc.getDocument();
+
+            CTBody body = ctDocument.getBody();
+
+            // filling paragraph list
+            for (CTP p : body.getPArray())	{
+                paragraphs.add(new XWPFParagraph(p, this));
+            }
+
+            // Get any tables
+            for(CTTbl table : body.getTblArray()) {
+                tables.add(new XWPFTable(table));
+            }
+
+            // Sort out headers and footers
+            headerFooterPolicy = new XWPFHeaderFooterPolicy(this);
+
+            for(POIXMLDocumentPart p : getRelations()){
+                String relation = p.getPackageRelationship().getRelationshipType();
+                if(relation.equals(XWPFRelation.COMMENT_RELATION_TYPE)){
+                    CommentsDocument cmntdoc = CommentsDocument.Factory.parse(p.getPackagePart().getInputStream());
+                    for(CTComment ctcomment : cmntdoc.getComments().getCommentArray()) {
+                        comments.add(new XWPFComment(ctcomment));
+                    }
+                }
+            }
+
+            initHyperlinks();
+
+        } catch (XmlException e) {
+            throw new POIXMLException(e);
+        }
+    }
+
+    private void initHyperlinks(){
+        // Get the hyperlinks
+        // TODO: make me optional/separated in private function
+        try	{
+            Iterator <PackageRelationship> relIter =
+                getPackagePart().getRelationshipsByType(XWPFRelation.HYPERLINK_RELATION_TYPE).iterator();
+            while(relIter.hasNext()) {
+                PackageRelationship rel = relIter.next();
+                hyperlinks.add(new XWPFHyperlink(rel.getId(), rel.getTargetURI().toString()));
+            }
+        } catch (InvalidFormatException e){
+            throw new POIXMLException(e);
+        }
+    }
+
+    /**
+     * Create a new SpreadsheetML package and setup the default minimal content
+     */
+    protected static Package newPackage() {
+        try {
+            Package pkg = Package.create(PackageHelper.createTempFile());
+            // Main part
+            PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
+            // Create main part relationship
+            pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT);
+            // Create main document part
+            pkg.createPart(corePartName, XWPFRelation.DOCUMENT.getContentType());
+
+            pkg.getPackageProperties().setCreatorProperty("Apache POI");
+
+            return pkg;
+        } catch (Exception e){
+            throw new POIXMLException(e);
         }
-        
-        // Sort out headers and footers
-        headerFooterPolicy = new XWPFHeaderFooterPolicy(this);
-	}
-	
-	/**
-	 * Returns the low level document base object
-	 */
-	public CTDocument1 getDocument() {
-		return wordDoc.getDocument();
-	}
-	
-	public Iterator<XWPFParagraph> getParagraphsIterator() {
-		return paragraphs.iterator();
-	}
-	public XWPFParagraph[] getParagraphs() {
-		return paragraphs.toArray(
-			new XWPFParagraph[paragraphs.size()]
-		);
-	}
-	
-	public Iterator<XWPFTable> getTablesIterator()
-	{
-		return tables.iterator();
-	}
-	
-	public XWPFHyperlink getHyperlinkByID(String id) {
-		Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
-		while(iter.hasNext())
-		{
-			XWPFHyperlink link = iter.next();
-			if(link.getId().equals(id))
-				return link; 
-		}
-		
-		return null;
-	}
-	public XWPFHyperlink[] getHyperlinks() {
-		return hyperlinks.toArray(
-				new XWPFHyperlink[hyperlinks.size()]
-		);
-	}
-	
-	public XWPFComment getCommentByID(String id) {
-		Iterator<XWPFComment> iter = comments.iterator();
-		while(iter.hasNext())
-		{
-			XWPFComment comment = iter.next();
-			if(comment.getId().equals(id))
-				return comment; 
-		}
-		
-		return null;
-	}
-	public XWPFComment[] getComments() {
-		return comments.toArray(
-				new XWPFComment[comments.size()]
-		);
-	}
-	
-	/**
-	 * Get the document part that's defined as the
-	 *  given relationship of the core document.
-	 */
-	public PackagePart getPartById(String id) {
-		try {
-			return getTargetPart(
-					getCorePart().getRelationship(id)
-			);
-		} catch(InvalidFormatException e) {
-			throw new IllegalArgumentException(e);
-		}
-	}
-
-	/**
-	 * Returns the policy on headers and footers, which
-	 *  also provides a way to get at them.
-	 */
-	public XWPFHeaderFooterPolicy getHeaderFooterPolicy() {
-		return headerFooterPolicy;
-	}
-	
-	/**
-	 * Returns the low level body of the document
-	 */
-	public CTBody getDocumentBody() {
-		return getDocument().getBody();
-	}
-	
-	/**
-	 * Returns the styles object used
-	 */
-	public CTStyles getStyle() throws XmlException, IOException {
-		PackagePart[] parts;
-		try {
-			parts = getRelatedByType(STYLES_RELATION_TYPE);
-		} catch(InvalidFormatException e) {
-			throw new IllegalStateException(e);
-		}
-		if(parts.length != 1) {
-			throw new IllegalStateException("Expecting one Styles document part, but found " + parts.length);
-		}
-		
-		StylesDocument sd =
-			StylesDocument.Factory.parse(parts[0].getInputStream());
-		return sd.getStyles();
-	}
-
-	protected PackageRelationshipCollection getCmntRelations() throws InvalidFormatException
-	{
-		return getCorePart().getRelationshipsByType(COMMENT_RELATION_TYPE);
-	}
+    }
+
+    /**
+     * Create a new CTWorkbook with all values set to default
+     */
+    protected void onDocumentCreate() {
+        hyperlinks = new ArrayList<XWPFHyperlink>();
+        comments = new ArrayList<XWPFComment>();
+        paragraphs = new ArrayList<XWPFParagraph>();
+        tables= new ArrayList<XWPFTable>();
+
+        ctDocument = CTDocument1.Factory.newInstance();
+        ctDocument.addNewBody();
+    }
+
+    /**
+     * Returns the low level document base object
+     */
+    public CTDocument1 getDocument() {
+        return ctDocument;
+    }
+
+    public Iterator<XWPFParagraph> getParagraphsIterator() {
+        return paragraphs.iterator();
+    }
+    public XWPFParagraph[] getParagraphs() {
+        return paragraphs.toArray(
+            new XWPFParagraph[paragraphs.size()]
+        );
+    }
+
+    public Iterator<XWPFTable> getTablesIterator()
+    {
+        return tables.iterator();
+    }
+
+    public XWPFHyperlink getHyperlinkByID(String id) {
+        Iterator<XWPFHyperlink> iter = hyperlinks.iterator();
+        while(iter.hasNext())
+        {
+            XWPFHyperlink link = iter.next();
+            if(link.getId().equals(id))
+                return link;
+        }
+
+        return null;
+    }
+    public XWPFHyperlink[] getHyperlinks() {
+        return hyperlinks.toArray(
+                new XWPFHyperlink[hyperlinks.size()]
+        );
+    }
+
+    public XWPFComment getCommentByID(String id) {
+        Iterator<XWPFComment> iter = comments.iterator();
+        while(iter.hasNext())
+        {
+            XWPFComment comment = iter.next();
+            if(comment.getId().equals(id))
+                return comment;
+        }
+
+        return null;
+    }
+    public XWPFComment[] getComments() {
+        return comments.toArray(
+                new XWPFComment[comments.size()]
+        );
+    }
+
+    /**
+     * Get the document part that's defined as the
+     *  given relationship of the core document.
+     */
+    public PackagePart getPartById(String id) {
+        try {
+            return getTargetPart(
+                    getCorePart().getRelationship(id)
+            );
+        } catch(InvalidFormatException e) {
+            throw new IllegalArgumentException(e);
+        }
+    }
+
+    /**
+     * Returns the policy on headers and footers, which
+     *  also provides a way to get at them.
+     */
+    public XWPFHeaderFooterPolicy getHeaderFooterPolicy() {
+        return headerFooterPolicy;
+    }
+
+    /**
+     * Returns the styles object used
+     */
+    public CTStyles getStyle() throws XmlException, IOException {
+        PackagePart[] parts;
+        try {
+            parts = getRelatedByType(XWPFRelation.STYLES_RELATION_TYPE);
+        } catch(InvalidFormatException e) {
+            throw new IllegalStateException(e);
+        }
+        if(parts.length != 1) {
+            throw new IllegalStateException("Expecting one Styles document part, but found " + parts.length);
+        }
+
+        StylesDocument sd =
+            StylesDocument.Factory.parse(parts[0].getInputStream());
+        return sd.getStyles();
+    }
 
     /**
      * Get the document's embedded files.
      */
     public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
+        List<PackagePart> embedds = new LinkedList<PackagePart>();
+
+        // Get the embeddings for the workbook
+        for(PackageRelationship rel : getPackagePart().getRelationshipsByType(OLE_OBJECT_REL_TYPE))
+            embedds.add(getTargetPart(rel));
+
+        for(PackageRelationship rel : getPackagePart().getRelationshipsByType(PACK_OBJECT_REL_TYPE))
+            embedds.add(getTargetPart(rel));
+
         return embedds;
     }
 
+    @Override
+    protected void commit() throws IOException {
+
+        XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
+        xmlOptions.setSaveSyntheticDocumentElement(new QName(CTDocument1.type.getName().getNamespaceURI(), "document"));
+        Map map = new HashMap();
+        map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
+        map.put("urn:schemas-microsoft-com:office:office", "o");
+        map.put("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "r");
+        map.put("urn:schemas-microsoft-com:vml", "v");
+        map.put("http://schemas.openxmlformats.org/markup-compatibility/2006", "ve");
+        map.put("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "w");
+        map.put("urn:schemas-microsoft-com:office:word", "w10");
+        map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne");
+        map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
+        xmlOptions.setSaveSuggestedPrefixes(map);
+
+        PackagePart part = getPackagePart();
+        OutputStream out = part.getOutputStream();
+        ctDocument.save(out, xmlOptions);
+        out.close();
+    }
+
+    /**
+     * Appends a new paragraph to this document
+     *
+     * @return a new paragraph
+     */
+    public XWPFParagraph createParagraph(){
+        return new XWPFParagraph(ctDocument.getBody().addNewP(), this);
+    }
+
 }
 

Added: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java?rev=712508&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java Sun Nov  9 08:18:46 2008
@@ -0,0 +1,73 @@
+/* ====================================================================
+   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.POIXMLFactory;
+import org.apache.poi.POIXMLDocumentPart;
+import org.apache.poi.POIXMLException;
+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 java.lang.reflect.Constructor;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class XWPFFactory extends POIXMLFactory  {
+
+    private static POILogger logger = POILogFactory.getLogger(XWPFFactory.class);
+
+    private XWPFFactory(){
+
+    }
+
+    private static final XWPFFactory inst = new XWPFFactory();
+
+    public static XWPFFactory getInstance(){
+        return inst;
+    }
+
+    public POIXMLDocumentPart createDocumentPart(PackageRelationship rel, PackagePart part){
+        POIXMLRelation descriptor = XWPFRelation.getInstance(rel.getRelationshipType());
+        if(descriptor == null || descriptor.getRelationClass() == null){
+            logger.log(POILogger.DEBUG, "using default POIXMLDocumentPart for " + rel.getRelationshipType());
+            return new POIXMLDocumentPart(part, rel);
+        }
+
+        try {
+            Class cls = descriptor.getRelationClass();
+            Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(PackagePart.class, PackageRelationship.class);
+            return constructor.newInstance(part, rel);
+        } catch (Exception e){
+            throw new POIXMLException(e);
+        }
+    }
+
+    public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor){
+        try {
+            Class cls = descriptor.getRelationClass();
+            Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor();
+            return constructor.newInstance();
+        } catch (Exception e){
+            throw new POIXMLException(e);
+        }
+    }
+
+}

Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java Sun Nov  9 08:18:46 2008
@@ -47,7 +47,7 @@
 			new XWPFParagraph[headerFooter.getPArray().length];
 		for(int i=0; i<paras.length; i++) {
 			paras[i] = new XWPFParagraph(
-					headerFooter.getPArray(i)
+					headerFooter.getPArray(i), null
 			);
 		}
 		return paras;

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java Sun Nov  9 08:18:46 2008
@@ -18,89 +18,83 @@
 
 import java.util.ArrayList;
 
-import org.apache.poi.xwpf.XWPFDocument;
-import org.apache.poi.xwpf.model.XMLParagraph;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPTab;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPicture;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtContentRun;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtRun;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
 
 /**
  * Sketch of XWPF paragraph class
  */
-public class XWPFParagraph extends XMLParagraph
+public class XWPFParagraph
 {
-    protected XWPFDocument docRef; // XXX: we'd like to have access to document's hyperlink, comments and other tables
+    private CTP paragraph;
+    protected XWPFDocument document; // XXX: we'd like to have access to document's hyperlink, comments and other tables
     /**
      * TODO - replace with RichText String
      */
     private StringBuffer text = new StringBuffer();
     private StringBuffer pictureText = new StringBuffer();
     
-    public XWPFParagraph(CTP prgrph, XWPFDocument docRef)
+    protected XWPFParagraph(CTP prgrph, XWPFDocument docRef)
     {
-        super(prgrph);
-        this.docRef = docRef;
-        
-        // All the runs to loop over
-        // TODO - replace this with some sort of XPath expression
-        //  to directly find all the CTRs, in the right order
-        ArrayList<CTR> rs = new ArrayList<CTR>();
-        CTR[] tmp;
-        
-        // Get the main text runs
-        tmp = paragraph.getRArray();
-        for(int i=0; i<tmp.length; i++) {
-        	rs.add(tmp[i]);
-        }
-        
-        // Not sure quite what these are, but they hold 
-        //  more text runs
-        CTSdtRun[] sdts = paragraph.getSdtArray();
-        for(int i=0; i<sdts.length; i++) {
-        	CTSdtContentRun run = sdts[i].getSdtContent();
-        	tmp = run.getRArray();
-            for(int j=0; j<tmp.length; j++) {
-            	rs.add(tmp[j]);
+        this.paragraph = prgrph;
+        this.document = docRef;
+
+        if(!isEmpty()) {
+            // All the runs to loop over
+            // TODO - replace this with some sort of XPath expression
+            //  to directly find all the CTRs, in the right order
+            ArrayList<CTR> rs = new ArrayList<CTR>();
+            CTR[] tmp;
+
+            // Get the main text runs
+            tmp = paragraph.getRArray();
+            for(int i=0; i<tmp.length; i++) {
+                rs.add(tmp[i]);
             }
-        }
-    
-        
-        // Get text of the paragraph
-        for (int j = 0; j < rs.size(); j++) {
-            // Grab the text and tabs of the paragraph
-        	// Do so in a way that preserves the ordering
-        	XmlCursor c = rs.get(j).newCursor();
-        	c.selectPath( "./*" );
-        	while(c.toNextSelection()) {
-        		XmlObject o = c.getObject();
-        		if(o instanceof CTText) {
-        			text.append( ((CTText)o).getStringValue() );
-        		}
-        		if(o instanceof CTPTab) {
-        			text.append("\t");
-        		}
-        	}
-        	
-            // Loop over pictures inside our
-            //  paragraph, looking for text in them
-            CTPicture[] picts = rs.get(j).getPictArray();
-            for (int k = 0; k < picts.length; k++) {
-                XmlObject[] t = picts[k].selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t");
-                for (int m = 0; m < t.length; m++) {
-                    NodeList kids = t[m].getDomNode().getChildNodes();
-                    for (int n = 0; n < kids.getLength(); n++) {
-                        if (kids.item(n) instanceof Text) {
-                            pictureText.append("\n" + kids.item(n).getNodeValue());
+
+            // Not sure quite what these are, but they hold
+            //  more text runs
+            CTSdtRun[] sdts = paragraph.getSdtArray();
+            for(int i=0; i<sdts.length; i++) {
+                CTSdtContentRun run = sdts[i].getSdtContent();
+                tmp = run.getRArray();
+                for(int j=0; j<tmp.length; j++) {
+                    rs.add(tmp[j]);
+                }
+            }
+
+
+            // Get text of the paragraph
+            for (int j = 0; j < rs.size(); j++) {
+                // Grab the text and tabs of the paragraph
+                // Do so in a way that preserves the ordering
+                XmlCursor c = rs.get(j).newCursor();
+                c.selectPath( "./*" );
+                while(c.toNextSelection()) {
+                    XmlObject o = c.getObject();
+                    if(o instanceof CTText) {
+                        text.append( ((CTText)o).getStringValue() );
+                    }
+                    if(o instanceof CTPTab) {
+                        text.append("\t");
+                    }
+                }
+
+                // Loop over pictures inside our
+                //  paragraph, looking for text in them
+                CTPicture[] picts = rs.get(j).getPictArray();
+                for (int k = 0; k < picts.length; k++) {
+                    XmlObject[] t = picts[k].selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t");
+                    for (int m = 0; m < t.length; m++) {
+                        NodeList kids = t[m].getDomNode().getChildNodes();
+                        for (int n = 0; n < kids.getLength(); n++) {
+                            if (kids.item(n) instanceof Text) {
+                                pictureText.append("\n");
+                                pictureText.append(kids.item(n).getNodeValue());
+                            }
                         }
                     }
                 }
@@ -108,22 +102,16 @@
         }
     }
     
-    public XWPFParagraph(CTP prgrph) {
-        this(prgrph, null);
+    public CTP getCTP() {
+        return paragraph;
     }
-    
-    public XWPFParagraph(XMLParagraph paragraph) {
-        this(paragraph.getCTP());
-    }
-    
-    
+
     public boolean isEmpty() {
     	return !paragraph.getDomNode().hasChildNodes();
     }
-    
-    
-    public XWPFDocument getDocRef() {
-        return docRef;
+
+    public XWPFDocument getDocument() {
+        return document;
     }
     
     /**
@@ -147,4 +135,49 @@
     public String getPictureText() {
     	return pictureText.toString();
     }
+
+    /**
+     * Appends a new run to this paragraph
+     *
+     * @return a new text run
+     */
+    public XWPFRun createRun(){
+        return new XWPFRun(paragraph.addNewR(), this);
+    }
+
+    /**
+     * Returns the paragraph alignment which shall be applied to text in this paragraph.
+     *
+     * <p>
+     * If this element is not set on a given paragraph, its value is determined by the setting previously
+     * set at any level of the style hierarchy (i.e. that previous setting remains unchanged).
+     * If this setting is never specified in the style hierarchy, then no alignment is applied to the paragraph.
+     * </p>
+     *
+     * @return the paragraph alignment of this paragraph.
+     */
+    public ParagraphAlignment getAlignment(){
+        CTPPr pr = paragraph.getPPr();
+        return pr == null || !pr.isSetJc() ? ParagraphAlignment.LEFT :
+                ParagraphAlignment.valueOf(pr.getJc().getVal().intValue());
+    }
+
+    /**
+     * Specifies the paragraph alignment which shall be applied to text in this paragraph.
+     *
+     * <p>
+     * If this element is not set on a given paragraph, its value is determined by the setting previously
+     * set at any level of the style hierarchy (i.e. that previous setting remains unchanged).
+     * If this setting is never specified in the style hierarchy, then no alignment is applied to the paragraph.
+     * </p>
+     *
+     * @param align the paragraph alignment to apply to this paragraph.
+     */
+    public void setAlignment(ParagraphAlignment align){
+        CTPPr pr = paragraph.isSetPPr() ? paragraph.getPPr() : paragraph.addNewPPr();
+        CTJc jc = pr.isSetJc() ? pr.getJc() : pr.addNewJc();
+        STJc.Enum en = STJc.Enum.forInt(align.getValue());
+        jc.setVal(en);
+    }
+
 }

Added: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java?rev=712508&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java Sun Nov  9 08:18:46 2008
@@ -0,0 +1,94 @@
+/* ====================================================================
+   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.POIXMLRelation;
+import org.apache.poi.POIXMLDocumentPart;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author Yegor Kozlov
+ */
+public class XWPFRelation extends POIXMLRelation {
+    public static final String MAIN_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml";
+    public static final String HEADER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml";
+    public static final String HEADER_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header";
+    public static final String FOOTER_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml";
+    public static final String FOOTER_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer";
+    public static final String STYLES_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml";
+    public static final String STYLES_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";
+    public static final String HYPERLINK_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink";
+    public static final String COMMENT_RELATION_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments";
+
+    /**
+     * A map to lookup POIXMLRelation by its relation type
+     */
+    protected static Map<String, XWPFRelation> _table = new HashMap<String, XWPFRelation>();
+
+
+    public static final XWPFRelation DOCUMENT = new XWPFRelation(
+            "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml",
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
+            "/word/document.xml",
+            null
+    );
+    public static final XWPFRelation FONT_TABLE = new XWPFRelation(
+            "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml",
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable",
+            "/word/fontTable.xml",
+            null
+    );
+    public static final XWPFRelation SETTINGS = new XWPFRelation(
+            "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml",
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",
+            "/word/settings.xml",
+            null
+    );
+    public static final XWPFRelation STYLES = new XWPFRelation(
+            "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml",
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
+            "/word/styles.xml",
+            null
+    );
+    public static final XWPFRelation WEB_SETTINGS = new XWPFRelation(
+            "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml",
+            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/webSettings",
+            "/word/webSettings.xml",
+            null
+    );
+
+
+    private XWPFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
+        super(type, rel, defaultName, cls);
+
+        if (cls != null && !_table.containsKey(rel)) _table.put(rel, this);
+    }
+
+    /**
+     * Get POIXMLRelation by relation type
+     *
+     * @param rel relation type, for example,
+     *            <code>http://schemas.openxmlformats.org/officeDocument/2006/relationships/image</code>
+     * @return registered POIXMLRelation or null if not found
+     */
+    public static XWPFRelation getInstance(String rel) {
+        return _table.get(rel);
+    }
+
+}

Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java
------------------------------------------------------------------------------
    svn:executable = *

Added: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java?rev=712508&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java Sun Nov  9 08:18:46 2008
@@ -0,0 +1,105 @@
+/* ====================================================================
+   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.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
+
+/**
+ * XWPFRun object  defines a region of text with a common set of properties
+ *
+ * @author Yegor Kozlov
+ */
+public class XWPFRun {
+    private CTR run;
+    private XWPFParagraph paragraph;
+
+    /**
+     *
+     * @param r the CTR bean which holds the run attributes
+     * @param p the parent paragraph
+     */
+    protected XWPFRun(CTR r, XWPFParagraph p){
+        this.run = r;
+        this.paragraph = p;
+    }
+
+    public CTR getCTR(){
+        return run;
+    }
+
+    public XWPFParagraph getParagraph(){
+        return paragraph;
+    }
+
+    /**
+     * Whether the bold property shall be applied to all non-complex script characters in the
+     * contents of this run when displayed in a document
+     *
+     * @return <code>true</code> if the bold property is applied
+     */
+    public boolean isBold(){
+        CTRPr pr = run.getRPr();
+        return pr != null && pr.isSetB();
+    }
+
+    /**
+     * Whether the bold property shall be applied to all non-complex script characters in the
+     * contents of this run when displayed in a document
+     *
+     * <p>
+     * This formatting property is a toggle property, which specifies that its behavior differs between its use within a
+     * style definition and its use as direct formatting. When used as part of a style definition, setting this property
+     * shall toggle the current state of that property as specified up to this point in the hierarchy (i.e. applied to not
+     * applied, and vice versa). Setting it to <code>false</code> (or an equivalent) shall result in the current
+     * setting remaining unchanged. However, when used as direct formatting, setting this property to true or false
+     * shall set the absolute state of the resulting property.
+     * </p>
+     * <p>
+     * If this element is not present, the default value is to leave the formatting applied at previous level in the style
+     * hierarchy. If this element is never applied in the style hierarchy, then bold shall not be applied to non-complex
+     * script characters.
+     * </p>
+     *
+     * @param value <code>true</code> if the bold property is applied to this run
+     */
+    public void setBold(boolean value){
+        CTRPr pr = run.isSetRPr() ? run.getRPr() : run.addNewRPr();
+        pr.addNewB().setVal(value ? STOnOff.TRUE : STOnOff.FALSE);
+    }
+
+    /**
+     * Return the string content of this text run
+     *
+     * @return the text of this text run or <code>null</code> if not set
+     */
+    public String getText(){
+        return run.sizeOfTArray() == 0 ? null : run.getTArray(0).getStringValue();
+    }
+
+    /**
+     * Sets the text of this text run
+     *
+     * @param value the literal text which shall be displayed in the document
+     */
+    public void setText(String value){
+        CTText t = run.sizeOfTArray() == 0 ? run.addNewT() : run.getTArray(0);
+        t.setStringValue(value);
+    }
+}

Propchange: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java Sun Nov  9 08:18:46 2008
@@ -37,7 +37,7 @@
         	StringBuffer rowText = new StringBuffer();
             for(CTTc cell : row.getTcArray()) {
                 for(CTP ctp : cell.getPArray()) {
-                    XWPFParagraph p = new XWPFParagraph(ctp);
+                    XWPFParagraph p = new XWPFParagraph(ctp, null);
                     if(rowText.length() > 0) {
                     	rowText.append('\t');
                     }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/TestEmbeded.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/TestEmbeded.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/TestEmbeded.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/TestEmbeded.java Sun Nov  9 08:18:46 2008
@@ -20,12 +20,11 @@
 package org.apache.poi;
 
 import java.io.File;
-import java.util.Iterator;
 
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.xslf.XSLFSlideShow;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.openxml4j.opc.Package;
 import org.openxml4j.opc.PackagePart;
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java Sun Nov  9 08:18:46 2008
@@ -19,6 +19,8 @@
 import java.io.File;
 
 import org.apache.poi.POIXMLDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFRelation;
 import org.openxml4j.opc.Package;
 import org.openxml4j.opc.PackagePart;
 
@@ -49,7 +51,7 @@
 		
 		boolean found = false;
 		for(PackagePart part : pack.getParts()) {
-			if(part.getContentType().equals(XWPFDocument.MAIN_CONTENT_TYPE)) {
+			if(part.getContentType().equals(XWPFRelation.MAIN_CONTENT_TYPE)) {
 				found = true;
 			}
 			System.out.println(part);
@@ -76,7 +78,7 @@
 		);
 		// Check it has key parts
 		assertNotNull(xml.getDocument());
-		assertNotNull(xml.getDocumentBody());
+		assertNotNull(xml.getDocument().getBody());
 		assertNotNull(xml.getStyle());
 		
 		// Complex file
@@ -84,7 +86,7 @@
 				POIXMLDocument.openPackage(complexFile.toString())
 		);
 		assertNotNull(xml.getDocument());
-		assertNotNull(xml.getDocumentBody());
+		assertNotNull(xml.getDocument().getBody());
 		assertNotNull(xml.getStyle());
 	}
 	

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java Sun Nov  9 08:18:46 2008
@@ -19,7 +19,7 @@
 import java.io.File;
 
 import org.apache.poi.POIXMLDocument;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 
 import junit.framework.TestCase;
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java Sun Nov  9 08:18:46 2008
@@ -19,7 +19,7 @@
 import java.io.File;
 
 import org.apache.poi.POIXMLDocument;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 
 import junit.framework.TestCase;
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java?rev=712508&r1=712507&r2=712508&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java Sun Nov  9 08:18:46 2008
@@ -19,7 +19,7 @@
 import java.io.File;
 
 import org.apache.poi.POIXMLDocument;
-import org.apache.poi.xwpf.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
 
 import junit.framework.TestCase;
 



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


Mime
View raw message