org.apache.poi.xwpf.usermodel
Class XWPFDocument

java.lang.Object
  extended by org.apache.poi.POIXMLDocumentPart
      extended by org.apache.poi.POIXMLDocument
          extended by org.apache.poi.xwpf.usermodel.XWPFDocument

public class XWPFDocument
extends POIXMLDocument

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


Field Summary
protected  java.util.List<XWPFComment> comments
           
protected  java.util.Map<java.lang.Integer,XWPFFootnote> endnotes
           
protected  java.util.Map<java.lang.Integer,XWPFFootnote> footnotes
           
protected  java.util.List<XWPFHyperlink> hyperlinks
           
protected  java.util.List<XWPFParagraph> paragraphs
           
protected  java.util.List<XWPFTable> tables
           
 
Fields inherited from class org.apache.poi.POIXMLDocument
CORE_PROPERTIES_REL_TYPE, CUSTOM_PROPERTIES_REL_TYPE, DOCUMENT_CREATOR, EXTENDED_PROPERTIES_REL_TYPE, OLE_OBJECT_REL_TYPE, PACK_OBJECT_REL_TYPE
 
Fields inherited from class org.apache.poi.POIXMLDocumentPart
DEFAULT_XML_OPTIONS
 
Constructor Summary
XWPFDocument()
           
XWPFDocument(java.io.InputStream is)
           
XWPFDocument(OPCPackage pkg)
           
 
Method Summary
protected  void commit()
          Save the content in the underlying package part.
 XWPFParagraph createParagraph()
          Appends a new paragraph to this document
 XWPFTable createTable()
          Create an empty table with one row and one column as default.
 XWPFTable createTable(int rows, int cols)
          Create an empty table with a number of rows and cols specified
 void createTOC()
           
 void enforceCommentsProtection()
          Enforce the Comments protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to comments (w:edit="comments")

sample snippet from settings.xml
 void enforceFillingFormsProtection()
          Enforce the Filling Forms protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to forms (w:edit="forms")

sample snippet from settings.xml
 void enforceReadonlyProtection()
          Enforces the readOnly protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to readOnly (w:edit="readOnly")

sample snippet from settings.xml
 void enforceTrackedChangesProtection()
          Enforce the Tracked Changes protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to trackedChanges (w:edit="trackedChanges")

sample snippet from settings.xml
 java.util.List<PackagePart> getAllEmbedds()
          Get the document's embedded files.
 XWPFComment getCommentByID(java.lang.String id)
           
 XWPFComment[] getComments()
           
 CTDocument1 getDocument()
          Returns the low level document base object
 XWPFFootnote getEndnoteByID(int id)
           
 XWPFFootnote getFootnoteByID(int id)
           
 java.util.Collection<XWPFFootnote> getFootnotes()
           
 XWPFHeaderFooterPolicy getHeaderFooterPolicy()
          Returns the policy on headers and footers, which also provides a way to get at them.
 XWPFHyperlink getHyperlinkByID(java.lang.String id)
           
 XWPFHyperlink[] getHyperlinks()
           
 XWPFParagraph[] getParagraphs()
           
 java.util.Iterator<XWPFParagraph> getParagraphsIterator()
           
 PackagePart getPartById(java.lang.String id)
          Get the document part that's defined as the given relationship of the core document.
 CTStyles getStyle()
          Returns the styles object used
 java.util.Iterator<XWPFTable> getTablesIterator()
           
 boolean isEnforcedCommentsProtection()
          Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is comments (w:edit="comments")

sample snippet from settings.xml
 boolean isEnforcedFillingFormsProtection()
          Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is forms (w:edit="forms")

sample snippet from settings.xml
 boolean isEnforcedReadonlyProtection()
          Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is readOnly (w:edit="readOnly")

sample snippet from settings.xml
 boolean isEnforcedTrackedChangesProtection()
          Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is trackedChanges (w:edit="trackedChanges")

sample snippet from settings.xml
protected static OPCPackage newPackage()
          Create a new SpreadsheetML package and setup the default minimal content
protected  void onDocumentCreate()
          Create a new CTWorkbook with all values set to default
protected  void onDocumentRead()
          Fired when a package part is read
 void removeProtectionEnforcement()
          Remove protection enforcement.
In the documentProtection tag inside settings.xml file
it sets the value of enforcement to "0" (w:enforcement="0")
 
Methods inherited from class org.apache.poi.POIXMLDocument
ensureWriteAccess, getCorePart, getPackage, getProperties, getRelatedByType, getTargetPart, getTargetPart, hasOOXMLHeader, load, openPackage, write
 
Methods inherited from class org.apache.poi.POIXMLDocumentPart
addRelation, createRelationship, createRelationship, createRelationship, getPackagePart, getPackageRelationship, getParent, getRelations, onSave, read, removeRelation, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

comments

protected java.util.List<XWPFComment> comments

hyperlinks

protected java.util.List<XWPFHyperlink> hyperlinks

paragraphs

protected java.util.List<XWPFParagraph> paragraphs

tables

protected java.util.List<XWPFTable> tables

footnotes

protected java.util.Map<java.lang.Integer,XWPFFootnote> footnotes

endnotes

protected java.util.Map<java.lang.Integer,XWPFFootnote> endnotes
Constructor Detail

XWPFDocument

public XWPFDocument(OPCPackage pkg)
             throws java.io.IOException
Throws:
java.io.IOException

XWPFDocument

public XWPFDocument(java.io.InputStream is)
             throws java.io.IOException
Throws:
java.io.IOException

XWPFDocument

public XWPFDocument()
Method Detail

onDocumentRead

