org.docx4j.openpackaging.contenttype
Class ContentTypeManagerImpl

java.lang.Object
  extended by org.docx4j.openpackaging.contenttype.ContentTypeManagerImpl
All Implemented Interfaces:
ContentTypeManager

public class ContentTypeManagerImpl
extends java.lang.Object
implements ContentTypeManager

Manage package content types ([Content_Types].xml ) .


Field Summary
static java.lang.String CONTENT_TYPES_PART_NAME
          Content type part name.
static java.lang.String TYPES_NAMESPACE_URI
          Content type namespace
 
Constructor Summary
ContentTypeManagerImpl()
           
ContentTypeManagerImpl(org.dom4j.Document contentTypes)
          Constructor.
 
Method Summary
 void addContentType(PartName partName, java.lang.String contentType)
          Build association extention-> content type (will be stored in [Content_Types].xml) for example ContentType="image/png" Extension="png"
 void addDefaultContentType(java.lang.String extension, java.lang.String contentType)
          Add a content type associated with the specified extension.
 void addOverrideContentType(java.net.URI partUri, java.lang.String contentType)
          Add an override content type for a specific part.
 void clearAll()
          Clear all content types.
 void clearOverrideContentTypes()
          Clear all override content types.
 Part CreateCommentsPartObject(java.lang.String partName)
           
 Part CreateCustomXmlPropertiesPartObject(java.lang.String partName)
           
 Part CreateDefaultPartObject(java.lang.String partName)
           
 Part CreateDocPropsCorePartObject(java.lang.String partName)
           
 Part CreateDocPropsCustomPartObject(java.lang.String partName)
           
 Part CreateDocPropsExtendedPartObject(java.lang.String partName)
           
 Part CreateDocumentSettingsPartObject(java.lang.String partName)
           
 Part CreateEndnotesPartObject(java.lang.String partName)
           
 Part CreateFontTablePartObject(java.lang.String partName)
           
 Part CreateFooterPartObject(java.lang.String partName)
           
 Part CreateFootnotesPartObject(java.lang.String partName)
           
 Part CreateGlossaryDocumentPartObject(java.lang.String partName)
           
 Part CreateHeaderPartObject(java.lang.String partName)
           
 Part CreateMainDocumentPartObject(java.lang.String partName)
           
 Part CreateNumberingPartObject(java.lang.String partName)
           
 Part CreateObfuscatedFontPartObject(java.lang.String partName)
           
 Package createPackage()
           
 Part CreateStyleDefinitionsPartObject(java.lang.String partName)
           
 Part CreateThemePartObject(java.lang.String partName)
           
 Part CreateWebSettingsPartObject(java.lang.String partName)
           
 java.lang.String getContentType(PartName partName)
          Get the content type for the specified part, if any.
 org.dom4j.Document getDocument()
          Generates the XML for the contents type part.
 Part getPart(java.lang.String partName)
           
 java.net.URI getPartNameOverridenByContentType(java.lang.String contentType)
           
 boolean isContentTypeRegistered(java.lang.String contentType)
          Check if the specified content type is already register.
 Part newPartForContentType(java.lang.String contentType, java.lang.String partName)
           
 void parseContentTypesFile(org.dom4j.Document xmlContentTypeDoc)
          Parse the content types part.
 void removeContentType(PartName partName)
          Delete a content type based on the specified part name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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 Detail

ContentTypeManagerImpl

public ContentTypeManagerImpl()

ContentTypeManagerImpl

public ContentTypeManagerImpl(org.dom4j.Document contentTypes)
                       throws InvalidFormatException
Constructor. Parses the content of the specified input stream.

Parameters:
archive - If different of null then the content types part is retrieve and parse.
Throws:
InvalidFormatException - If the content types part content is not valid.
Method Detail

addContentType

public void addContentType(PartName partName,
                           java.lang.String contentType)
Build association extention-> content type (will be stored in [Content_Types].xml) for example ContentType="image/png" Extension="png"

Specified by:
addContentType in interface ContentTypeManager
Parameters:
partUri - the uri that will be stored

addDefaultContentType

public void addDefaultContentType(java.lang.String extension,
                                  java.lang.String contentType)
Add a content type associated with the specified extension.

Specified by:
addDefaultContentType in interface ContentTypeManager
Parameters:
extension - The part name extension to bind to a content type.
contentType - The content type associated with the specified extension.

addOverrideContentType

public void addOverrideContentType(java.net.URI partUri,
                                   java.lang.String contentType)
Add an override content type for a specific part.

Specified by:
addOverrideContentType in interface ContentTypeManager
Parameters:
partUri - Uri of the part.
contentType - Content type of the part.

clearAll

public void clearAll()
Clear all content types.

Specified by:
clearAll in interface ContentTypeManager

clearOverrideContentTypes

public void clearOverrideContentTypes()
Clear all override content types.

Specified by:
clearOverrideContentTypes in interface ContentTypeManager

CreateCommentsPartObject

public Part CreateCommentsPartObject(java.lang.String partName)
                              throws InvalidFormatException
Specified by:
CreateCommentsPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateCustomXmlPropertiesPartObject

public Part CreateCustomXmlPropertiesPartObject(java.lang.String partName)
                                         throws InvalidFormatException
Specified by:
CreateCustomXmlPropertiesPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateDefaultPartObject

