org.apache.poi
Class POIXMLDocumentPart

java.lang.Object
  extended by org.apache.poi.POIXMLDocumentPart
Direct Known Subclasses:
CalculationChain, CommentsTable, MapInfo, POIXMLDocument, SharedStringsTable, SingleXmlCells, StylesTable, Table, XSSFDrawing, XSSFPictureData, XSSFSheet, XSSFVMLDrawing, XWPFHeaderFooter, XWPFSettings

public class POIXMLDocumentPart
extends java.lang.Object

Represents an entry of a OOXML package.

Each POIXMLDocumentPart keeps a reference to the underlying a PackagePart.

Author:
Yegor Kozlov

Field Summary
static XmlOptions DEFAULT_XML_OPTIONS
           
 
Constructor Summary
POIXMLDocumentPart()
          Creates new POIXMLDocumentPart - called by client code to create new parts from scratch.
POIXMLDocumentPart(OPCPackage pkg)
          Construct POIXMLDocumentPart representing a "core document" package part.
POIXMLDocumentPart(PackagePart part, PackageRelationship rel)
          Creates an POIXMLDocumentPart representing the given package part and relationship.
 
Method Summary
protected  void addRelation(POIXMLDocumentPart part)
          Add a new child POIXMLDocumentPart
protected  void commit()
          Save the content in the underlying package part.
 POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory)
          Create a new child POIXMLDocumentPart
 POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx)
           
protected  POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation)
          Create a new child POIXMLDocumentPart
 PackagePart getPackagePart()
          Provides access to the underlying PackagePart
 PackageRelationship getPackageRelationship()
          Provides access to the PackageRelationship that identifies this POIXMLDocumentPart
 POIXMLDocumentPart getParent()
          Returns the parent POIXMLDocumentPart.
 java.util.List<POIXMLDocumentPart> getRelations()
          Returns the list of child relations for this POIXMLDocumentPart
protected  void onDocumentCreate()
          Fired when a new package part is created
protected  void onDocumentRead()
          Fired when a package part is read
protected  void onSave(java.util.Set<PackagePart> alreadySaved)
          Save changes in the underlying OOXML package.
protected  void read(POIXMLFactory factory, java.util.Map<PackagePart,POIXMLDocumentPart> context)
          Iterate through the underlying PackagePart and create child POIXMLFactory instances using the specified factory
 void removeRelation(POIXMLDocumentPart part)
          Remove the specified part in this package.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_XML_OPTIONS

public static final XmlOptions DEFAULT_XML_OPTIONS
Constructor Detail

POIXMLDocumentPart

public POIXMLDocumentPart(OPCPackage pkg)
Construct POIXMLDocumentPart representing a "core document" package part.


POIXMLDocumentPart

public POIXMLDocumentPart()
Creates new POIXMLDocumentPart - called by client code to create new parts from scratch.

See Also:
createRelationship(POIXMLRelation, POIXMLFactory, int, boolean)

POIXMLDocumentPart

public POIXMLDocumentPart(PackagePart part,
                          PackageRelationship rel)
Creates an POIXMLDocumentPart representing the given package part and relationship. Called by read(POIXMLFactory, java.util.Map) when reading in an exisiting file.

Parameters:
part - - The package part that holds xml data represenring this sheet.
rel - - the relationship of the given package part
See Also:
read(POIXMLFactory, java.util.Map)
Method Detail

getPackagePart

public final PackagePart getPackagePart()
Provides access to the underlying PackagePart

Returns:
the underlying PackagePart

getPackageRelationship

public final PackageRelationship getPackageRelationship()
Provides access to the PackageRelationship that identifies this POIXMLDocumentPart

Returns:
the PackageRelationship that identifies this POIXMLDocumentPart

getRelations

public final java.util.List<POIXMLDocumentPart> getRelations()
Returns the list of child relations for this POIXMLDocumentPart

Returns:
child relations

addRelation

protected final void addRelation(POIXMLDocumentPart part)
Add a new child POIXMLDocumentPart

Parameters:
part - the child to add

removeRelation

public final void removeRelation(POIXMLDocumentPart part)
Remove the specified part in this package.


getParent

public final POIXMLDocumentPart getParent()
Returns the parent POIXMLDocumentPart. All parts except root have not-null parent.

Returns:
the parent POIXMLDocumentPart or null for the root element.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

commit

protected void commit()
               throws java.io.IOException
Save the content in the underlying package part. Default implementation is empty meaning that the package part is left unmodified. Sub-classes should override and add logic to marshal the "model" into Ooxml4J. For example, the code saving a generic XML entry may look as follows:

 protected void commit() throws IOException {
   PackagePart part = getPackagePart();
   OutputStream out = part.getOutputStream();
   XmlObject bean = getXmlBean(); //the "model" which holds changes in memory
   bean.save(out, DEFAULT_XML_OPTIONS);
   out.close();
 }
  

Throws:
java.io.IOException

onSave

protected final void onSave(java.util.Set<PackagePart> alreadySaved)
                     throws java.io.IOException
Save changes in the underlying OOXML package. Recursively fires commit() for each package part

Parameters:
alreadySaved - context set containing already visited nodes
Throws:
java.io.IOException

createRelationship

public final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor,
                                                   POIXMLFactory factory)
Create a new child POIXMLDocumentPart

Parameters:
descriptor - the part descriptor
factory - the factory that will create an instance of the requested relation
Returns:
the created child POIXMLDocumentPart

createRelationship

public final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor,
                                                   POIXMLFactory factory,
                                                   int idx)

createRelationship

protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor,
                                                      POIXMLFactory factory,
                                                      int idx,
                                                      boolean noRelation)
Create a new child POIXMLDocumentPart

Parameters:
descriptor - the part descriptor
factory - the factory that will create an instance of the requested relation
idx - part number
noRelation - if true, then no relationship is added.
Returns:
the created child POIXMLDocumentPart

read

protected void read(POIXMLFactory factory,
                    java.util.Map<PackagePart,POIXMLDocumentPart> context)
             throws OpenXML4JException
Iterate through the underlying PackagePart and create child POIXMLFactory instances using the specified factory

Parameters:
factory - the factory object that creates POIXMLFactory instances
context - context map containing already visited noted keyed by targetURI
Throws:
OpenXML4JException

onDocumentCreate

protected void onDocumentCreate()
                         throws java.io.IOException
Fired when a new package part is created

Throws:
java.io.IOException

onDocumentRead

protected void onDocumentRead()
                       throws java.io.IOException
Fired when a package part is read

Throws:
java.io.IOException


Copyright 2012 The Apache Software Foundation or its licensors, as applicable.