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
public abstract class OpcPackage extends Base implements PackageIdentifier
Represent a Package as defined in the Open Packaging Specification.
- Author:
- Jason Harrop
-
Field Summary
Fields Modifier and Type Field Description protected ContentTypeManagercontentTypeManagerprotected java.util.HashMap<java.lang.String,CustomXmlPart>customXmlDataStoragePartsprotected DocPropsCorePartdocPropsCorePartprotected DocPropsCustomPartdocPropsCustomPartprotected DocPropsExtendedPartdocPropsExtendedPartprotected java.util.HashMap<ExternalTarget,Part>externalResourcesjava.util.HashMap<java.lang.String,java.lang.String>handledThis HashMap is intended to prevent loops during the loading of this package.protected PartspartsPackage parts collection. -
Constructor Summary
Constructors Constructor Description OpcPackage()Constructor.OpcPackage(ContentTypeManager contentTypeManager)Constructor. -
Method Summary
Modifier and Type Method Description voidaddDocPropsCorePart()voidaddDocPropsCustomPart()voidaddDocPropsExtendedPart()OpcPackageclone()OpcPackagecloneAs(java.lang.String targetContentType)ContentTypeManagergetContentTypeManager()java.util.HashMap<java.lang.String,CustomXmlPart>getCustomXmlDataStorageParts()keyed by item id (in lower case)DocPropsCorePartgetDocPropsCorePart()Get the DocPropsCorePart, if any.DocPropsCustomPartgetDocPropsCustomPart()Get DocPropsCustomPart, if any.DocPropsExtendedPartgetDocPropsExtendedPart()Get the DocPropsExtendedPart, if any.java.util.HashMap<ExternalTarget,Part>getExternalResources()OpcPackagegetPackage()PartsgetParts()Retrieve the Parts object.PartStoregetSourcePartStore()PartStoregetTargetPartStore()java.lang.StringgetTitle()booleanisNew()Was this pkg created from scratch in docx4j, or loaded?static OpcPackageload(java.io.File docxFile)Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an existing File (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(java.io.File docxFile, java.lang.String password)Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an existing File (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(java.io.File file, Filetype type)convenience 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(java.io.File file, Filetype type, java.lang.String password)convenience 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(java.io.InputStream inputStream)Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(java.io.InputStream is, boolean docxFormat)Deprecated.static OpcPackageload(java.io.InputStream inputStream, java.lang.String password)Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(java.io.InputStream is, Filetype type)convenience method to load a word2007 document from an existing inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(java.io.InputStream is, Filetype type, java.lang.String password)convenience method to load a word2007 document from an existing inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).static OpcPackageload(PackageIdentifier pkgIdentifier, java.io.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, java.io.File docxFile, java.lang.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, java.io.InputStream inputStream)Convenience method to create a WordprocessingMLPackage or PresentationMLPackage from an inputstream (.docx/.docxm, .ppxtx or Flat OPC .xml).java.lang.Stringname()voidreset()Reinit fields so this pkg object can be re-used.voidsave(java.io.File file)Convenience method to save a WordprocessingMLPackage or PresentationMLPackage to a File.voidsave(java.io.File outFile, int flags)Save this pkg to a File.voidsave(java.io.File outFile, int flags, java.lang.String password)Save this pkg to a file.voidsave(java.io.OutputStream outStream)Save this pkg to an OutputStream in the usual zipped up format (Docx4J.FLAG_SAVE_ZIP_FILE)voidsave(java.io.OutputStream outStream, int flags)Save this pkg to an OutputStream.voidsave(java.io.OutputStream outStream, int flags, java.lang.String password)Save this pkg to an OutputStream.voidsetContentTypeManager(ContentTypeManager contentTypeManager)voidsetName(java.lang.String name)Allocate a name to this package, for the purposes of Docx4jEvent, and logging.voidsetNew(boolean isNew)booleansetPartShortcut(Part part, java.lang.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)voidsetTitle(java.lang.String title)Methods inherited from class org.docx4j.openpackaging.Base
addTargetPart, addTargetPart, addTargetPart, addTargetPart, getContentType, getPartName, getRelationshipsPart, getRelationshipsPart, getUserData, setContentType, setPartName, setRelationships, setUserData
-
Field Details
-
handled
public java.util.HashMap<java.lang.String,java.lang.String> handledThis 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. -
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, java.io.File docxFile) throws Docx4JExceptionConvenience 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
public static OpcPackage load(java.io.File docxFile, java.lang.String password) throws Docx4JExceptionConvenience 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, java.io.File docxFile, java.lang.String password) throws Docx4JExceptionConvenience 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, java.io.InputStream inputStream) throws Docx4JExceptionConvenience 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
public static OpcPackage load(java.io.InputStream inputStream, java.lang.String password) throws Docx4JExceptionConvenience 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(java.io.InputStream is, boolean docxFormat) throws Docx4JExceptionDeprecated.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(java.io.InputStream is, Filetype type, java.lang.String password) throws Docx4JExceptionconvenience 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
public static OpcPackage load(java.io.File file, Filetype type, java.lang.String password) throws Docx4JExceptionconvenience 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
public void save(java.io.File outFile, int flags, java.lang.String password) throws Docx4JExceptionSave 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
public void save(java.io.OutputStream outStream, int flags, java.lang.String password) throws Docx4JExceptionSave 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
public void setTitle(java.lang.String title)- Since:
- 3.0.0
-
getTitle
public java.lang.String getTitle()- Since:
- 3.0.0
-
clone
- Overrides:
clonein classjava.lang.Object- Since:
- 2.7.2
-
cloneAs
- Returns:
- Throws:
Docx4JException- Since:
- 6.1.0
-
name
public java.lang.String name()- Specified by:
namein interfacePackageIdentifier
-
setName
public void setName(java.lang.String name)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.
-