Class ContentTypeManager
java.lang.Object
org.docx4j.openpackaging.contenttype.ContentTypeManager
public class ContentTypeManager
extends java.lang.Object
Manage package content types ([Content_Types].xml ) .
- Version:
- 1.0
- Author:
- Julien Chable
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCONTENT_TYPES_PART_NAMEContent type part name.protected static org.slf4j.Loggerlogstatic java.lang.StringTYPES_NAMESPACE_URIContent type namespace -
Constructor Summary
Constructors Constructor Description ContentTypeManager() -
Method Summary
Modifier and Type Method Description voidaddDefaultContentType(java.lang.String extension, java.lang.String contentType)voidaddDefaultContentType(java.lang.String extension, CTDefault contentType)Add a content type associated with the specified extension.voidaddOverrideContentType(java.net.URI partUri, java.lang.String contentType)voidaddOverrideContentType(java.net.URI partUri, CTOverride contentType)Add an override content type for a specific part.voidaddOverrideContentType(PartName partName, java.lang.String contentType)voidclearAll()Clear all content types.voidclearOverrideContentTypes()Clear all override content types.PartCreateCommentsPartObject(java.lang.String partName)PartCreateCustomXmlDataStoragePropertiesPartObject(java.lang.String partName)PartCreateDefaultXmlPartObject(java.lang.String partName)PartCreateDocPropsCorePartObject(java.lang.String partName)PartCreateDocPropsCustomPartObject(java.lang.String partName)PartCreateDocPropsExtendedPartObject(java.lang.String partName)PartCreateDocumentSettingsPartObject(java.lang.String partName)PartCreateEndnotesPartObject(java.lang.String partName)PartCreateFontTablePartObject(java.lang.String partName)PartCreateFooterPartObject(java.lang.String partName)PartCreateFootnotesPartObject(java.lang.String partName)PartCreateGlossaryDocumentPartObject(java.lang.String partName)PartCreateHeaderPartObject(java.lang.String partName)PartCreateMainDocumentPartObject(java.lang.String partName)PartCreateNumberingPartObject(java.lang.String partName)PartCreateObfuscatedFontPartObject(java.lang.String partName)OpcPackagecreatePackage(java.lang.String pkgContentType)Return a package of the appropriate type.PartCreateStyleDefinitionsPartObject(java.lang.String partName)PartCreateThemePartObject(java.lang.String partName)PartCreateWebSettingsPartObject(java.lang.String partName)java.lang.StringgetContentType(PartName partName)Get the content type for the specified part, if any.java.util.TreeMap<java.lang.String,CTDefault>getDefaultContentType()java.util.TreeMap<java.net.URI,CTOverride>getOverrideContentType()PartgetPart(java.lang.String partName, Relationship rel)java.net.URIgetPartNameOverridenByContentType(java.lang.String contentType)booleanisContentEqual(ContentTypeManager other)booleanisContentTypeRegistered(java.lang.String contentType)Check if the specified content type is already registered as a default content type.booleanisOverrideContentTypeRegistered(java.lang.String contentType)Check if the specified content type is already registered as a default content type.voidmarshal(java.io.OutputStream os)voidmarshal(org.w3c.dom.Node node)PartnewPartForContentType(java.lang.String contentType, java.lang.String partName, Relationship rel)voidparseContentTypesFile(java.io.InputStream contentTypes)voidremoveContentType(PartName partName)Deprecated.voidremoveDefaultContentType(java.lang.String ext)Delete a default content type based on the specified part name.voidremoveOverrideContentType(PartName partName)Delete an override content type based on the specified part name.java.lang.StringtoString()
-
Field Details
-
log
protected static org.slf4j.Logger log -
CONTENT_TYPES_PART_NAME
public static final java.lang.String CONTENT_TYPES_PART_NAMEContent type part name.- See Also:
- Constant Field Values
-
TYPES_NAMESPACE_URI
public static final java.lang.String TYPES_NAMESPACE_URIContent type namespace- See Also:
- Constant Field Values
-
-
Constructor Details
-
ContentTypeManager
public ContentTypeManager()
-
-
Method Details
-
getDefaultContentType
- Returns:
- the defaultContentType
- Since:
- 2.8.1
-
getOverrideContentType
- Returns:
- the overrideContentType
- Since:
- 2.8.1
-
addOverrideContentType
Add an override content type for a specific part.- Parameters:
partUri- Uri of the part.contentType- Content type of the part.
-
addOverrideContentType
public void addOverrideContentType(java.net.URI partUri, java.lang.String contentType) -
getPartNameOverridenByContentType
public java.net.URI getPartNameOverridenByContentType(java.lang.String contentType) -
getPart
public Part getPart(java.lang.String partName, Relationship rel) throws java.net.URISyntaxException, PartUnrecognisedException, InvalidFormatException- Throws:
java.net.URISyntaxExceptionPartUnrecognisedExceptionInvalidFormatException
-
newPartForContentType
public Part newPartForContentType(java.lang.String contentType, java.lang.String partName, Relationship rel) throws InvalidFormatException, PartUnrecognisedException -
CreateDefaultXmlPartObject
- Throws:
InvalidFormatException
-
CreateMainDocumentPartObject
- Throws:
InvalidFormatException
-
CreateStyleDefinitionsPartObject
public Part CreateStyleDefinitionsPartObject(java.lang.String partName) throws InvalidFormatException- Throws:
InvalidFormatException
-
CreateDocumentSettingsPartObject
public Part CreateDocumentSettingsPartObject(java.lang.String partName) throws InvalidFormatException- Throws:
InvalidFormatException
-
CreateWebSettingsPartObject
- Throws:
InvalidFormatException
-
CreateFontTablePartObject
- Throws:
InvalidFormatException
-
CreateThemePartObject
- Throws:
InvalidFormatException
-
CreateDocPropsCorePartObject
- Throws:
InvalidFormatException
-
CreateDocPropsExtendedPartObject
public Part CreateDocPropsExtendedPartObject(java.lang.String partName) throws InvalidFormatException- Throws:
InvalidFormatException
-
CreateDocPropsCustomPartObject
public Part CreateDocPropsCustomPartObject(java.lang.String partName) throws InvalidFormatException- Throws:
InvalidFormatException
-
CreateCommentsPartObject
- Throws:
InvalidFormatException
-
CreateCustomXmlDataStoragePropertiesPartObject
public Part CreateCustomXmlDataStoragePropertiesPartObject(java.lang.String partName) throws InvalidFormatException- Throws:
InvalidFormatException
-
CreateEndnotesPartObject
- Throws:
InvalidFormatException
-
CreateFooterPartObject
- Throws:
InvalidFormatException
-
CreateFootnotesPartObject
- Throws:
InvalidFormatException
-
CreateGlossaryDocumentPartObject
public Part CreateGlossaryDocumentPartObject(java.lang.String partName) throws InvalidFormatException- Throws:
InvalidFormatException
-
CreateHeaderPartObject
- Throws:
InvalidFormatException
-
CreateNumberingPartObject
- Throws:
InvalidFormatException
-
CreateObfuscatedFontPartObject
public Part CreateObfuscatedFontPartObject(java.lang.String partName) throws InvalidFormatException- Throws:
InvalidFormatException
-
addDefaultContentType
Add a content type associated with the specified extension.- Parameters:
extension- The part name extension to bind to a content type.contentType- The content type associated with the specified extension.
-
addDefaultContentType
public void addDefaultContentType(java.lang.String extension, java.lang.String contentType) -
addOverrideContentType
- Parameters:
partName-contentType-- Since:
- 6.1.0
-
removeContentType
Deprecated.Delete a content type based on the specified part name. If the specified part name is registered with an override content type, then this content type is removed, else the content type is removed in the default content type list if it exists. Deprecated since you'd typically NOT want to accidentally remove *.xml or *.rels from the default Content type list- Parameters:
partUri- The part URI associated with the override content type to delete.
-
removeOverrideContentType
Delete an override content type based on the specified part name.- Parameters:
partUri- The part URI associated with the override content type to delete.- Since:
- 6.1.0
-
removeDefaultContentType
public void removeDefaultContentType(java.lang.String ext)Delete a default content type based on the specified part name. Note that you'd typically NOT want to remove *.xml or *.rels from the default Content type list- Parameters:
partUri- The part URI associated with the override content type to delete.- Since:
- 6.1.0
-
isContentTypeRegistered
public boolean isContentTypeRegistered(java.lang.String contentType)Check if the specified content type is already registered as a default content type. We don't currently have a method to check whether its registered as an override content type; getContentType(PartName partName) may suffice for that purpose.- Parameters:
contentType- The content type to check.- Returns:
trueif the specified content type is already registered, thenfalse.
-
isOverrideContentTypeRegistered
public boolean isOverrideContentTypeRegistered(java.lang.String contentType)Check if the specified content type is already registered as a default content type. We don't currently have a method to check whether its registered as an override content type; getContentType(PartName partName) may suffice for that purpose.- Parameters:
contentType- The content type to check.- Returns:
trueif the specified content type is already registered, thenfalse.- Since:
- 6.1.0
-
getContentType
Get the content type for the specified part, if any.- Parameters:
partUri- The URI part to check.- Returns:
- The content type associated with the URI (in case of an override
content type) or the extension (in case of default content type),
else
null.
-
clearAll
public void clearAll()Clear all content types. -
clearOverrideContentTypes
public void clearOverrideContentTypes()Clear all override content types. -
parseContentTypesFile
- Throws:
InvalidFormatException
-
marshal
public void marshal(org.w3c.dom.Node node) throws javax.xml.bind.JAXBException- Throws:
javax.xml.bind.JAXBException
-
marshal
public void marshal(java.io.OutputStream os) throws javax.xml.bind.JAXBException- Throws:
javax.xml.bind.JAXBException
-
createPackage
Return a package of the appropriate type. Used when loading an existing Package, with an already populated [Content_Types].xml. When creating a new Package, start with the new WordprocessingMLPackage constructor.- Throws:
InvalidFormatException
-
isContentEqual
- Throws:
Docx4JException
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-