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 Details

    • log

      protected static org.slf4j.Logger log
    • CONTENT_TYPES_PART_NAME

      public static final java.lang.String CONTENT_TYPES_PART_NAME
      Content type part name.
      See Also:
      Constant Field Values
    • TYPES_NAMESPACE_URI

      public static final java.lang.String TYPES_NAMESPACE_URI
      Content type namespace
      See Also:
      Constant Field Values
  • Constructor Details

    • ContentTypeManager

      public ContentTypeManager()
  • Method Details

    • getDefaultContentType

      public java.util.TreeMap<java.lang.String,​CTDefault> getDefaultContentType()
      Returns:
      the defaultContentType
      Since:
      2.8.1
    • getOverrideContentType

      public java.util.TreeMap<java.net.URI,​CTOverride> getOverrideContentType()
      Returns:
      the overrideContentType
      Since:
      2.8.1
    • addOverrideContentType

      public void addOverrideContentType​(java.net.URI partUri, CTOverride contentType)
      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.URISyntaxException
      PartUnrecognisedException
      InvalidFormatException
    • newPartForContentType

      public Part newPartForContentType​(java.lang.String contentType, java.lang.String partName, Relationship rel) throws InvalidFormatException, PartUnrecognisedException
      Throws:
      InvalidFormatException
      PartUnrecognisedException
    • CreateDefaultXmlPartObject

      public Part CreateDefaultXmlPartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateMainDocumentPartObject

      public Part CreateMainDocumentPartObject​(java.lang.String partName) throws InvalidFormatException
      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

      public Part CreateWebSettingsPartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateFontTablePartObject

      public Part CreateFontTablePartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateThemePartObject

      public Part CreateThemePartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateDocPropsCorePartObject

      public Part CreateDocPropsCorePartObject​(java.lang.String partName) throws InvalidFormatException
      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

      public Part CreateCommentsPartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateCustomXmlDataStoragePropertiesPartObject

      public Part CreateCustomXmlDataStoragePropertiesPartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateEndnotesPartObject

      public Part CreateEndnotesPartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateFooterPartObject

      public Part CreateFooterPartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateFootnotesPartObject

      public Part CreateFootnotesPartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateGlossaryDocumentPartObject

      public Part CreateGlossaryDocumentPartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateHeaderPartObject

      public Part CreateHeaderPartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateNumberingPartObject

      public Part CreateNumberingPartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • CreateObfuscatedFontPartObject

      public Part CreateObfuscatedFontPartObject​(java.lang.String partName) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • addDefaultContentType

      public void addDefaultContentType​(java.lang.String extension, CTDefault contentType)
      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

      public void addOverrideContentType​(PartName partName, java.lang.String contentType)
      Parameters:
      partName -
      contentType -
      Since:
      6.1.0
    • removeContentType

      @Deprecated public void removeContentType​(PartName partName)
      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

      public void removeOverrideContentType​(PartName partName)
      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:
      true if the specified content type is already registered, then false.
    • 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:
      true if the specified content type is already registered, then false.
      Since:
      6.1.0
    • getContentType

      public java.lang.String getContentType​(PartName partName)
      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

      public void parseContentTypesFile​(java.io.InputStream contentTypes) throws InvalidFormatException
      Throws:
      InvalidFormatException
    • marshal

      public void marshal​(org.w3c.dom.Node node) throws jakarta.xml.bind.JAXBException
      Throws:
      jakarta.xml.bind.JAXBException
    • marshal

      public void marshal​(java.io.OutputStream os) throws jakarta.xml.bind.JAXBException
      Throws:
      jakarta.xml.bind.JAXBException
    • createPackage

      public OpcPackage createPackage​(java.lang.String pkgContentType) throws InvalidFormatException
      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

      public boolean isContentEqual​(ContentTypeManager other) throws Docx4JException
      Throws:
      Docx4JException
    • toString

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