Class XHTMLDocument

All Implemented Interfaces:
CSSDocument, CSSNode, Serializable, Cloneable, Branch, Document, Node, Document, Node, DocumentStyle
Direct Known Subclasses:
DOM4JUserAgent.AgentXHTMLDocumentFactory.AgentXHTMLDocument

public class XHTMLDocument extends DOMDocument implements CSSDocument
XHTML-specific implementation of a DOM4J Document.
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • elementID

      protected String elementID(Element element)
      Overrides:
      elementID in class AbstractBranch
    • getCompatMode

      public String getCompatMode()
      Get the compatibility mode (compatMode) attribute.
      Specified by:
      getCompatMode in interface CSSDocument
      Returns:
      the string "BackCompat" if document’s mode is QUIRKS, otherwise "CSS1Compat".
    • getComplianceMode

      public CSSDocument.ComplianceMode getComplianceMode()
      Description copied from interface: CSSDocument
      Get the compliance mode of this document.

      The styling in this document operate under a compliance mode. Two modes are supported: STRICT and QUIRKS.

      QUIRKS and STRICT differ in the matching of class and ID selectors, and the default user agent sheet is slightly different.

      Specified by:
      getComplianceMode in interface CSSDocument
      Returns:
      the compliance mode.
    • getOwnerDocument

      public XHTMLDocument getOwnerDocument()
      Description copied from interface: CSSNode
      Specified by:
      getOwnerDocument in interface CSSNode
      Specified by:
      getOwnerDocument in interface Node
      Overrides:
      getOwnerDocument in class DOMDocument
    • getDocumentElement

      public XHTMLElement getDocumentElement()
      Description copied from interface: CSSDocument
      Get the child node which is the document element of this document.
      Specified by:
      getDocumentElement in interface CSSDocument
      Specified by:
      getDocumentElement in interface Document
      Overrides:
      getDocumentElement in class DOMDocument
      Returns:
      the document element.
    • getElementById

      public XHTMLElement getElementById(String elementId)
      Description copied from interface: CSSDocument
      Specified by:
      getElementById in interface CSSDocument
      Specified by:
      getElementById in interface Document
      Overrides:
      getElementById in class DOMDocument
    • createElement

      public XHTMLElement createElement(String name) throws DOMException
      Description copied from interface: CSSDocument
      Creates an element of the type specified.

      The presence of IMPLIED attributes is implementation-dependent.

      Specified by:
      createElement in interface CSSDocument
      Specified by:
      createElement in interface Document
      Overrides:
      createElement in class DOMDocument
      Parameters:
      name - the tag name of the element to create.
      Returns:
      the new CSSElement.
      Throws:
      DOMException - INVALID_CHARACTER_ERR if the name is not an XML valid name.
    • createElementNS

      public XHTMLElement createElementNS(String namespaceURI, String qualifiedName) throws DOMException
      Description copied from interface: CSSDocument
      Specified by:
      createElementNS in interface CSSDocument
      Specified by:
      createElementNS in interface Document
      Overrides:
      createElementNS in class DOMDocument
      Throws:
      DOMException
    • setUserData

      public Object setUserData(String key, Object data, UserDataHandler handler)
      Specified by:
      setUserData in interface Node
      Overrides:
      setUserData in class DOMDocument
    • getInputEncoding

      public String getInputEncoding()
      Give the encoding used when the document was parsed, if known.
      Specified by:
      getInputEncoding in interface Document
      Overrides:
      getInputEncoding in class DOMDocument
      Returns:
      null.
    • getFeature

      @Deprecated public Object getFeature(String feature, String version)
      Deprecated.
      Specified by:
      getFeature in interface Node
      Overrides:
      getFeature in class DOMDocument
    • getStrictErrorChecking

      @Deprecated public boolean getStrictErrorChecking()
      Deprecated.
      Specified by:
      getStrictErrorChecking in interface Document
      Overrides:
      getStrictErrorChecking in class DOMDocument
    • setStrictErrorChecking

      @Deprecated public void setStrictErrorChecking(boolean strictErrorChecking)
      Deprecated.
      Specified by:
      setStrictErrorChecking in interface Document
      Overrides:
      setStrictErrorChecking in class DOMDocument
    • normalizeDocument

      @Deprecated public void normalizeDocument()
      Deprecated.
      Specified by:
      normalizeDocument in interface Document
      Overrides:
      normalizeDocument in class DOMDocument
    • getXmlEncoding

      @Deprecated public String getXmlEncoding()
      Deprecated.
      Now deprecated, this method gave the encoding specified at the XML declaration.
      Specified by:
      getXmlEncoding in interface Document
      Overrides:
      getXmlEncoding in class DOMDocument
      Returns:
      null.
    • getXmlStandalone

      @Deprecated public boolean getXmlStandalone()
      Deprecated.
      Get whether this document is standalone as specified at the XML declaration.
      Specified by:
      getXmlStandalone in interface Document
      Overrides:
      getXmlStandalone in class DOMDocument
      Returns:
      null.
    • getXmlVersion

      @Deprecated public String getXmlVersion()
      Deprecated.
      Get the version for the "XML" feature.
      Specified by:
      getXmlVersion in interface Document
      Overrides:
      getXmlVersion in class DOMDocument
      Returns:
      null.
    • registerProperty

      public void registerProperty(CSSPropertyDefinition definition)
      Description copied from interface: CSSDocument
      Registers the definition of a custom property.
      Specified by:
      registerProperty in interface CSSDocument
      Parameters:
      definition - the definition.
      See Also:
    • getStyleSheets

      public StyleSheetList getStyleSheets()
      A list containing all the style sheets explicitly linked into or embedded in a document. For HTML documents, this includes external style sheets, included via the HTML LINK element, and inline STYLE elements. In XML, this includes external style sheets, included via style sheet processing instructions (see [XML StyleSheet]).
      Specified by:
      getStyleSheets in interface CSSDocument
      Specified by:
      getStyleSheets in interface DocumentStyle
    • getStyleSheet

      public DocumentCSSStyleSheet getStyleSheet()
      Gets the merged style sheet that applies to this document, resulting from the merge of the document's default style sheet, the document linked or embedded style sheets, and the non-important part of the user style sheet. Does not include overriden styles nor the 'important' part of the user-defined style sheet.

      The style sheet is lazily built.

      Specified by:
      getStyleSheet in interface CSSDocument
      Returns:
      the merged style sheet that applies to this document.
    • addStyleSheet

      public boolean addStyleSheet(InputSource cssSrc) throws DOMException, IOException
      Adds a style sheet (contained by the given InputSource) to the global style sheet defined by the document's default style sheet and all the linked and embedded styles.
      Parameters:
      cssSrc - the document's InputSource.
      Returns:
      true if the parsing reported no errors or fatal errors, false otherwise.
      Throws:
      DOMException - if a DOM problem is found parsing the sheet.
      IOException - if a problem is found reading the sheet.
    • getStyleSheetSets

      public DOMStringList getStyleSheetSets()
      Gets the list of available alternate styles.
      Specified by:
      getStyleSheetSets in interface CSSDocument
      Returns:
      the list of available alternate style titles.
    • getSelectedStyleSheetSet

      public String getSelectedStyleSheetSet()
      Gets the title of the currently selected style sheet set.
      Specified by:
      getSelectedStyleSheetSet in interface CSSDocument
      Returns:
      the title of the currently selected style sheet, the empty string if none is selected, or null if there are style sheets from different style sheet sets that have their style sheet disabled flag unset.
    • setSelectedStyleSheetSet

      public void setSelectedStyleSheetSet(String name)
      Selects a style sheet set, disabling the other non-persistent sheet sets. If the name is the empty string, all non-persistent sheets will be disabled. Otherwise, if the name does not match any of the sets, does nothing.
      Specified by:
      setSelectedStyleSheetSet in interface CSSDocument
      Parameters:
      name - the case-sensitive name of the set to select.
    • getLastStyleSheetSet

      public String getLastStyleSheetSet()
      Gets the style sheet set that was last selected.
      Specified by:
      getLastStyleSheetSet in interface CSSDocument
      Returns:
      the last selected style sheet set, or null if none.
    • enableStyleSheetsForSet

      public void enableStyleSheetsForSet(String name)
      Enables a style sheet set. If the name does not match any of the sets, does nothing.
      Specified by:
      enableStyleSheetsForSet in interface CSSDocument
      Parameters:
      name - the case-sensitive name of the set to enable.
    • getStyleDatabase

      public StyleDatabase getStyleDatabase()
      Gets the style database currently used to apply specific styles to this document.
      Specified by:
      getStyleDatabase in interface CSSDocument
      Returns:
      the style database, or null if no style database has been selected.
    • getTargetMedium

      public String getTargetMedium()
      This document's current target medium name.
      Specified by:
      getTargetMedium in interface CSSDocument
      Returns:
      the target medium name of this document.
    • setTargetMedium

      public void setTargetMedium(String medium) throws CSSMediaException
      Set the medium that will be used to compute the styles of this document.
      Specified by:
      setTargetMedium in interface CSSDocument
      Parameters:
      medium - the name of the target medium, like 'screen' or 'print'.
      Throws:
      CSSMediaException - if the document is unable to target the given medium.
    • getCanvas

      public CSSCanvas getCanvas()
      Gets the document's canvas for the current target medium.
      Specified by:
      getCanvas in interface CSSDocument
      Returns:
      the canvas, or null if no target medium has been set, or the DeviceFactory does not support canvas for the target medium.
    • rebuildCascade

      public void rebuildCascade()
      Description copied from interface: CSSDocument
      Forces the cascade to be rebuilt the next time that a computed style is obtained.

      This method should be called after you modify the styles in a way that is not detected by the library (like modifying a value).

      Specified by:
      rebuildCascade in interface CSSDocument
    • getDocumentFactory

      protected XHTMLDocumentFactory getDocumentFactory()
      Overrides:
      getDocumentFactory in class DOMDocument
    • createErrorHandler

      protected ErrorHandler createErrorHandler()
    • getErrorHandler

      public ErrorHandler getErrorHandler()
      Description copied from interface: CSSDocument
      Gets the document-level error handler.
      Specified by:
      getErrorHandler in interface CSSDocument
      Returns:
      the error handler.
    • hasStyleIssues

      public boolean hasStyleIssues()
      Has any of the linked or embedded style sheets any error or warning ?
      Specified by:
      hasStyleIssues in interface CSSDocument
      Returns:
      true if any of the linked or embedded style sheets has any NSAC or rule error or warning, false otherwise.
    • onMetaAdded

      public void onMetaAdded(String name, String attribute)
    • onMetaRemoved

      public void onMetaRemoved(String name, String attribute)
    • getBaseURL

      public URL getBaseURL()
      Gets the base URL of this Document.

      If the Document's head element has a base child element, the base URI is computed using the value of the href attribute of the base element. It can also be set with the setBaseURL method.

      Specified by:
      getBaseURL in interface CSSDocument
      Returns:
      the base URL, or null if no base URL could be found.
    • getBaseURI

      public String getBaseURI()
      Gets the absolute base URI of this node.
      Specified by:
      getBaseURI in interface Node
      Overrides:
      getBaseURI in class DOMDocument
      Returns:
      the absolute base URI of this node, or null if an absolute URI could not be obtained.
    • setBaseURL

      public void setBaseURL(URL baseURL)
      Sets the Base URL of this Document.
      Parameters:
      baseURL - the base URL.
    • getURL

      public URL getURL(String uri) throws MalformedURLException
      Gets an URL for the given URI, taking into account the Base URL if appropriate.
      Specified by:
      getURL in interface CSSDocument
      Parameters:
      uri - the uri.
      Returns:
      the absolute URL.
      Throws:
      MalformedURLException - if the uri was wrong.
    • isSafeOrigin

      public boolean isSafeOrigin(URL linkedURL)
      Is the provided URL a safe origin to load certain external resources?
      Specified by:
      isSafeOrigin in interface CSSDocument
      Parameters:
      linkedURL - the URL of the external resource.
      Returns:
      true if is a safe origin, false otherwise.
    • isAuthorizedOrigin

      public boolean isAuthorizedOrigin(URL url)
      Determine whether the retrieval of the given URL is authorized.

      If the URL's protocol is not http nor https and document's base URL's scheme is neither file nor jar, it is denied.

      Specified by:
      isAuthorizedOrigin in interface CSSDocument
      Parameters:
      url - the URL to check.
      Returns:
      true if allowed.
    • getReferrerPolicy

      public String getReferrerPolicy()
      Get the referrer policy obtained through the 'Referrer-Policy' header or a meta element.
      Specified by:
      getReferrerPolicy in interface CSSDocument
      Returns:
      the referrer policy, or the empty string if none was specified.
    • setReferrerPolicyHeader

      protected void setReferrerPolicyHeader(String policy)
    • setDocumentURI

      public void setDocumentURI(String documentURI)
      Specified by:
      setDocumentURI in interface Document
      Overrides:
      setDocumentURI in class DOMDocument
    • getDocumentURI

      public String getDocumentURI()
      Specified by:
      getDocumentURI in interface Document
      Overrides:
      getDocumentURI in class DOMDocument
    • openConnection

      public URLConnection openConnection(URL url) throws IOException
      Opens a connection for the given URL.
      Specified by:
      openConnection in interface CSSDocument
      Parameters:
      url - the URL to open a connection to.
      Returns:
      the URL connection.
      Throws:
      IOException - if the connection could not be opened.
    • openStream

      public InputStream openStream(String uri) throws IOException
      Opens an InputStream for the given URI, taking into account the Base URL if needed.
      Parameters:
      uri - the uri to open a connection.
      Returns:
      the InputStream.
      Throws:
      IOException - if the uri was wrong, or the stream could not be opened.
    • isVisitedURI

      public boolean isVisitedURI(String href)
      Description copied from interface: CSSDocument
      Has this URI been visited by the agent ?
      Specified by:
      isVisitedURI in interface CSSDocument
      Parameters:
      href - the URI.
      Returns:
      true if visited, false if not visited or the agent does not support history.