protected void onDocumentRead()
                       throws java.io.IOException
Description copied from class: POIXMLDocumentPart
Fired when a package part is read

Overrides:
onDocumentRead in class POIXMLDocumentPart
Throws:
java.io.IOException

newPackage

protected static OPCPackage newPackage()
Create a new SpreadsheetML package and setup the default minimal content


onDocumentCreate

protected void onDocumentCreate()
Create a new CTWorkbook with all values set to default

Overrides:
onDocumentCreate in class POIXMLDocumentPart

getDocument

@Internal
public CTDocument1 getDocument()
Returns the low level document base object


getParagraphsIterator

public java.util.Iterator<XWPFParagraph> getParagraphsIterator()

getParagraphs

public XWPFParagraph[] getParagraphs()

getTablesIterator

public java.util.Iterator<XWPFTable> getTablesIterator()

getHyperlinkByID

public XWPFHyperlink getHyperlinkByID(java.lang.String id)

getFootnoteByID

public XWPFFootnote getFootnoteByID(int id)

getEndnoteByID

public XWPFFootnote getEndnoteByID(int id)

getFootnotes

public java.util.Collection<XWPFFootnote> getFootnotes()

getHyperlinks

public XWPFHyperlink[] getHyperlinks()

getCommentByID

public XWPFComment getCommentByID(java.lang.String id)

getComments

public XWPFComment[] getComments()

getPartById

public PackagePart getPartById(java.lang.String id)
Get the document part that's defined as the given relationship of the core document.


getHeaderFooterPolicy

public XWPFHeaderFooterPolicy getHeaderFooterPolicy()
Returns the policy on headers and footers, which also provides a way to get at them.


getStyle

@Internal
public CTStyles getStyle()
                  throws XmlException,
                         java.io.IOException
Returns the styles object used

Throws:
XmlException
java.io.IOException

getAllEmbedds

public java.util.List<PackagePart> getAllEmbedds()
                                          throws OpenXML4JException
Get the document's embedded files.

Specified by:
getAllEmbedds in class POIXMLDocument
Throws:
OpenXML4JException

commit

protected void commit()
               throws java.io.IOException
Description copied from class: POIXMLDocumentPart
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();
 }
  

Overrides:
commit in class POIXMLDocumentPart
Throws:
java.io.IOException

createParagraph

public XWPFParagraph createParagraph()
Appends a new paragraph to this document

Returns:
a new paragraph

createTable

public XWPFTable createTable()
Create an empty table with one row and one column as default.

Returns:
a new table

createTable

public XWPFTable createTable(int rows,
                             int cols)
Create an empty table with a number of rows and cols specified

Parameters:
rows -
cols -
Returns:
table

createTOC

public void createTOC()

isEnforcedReadonlyProtection

public boolean isEnforcedReadonlyProtection()
Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is readOnly (w:edit="readOnly")

sample snippet from settings.xml
     <w:settings  ... >
         <w:documentProtection w:edit="readOnly" w:enforcement="1"/>
 

Returns:
true if documentProtection is enforced with option readOnly

isEnforcedFillingFormsProtection

public boolean isEnforcedFillingFormsProtection()
Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is forms (w:edit="forms")

sample snippet from settings.xml
     <w:settings  ... >
         <w:documentProtection w:edit="forms" w:enforcement="1"/>
 

Returns:
true if documentProtection is enforced with option forms

isEnforcedCommentsProtection

public boolean isEnforcedCommentsProtection()
Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is comments (w:edit="comments")

sample snippet from settings.xml
     <w:settings  ... >
         <w:documentProtection w:edit="comments" w:enforcement="1"/>
 

Returns:
true if documentProtection is enforced with option comments

isEnforcedTrackedChangesProtection

public boolean isEnforcedTrackedChangesProtection()
Verifies that the documentProtection tag in settings.xml file
specifies that the protection is enforced (w:enforcement="1")
and that the kind of protection is trackedChanges (w:edit="trackedChanges")

sample snippet from settings.xml
     <w:settings  ... >
         <w:documentProtection w:edit="trackedChanges" w:enforcement="1"/>
 

Returns:
true if documentProtection is enforced with option trackedChanges

enforceReadonlyProtection

public void enforceReadonlyProtection()
Enforces the readOnly protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to readOnly (w:edit="readOnly")

sample snippet from settings.xml
     <w:settings  ... >
         <w:documentProtection w:edit="readOnly" w:enforcement="1"/>
 


enforceFillingFormsProtection

public void enforceFillingFormsProtection()
Enforce the Filling Forms protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to forms (w:edit="forms")

sample snippet from settings.xml
     <w:settings  ... >
         <w:documentProtection w:edit="forms" w:enforcement="1"/>
 


enforceCommentsProtection

public void enforceCommentsProtection()
Enforce the Comments protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to comments (w:edit="comments")

sample snippet from settings.xml
     <w:settings  ... >
         <w:documentProtection w:edit="comments" w:enforcement="1"/>
 


enforceTrackedChangesProtection

public void enforceTrackedChangesProtection()
Enforce the Tracked Changes protection.
In the documentProtection tag inside settings.xml file,
it sets the value of enforcement to "1" (w:enforcement="1")
and the value of edit to trackedChanges (w:edit="trackedChanges")

sample snippet from settings.xml
     <w:settings  ... >
         <w:documentProtection w:edit="trackedChanges" w:enforcement="1"/>
 


removeProtectionEnforcement

public void removeProtectionEnforcement()
Remove protection enforcement.
In the documentProtection tag inside settings.xml file
it sets the value of enforcement to "0" (w:enforcement="0")



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