public Part CreateDefaultPartObject(java.lang.String partName)
                             throws InvalidFormatException
Specified by:
CreateDefaultPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateDocPropsCorePartObject

public Part CreateDocPropsCorePartObject(java.lang.String partName)
                                  throws InvalidFormatException
Specified by:
CreateDocPropsCorePartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateDocPropsCustomPartObject

public Part CreateDocPropsCustomPartObject(java.lang.String partName)
                                    throws InvalidFormatException
Specified by:
CreateDocPropsCustomPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateDocPropsExtendedPartObject

public Part CreateDocPropsExtendedPartObject(java.lang.String partName)
                                      throws InvalidFormatException
Specified by:
CreateDocPropsExtendedPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateDocumentSettingsPartObject

public Part CreateDocumentSettingsPartObject(java.lang.String partName)
                                      throws InvalidFormatException
Specified by:
CreateDocumentSettingsPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateEndnotesPartObject

public Part CreateEndnotesPartObject(java.lang.String partName)
                              throws InvalidFormatException
Specified by:
CreateEndnotesPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateFontTablePartObject

public Part CreateFontTablePartObject(java.lang.String partName)
                               throws InvalidFormatException
Specified by:
CreateFontTablePartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateFooterPartObject

public Part CreateFooterPartObject(java.lang.String partName)
                            throws InvalidFormatException
Specified by:
CreateFooterPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateFootnotesPartObject

public Part CreateFootnotesPartObject(java.lang.String partName)
                               throws InvalidFormatException
Specified by:
CreateFootnotesPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateGlossaryDocumentPartObject

public Part CreateGlossaryDocumentPartObject(java.lang.String partName)
                                      throws InvalidFormatException
Specified by:
CreateGlossaryDocumentPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateHeaderPartObject

public Part CreateHeaderPartObject(java.lang.String partName)
                            throws InvalidFormatException
Specified by:
CreateHeaderPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateMainDocumentPartObject

public Part CreateMainDocumentPartObject(java.lang.String partName)
                                  throws InvalidFormatException
Specified by:
CreateMainDocumentPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateNumberingPartObject

public Part CreateNumberingPartObject(java.lang.String partName)
                               throws InvalidFormatException
Specified by:
CreateNumberingPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateObfuscatedFontPartObject

public Part CreateObfuscatedFontPartObject(java.lang.String partName)
                                    throws InvalidFormatException
Specified by:
CreateObfuscatedFontPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

createPackage

public Package createPackage()
                      throws InvalidFormatException
Specified by:
createPackage in interface ContentTypeManager
Throws:
InvalidFormatException

CreateStyleDefinitionsPartObject

public Part CreateStyleDefinitionsPartObject(java.lang.String partName)
                                      throws InvalidFormatException
Specified by:
CreateStyleDefinitionsPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateThemePartObject

public Part CreateThemePartObject(java.lang.String partName)
                           throws InvalidFormatException
Specified by:
CreateThemePartObject in interface ContentTypeManager
Throws:
InvalidFormatException

CreateWebSettingsPartObject

public Part CreateWebSettingsPartObject(java.lang.String partName)
                                 throws InvalidFormatException
Specified by:
CreateWebSettingsPartObject in interface ContentTypeManager
Throws:
InvalidFormatException

getContentType

public java.lang.String getContentType(PartName partName)
Get the content type for the specified part, if any.

Specified by:
getContentType in interface ContentTypeManager
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.

getDocument

public org.dom4j.Document getDocument()
Generates the XML for the contents type part.

Specified by:
getDocument in interface ContentTypeManager
Parameters:
outStream - The output stream use to save the XML content of the content types part.
Returns:
true if the operation success, else false.

getPart

public Part getPart(java.lang.String partName)
             throws java.net.URISyntaxException,
                    InvalidFormatException
Specified by:
getPart in interface ContentTypeManager
Throws:
java.net.URISyntaxException
InvalidFormatException

getPartNameOverridenByContentType

public java.net.URI getPartNameOverridenByContentType(java.lang.String contentType)
Specified by:
getPartNameOverridenByContentType in interface ContentTypeManager

isContentTypeRegistered

public boolean isContentTypeRegistered(java.lang.String contentType)
Check if the specified content type is already register.

Specified by:
isContentTypeRegistered in interface ContentTypeManager
Parameters:
contentType - The content type to check.
Returns:
true if the specified content type is already register, then false.

newPartForContentType

public Part newPartForContentType(java.lang.String contentType,
                                  java.lang.String partName)
                           throws InvalidFormatException
Specified by:
newPartForContentType in interface ContentTypeManager
Throws:
InvalidFormatException

parseContentTypesFile

public void parseContentTypesFile(org.dom4j.Document xmlContentTypeDoc)
                           throws InvalidFormatException
Parse the content types part.

Specified by:
parseContentTypesFile in interface ContentTypeManager
Throws:
InvalidFormatException - Throws if the content type doesn't exist or the XML format is invalid.

removeContentType

public void removeContentType(PartName partName)
Delete a content type based on the specified part name. If the specified part name is register with an override content type, then this content type is remove, else the content type is remove in the default content type list if it exists.

Specified by:
removeContentType in interface ContentTypeManager
Parameters:
partUri - The part URI associated with the override content type to delete.