Class OpcPackage
java.lang.Object
org.docx4j.openpackaging.Base
org.docx4j.openpackaging.packages.OpcPackage
- All Implemented Interfaces:
PackageIdentifier
- Direct Known Subclasses:
DefaultPackage,GloxPackage,PresentationMLPackage,SpreadsheetMLPackage,WordprocessingMLPackage
Represent a Package as defined in the Open Packaging Specification.
- Author:
- Jason Harrop
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ContentTypeManagerprotected HashMap<String,CustomXmlPart> protected DocPropsCorePartprotected DocPropsCustomPartprotected DocPropsExtendedPartprotected HashMap<ExternalTarget,Part> This HashMap is intended to prevent loops during the loading of this package.protected PartsPackage parts collection.Fields inherited from class org.docx4j.openpackaging.Base
contentType, partName, relationships -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidclone()keyed by item id (in lower case)Get the DocPropsCorePart, if any.Get DocPropsCustomPart, if any.Get the DocPropsExtendedPart, if any.getParts()Retrieve the Parts object.getTitle()booleanisNew()Was this pkg created from scratch in docx4j, or loaded?static OpcPackageConvenience method to create a WordprocessingMLPackage or PresentationMLPackage from an existing File (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageConvenience method to create a WordprocessingMLPackage or PresentationMLPackage from an existing File (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageconvenience method to load from a file, where you know the Filetype (if it is Filetype.ZippedPackage, ZipFile will be used instead of ZipArchiveInputStream)static OpcPackageconvenience method to load from a file, where you know the Filetype (if it is Filetype.ZippedPackage, ZipFile will be used instead of ZipArchiveInputStream)static OpcPackageload(InputStream inputStream) Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(InputStream is, boolean docxFormat) Deprecated.static OpcPackageload(InputStream inputStream, String password) Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(InputStream is, Filetype type) convenience method to load a word2007 document from an existing inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(InputStream is, Filetype type, String password) convenience method to load a word2007 document from an existing inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(PackageIdentifier pkgIdentifier, File docxFile) Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an existing File (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(PackageIdentifier pkgIdentifier, File docxFile, String password) Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an existing File (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(PackageIdentifier pkgIdentifier, InputStream inputStream) Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).name()voidreset()Reinit fields so this pkg object can be re-used.voidConvenience method to save a WordprocessingMLPackage or PresentationMLPackage to a File.voidSave this pkg to a File.voidSave this pkg to a file.voidsave(OutputStream outStream) Save this pkg to an OutputStream in the usual zipped up format (Docx4J.FLAG_SAVE_ZIP_FILE)voidsave(OutputStream outStream, int flags) Save this pkg to an OutputStream.voidsave(OutputStream outStream, int flags, String password) Save this pkg to an OutputStream.voidsetContentTypeManager(ContentTypeManager contentTypeManager) voidAllocate a name to this package, for the purposes of Docx4jEvent, and logging.voidsetNew(boolean isNew) booleansetPartShortcut(Part part, String relationshipType) Tell the source Part about this target Part, so the source can use this part via a convenience method.voidsetSourcePartStore(PartStore partStore) voidsetTargetPartStore(PartStore partStore) voidMethods inherited from class org.docx4j.openpackaging.Base
addTargetPart, addTargetPart, addTargetPart, addTargetPart, getContentType, getPartName, getRelationshipsPart, getRelationshipsPart, getUserData, setContentType, setPartName, setRelationships, setUserData
-
Field Details
-
handled
This HashMap is intended to prevent loops during the loading of this package. TODO This doesn't really tell us anything that the contents of Parts couldn't also tell us (except that that doesn't contain the rels parts), so consider removing. At least replace it with a method, so this implementation detail is hidden! -
parts
Package parts collection. This is a collection of _all_ parts in the package (_except_ relationship parts), not just those referred to by the package-level relationships. It doesn't include external resources. -
externalResources
-
customXmlDataStorageParts
-
contentTypeManager
-
docPropsCorePart
-
docPropsExtendedPart
-
docPropsCustomPart
-
-
Constructor Details
-
OpcPackage
public OpcPackage()Constructor. Also creates a new content type manager -
OpcPackage
Constructor.- Parameters:
contentTypeManager- The content type manager to use
-
-
Method Details
-
getParts
Retrieve the Parts object. -
getDrawingPropsIdTracker
-
getExternalResources
-
getCustomXmlDataStorageParts
keyed by item id (in lower case)- Returns:
-
getContentTypeManager
-
setContentTypeManager
-
getSourcePartStore
- Returns:
- the partStore
- Since:
- 3.0.
-
setSourcePartStore
- Parameters:
partStore- the partStore to set- Since:
- 3.0.
-
getTargetPartStore
- Returns:
- the partStore
- Since:
- 3.0.
-
setTargetPartStore
- Parameters:
partStore- the partStore to set- Since:
- 3.0.
-
getPackage
- Specified by:
getPackagein classBase
-
isNew
public boolean isNew()Was this pkg created from scratch in docx4j, or loaded?- Returns:
-
setNew
public void setNew(boolean isNew) -
load
public static OpcPackage load(PackageIdentifier pkgIdentifier, File docxFile) throws Docx4JException Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an existing File (.docx/.docxm, .ppxtx or Flat OPC .xml).- Parameters:
docxFile- The docx file- Throws:
Docx4JException- Since:
- 3.1.0
-
load
Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an existing File (.docx/.docxm, .ppxtx or Flat OPC .xml).- Parameters:
docxFile- The docx file- Throws:
Docx4JException
-
load
Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an existing File (.docx/.docxm, .ppxtx or Flat OPC .xml).- Parameters:
docxFile- The docx filepassword- The password, if the file is password protected (compound)- Throws:
Docx4JException
-
load
public static OpcPackage load(PackageIdentifier pkgIdentifier, File docxFile, String password) throws Docx4JException Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an existing File (.docx/.docxm, .ppxtx or Flat OPC .xml).- Parameters:
docxFile- The docx filepassword- The password, if the file is password protected (compound)- Throws:
Docx4JException
-
load
Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml). It detects the convenient format inspecting two first bytes of stream (magic bytes). For office 2007 'x' formats, these two bytes are 'PK' (same as zip file)- Parameters:
inputStream- The docx file- Throws:
Docx4JException
-
load
public static OpcPackage load(PackageIdentifier pkgIdentifier, InputStream inputStream) throws Docx4JException Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml). It detects the convenient format inspecting two first bytes of stream (magic bytes). For office 2007 'x' formats, these two bytes are 'PK' (same as zip file)- Parameters:
inputStream- The docx file- Throws:
Docx4JException- Since:
- 3.1.0
-
load
Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml). It detects the convenient format inspecting two first bytes of stream (magic bytes). For office 2007 'x' formats, these two bytes are 'PK' (same as zip file)- Parameters:
inputStream- The docx filepassword- The password, if the file is password protected (compound)- Throws:
Docx4JException
-
load
@Deprecated public static OpcPackage load(InputStream is, boolean docxFormat) throws Docx4JException Deprecated.convenience method to load a word2007 document from an existing inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml). Included for backwards compatibility- Parameters:
is-docxFormat-- Returns:
- Throws:
Docx4JException
-
load
convenience method to load a word2007 document from an existing inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).- Parameters:
is-docxFormat-- Returns:
- Throws:
Docx4JException
-
load
public static OpcPackage load(InputStream is, Filetype type, String password) throws Docx4JException convenience method to load a word2007 document from an existing inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).- Parameters:
is-docxFormat-- Returns:
- Throws:
Docx4JException
-
load
convenience method to load from a file, where you know the Filetype (if it is Filetype.ZippedPackage, ZipFile will be used instead of ZipArchiveInputStream)- Parameters:
is-docxFormat-- Returns:
- Throws:
Docx4JException
-
load
convenience method to load from a file, where you know the Filetype (if it is Filetype.ZippedPackage, ZipFile will be used instead of ZipArchiveInputStream)- Parameters:
is-docxFormat-- Returns:
- Throws:
Docx4JException
-
save
Convenience method to save a WordprocessingMLPackage or PresentationMLPackage to a File. If the file ends with .xml, use Flat OPC XML format; otherwise zip it up.- Throws:
Docx4JException
-
save
Save this pkg to a File. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE or Docx4J.FLAG_SAVE_FLAT_XML- Throws:
Docx4JException- Since:
- 3.1.0
-
save
Save this pkg to a file. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE or Docx4J.FLAG_SAVE_FLAT_XML or one of the Docx4J.FLAG_SAVE_ENCRYPTED_ variants (recommend FLAG_SAVE_ENCRYPTED_AGILE) For the FLAG_SAVE_ENCRYPTED_ variants, you need to provide a password. *- Throws:
Docx4JException- Since:
- 3.3.0
-
save
Save this pkg to an OutputStream in the usual zipped up format (Docx4J.FLAG_SAVE_ZIP_FILE)- Throws:
Docx4JException- Since:
- 3.1.0
-
save
Save this pkg to an OutputStream. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE or Docx4J.FLAG_SAVE_FLAT_XML- Throws:
Docx4JException- Since:
- 3.1.0
-
save
Save this pkg to an OutputStream. The flag is typically Docx4J.FLAG_SAVE_ZIP_FILE or Docx4J.FLAG_SAVE_FLAT_XML or one of the Docx4J.FLAG_SAVE_ENCRYPTED_ variants (recommend FLAG_SAVE_ENCRYPTED_AGILE) For the FLAG_SAVE_ENCRYPTED_ variants, you need to provide a password.- Throws:
Docx4JException- Since:
- 3.3.0
-
setPartShortcut
Description copied from class:BaseTell the source Part about this target Part, so the source can use this part via a convenience method.- Specified by:
setPartShortcutin classBase- Returns:
- true if the source Part does use the target Part in a convenience method.
-
getDocPropsCorePart
Get the DocPropsCorePart, if any.- Returns:
-
addDocPropsCorePart
public void addDocPropsCorePart() -
getDocPropsExtendedPart
Get the DocPropsExtendedPart, if any.- Returns:
-
addDocPropsExtendedPart
public void addDocPropsExtendedPart() -
getDocPropsCustomPart
Get DocPropsCustomPart, if any.- Returns:
-
addDocPropsCustomPart
public void addDocPropsCustomPart() -
setTitle
- Since:
- 3.0.0
-
getTitle
- Since:
- 3.0.0
-
clone
-
cloneAs
- Returns:
- Throws:
Docx4JException- Since:
- 6.1.0
-
name
- Specified by:
namein interfacePackageIdentifier
-
setName
Allocate a name to this package, for the purposes of Docx4jEvent, and logging. -
reset
public void reset()Reinit fields so this pkg object can be re-used.
-