poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1130120 [1/4] - in /poi/trunk: src/documentation/content/xdocs/ src/java/org/apache/poi/util/ src/ooxml/java/org/apache/poi/ src/ooxml/java/org/apache/poi/openxml4j/opc/ src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ src/ooxml/java/...
Date Wed, 01 Jun 2011 12:07:18 GMT
Author: yegor
Date: Wed Jun  1 12:07:16 2011
New Revision: 1130120

URL: http://svn.apache.org/viewvc?rev=1130120&view=rev
Log:
bug 51265: Enhanced Handling of Picture Parts in XWPF

Added:
    poi/trunk/src/ooxml/java/org/apache/poi/util/IdentifierManager.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocumentPart.java
      - copied, changed from r1130067, poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/util/
    poi/trunk/src/ooxml/testcases/org/apache/poi/util/TestIdentifierManager.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java
      - copied, changed from r1130067, poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
    poi/trunk/test-data/document/abstract1.jpg   (with props)
    poi/trunk/test-data/document/abstract2.jpg   (with props)
    poi/trunk/test-data/document/abstract3.jpg   (with props)
    poi/trunk/test-data/document/abstract4.jpg   (with props)
    poi/trunk/test-data/document/issue_51265_1.docx   (with props)
    poi/trunk/test-data/document/issue_51265_2.docx   (with props)
    poi/trunk/test-data/document/issue_51265_3.docx   (with props)
    poi/trunk/test-data/document/nature1.gif   (with props)
    poi/trunk/test-data/document/nature1.jpg   (with props)
    poi/trunk/test-data/document/nature1.png   (with props)
    poi/trunk/test-data/document/nature2.jpg   (with props)
    poi/trunk/test-data/document/nature3.jpg   (with props)
    poi/trunk/test-data/document/nature4.jpg   (with props)
Removed:
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestXWPFDocument.java
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/util/IOUtils.java
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
    poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBody.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBodyElement.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFooter.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeader.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPicture.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFPictureData.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSettings.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFStyles.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableRow.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/TestPOIXMLProperties.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/AllXWPFTests.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestAllExtendedProperties.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/TestPackageCorePropertiesGetKeywords.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/XWPFTestDataSamples.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFDecorators.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/model/TestXWPFHeaderFooterPolicy.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFHeader.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFPictureData.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1130120&r1=1130119&r2=1130120&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Wed Jun  1 12:07:16 2011
@@ -34,10 +34,11 @@
 
     <changes>
         <release version="3.8-beta4" date="2011-??-??">
+           <action dev="poi-developers" type="add">51265 - Enhanced Handling of Picture Parts in XWPF</action>
            <action dev="poi-developers" type="add">51292 - Additional HWPF Table Cell Descriptor values</action>
         </release>
-        <release version="3.8-beta3" date="2011-??-??">
-           <action dev="poi-developers" type="fix">51098 - Correct calculate image width/height, if image fits into one cell</action>
+        <release version="3.8-beta3" date="2011-06-06">
+           <action dev="poi-developers" type="fix">51098 - Correctly calculate image width/height, if image fits into one cell</action>
            <action dev="poi-developers" type="fix">47147 - Correct extra paragraphs from XWPF Table Cells</action>
            <action dev="poi-developers" type="add">51188 - Support for getting and setting XPWF zoom settings</action>
            <action dev="poi-developers" type="add">51134 - Support for adding Numbering and Styles to a XWPF document that doesn't already have them</action>

Modified: poi/trunk/src/java/org/apache/poi/util/IOUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/IOUtils.java?rev=1130120&r1=1130119&r2=1130120&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/IOUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/IOUtils.java Wed Jun  1 12:07:16 2011
@@ -23,6 +23,8 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.nio.channels.ReadableByteChannel;
+import java.util.zip.CRC32;
+import java.util.zip.Checksum;
 
 public final class IOUtils {
 	private IOUtils() {
@@ -129,4 +131,10 @@ public final class IOUtils {
 			}
 		}
 	}
+
+    public static long calculateChecksum(byte[] data) {
+        Checksum sum = new CRC32();
+        sum.update(data, 0, data.length);
+        return sum.getValue();
+    }
 }

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=1130120&r1=1130119&r2=1130120&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocument.java Wed Jun  1 12:07:16 2011
@@ -30,10 +30,8 @@ import org.apache.poi.openxml4j.exceptio
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
 import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.openxml4j.opc.PackagePart;
-import org.apache.poi.openxml4j.opc.PackagePartName;
 import org.apache.poi.openxml4j.opc.PackageRelationship;
 import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
-import org.apache.poi.openxml4j.opc.PackagingURIHelper;
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.util.IOUtils;
 
