com.groupdocs.editor

Class EditableDocument

  • All Implemented Interfaces:
    com.aspose.ms.System.IDisposable, IAuxDisposable


    public final class EditableDocument
    extends Object
    implements IAuxDisposable

    Intermediate document, that contains content before and after editing


    Instance of EditableDocument class can be produced by the Editor.Edit() method or created by the user himself using static factories. EditableDocument internally stores document in its own closed format, which is compatible (convertible) with all import and export formats, that GroupDocs.Editor supports. In order to make document editable in any WYSIWYG client-side editor (like CKEditor or TinyMCE), EditableDocument provides methods for generating HTML markup and producing resources, that can be accepted by the user.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      com.aspose.ms.lang.Event<com.aspose.ms.System.EventHandler> Disposed 
    • Constructor Summary

      Constructors 
      Constructor and Description
      EditableDocument(byte initialDocumentType, com.groupdocs.editor.htmlcss.html.HtmlDom origin) 
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      void dispose()
      Disposes this Editable document instance, disposing its content and making its methods and properties non-working
      static EditableDocument fromBodyMarkupAndResourceFolder(String htmlBodyContent, String resourceFolderPath)
      Static factory, that creates an instance of EditableDocument from a specified HTML markup, that doesn't contain an HTML header, but only inner markup of HTML BODY element, and from resources, located in the folder, specified by the full path
      static EditableDocument fromFile(String htmlFilePath, String resourceFolderPath)
      Static factory, that creates an instance of EditableDocument from a HTML file, that is specified by a path to the *.html file itself and a folder with linked resources
      static EditableDocument fromMarkup(String newHtmlContent, List<IHtmlResource> resources)
      Static factory, that creates an instance of EditableDocument from specified HTML markup and a set of corresponding linked resources
      List<IHtmlResource> getAllResources()
      Returns a list of all existing resources: all stylesheets, images from HTML and all stylesheets, fonts
      com.aspose.ms.System.Collections.Generic.List<IHtmlResource> getAllResourcesInternal() 
      String getBodyContent()
      Returns a body of the HTML document (content between opening and closing BODY tags without these tags) as a string.
      String getBodyContent(String externalImagesPrefix)
      Returns a body of the HTML document (content between opening and closing BODY tags without these tags) as a string, where links to the external resources contain specified prefix.
      String getContent()
      Returns overall content of the HTML document as a string.
      String getContent(String externalImagesPrefix, String externalCssPrefix)
      Returns overall content of the HTML document as a string, where links to the external resources contain specified prefix.
      List<CssText> getCss()
      Returns a list of CSS resources
      List<String> getCssContent()
      Returns content of all external stylesheets as a list of strings, where one string represents one stylesheet.
      List<String> getCssContent(String externalImagesPrefix, String externalFontsPrefix)
      Returns content of all external stylesheets as a list of strings, where one string represents one stylesheet.
      com.aspose.ms.System.Collections.Generic.List<String> getCssContentInternal() 
      com.aspose.ms.System.Collections.Generic.List<String> getCssContentInternal(String externalImagesPrefix, String externalFontsPrefix) 
      com.aspose.ms.System.Collections.Generic.List<CssText> getCssInternal() 
      String getEmbeddedHtml()
      Returns all content of this HTML document with all related resources in a form of a single string, where all resources are embedded inside the HTML markup in a base64-encoded form.
      List<FontResourceBase> getFonts()
      Allows to obtain external font resources, which are used by this HTML document
      com.aspose.ms.System.Collections.Generic.List<FontResourceBase> getFontsInternal() 
      List<IImageResource> getImages()
      Allows to obtain external image resources (raster images), which are used by this HTML document
      com.aspose.ms.System.Collections.Generic.List<IImageResource> getImagesInternal() 
      com.groupdocs.editor.htmlcss.html.HtmlDom getOrigin()
      Returns an original HTML DOM instance
      byte getOriginatingType()
      Returns an originating type of this EditableDocument
      boolean isDisposed()
      Determines whether this Editable document was already disposed (true) or not (false)
      void save(String htmlFilePath)
      Saves this HTML document to the file on specified path, where HTML markup will be stored, and to the accompanying folder with resources.
      void save(String htmlFilePath, String resourcesFolderPath)
      Saves this HTML document to the file on specified path, where HTML markup will be stored, and to the accompanying folder with resources, which is located on specified path.
    • Field Detail

      • Disposed

        public final com.aspose.ms.lang.Event<com.aspose.ms.System.EventHandler> Disposed
    • Constructor Detail

      • EditableDocument

        public EditableDocument(byte initialDocumentType,
                        com.groupdocs.editor.htmlcss.html.HtmlDom origin)
    • Method Detail

      • dispose

        public final void dispose()

        Disposes this Editable document instance, disposing its content and making its methods and properties non-working

        Specified by:
        dispose in interface com.aspose.ms.System.IDisposable
      • fromBodyMarkupAndResourceFolder

        public static EditableDocument fromBodyMarkupAndResourceFolder(String htmlBodyContent,
                                                       String resourceFolderPath)

        Static factory, that creates an instance of EditableDocument from a specified HTML markup, that doesn't contain an HTML header, but only inner markup of HTML BODY element, and from resources, located in the folder, specified by the full path

        Parameters:
        htmlBodyContent - String, that contains raw HTML markup, which is located inside HTML->BODY element (without BODY itself), that should be parsed. Cannot be NULL, empty or invalid.
        resourceFolderPath - Mandatory path to the folder with resources. All stylesheets, which are located in this folder, will be used.


        In general a well-formed HTML document contains an HTML Document Definition (DOCTYPE) and a root HTML element, that, in turn, has two and only two children: HEAD (with document meta-information) and a BODY (with document content). All stylesheets are included and/or embedded in the HEAD element (LINK and/or STYLE elements respectively), and are 'used by' content markup (by using 'class' and 'id' attributes, in most cases). However, most of client-side WYSIWYG HTML-editors like TinyMCE and CKEditor are working only with inner content of BODY element: they can obtain only such markup on input and produce such markup on output. For passing a HTML->BODY markup <i>into</i> the HTML-editor there is a getBodyContent() method. And, in counterpart, for obtaining HTML markup <i>from</i> HTML-editor this method exists. First string parameter obtains an inner content of HTML->BODY element, while 2nd parameter — resourceFolderPath — is a full path to the existing folder, that contains all HTML resources, used by HTML markup. GroupDocs.Editor will scan this folder and include all valid *.css files as stylesheets for the document.
        Returns:
        New non-null instance of EditableDocument
      • fromFile

        public static EditableDocument fromFile(String htmlFilePath,
                                String resourceFolderPath)

        Static factory, that creates an instance of EditableDocument from a HTML file, that is specified by a path to the *.html file itself and a folder with linked resources

        Parameters:
        htmlFilePath - String, that contains a full path to the HTML file. Cannot be null, should be valid file path, and file itself should exists.
        resourceFolderPath - Optional path to the folder with HTML resources. If NULL, invalid or such folder doesn't exist, Editor will try to find the this folder by itself, analyzing the HTML markup
        Returns:
        New non-null instance of EditableDocument
      • fromMarkup

        public static EditableDocument fromMarkup(String newHtmlContent,
                                  List<IHtmlResource> resources)

        Static factory, that creates an instance of EditableDocument from specified HTML markup and a set of corresponding linked resources

        Parameters:
        newHtmlContent - String, that contains raw HTML markup, that should be parsed. Cannot be NULL, empty or invalid.
        resources - Collection of all resources (images, stylesheets, fonts), that are used in the HTML-document, specified in newHtmlContent parameter. May be absent (NULL or empty collection).
        Returns:
        New non-null instance of EditableDocument
      • getAllResources

        public final List<IHtmlResource> getAllResources()

        Returns a list of all existing resources: all stylesheets, images from HTML and all stylesheets, fonts


        This property returns a concatenated result of 'Images', 'Fonts', and 'Css' properties
      • getAllResourcesInternal

        public com.aspose.ms.System.Collections.Generic.List<IHtmlResource> getAllResourcesInternal()
      • getBodyContent

        public final String getBodyContent()

        Returns a body of the HTML document (content between opening and closing BODY tags without these tags) as a string.

        Returns:
        String, which contains the body of the HTML document


        WYSIWYG editors operate with the body of the document and cannot correctly process its meta information from the HEAD block. This method is designed for such cases. This overload doesn't allow to adjust URIs for external resource requests.
      • getBodyContent

        public final String getBodyContent(String externalImagesPrefix)

        Returns a body of the HTML document (content between opening and closing BODY tags without these tags) as a string, where links to the external resources contain specified prefix.

        Parameters:
        externalImagesPrefix - Through this parameter used can specify a prefix, which will be added to the links to all external images in IMG elements, which will be present in the resultant HTML string. If NULL or empty, prefixes will not be added.


        WYSIWYG editors operate with the body of the document and cannot correctly process its meta information from the HEAD block. This method is designed for such cases. This overload allows to adjust URIs for external resource requests.
        Returns:
        String, which contains the body of the HTML document with links, adjusted to the external images
      • getContent

        public final String getContent()

        Returns overall content of the HTML document as a string.

        Returns:
        String, which contains the content of the HTML document
      • getContent

        public final String getContent(String externalImagesPrefix,
                        String externalCssPrefix)

        Returns overall content of the HTML document as a string, where links to the external resources contain specified prefix.

        Parameters:
        externalImagesPrefix - Through this parameter used can specify a prefix, which will be added to the links to all external images in IMG elements, which will be present in the resultant HTML string. If NULL or empty, prefixes will not be added.
        externalCssPrefix - Through this parameter used can specify a prefix, which will be added to the links to all external stylesheets in LINK elements, which will be present in the resultant HTML string. If NULL or empty, prefixes will not be added.
        Returns:
        String, which contains the content of the HTML document with links, adjusted to the external resources
      • getCss

        public final List<CssText> getCss()

        Returns a list of CSS resources

      • getCssContent

        public final List<String> getCssContent()

        Returns content of all external stylesheets as a list of strings, where one string represents one stylesheet. Returns empty list, if there is no CSS for this document.

        Returns:
        A list of strings, where each string holds a content of one CSS document
      • getCssContent

        public final List<String> getCssContent(String externalImagesPrefix,
                                 String externalFontsPrefix)

        Returns content of all external stylesheets as a list of strings, where one string represents one stylesheet. Specified prefix will be applied to every link to the external resource in every resultant stylesheet. Returns empty list, if there is no CSS for this document.

        Parameters:
        externalImagesPrefix - Through this parameter used can specify a prefix, which will be added to the links to all external images, which will be present in CSS declarations in the resultant CSS strings. If NULL or empty, prefixes will not be added.
        externalFontsPrefix - Through this parameter used can specify a prefix, which will be added to the links to all external fonts in the
        Returns:
        A list of strings, where each string holds a content of one CSS document
      • getCssContentInternal

        public com.aspose.ms.System.Collections.Generic.List<String> getCssContentInternal()
      • getCssContentInternal

        public com.aspose.ms.System.Collections.Generic.List<String> getCssContentInternal(String externalImagesPrefix,
                                                                                  String externalFontsPrefix)
      • getCssInternal

        public com.aspose.ms.System.Collections.Generic.List<CssText> getCssInternal()
      • getEmbeddedHtml

        public final String getEmbeddedHtml()

        Returns all content of this HTML document with all related resources in a form of a single string, where all resources are embedded inside the HTML markup in a base64-encoded form.

        Returns:
        String, which is not NULL or empty in any case
        Throws:
        com.aspose.ms.System.ObjectDisposedException - This EditableDocument instance was already disposed


        This method converts this EditableDocument into HTML and serializes in into single string, where all resources are embedded into string along with HTML markup: * All images from HTML->BODY are converted to base64 format and are located in the IMG 'src' attribute; * All stylesheets are stored in the STYLE elements inside HTML->HEAD sections; * All images from stylesheets are converted to base64 format and located in the appropriate CSS declarations; * All fonts from stylesheets are converted to base64 format and located in the appropriate @font-face at-rules.
      • getFonts

        public final List<FontResourceBase> getFonts()

        Allows to obtain external font resources, which are used by this HTML document

      • getFontsInternal

        public com.aspose.ms.System.Collections.Generic.List<FontResourceBase> getFontsInternal()
      • getImages

        public final List<IImageResource> getImages()

        Allows to obtain external image resources (raster images), which are used by this HTML document

      • getImagesInternal

        public com.aspose.ms.System.Collections.Generic.List<IImageResource> getImagesInternal()
      • getOrigin

        public final com.groupdocs.editor.htmlcss.html.HtmlDom getOrigin()

        Returns an original HTML DOM instance

      • getOriginatingType

        public final byte getOriginatingType()

        Returns an originating type of this EditableDocument

      • isDisposed

        public final boolean isDisposed()

        Determines whether this Editable document was already disposed (true) or not (false)

        Specified by:
        isDisposed in interface IAuxDisposable
      • save

        public final void save(String htmlFilePath)

        Saves this HTML document to the file on specified path, where HTML markup will be stored, and to the accompanying folder with resources.

        Parameters:
        htmlFilePath - Full path to the file, where HTML markup will be stored. File will be created or overwritten, if exists. Accompanying resource folder will be created in the same folder, where HTML file exist.
      • save

        public final void save(String htmlFilePath,
                String resourcesFolderPath)

        Saves this HTML document to the file on specified path, where HTML markup will be stored, and to the accompanying folder with resources, which is located on specified path.

        Parameters:
        htmlFilePath - Full path to the file, where HTML markup will be stored. Cannot be NULL or empty. File will be created or overwritten, if exists.
        resourcesFolderPath - Full path to the accompanying folder, where all related resources will be stored. If NULL or empty, folder will be created automatically in the same directory, where *.html file. If specified and not exists, will be created.