Class DocumentHandlerFactory

java.lang.Object
chemaxon.formats.documents.jchemoffice.DocumentHandlerFactory

@PublicAPI public class DocumentHandlerFactory extends Object
The DocumentHandlerFactory class is the entry point to instantiate classes which implement the
  • IDocumentWriter,
  • IDocumentReader
  • IDocumentConverter interfaces.
  • Constructor Details

    • DocumentHandlerFactory

      public DocumentHandlerFactory()
  • Method Details

    • createDocumentWriter

      public static IDocumentWriter createDocumentWriter(DocumentType documentType, String filePath) throws Exception
      The static createDocumentWriter method instantiates a class which implements the IDocumentWriter interface. The new object can be used to edit the file given in the filePath parameter.

      The following is one example how to use the createDocumentWriter. The code:

       File testFile = File.createTempFile("Testdocs", ".pptx");
       IDocumentWriter writer = DocumentHandlerFactory.createDocumentWriter(DocumentType.PPT, testFile.getPath());
       
      Parameters:
      documentType - - The type of the document. It can be Word or PPT as defined in the DocumentType enum
      filePath - - The path of the file which will be edited
      Returns:
      The document writer object.
      Throws:
      Exception
    • createDocumentWriter

      public static IDocumentWriter createDocumentWriter(DocumentType documentType, InputStream inputStream, OutputStream outputStream) throws Exception
      The static createDocumentWriter method instantiates a class which implements the IDocumentWriter interface. The new object can be used to read from the inputstream and write to the stream given in the outputstream parameter *

      The following is one example how to use the createDocumentWriter. The code:

       File testFileRead = File.createTempFile("TestdocsR", ".pptx");
       FileInputStream inputStream = new FileInputStream(testFileRead.getPath());
       File testFileWrite = File.createTempFile("TestdocsW", ".pptx");
       FileOutputStream outputStream = new FileOutputStream(testFileWrite);
       IDocumentWriter writer = DocumentHandlerFactory.createDocumentWriter(DocumentType.PPT, inputStream,
               outputStream);
       
      Parameters:
      documentType - - The type of the document. It can be Word or PPT as defined in the DocumentType enum
      inputStream - - The input stream from where the document should be read
      outputStream - - The output stream where the edited document should be written
      Returns:
      the document writer object
      Throws:
      Exception
    • createDocumentWriter

      public static IDocumentWriter createDocumentWriter(DocumentType documentType, OutputStream outputStream) throws Exception
      The static createDocumentWriter method instantiates a class which implements the IDocumentWriter interface. The new object can be used to read and write from/to the stream given in the output stream parameter

      The following is one example how to use the createDocumentWriter. The code:

      
       File testFileWrite = File.createTempFile("Testdocs", ".pptx");
       FileOutputStream outputStream = new FileOutputStream(testFileWrite);
       IDocumentWriter writer = DocumentHandlerFactory.createDocumentWriter(DocumentType.PPT, outputStream);
       
      Parameters:
      documentType - - The type of the document. It can be Word or PPT as defined in the DocumentType enum
      outputStream - - The output stream where the edited document should be written
      Returns:
      IDocumentWriter
      Throws:
      Exception
    • createDocumentReader

      public static IDocumentReader createDocumentReader(DocumentType documentType, String filePath) throws Exception
      The static createDocumentReader method instantiates a class which implements the IDocumentReader interface. The new object can be used to read from the file given in the filepath parameter.

      The following is one example how to use the createDocumentReader. The code:

       IDocumentReader reader = DocumentHandlerFactory.createDocumentReader(DocumentType.Word, "TestFiles/Test.docx");
       
      Parameters:
      documentType - - The type of the document. It can be Word or PPT as defined in the DocumentType enum
      filePath - - The path of the file from where the document should be read
      Returns:
      IDocumentReader
      Throws:
      Exception
    • createDocumentReader

      public static IDocumentReader createDocumentReader(DocumentType documentType, InputStream inputStream) throws Exception
      The static createDocumentReader method instantiates a class which implements the IDocumentReader interface. The new object can be used to read from the stream given in the inputStream parameter

      The following is one example how to use the createDocumentReader. The code:

       File testFileRead = File.createTempFile("Testdocs", ".docx");
       FileInputStream inputStream = new FileInputStream(testFileRead.getPath());
       IDocumentReader reader = DocumentHandlerFactory.createDocumentReader(DocumentType.Word, inputStream);
       
      Parameters:
      documentType - - The type of the document. It can be Word or PPT as defined in the DocumentType enum
      inputStream - - The input stream from where the document should be read
      Returns:
      IDocumentReader
      Throws:
      Exception
    • createDocumentConverter

      public static IDocumentConverter createDocumentConverter(DocumentType documentType, String filePath) throws Exception
      The static createDocumentConverter method instantiates a class which implements the IDocumentConverter interface. The new object can be used to convert the structures in the given document from one format to another format

      The following is one example how to use the createDocumentConverter. The code:

      
       IDocumentConverter converter = DocumentHandlerFactory.createDocumentConverter(DocumentType.Word,
               "TestFiles/Test.docx");
       
      Parameters:
      documentType - - The type of the document. It can be Word or PPT as defined in the DocumentType enum
      filePath - - The path of the file in what the structures should be converted
      Returns:
      IDocumentConverter
      Throws:
      Exception
    • createDocumentTemplateWriter

      public static IDocumentTemplateWriter createDocumentTemplateWriter(DocumentType documentType, String templateFilePath, String targetPath) throws Exception
      The static createDocumentTemplateWriter method instantiates a class which implements the IDocumentTemplateWriter interface. The new reports are to be generated in targetPath from the templateFilePath document parameter.

      The following is one example how to use the createDocumentWriter. The code:

       File testFile = File.createTempFile("Testdocs", ".pptx");
       IDocumentWriter writer = DocumentHandlerFactory.createDocumentTemplateWriter(DocumentType.PPT, testFile.getPath(), "C:\\Reports");
       
      Parameters:
      documentType - - The type of the document. It can be Word or PPT as defined in the DocumentType enum
      templateFilePath - - The path of the document template which will be used as a source
      targetPath - - The path of the folder where the generated reports will be written
      Returns:
      The template document writer object
      Throws:
      Exception
    • createDocumentTemplateWriter

      public static IDocumentTemplateWriter createDocumentTemplateWriter(DocumentType documentType, InputStream inputTemplateStream, String targetPath) throws Exception
      The static createDocumentWriter method instantiates a class which implements the IDocumentTemplateWriter interface. The new reports are to be generated in targetPath from the inputTemplateStream document parameter.

      The following is one example how to use the createDocumentWriter. The code:

       File testFileRead = File.createTempFile("TestdocsR", ".pptx");
       FileInputStream inputStream = new FileInputStream(testFileRead.getPath());
       IDocumentWriter writer = DocumentHandlerFactory.createDocumentWriter(DocumentType.PPT, inputStream, "C:\\Reports");
       
      Parameters:
      documentType - - The type of the document. It can be Word or PPT as defined in the DocumentType enum
      inputTemplateStream - - The stream of the document template which will be used as a source
      targetPath - - The path of the folder where the generated reports will be written
      Returns:
      The template document writer object
      Throws:
      Exception
    • createDocumentOLEConverter

      public static IDocumentConverter createDocumentOLEConverter(DocumentType documentType, String filePath) throws IOException
      The static createDocumentOLEConverter method instantiates a class which implements the IDocumentConverter interface. The document located in targetPath will be converted from the old-style OLE to JChem for Office objects/shapes embedded document report.

      The following is one example how to use the OLEConverter. The code:

      
       IDocumentConverter converter = DocumentHandlerFactory.createDocumentOLEConverter(DocumentType.Word,
               "TestFiles/Test.docx");
       
      Parameters:
      documentType - - The type of the document. It can be Word or PPT as defined in the DocumentType enum
      filePath - - File of the target document that needs to be converted from OLE to JChem For Office
      Returns:
      The document converter object
      Throws:
      IOException
    • createDocumentOLEConverter

      public static IDocumentConverter createDocumentOLEConverter(DocumentType documentType, String filePath, chemaxon.formats.documents.jchemoffice.SupportedOLETypes oleTypes) throws IOException
      The static createDocumentOLEConverter method instantiates a class which implements the IDocumentConverter interface. The document located in targetPath will be converted from the old-style OLE to JChem for Office objects/shapes embedded document report.

      The following is one example how to use the OLEConverter. The code:

      
       IDocumentConverter converter = DocumentHandlerFactory.createDocumentOLEConverter(DocumentType.Word,
               "TestFiles/Test.docx", SupportedOLETypes.CDX);
       
      Parameters:
      documentType - - The type of the document. It can be Word or PPT as defined in the DocumentType enum
      filePath - - File of the target document that needs to be converted from OLE to JChem For Office
      oleTypes - - if we do not want to convert all types of OLE embeddings to JChem for Office it can be filtered by the Supported OLE types enum By specifying the SupportedOLETypes.CDX value all ChemDraw OLE objects will only be converted.
      Returns:
      The document converter object
      Throws:
      IOException