@@ -81,33 +79,6 @@ public abstract class POIXMLDocument ext
     }
 
     /**
-     * Get the PackagePart that is the target of a relationship.
-     *
-     * @param rel The relationship
-     * @return The target part
-     * @throws InvalidFormatException
-     */
-    protected PackagePart getTargetPart(PackageRelationship rel) throws InvalidFormatException {
-        return getTargetPart(getPackage(), rel);
-    }
-    /**
-     * Get the PackagePart that is the target of a relationship.
-     *
-     * @param rel The relationship
-     * @param pkg The package to fetch from
-     * @return The target part
-     * @throws InvalidFormatException
-     */
-    protected static PackagePart getTargetPart(OPCPackage pkg, PackageRelationship rel) throws InvalidFormatException {
-        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
-        PackagePart part = pkg.getPart(relName);
-        if (part == null) {
-            throw new IllegalArgumentException("No part found for relationship " + rel);
-        }
-        return part;
-    }
-
-    /**
      * Retrieves all the PackageParts which are defined as
      *  relationships of the base document with the
      *  specified content type.
@@ -125,8 +96,6 @@ public abstract class POIXMLDocument ext
         return parts;
     }
 
-
-
     /**
      * Checks that the supplied InputStream (which MUST
      *  support mark and reset, or be a PushbackInputStream)
@@ -153,10 +122,10 @@ public abstract class POIXMLDocument ext
 
         // Did it match the ooxml zip signature?
         return (
-            header[0] == POIFSConstants.OOXML_FILE_HEADER[0] &&
-            header[1] == POIFSConstants.OOXML_FILE_HEADER[1] &&
-            header[2] == POIFSConstants.OOXML_FILE_HEADER[2] &&
-            header[3] == POIFSConstants.OOXML_FILE_HEADER[3]
+                header[0] == POIFSConstants.OOXML_FILE_HEADER[0] &&
+                header[1] == POIFSConstants.OOXML_FILE_HEADER[1] &&
+                header[2] == POIFSConstants.OOXML_FILE_HEADER[2] &&
+                header[3] == POIFSConstants.OOXML_FILE_HEADER[3]
         );
     }
 
@@ -181,14 +150,14 @@ public abstract class POIXMLDocument ext
     public abstract List<PackagePart> getAllEmbedds() throws OpenXML4JException;
 
     protected final void load(POIXMLFactory factory) throws IOException {
-    	Map<PackagePart, POIXMLDocumentPart> context = new HashMap<PackagePart, POIXMLDocumentPart>();
+        Map<PackagePart, POIXMLDocumentPart> context = new HashMap<PackagePart, POIXMLDocumentPart>();
         try {
             read(factory, context);
         } catch (OpenXML4JException e){
             throw new POIXMLException(e);
         }
-    	onDocumentRead();
-    	context.clear();
+        onDocumentRead();
+        context.clear();
     }
 
     /**

Modified: poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java?rev=1130120&r1=1130119&r2=1130120&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java Wed Jun  1 12:07:16 2011
@@ -17,15 +17,23 @@
 package org.apache.poi;
 
 import java.io.IOException;
-import java.util.*;
 import java.net.URI;
+import java.util.*;
+import java.util.Map.Entry;
 
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.poi.util.POILogger;
-import org.apache.poi.util.POILogFactory;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
-import org.apache.poi.openxml4j.opc.*;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackagePart;
+import org.apache.poi.openxml4j.opc.PackagePartName;
+import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
+import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
+import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.openxml4j.opc.TargetMode;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+import org.apache.xmlbeans.XmlOptions;
 
 /**
  * Represents an entry of a OOXML package.
@@ -47,19 +55,55 @@ public class POIXMLDocumentPart {
         DEFAULT_XML_OPTIONS.setSaveAggressiveNamespaces();
     }
 
+
     private PackagePart packagePart;
     private PackageRelationship packageRel;
     private POIXMLDocumentPart parent;
-    private List<POIXMLDocumentPart> relations;
+    private Map<String,POIXMLDocumentPart> relations = new LinkedHashMap<String,POIXMLDocumentPart>();
+
+    /**
+     * Get the PackagePart that is the target of a relationship.
+     *
+     * @param rel The relationship
+     * @param pkg The package to fetch from
+     * @return The target part
+     * @throws InvalidFormatException
+     */
+    protected static PackagePart getTargetPart(OPCPackage pkg, PackageRelationship rel)
+    throws InvalidFormatException {
+        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
+        PackagePart part = pkg.getPart(relName);
+        if (part == null) {
+            throw new IllegalArgumentException("No part found for relationship " + rel);
+        }
+        return part;
+    }
+    /**
+     * Counter that provides the amount of incoming relations from other parts
+     * to this part.
+     */
+    private int relationCounter = 0;
+
+    int incrementRelationCounter() {
+        relationCounter++;
+        return relationCounter;
+    }
+
+    int decrementRelationCounter() {
+        relationCounter--;
+        return relationCounter;
+    }
+
+    int getRelationCounter() {
+        return relationCounter;
+    }
 
     /**
      * Construct POIXMLDocumentPart representing a "core document" package part.
      */
     public POIXMLDocumentPart(OPCPackage pkg) {
-        PackageRelationship coreRel = pkg.getRelationshipsByType(
-                PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
+        PackageRelationship coreRel = pkg.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
 
-        this.relations = new LinkedList<POIXMLDocumentPart>();
         this.packagePart = pkg.getPart(coreRel);
         this.packageRel = coreRel;
     }
@@ -70,7 +114,6 @@ public class POIXMLDocumentPart {
      * @see #createRelationship(POIXMLRelation, POIXMLFactory, int, boolean)
      */
     public POIXMLDocumentPart(){
-        this.relations = new LinkedList<POIXMLDocumentPart>();
     }
 
     /**
@@ -82,7 +125,6 @@ public class POIXMLDocumentPart {
      * @see #read(POIXMLFactory, java.util.Map) 
      */
     public POIXMLDocumentPart(PackagePart part, PackageRelationship rel){
-        this.relations = new LinkedList<POIXMLDocumentPart>();
         this.packagePart = part;
         this.packageRel = rel;
     }
@@ -97,7 +139,6 @@ public class POIXMLDocumentPart {
      * @see #read(POIXMLFactory, java.util.Map)
      */
     public POIXMLDocumentPart(POIXMLDocumentPart parent, PackagePart part, PackageRelationship rel){
-        this.relations = new LinkedList<POIXMLDocumentPart>();
         this.packagePart = part;
         this.packageRel = rel;
         this.parent = parent;
@@ -109,16 +150,16 @@ public class POIXMLDocumentPart {
      *  current core document 
      */
     protected final void rebase(OPCPackage pkg) throws InvalidFormatException {
-       PackageRelationshipCollection cores =
-          packagePart.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
-       if(cores.size() != 1) {
-          throw new IllegalStateException(
+        PackageRelationshipCollection cores =
+            packagePart.getRelationshipsByType(PackageRelationshipTypes.CORE_DOCUMENT);
+        if(cores.size() != 1) {
+            throw new IllegalStateException(
                 "Tried to rebase using " + PackageRelationshipTypes.CORE_DOCUMENT +
                 " but found " + cores.size() + " parts of the right type"
-          );
-       }
-       packageRel = cores.getRelationship(0);
-       packagePart = POIXMLDocument.getTargetPart(pkg, packageRel);
+            );
+        }
+        packageRel = cores.getRelationship(0);
+        packagePart = POIXMLDocument.getTargetPart(pkg, packageRel);
     }
 
     /**
@@ -145,7 +186,46 @@ public class POIXMLDocumentPart {
      * @return child relations
      */
     public final List<POIXMLDocumentPart> getRelations(){
-        return relations;
+        return Collections.unmodifiableList(new ArrayList<POIXMLDocumentPart>(relations.values()));
+    }
+
+    /**
+     * Returns the target {@link POIXMLDocumentPart}, where a
+     * {@link PackageRelationship} is set from the {@link PackagePart} of this
+     * {@link POIXMLDocumentPart} to the {@link PackagePart} of the target
+     * {@link POIXMLDocumentPart} with a {@link PackageRelationship#getId()}
+     * matching the given parameter value.
+     * 
+     * @param id
+     *            The relation id to look for
+     * @return the target part of the relation, or null, if none exists
+     */
+    public final POIXMLDocumentPart getRelationById(String id) {
+        return relations.get(id);
+    }
+
+    /**
+     * Returns the {@link PackageRelationship#getId()} of the
+     * {@link PackageRelationship}, that sources from the {@link PackagePart} of
+     * this {@link POIXMLDocumentPart} to the {@link PackagePart} of the given
+     * parameter value.
+     * 
+     * @param part
+     *            The {@link POIXMLDocumentPart} for which the according
+     *            relation-id shall be found.
+     * @return The value of the {@link PackageRelationship#getId()} or null, if
+     *         parts are not related.
+     */
+    public final String getRelationId(POIXMLDocumentPart part) {
+        Iterator<Entry<String, POIXMLDocumentPart>> iter = relations.entrySet().iterator();
+        while (iter.hasNext())
+        {
+            Entry<String, POIXMLDocumentPart> entry = iter.next();
+            if (entry.getValue() == part) {
+                return entry.getKey();
+            }
+        }
+        return null;
     }
 
     /**
@@ -153,17 +233,54 @@ public class POIXMLDocumentPart {
      *
      * @param part the child to add
      */
-    protected final void addRelation(POIXMLDocumentPart part){
-        relations.add(part);
+    protected final void addRelation(String id,POIXMLDocumentPart part){
+        relations.put(id,part);
+        part.incrementRelationCounter();
+    }
+
+    /**
+     * Remove the relation to the specified part in this package and remove the
+     * part, if it is no longer needed.
+     */
+    protected final void removeRelation(POIXMLDocumentPart part){
+        removeRelation(part,true);
     }
 
     /**
-     * Remove the specified part in this package.
+     * Remove the relation to the specified part in this package and remove the
+     * part, if it is no longer needed and flag is set to true.
+     * 
+     * @param part
+     *            The related part, to which the relation shall be removed.
+     * @param removeUnusedParts
+     *            true, if the part shall be removed from the package if not
+     *            needed any longer.
      */
-    public final void removeRelation(POIXMLDocumentPart part){
-        getPackagePart().removeRelationship(part.getPackageRelationship().getId());
-        getPackagePart().getPackage().removePart(part.getPackagePart());
-        relations.remove(part);
+    protected final boolean removeRelation(POIXMLDocumentPart part, boolean removeUnusedParts){
+        String id = getRelationId(part);
+        if (id == null) {
+            // part is not related with this POIXMLDocumentPart
+            return false;
+        }
+        /* decrement usage counter */
+        part.decrementRelationCounter();
+        /* remove packagepart relationship */
+        getPackagePart().removeRelationship(id);
+        /* remove POIXMLDocument from relations */
+        relations.remove(id);
+
+        if (removeUnusedParts) {
+            /* if last relation to target part was removed, delete according target part */
+            if (part.getRelationCounter() == 0) {
+                try {
+                    part.onDocumentRemove();
+                } catch (IOException e) {
+                    throw new POIXMLException(e);
+                }
+                getPackagePart().getPackage().removePart(part.getPackagePart());
+            }
+        }
+        return true;
     }
 
     /**
@@ -209,13 +326,13 @@ public class POIXMLDocumentPart {
      * @param alreadySaved    context set containing already visited nodes
      */
     protected final void onSave(Set<PackagePart> alreadySaved) throws IOException{
-    	commit();
-    	alreadySaved.add(this.getPackagePart());
-    	for(POIXMLDocumentPart p : relations){
+        commit();
+        alreadySaved.add(this.getPackagePart());
+        for(POIXMLDocumentPart p : relations.values()){
             if (!alreadySaved.contains(p.getPackagePart())) {
-    			p.onSave(alreadySaved);
-    		}
-    	}
+                p.onSave(alreadySaved);
+            }
+        }
     }
 
     /**
@@ -246,15 +363,19 @@ public class POIXMLDocumentPart {
         try {
             PackagePartName ppName = PackagingURIHelper.createPartName(descriptor.getFileName(idx));
             PackageRelationship rel = null;
+            PackagePart part = packagePart.getPackage().createPart(ppName, descriptor.getContentType());
             if(!noRelation) {
-               rel = packagePart.addRelationship(ppName, TargetMode.INTERNAL, descriptor.getRelation());
+                /* only add to relations, if according relationship is being created. */
+                rel = packagePart.addRelationship(ppName, TargetMode.INTERNAL, descriptor.getRelation());
             }
-            PackagePart part = packagePart.getPackage().createPart(ppName, descriptor.getContentType());
             POIXMLDocumentPart doc = factory.newDocumentPart(descriptor);
             doc.packageRel = rel;
             doc.packagePart = part;
             doc.parent = this;
-            addRelation(doc);
+            if(!noRelation) {
+                /* only add to relations, if according relationship is being created. */
+                addRelation(rel.getId(),doc);
+            }
             return doc;
         } catch (Exception e){
             throw new POIXMLException(e);
@@ -269,40 +390,40 @@ public class POIXMLDocumentPart {
      * @param context   context map containing already visited noted keyed by targetURI
      */
     protected void read(POIXMLFactory factory, Map<PackagePart, POIXMLDocumentPart> context) throws OpenXML4JException {
-    	PackageRelationshipCollection rels = packagePart.getRelationships();
-    	for (PackageRelationship rel : rels) {
-    	   if(rel.getTargetMode() == TargetMode.INTERNAL){
-    	      URI uri = rel.getTargetURI();
-
-    	      PackagePart p;
-    	      if(uri.getRawFragment() != null) {
-    	         /*
-    	          * For internal references (e.g. '#Sheet1!A1') the package part is null
-    	          */
-    	         p = null;
-    	      } else {
-    	         PackagePartName relName = PackagingURIHelper.createPartName(uri);
-    	         p = packagePart.getPackage().getPart(relName);
-    	         if(p == null) {
-    	            logger.log(POILogger.ERROR, "Skipped invalid entry " + rel.getTargetURI());
-    	            continue;
-    	         }
-    	      }
-
-    	      if (!context.containsKey(p)) {
-    	         POIXMLDocumentPart childPart = factory.createDocumentPart(this, rel, p);
-    	         childPart.parent = this;
-    	         addRelation(childPart);
-    	         if(p != null){
-    	            context.put(p, childPart);
-    	            if(p.hasRelationships()) childPart.read(factory, context);
-    	         }
-    	      }
-    	      else {
-    	         addRelation(context.get(p));
-    	      }
-    	   }
-    	}
+        PackageRelationshipCollection rels = packagePart.getRelationships();
+        for (PackageRelationship rel : rels) {
+            if(rel.getTargetMode() == TargetMode.INTERNAL){
+                URI uri = rel.getTargetURI();
+
+                PackagePart p;
+                if(uri.getRawFragment() != null) {
+                    /*
+                     * For internal references (e.g. '#Sheet1!A1') the package part is null
+                     */
+                    p = null;
+                } else {
+                    PackagePartName relName = PackagingURIHelper.createPartName(uri);
+                    p = packagePart.getPackage().getPart(relName);
+                    if(p == null) {
+                        logger.log(POILogger.ERROR, "Skipped invalid entry " + rel.getTargetURI());
+                        continue;
+                    }
+                }
+
+                if (!context.containsKey(p)) {
+                    POIXMLDocumentPart childPart = factory.createDocumentPart(this, rel, p);
+                    childPart.parent = this;
+                    addRelation(rel.getId(),childPart);
+                    if(p != null){
+                        context.put(p, childPart);
+                        if(p.hasRelationships()) childPart.read(factory, context);
+                    }
+                }
+                else {
+                    addRelation(rel.getId(),context.get(p));
+                }
+            }
+        }
     }
 
     /**
@@ -315,7 +436,25 @@ public class POIXMLDocumentPart {
     /**
      * Fired when a package part is read
      */
-    protected void onDocumentRead() throws IOException{
+    protected void onDocumentRead() throws IOException {
+
+    }
+
+    /**
+     * Get the PackagePart that is the target of a relationship.
+     *
+     * @param rel The relationship
+     * @return The target part
+     * @throws InvalidFormatException
+     */
+    protected PackagePart getTargetPart(PackageRelationship rel) throws InvalidFormatException {
+        return getTargetPart(getPackagePart().getPackage(), rel);
+    }
+
+    /**
+     * Fired when a package part is about to be removed from the package
+     */
+    protected void onDocumentRemove() throws IOException {
 
     }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java?rev=1130120&r1=1130119&r2=1130120&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java Wed Jun  1 12:07:16 2011
@@ -31,7 +31,10 @@ import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
@@ -554,6 +557,25 @@ public abstract class OPCPackage impleme
 	}
 
 	/**
+	 * @return
+	 */
+	public List<PackagePart> getPartsByName(final Pattern namePattern) {
+	    if (namePattern == null) {
+	        throw new IllegalArgumentException("name pattern must not be null");
+	    }
+	    ArrayList<PackagePart> result = new ArrayList<PackagePart>();
+	    for (PackagePart part : partList.values()) {
+	        PackagePartName partName = part.getPartName();
+	        String name = partName.getName();
+	        Matcher matcher = namePattern.matcher(name);
+	        if (matcher.matches()) {
+	            result.add(part);
+	        }
+	    }
+	    return result;
+	}
+
+	/**
 	 * Get the target part from the specified relationship.
 	 *
 	 * @param partRel

Modified: poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java?rev=1130120&r1=1130119&r2=1130120&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java Wed Jun  1 12:07:16 2011
@@ -22,7 +22,7 @@ import java.io.OutputStream;
 import java.text.ParsePosition;
 import java.text.SimpleDateFormat;
 import java.util.Date;
-import java.util.Locale;
+
 import java.util.TimeZone;
 
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;

Added: poi/trunk/src/ooxml/java/org/apache/poi/util/IdentifierManager.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/util/IdentifierManager.java?rev=1130120&view=auto
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/util/IdentifierManager.java (added)
+++ poi/trunk/src/ooxml/java/org/apache/poi/util/IdentifierManager.java Wed Jun  1 12:07:16 2011
@@ -0,0 +1,268 @@
+/* ====================================================================
+   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.util;
+
+import java.util.LinkedList;
+import java.util.ListIterator;
+
+/**
+ * <p>
+ * 24.08.2009<br>
+ * </p>
+ * 
+ * @author Stefan Stern<br>
+ */
+
+public class IdentifierManager {
+
+    public static final long MAX_ID = Long.MAX_VALUE - 1;
+
+    public static final long MIN_ID = 0L;
+
+    /**
+	 * 
+	 */
+    private final long upperbound;
+
+    /**
+	 * 
+	 */
+    private final long lowerbound;
+
+    /**
+	 * List of segments of available identifiers
+	 */
+    private LinkedList<Segment> segments;
+
+    /**
+     * @param lowerbound the lower limit of the id-range to manage. Must be greater than or equal to {@link #MIN_ID}.
+     * @param upperbound the upper limit of the id-range to manage. Must be less then or equal {@link #MAX_ID}.
+     */
+    public IdentifierManager(long lowerbound, long upperbound) {
+        if (lowerbound > upperbound) {
+            String message = "lowerbound must not be greater than upperbound";
+            throw new IllegalArgumentException(message);
+        }
+        else if (lowerbound < MIN_ID) { 
+            String message = "lowerbound must be greater than or equal to " + Long.toString(MIN_ID);
+            throw new IllegalArgumentException(message);
+        }
+        else if (upperbound > MAX_ID) {
+            /*
+             * while MAX_ID is Long.MAX_VALUE, this check is pointless. But if
+             * someone subclasses / tweaks the limits, this check if fine.
+             */
+            String message = "upperbound must be less thean or equal " + Long.toString(MAX_ID);
+            throw new IllegalArgumentException(message);
+        }
+        this.lowerbound = lowerbound;
+        this.upperbound = upperbound;
+        this.segments = new LinkedList<Segment>();
+        segments.add(new Segment(lowerbound, upperbound));
+    }
+
+    public long reserve(long id) {
+        if (id < lowerbound || id > upperbound) {
+            throw new IllegalArgumentException("Value for parameter 'id' was out of bounds");
+        }
+        verifyIdentifiersLeft();
+        
+        if (id == upperbound) {
+            Segment lastSegment = segments.getLast();
+            if (lastSegment.end == upperbound) {
+                lastSegment.end = upperbound - 1;
+                if (lastSegment.start > lastSegment.end) {
+                    segments.removeLast();
+                }
+                return id;
+            }
+            return reserveNew();
+        }
+
+        if (id == lowerbound) {
+            Segment firstSegment = segments.getFirst();
+            if (firstSegment.start == lowerbound) {
+                firstSegment.start = lowerbound + 1;
+                if (firstSegment.end < firstSegment.start) {
+                    segments.removeFirst();
+                }
+                return id;
+            }
+            return reserveNew();
+        }
+
+        ListIterator<Segment> iter = segments.listIterator();
+        while (iter.hasNext()) {
+            Segment segment = iter.next();
+            if (segment.end < id) {
+                continue;
+            }
+            else if (segment.start > id) {
+                break;
+            }
+            else if (segment.start == id) {
+                segment.start = id + 1;
+                if (segment.end < segment.start) {
+                    iter.remove();
+                }
+                return id;
+            }
+            else if (segment.end == id) {
+                segment.end = id - 1;
+                if (segment.start > segment.end) {
+                    iter.remove();
+                }
+                return id;
+            }
+            else {
+                iter.add(new Segment(id + 1, segment.end));
+                segment.end = id - 1;
+                return id;
+            }
+        }
+        return reserveNew();
+    }
+
+    /**
+     * @return a new identifier. 
+     * @throws IllegalStateException if no more identifiers are available, then an Exception is raised.
+     */
+    public long reserveNew() {
+        verifyIdentifiersLeft();
+        Segment segment = segments.getFirst();
+        long result = segment.start;
+        segment.start += 1;
+        if (segment.start > segment.end) {
+            segments.removeFirst();
+        }
+        return result;
+    }
+
+    /**
+     * @param id
+     * the identifier to release. Must be greater than or equal to
+     * {@link #lowerbound} and must be less than or equal to {@link #upperbound}
+     * @return true, if the identifier was reserved and has been successfully
+     * released, false, if the identifier was not reserved.
+     */
+    public boolean release(long id) {
+        if (id < lowerbound || id > upperbound) {
+            throw new IllegalArgumentException("Value for parameter 'id' was out of bounds");
+        }
+
+        if (id == upperbound) {
+            Segment lastSegment = segments.getLast();
+            if (lastSegment.end == upperbound - 1) {
+                lastSegment.end = upperbound;
+                return true;
+            } else if (lastSegment.end == upperbound) {
+                return false;
+            } else {
+                segments.add(new Segment(upperbound, upperbound));
+                return true;
+            }
+        }
+
+        if (id == lowerbound) {
+            Segment firstSegment = segments.getFirst();
+            if (firstSegment.start == lowerbound + 1) {
+                firstSegment.start = lowerbound;
+                return true;
+            } else if (firstSegment.start == lowerbound) {
+                return false;
+            } else {
+                segments.addFirst(new Segment(lowerbound, lowerbound));
+                return true;
+            }
+        }
+
+        long higher = id + 1;
+        long lower = id - 1;
+        ListIterator<Segment> iter = segments.listIterator();
+
+        while (iter.hasNext()) {
+            Segment segment = iter.next();
+            if (segment.end < lower) {
+                continue;
+            }
+            if (segment.start > higher) {
+                iter.previous();
+                iter.add(new Segment(id, id));
+                return true;
+            }
+            if (segment.start == higher) {
+                segment.start = id;
+                return true;
+            }
+            else if (segment.end == lower) {
+                segment.end = id;
+                /* check if releasing this elements glues two segments into one */
+                if (iter.hasNext()) {
+                  Segment next = iter.next();
+                    if (next.start == segment.end + 1) {
+                        segment.end = next.end;
+                        iter.remove();
+                    }
+                }
+                return true;
+            }
+            else {
+                /* id was not reserved, return false */
+                break;
+            }
+        }
+        return false;
+    }
+
+    public long getRemainingIdentifiers() {
+        long result = 0;
+        for (Segment segment : segments) {
+            result = result - segment.start;
+            result = result + segment.end + 1;
+        }
+        return result;
+    }
+
+    /**
+	 * 
+	 */
+    private void verifyIdentifiersLeft() {
+        if (segments.isEmpty()) {
+            throw new IllegalStateException("No identifiers left");
+        }
+    }
+
+    private static class Segment {
+
+        public Segment(long start, long end) {
+            this.start = start;
+            this.end = end;
+        }
+
+        public long start;
+        public long end;
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see java.lang.Object#toString()
+         */
+        public String toString() {
+            return "[" + start + "; " + end + "]";
+        }
+    }
+}

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java?rev=1130120&r1=1130119&r2=1130120&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDrawing.java Wed Jun  1 12:07:16 2011
@@ -213,7 +213,7 @@ public final class XSSFDrawing extends P
         XSSFPictureData data = wb.getAllPictures().get(pictureIndex);
         PackagePartName ppName = data.getPackagePart().getPartName();
         PackageRelationship rel = getPackagePart().addRelationship(ppName, TargetMode.INTERNAL, XSSFRelation.IMAGES.getRelation());
-        addRelation(new XSSFPictureData(data.getPackagePart(), rel));
+        addRelation(rel.getId(),new XSSFPictureData(data.getPackagePart(), rel));
         return rel;
     }
 

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=1130120&r1=1130119&r2=1130120&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 Wed Jun  1 12:07:16 2011
@@ -24,7 +24,6 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.poi.POIXMLDocumentPart;
-import org.apache.poi.openxml4j.opc.PackagePart;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.apache.poi.xwpf.usermodel.XWPFFactory;
 import org.apache.poi.xwpf.usermodel.XWPFFooter;
@@ -68,244 +67,234 @@ import schemasMicrosoftComVml.STTrueFals
  *  the right headers and footers for the document.
  */
 public class XWPFHeaderFooterPolicy {
-	public static final Enum DEFAULT = STHdrFtr.DEFAULT;
-	public static final Enum EVEN = STHdrFtr.EVEN;
-	public static final Enum FIRST = STHdrFtr.FIRST;
-
-	private XWPFDocument doc;
-	
-	private XWPFHeader firstPageHeader;
-	private XWPFFooter firstPageFooter;
-	
-	private XWPFHeader evenPageHeader;
-	private XWPFFooter evenPageFooter;
-	
-	private XWPFHeader defaultHeader;
-	private XWPFFooter defaultFooter;
-	
-        /**
-         * Figures out the policy for the given document,
-         *  and creates any header and footer objects
-         *  as required.
-         */
-        public XWPFHeaderFooterPolicy(XWPFDocument doc) throws IOException, XmlException {
-                this(doc, doc.getDocument().getBody().getSectPr());
-        }
-
-	/**
-	 * Figures out the policy for the given document,
-	 *  and creates any header and footer objects
-	 *  as required.
-	 */
-	public XWPFHeaderFooterPolicy(XWPFDocument doc, CTSectPr sectPr) throws IOException, XmlException {
-		// Grab what headers and footers have been defined
-		// 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
-		this.doc = doc;
-		for(int i=0; i<sectPr.sizeOfHeaderReferenceArray(); i++) {
-			// Get the header
-			CTHdrFtrRef ref = sectPr.getHeaderReferenceArray(i);
-			PackagePart hdrPart = doc.getPartById(ref.getId());
+    public static final Enum DEFAULT = STHdrFtr.DEFAULT;
+    public static final Enum EVEN = STHdrFtr.EVEN;
+    public static final Enum FIRST = STHdrFtr.FIRST;
+
+    private XWPFDocument doc;
+
+    private XWPFHeader firstPageHeader;
+    private XWPFFooter firstPageFooter;
+
+    private XWPFHeader evenPageHeader;
+    private XWPFFooter evenPageFooter;
+
+    private XWPFHeader defaultHeader;
+    private XWPFFooter defaultFooter;
+
+    /**
+     * Figures out the policy for the given document,
+     *  and creates any header and footer objects
+     *  as required.
+     */
+    public XWPFHeaderFooterPolicy(XWPFDocument doc) throws IOException, XmlException {
+        this(doc, doc.getDocument().getBody().getSectPr());
+    }
 
+    /**
+     * Figures out the policy for the given document,
+     *  and creates any header and footer objects
+     *  as required.
+     */
+    public XWPFHeaderFooterPolicy(XWPFDocument doc, CTSectPr sectPr) throws IOException, XmlException {
+        // Grab what headers and footers have been defined
+        // 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
+        this.doc = doc;
+        for(int i=0; i<sectPr.sizeOfHeaderReferenceArray(); i++) {
+            // Get the header
+            CTHdrFtrRef ref = sectPr.getHeaderReferenceArray(i);
+            POIXMLDocumentPart relatedPart = doc.getRelationById(ref.getId());
             XWPFHeader hdr = null;
-
-            for (POIXMLDocumentPart part : doc.getRelations()) {
-                if (part.getPackagePart().getPartName().equals(hdrPart.getPartName())) {
-                    hdr = (XWPFHeader) part;
-                }
+            if (relatedPart != null && relatedPart instanceof XWPFHeader) {
+                hdr = (XWPFHeader) relatedPart;
             }
+            // Assign it
+            Enum type = ref.getType();
+            assignHeader(hdr, type);
+        }
+        for(int i=0; i<sectPr.sizeOfFooterReferenceArray(); i++) {
+            // Get the footer
+            CTHdrFtrRef ref = sectPr.getFooterReferenceArray(i);
+            POIXMLDocumentPart relatedPart = doc.getRelationById(ref.getId());
+            XWPFFooter ftr = null;
+            if (relatedPart != null && relatedPart instanceof XWPFFooter)
+            {
+                ftr = (XWPFFooter) relatedPart;
+            }
+            // Assign it
+            Enum type = ref.getType();
+            assignFooter(ftr, type);
+        }
+    }
 
-			// Assign it
-			Enum type = ref.getType();
-			assignHeader(hdr, type);
-		}
-		for(int i=0; i<sectPr.sizeOfFooterReferenceArray(); i++) {
-			// Get the footer
-			CTHdrFtrRef ref = sectPr.getFooterReferenceArray(i);
-			PackagePart ftrPart = doc.getPartById(ref.getId());
-			XWPFFooter ftr = new XWPFFooter(doc, 
-					FtrDocument.Factory.parse(ftrPart.getInputStream()).getFtr());
-
-			// Assign it
-			Enum type = ref.getType();
-			assignFooter(ftr, type);
-		}
-	}
-
-
-	private void assignFooter(XWPFFooter ftr, Enum type) {
-		if(type == STHdrFtr.FIRST) {
-			firstPageFooter = ftr;
-		} else if(type == STHdrFtr.EVEN) {
-			evenPageFooter = ftr;
-		} else {
-			defaultFooter = ftr;
-		}
-	}
-
-
-	private void assignHeader(XWPFHeader hdr, Enum type) {
-		if(type == STHdrFtr.FIRST) {
-			firstPageHeader = hdr;
-		} else if(type == STHdrFtr.EVEN) {
-			evenPageHeader = hdr;
-		} else {
-			defaultHeader = hdr;
-		}
-	}
+    private void assignFooter(XWPFFooter ftr, Enum type) {
+        if(type == STHdrFtr.FIRST) {
+            firstPageFooter = ftr;
+        } else if(type == STHdrFtr.EVEN) {
+            evenPageFooter = ftr;
+        } else {
+            defaultFooter = ftr;
+        }
+    }
+
+    private void assignHeader(XWPFHeader hdr, Enum type) {
+        if(type == STHdrFtr.FIRST) {
+            firstPageHeader = hdr;
+        } else if(type == STHdrFtr.EVEN) {
+            evenPageHeader = hdr;
+        } else {
+            defaultHeader = hdr;
+        }
+    }
 
     public XWPFHeader createHeader(Enum type) throws IOException {
-    	return createHeader(type, null);
+        return createHeader(type, null);
     }
-    
+
     public XWPFHeader createHeader(Enum type, XWPFParagraph[] pars) throws IOException {
-    	XWPFRelation relation = XWPFRelation.HEADER;
-    	String pStyle = "Header";
-    	int i = getRelationIndex(relation);
-    	HdrDocument hdrDoc = HdrDocument.Factory.newInstance();
-    	XWPFHeader wrapper = (XWPFHeader)doc.createRelationship(relation, XWPFFactory.getInstance(), i);
-
-    	CTHdrFtr hdr = buildHdr(type, pStyle, wrapper, pars);
-    	wrapper.setHeaderFooter(hdr);
-    	
-    	OutputStream outputStream = wrapper.getPackagePart().getOutputStream();
-    	hdrDoc.setHdr(hdr);
-    	
+        XWPFRelation relation = XWPFRelation.HEADER;
+        String pStyle = "Header";
+        int i = getRelationIndex(relation);
+        HdrDocument hdrDoc = HdrDocument.Factory.newInstance();
+        XWPFHeader wrapper = (XWPFHeader)doc.createRelationship(relation, XWPFFactory.getInstance(), i);
+
+        CTHdrFtr hdr = buildHdr(type, pStyle, wrapper, pars);
+        wrapper.setHeaderFooter(hdr);
+
+        OutputStream outputStream = wrapper.getPackagePart().getOutputStream();
+        hdrDoc.setHdr(hdr);
+
         XmlOptions xmlOptions = commit(wrapper);
 
-    	assignHeader(wrapper, type);
-		hdrDoc.save(outputStream, xmlOptions);
-		outputStream.close();
-    	return wrapper;
+        assignHeader(wrapper, type);
+        hdrDoc.save(outputStream, xmlOptions);
+        outputStream.close();
+        return wrapper;
     }
-    
-    
 
     public XWPFFooter createFooter(Enum type) throws IOException {
-    	return createFooter(type, null);
+        return createFooter(type, null);
     }
-    
+
     public XWPFFooter createFooter(Enum type, XWPFParagraph[] pars) throws IOException {
-    	XWPFRelation relation = XWPFRelation.FOOTER;
-    	String pStyle = "Footer";
-    	int i = getRelationIndex(relation);
-    	FtrDocument ftrDoc = FtrDocument.Factory.newInstance();
-    	XWPFFooter wrapper = (XWPFFooter)doc.createRelationship(relation, XWPFFactory.getInstance(), i);
-
-    	CTHdrFtr ftr = buildFtr(type, pStyle, wrapper, pars);
-      wrapper.setHeaderFooter(ftr);
-    	
-    	OutputStream outputStream = wrapper.getPackagePart().getOutputStream();
-    	ftrDoc.setFtr(ftr);
-    	
+        XWPFRelation relation = XWPFRelation.FOOTER;
+        String pStyle = "Footer";
+        int i = getRelationIndex(relation);
+        FtrDocument ftrDoc = FtrDocument.Factory.newInstance();
+        XWPFFooter wrapper = (XWPFFooter)doc.createRelationship(relation, XWPFFactory.getInstance(), i);
+
+        CTHdrFtr ftr = buildFtr(type, pStyle, wrapper, pars);
+        wrapper.setHeaderFooter(ftr);
+
+        OutputStream outputStream = wrapper.getPackagePart().getOutputStream();
+        ftrDoc.setFtr(ftr);
+
         XmlOptions xmlOptions = commit(wrapper);
 
-    	assignFooter(wrapper, type);
-		ftrDoc.save(outputStream, xmlOptions);
-		outputStream.close();
-    	return wrapper;
-    }
-
-
-	private int getRelationIndex(XWPFRelation relation) {
-		List<POIXMLDocumentPart> relations = doc.getRelations();
-    	int i = 1;
-		for (Iterator<POIXMLDocumentPart> it = relations.iterator(); it.hasNext() ; ) {
-    		POIXMLDocumentPart item = it.next();
-    		if (item.getPackageRelationship().getRelationshipType().equals(relation.getRelation())) {
-    			i++;	
-    		}
-    	}
-		return i;
-	}
-
-
-	private CTHdrFtr buildFtr(Enum type, String pStyle, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) {
-		//CTHdrFtr ftr = buildHdrFtr(pStyle, pars);				// MB 24 May 2010
-		CTHdrFtr ftr = buildHdrFtr(pStyle, pars, wrapper);		// MB 24 May 2010
-    	setFooterReference(type, wrapper);
-		return ftr;
-	}
-
-
-	private CTHdrFtr buildHdr(Enum type, String pStyle, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) {
-		//CTHdrFtr hdr = buildHdrFtr(pStyle, pars);				// MB 24 May 2010
-		CTHdrFtr hdr = buildHdrFtr(pStyle, pars, wrapper);		// MB 24 May 2010
-    	setHeaderReference(type, wrapper);
-		return hdr;
-	}
-
-	private CTHdrFtr buildHdrFtr(String pStyle, XWPFParagraph[] paragraphs) {
-		CTHdrFtr ftr = CTHdrFtr.Factory.newInstance();
-		if (paragraphs != null) {
-			for (int i = 0 ; i < paragraphs.length ; i++) {
-				CTP p = ftr.addNewP();
-				//ftr.setPArray(0, paragraphs[i].getCTP());		// MB 23 May 2010
-				ftr.setPArray(i, paragraphs[i].getCTP());   	// MB 23 May 2010
-			}
-		}
-		else {
-			CTP p = ftr.addNewP();
-			byte[] rsidr = doc.getDocument().getBody().getPArray(0).getRsidR();
-			byte[] rsidrdefault = doc.getDocument().getBody().getPArray(0).getRsidRDefault();
-			p.setRsidP(rsidr);
-			p.setRsidRDefault(rsidrdefault);
-			CTPPr pPr = p.addNewPPr();
-			pPr.addNewPStyle().setVal(pStyle);
-		}
-		return ftr;
-	}
-	
-	/**
-	 * MB 24 May 2010. Created this overloaded buildHdrFtr() method because testing demonstrated
-	 * that the XWPFFooter or XWPFHeader object returned by calls to the createHeader(int, XWPFParagraph[])
-	 * and createFooter(int, XWPFParagraph[]) methods or the getXXXXXHeader/Footer methods where
-	 * headers or footers had been added to a document since it had been created/opened, returned
-	 * an object that contained no XWPFParagraph objects even if the header/footer itself did contain
-	 * text. The reason was that this line of code; CTHdrFtr ftr = CTHdrFtr.Factory.newInstance(); 
-	 * created a brand new instance of the CTHDRFtr class which was then populated with data when
-	 * it should have recovered the CTHdrFtr object encapsulated within the XWPFHeaderFooter object
-	 * that had previoulsy been instantiated in the createHeader(int, XWPFParagraph[]) or 
-	 * createFooter(int, XWPFParagraph[]) methods.
-	 */
-	private CTHdrFtr buildHdrFtr(String pStyle, XWPFParagraph[] paragraphs, XWPFHeaderFooter wrapper) {
-		CTHdrFtr ftr = wrapper._getHdrFtr();
-		if (paragraphs != null) {
-			for (int i = 0 ; i < paragraphs.length ; i++) {
-				CTP p = ftr.addNewP();
-				ftr.setPArray(i, paragraphs[i].getCTP());
-			}
-		}
-		else {
-			CTP p = ftr.addNewP();
-			byte[] rsidr = doc.getDocument().getBody().getPArray(0).getRsidR();
-			byte[] rsidrdefault = doc.getDocument().getBody().getPArray(0).getRsidRDefault();
-			p.setRsidP(rsidr);
-			p.setRsidRDefault(rsidrdefault);
-			CTPPr pPr = p.addNewPPr();
-			pPr.addNewPStyle().setVal(pStyle);
-		}
-		return ftr;
-	}
-
-
-	private void setFooterReference(Enum type, XWPFHeaderFooter wrapper) {
-		CTHdrFtrRef ref = doc.getDocument().getBody().getSectPr().addNewFooterReference();
-    	ref.setType(type);
-    	ref.setId(wrapper.getPackageRelationship().getId());
-	}
-
-
-	private void setHeaderReference(Enum type, XWPFHeaderFooter wrapper) {
-		CTHdrFtrRef ref = doc.getDocument().getBody().getSectPr().addNewHeaderReference();
-    	ref.setType(type);
-    	ref.setId(wrapper.getPackageRelationship().getId());
-	}
+        assignFooter(wrapper, type);
+        ftrDoc.save(outputStream, xmlOptions);
+        outputStream.close();
+        return wrapper;
+    }
+
+    private int getRelationIndex(XWPFRelation relation) {
+        List<POIXMLDocumentPart> relations = doc.getRelations();
+        int i = 1;
+        for (Iterator<POIXMLDocumentPart> it = relations.iterator(); it.hasNext() ; ) {
+            POIXMLDocumentPart item = it.next();
+            if (item.getPackageRelationship().getRelationshipType().equals(relation.getRelation())) {
+                i++;	
+            }
+        }
+        return i;
+    }
+
+    private CTHdrFtr buildFtr(Enum type, String pStyle, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) {
+        //CTHdrFtr ftr = buildHdrFtr(pStyle, pars);				// MB 24 May 2010
+        CTHdrFtr ftr = buildHdrFtr(pStyle, pars, wrapper);		// MB 24 May 2010
+        setFooterReference(type, wrapper);
+        return ftr;
+    }
+
+    private CTHdrFtr buildHdr(Enum type, String pStyle, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) {
+        //CTHdrFtr hdr = buildHdrFtr(pStyle, pars);				// MB 24 May 2010
+        CTHdrFtr hdr = buildHdrFtr(pStyle, pars, wrapper);		// MB 24 May 2010
+        setHeaderReference(type, wrapper);
+        return hdr;
+    }
+
+    private CTHdrFtr buildHdrFtr(String pStyle, XWPFParagraph[] paragraphs) {
+        CTHdrFtr ftr = CTHdrFtr.Factory.newInstance();
+        if (paragraphs != null) {
+            for (int i = 0 ; i < paragraphs.length ; i++) {
+                CTP p = ftr.addNewP();
+                //ftr.setPArray(0, paragraphs[i].getCTP());		// MB 23 May 2010
+                ftr.setPArray(i, paragraphs[i].getCTP());   	// MB 23 May 2010
+            }
+        }
+        else {
+            CTP p = ftr.addNewP();
+            byte[] rsidr = doc.getDocument().getBody().getPArray(0).getRsidR();
+            byte[] rsidrdefault = doc.getDocument().getBody().getPArray(0).getRsidRDefault();
+            p.setRsidP(rsidr);
+            p.setRsidRDefault(rsidrdefault);
+            CTPPr pPr = p.addNewPPr();
+            pPr.addNewPStyle().setVal(pStyle);
+        }
+        return ftr;
+    }
+
+    /**
+     * MB 24 May 2010. Created this overloaded buildHdrFtr() method because testing demonstrated
+     * that the XWPFFooter or XWPFHeader object returned by calls to the createHeader(int, XWPFParagraph[])
+     * and createFooter(int, XWPFParagraph[]) methods or the getXXXXXHeader/Footer methods where
+     * headers or footers had been added to a document since it had been created/opened, returned
+     * an object that contained no XWPFParagraph objects even if the header/footer itself did contain
+     * text. The reason was that this line of code; CTHdrFtr ftr = CTHdrFtr.Factory.newInstance(); 
+     * created a brand new instance of the CTHDRFtr class which was then populated with data when
+     * it should have recovered the CTHdrFtr object encapsulated within the XWPFHeaderFooter object
+     * that had previoulsy been instantiated in the createHeader(int, XWPFParagraph[]) or 
+     * createFooter(int, XWPFParagraph[]) methods.
+     */
+    private CTHdrFtr buildHdrFtr(String pStyle, XWPFParagraph[] paragraphs, XWPFHeaderFooter wrapper) {
+        CTHdrFtr ftr = wrapper._getHdrFtr();
+        if (paragraphs != null) {
+            for (int i = 0 ; i < paragraphs.length ; i++) {
+                CTP p = ftr.addNewP();
+                ftr.setPArray(i, paragraphs[i].getCTP());
+            }
+        }
+        else {
+            CTP p = ftr.addNewP();
+            byte[] rsidr = doc.getDocument().getBody().getPArray(0).getRsidR();
+            byte[] rsidrdefault = doc.getDocument().getBody().getPArray(0).getRsidRDefault();
+            p.setRsidP(rsidr);
+            p.setRsidRDefault(rsidrdefault);
+            CTPPr pPr = p.addNewPPr();
+            pPr.addNewPStyle().setVal(pStyle);
+        }
+        return ftr;
+    }
 
 
-	private XmlOptions commit(XWPFHeaderFooter wrapper) {
-		XmlOptions xmlOptions = new XmlOptions(wrapper.DEFAULT_XML_OPTIONS);
+    private void setFooterReference(Enum type, XWPFHeaderFooter wrapper) {
+        CTHdrFtrRef ref = doc.getDocument().getBody().getSectPr().addNewFooterReference();
+        ref.setType(type);
+        ref.setId(wrapper.getPackageRelationship().getId());
+    }
+
+
+    private void setHeaderReference(Enum type, XWPFHeaderFooter wrapper) {
+        CTHdrFtrRef ref = doc.getDocument().getBody().getSectPr().addNewHeaderReference();
+        ref.setType(type);
+        ref.setId(wrapper.getPackageRelationship().getId());
+    }
+
+
+    private XmlOptions commit(XWPFHeaderFooter wrapper) {
+        XmlOptions xmlOptions = new XmlOptions(wrapper.DEFAULT_XML_OPTIONS);
         Map<String, String> map = new HashMap<String, String>();
         map.put("http://schemas.openxmlformats.org/officeDocument/2006/math", "m");
         map.put("urn:schemas-microsoft-com:office:office", "o");
@@ -317,154 +306,152 @@ public class XWPFHeaderFooterPolicy {
         map.put("http://schemas.microsoft.com/office/word/2006/wordml", "wne");
         map.put("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", "wp");
         xmlOptions.setSaveSuggestedPrefixes(map);
-		return xmlOptions;
-	}
-	
-	public XWPFHeader getFirstPageHeader() {
-		return firstPageHeader;
-	}
-	public XWPFFooter getFirstPageFooter() {
-		return firstPageFooter;
-	}
-	/**
-	 * Returns the odd page header. This is
-	 *  also the same as the default one...
-	 */
-	public XWPFHeader getOddPageHeader() {
-		return defaultHeader;
-	}
-	/**
-	 * Returns the odd page footer. This is
-	 *  also the same as the default one...
-	 */
-	public XWPFFooter getOddPageFooter() {
-		return defaultFooter;
-	}
-	public XWPFHeader getEvenPageHeader() {
-		return evenPageHeader;
-	}
-	public XWPFFooter getEvenPageFooter() {
-		return evenPageFooter;
-	}
-	public XWPFHeader getDefaultHeader() {
-		return defaultHeader;
-	}
-	public XWPFFooter getDefaultFooter() {
-		return defaultFooter;
-	}
-
-	/**
-	 * Get the header that applies to the given
-	 *  (1 based) page.
-	 * @param pageNumber The one based page number
-	 */
-	public XWPFHeader getHeader(int pageNumber) {
-		if(pageNumber == 1 && firstPageHeader != null) {
-			return firstPageHeader;
-		}
-		if(pageNumber % 2 == 0 && evenPageHeader != null) {
-			return evenPageHeader;
-		}
-		return defaultHeader;
-	}
-	/**
-	 * Get the footer that applies to the given
-	 *  (1 based) page.
-	 * @param pageNumber The one based page number
-	 */
-	public XWPFFooter getFooter(int pageNumber) {
-		if(pageNumber == 1 && firstPageFooter != null) {
-			return firstPageFooter;
-		}
-		if(pageNumber % 2 == 0 && evenPageFooter != null) {
-			return evenPageFooter;
-		}
-		return defaultFooter;
-	}
-
-
-	public void createWatermark(String text) {
-		XWPFParagraph[] pars = new XWPFParagraph[1];
-		try {
-			pars[0] = getWatermarkParagraph(text, 1);
-			createHeader(DEFAULT, pars);
-			pars[0] = getWatermarkParagraph(text, 2);
-			createHeader(FIRST, pars);
-			pars[0] = getWatermarkParagraph(text, 3);
-			createHeader(EVEN, pars);
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	}
-	
-	
-	/*
-	 * This is the default Watermark paragraph; the only variable is the text message
-	 * TODO: manage all the other variables
-	 */
-	private XWPFParagraph getWatermarkParagraph(String text, int idx) {
-		CTP p = CTP.Factory.newInstance();
-		byte[] rsidr = doc.getDocument().getBody().getPArray(0).getRsidR();
-		byte[] rsidrdefault = doc.getDocument().getBody().getPArray(0).getRsidRDefault();
-		p.setRsidP(rsidr);
-		p.setRsidRDefault(rsidrdefault);
-		CTPPr pPr = p.addNewPPr();
-		pPr.addNewPStyle().setVal("Header");
-		// start watermark paragraph
-		CTR r = p.addNewR();
-		CTRPr rPr = r.addNewRPr();
-		rPr.addNewNoProof();
-		CTPicture pict = r.addNewPict();
-		CTGroup group = CTGroup.Factory.newInstance();
-		CTShapetype shapetype = group.addNewShapetype();
-		shapetype.setId("_x0000_t136");
-		shapetype.setCoordsize("1600,21600");
-		shapetype.setSpt(136);
-		shapetype.setAdj("10800");
-		shapetype.setPath2("m@7,0l@8,0m@5,21600l@6,21600e");
-		CTFormulas formulas = shapetype.addNewFormulas();
-		formulas.addNewF().setEqn("sum #0 0 10800");
-		formulas.addNewF().setEqn("prod #0 2 1");
-		formulas.addNewF().setEqn("sum 21600 0 @1");
-		formulas.addNewF().setEqn("sum 0 0 @2");
-		formulas.addNewF().setEqn("sum 21600 0 @3");
-		formulas.addNewF().setEqn("if @0 @3 0");
-		formulas.addNewF().setEqn("if @0 21600 @1");
-		formulas.addNewF().setEqn("if @0 0 @2");
-		formulas.addNewF().setEqn("if @0 @4 21600");
-		formulas.addNewF().setEqn("mid @5 @6");
-		formulas.addNewF().setEqn("mid @8 @5");
-		formulas.addNewF().setEqn("mid @7 @8");
-		formulas.addNewF().setEqn("mid @6 @7");
-		formulas.addNewF().setEqn("sum @6 0 @5");
-		CTPath path = shapetype.addNewPath();
-		path.setTextpathok(STTrueFalse.T);
-		path.setConnecttype(STConnectType.CUSTOM);
-		path.setConnectlocs("@9,0;@10,10800;@11,21600;@12,10800");
-		path.setConnectangles("270,180,90,0");
-		CTTextPath shapeTypeTextPath = shapetype.addNewTextpath();
-		shapeTypeTextPath.setOn(STTrueFalse.T);
-		shapeTypeTextPath.setFitshape(STTrueFalse.T);
-		CTHandles handles = shapetype.addNewHandles();
-		CTH h = handles.addNewH();
-		h.setPosition("#0,bottomRight");
-		h.setXrange("6629,14971");
-		CTLock lock = shapetype.addNewLock();
-		lock.setExt(STExt.EDIT);
-		CTShape shape = group.addNewShape();
-		shape.setId("PowerPlusWaterMarkObject" + idx);
-		shape.setSpid("_x0000_s102" + (4+idx));
-		shape.setType("#_x0000_t136");
-		shape.setStyle("position:absolute;margin-left:0;margin-top:0;width:415pt;height:207.5pt;z-index:-251654144;mso-wrap-edited:f;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin");
-		shape.setWrapcoords("616 5068 390 16297 39 16921 -39 17155 7265 17545 7186 17467 -39 17467 18904 17467 10507 17467 8710 17545 18904 17077 18787 16843 18358 16297 18279 12554 19178 12476 20701 11774 20779 11228 21131 10059 21248 8811 21248 7563 20975 6316 20935 5380 19490 5146 14022 5068 2616 5068");
-		shape.setFillcolor("black");
-		shape.setStroked(STTrueFalse.FALSE);
-		CTTextPath shapeTextPath = shape.addNewTextpath();
-		shapeTextPath.setStyle("font-family:&quot;Cambria&quot;;font-size:1pt");
-		shapeTextPath.setString(text);
-		pict.set(group);
-		// end watermark paragraph
-		return new XWPFParagraph(p, doc);
-	}
+        return xmlOptions;
+    }
+
+    public XWPFHeader getFirstPageHeader() {
+        return firstPageHeader;
+    }
+    public XWPFFooter getFirstPageFooter() {
+        return firstPageFooter;
+    }
+    /**
+     * Returns the odd page header. This is
+     *  also the same as the default one...
+     */
+    public XWPFHeader getOddPageHeader() {
+        return defaultHeader;
+    }
+    /**
+     * Returns the odd page footer. This is
+     *  also the same as the default one...
+     */
+    public XWPFFooter getOddPageFooter() {
+        return defaultFooter;
+    }
+    public XWPFHeader getEvenPageHeader() {
+        return evenPageHeader;
+    }
+    public XWPFFooter getEvenPageFooter() {
+        return evenPageFooter;
+    }
+    public XWPFHeader getDefaultHeader() {
+        return defaultHeader;
+    }
+    public XWPFFooter getDefaultFooter() {
+        return defaultFooter;
+    }
+
+    /**
+     * Get the header that applies to the given
+     *  (1 based) page.
+     * @param pageNumber The one based page number
+     */
+    public XWPFHeader getHeader(int pageNumber) {
+        if(pageNumber == 1 && firstPageHeader != null) {
+            return firstPageHeader;
+        }
+        if(pageNumber % 2 == 0 && evenPageHeader != null) {
+            return evenPageHeader;
+        }
+        return defaultHeader;
+    }
+    /**
+     * Get the footer that applies to the given
+     *  (1 based) page.
+     * @param pageNumber The one based page number
+     */
+    public XWPFFooter getFooter(int pageNumber) {
+        if(pageNumber == 1 && firstPageFooter != null) {
+            return firstPageFooter;
+        }
+        if(pageNumber % 2 == 0 && evenPageFooter != null) {
+            return evenPageFooter;
+        }
+        return defaultFooter;
+    }
+
+    public void createWatermark(String text) {
+        XWPFParagraph[] pars = new XWPFParagraph[1];
+        try {
+            pars[0] = getWatermarkParagraph(text, 1);
+            createHeader(DEFAULT, pars);
+            pars[0] = getWatermarkParagraph(text, 2);
+            createHeader(FIRST, pars);
+            pars[0] = getWatermarkParagraph(text, 3);
+            createHeader(EVEN, pars);
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    /*
+     * This is the default Watermark paragraph; the only variable is the text message
+     * TODO: manage all the other variables
+     */
+    private XWPFParagraph getWatermarkParagraph(String text, int idx) {
+        CTP p = CTP.Factory.newInstance();
+        byte[] rsidr = doc.getDocument().getBody().getPArray(0).getRsidR();
+        byte[] rsidrdefault = doc.getDocument().getBody().getPArray(0).getRsidRDefault();
+        p.setRsidP(rsidr);
+        p.setRsidRDefault(rsidrdefault);
+        CTPPr pPr = p.addNewPPr();
+        pPr.addNewPStyle().setVal("Header");
+        // start watermark paragraph
+        CTR r = p.addNewR();
+        CTRPr rPr = r.addNewRPr();
+        rPr.addNewNoProof();
+        CTPicture pict = r.addNewPict();
+        CTGroup group = CTGroup.Factory.newInstance();
+        CTShapetype shapetype = group.addNewShapetype();
+        shapetype.setId("_x0000_t136");
+        shapetype.setCoordsize("1600,21600");
+        shapetype.setSpt(136);
+        shapetype.setAdj("10800");
+        shapetype.setPath2("m@7,0l@8,0m@5,21600l@6,21600e");
+        CTFormulas formulas = shapetype.addNewFormulas();
+        formulas.addNewF().setEqn("sum #0 0 10800");
+        formulas.addNewF().setEqn("prod #0 2 1");
+        formulas.addNewF().setEqn("sum 21600 0 @1");
+        formulas.addNewF().setEqn("sum 0 0 @2");
+        formulas.addNewF().setEqn("sum 21600 0 @3");
+        formulas.addNewF().setEqn("if @0 @3 0");
+        formulas.addNewF().setEqn("if @0 21600 @1");
+        formulas.addNewF().setEqn("if @0 0 @2");
+        formulas.addNewF().setEqn("if @0 @4 21600");
+        formulas.addNewF().setEqn("mid @5 @6");
+        formulas.addNewF().setEqn("mid @8 @5");
+        formulas.addNewF().setEqn("mid @7 @8");
+        formulas.addNewF().setEqn("mid @6 @7");
+        formulas.addNewF().setEqn("sum @6 0 @5");
+        CTPath path = shapetype.addNewPath();
+        path.setTextpathok(STTrueFalse.T);
+        path.setConnecttype(STConnectType.CUSTOM);
+        path.setConnectlocs("@9,0;@10,10800;@11,21600;@12,10800");
+        path.setConnectangles("270,180,90,0");
+        CTTextPath shapeTypeTextPath = shapetype.addNewTextpath();
+        shapeTypeTextPath.setOn(STTrueFalse.T);
+        shapeTypeTextPath.setFitshape(STTrueFalse.T);
+        CTHandles handles = shapetype.addNewHandles();
+        CTH h = handles.addNewH();
+        h.setPosition("#0,bottomRight");
+        h.setXrange("6629,14971");
+        CTLock lock = shapetype.addNewLock();
+        lock.setExt(STExt.EDIT);
+        CTShape shape = group.addNewShape();
+        shape.setId("PowerPlusWaterMarkObject" + idx);
+        shape.setSpid("_x0000_s102" + (4+idx));
+        shape.setType("#_x0000_t136");
+        shape.setStyle("position:absolute;margin-left:0;margin-top:0;width:415pt;height:207.5pt;z-index:-251654144;mso-wrap-edited:f;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin");
+        shape.setWrapcoords("616 5068 390 16297 39 16921 -39 17155 7265 17545 7186 17467 -39 17467 18904 17467 10507 17467 8710 17545 18904 17077 18787 16843 18358 16297 18279 12554 19178 12476 20701 11774 20779 11228 21131 10059 21248 8811 21248 7563 20975 6316 20935 5380 19490 5146 14022 5068 2616 5068");
+        shape.setFillcolor("black");
+        shape.setStroked(STTrueFalse.FALSE);
+        CTTextPath shapeTextPath = shape.addNewTextpath();
+        shapeTextPath.setStyle("font-family:&quot;Cambria&quot;;font-size:1pt");
+        shapeTextPath.setString(text);
+        pict.set(group);
+        // end watermark paragraph
+        return new XWPFParagraph(p, doc);
+    }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBody.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBody.java?rev=1130120&r1=1130119&r2=1130120&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBody.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBody.java Wed Jun  1 12:07:16 2011
@@ -19,6 +19,7 @@ package org.apache.poi.xwpf.usermodel;
 
 import java.util.List;
 
+import org.apache.poi.POIXMLDocumentPart;
 import org.apache.xmlbeans.XmlCursor;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
@@ -42,7 +43,7 @@ public interface IBody {
 	 * belongs.
 	 * @return the Part, to which the body belongs
 	 */
-	IBody getPart();
+	POIXMLDocumentPart getPart();
 	
 	/**
 	 * get the PartType of the body, for example

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBodyElement.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBodyElement.java?rev=1130120&r1=1130119&r2=1130120&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBodyElement.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/IBodyElement.java Wed Jun  1 12:07:16 2011
@@ -17,6 +17,7 @@
 
 package org.apache.poi.xwpf.usermodel;
 
+import org.apache.poi.POIXMLDocumentPart;
 
 /**
  * 9 Jan 2010
@@ -24,7 +25,8 @@ package org.apache.poi.xwpf.usermodel;
  *
  */
 public interface IBodyElement{
-	IBody getPart();
+	IBody getBody();
+    POIXMLDocumentPart getPart();
 	BodyType getPartType();
 	BodyElementType getElementType();
 }



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


Mime
View raw message