Package com.google.gerrit.httpd
Class HtmlDomUtil
java.lang.Object
com.google.gerrit.httpd.HtmlDomUtil
Utility functions to deal with HTML using W3C DOM operations.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Append an HTML <input type="hidden"> to the form.attachNonce
(String html, String nonce) Attaches nonce to all script elements in html.static Document
Clone a document so it can be safely modified on a per-request basis.static byte[]
compress
(byte[] raw) Compress the document.static Element
Find an element by its "id" attribute; null if no element is found.static Document
Construct a new empty document.static Document
Parse an XHTML file from our CLASSPATH and return the instance.static Document
Parse an XHTML file from the local drive and return the instance.static String
Read a Read a UTF-8 text file from our CLASSPATH and return it.static String
Read a UTF-8 text file from the local drive.static String
Convert a document to a String, assuming later encoding to UTF-8.static byte[]
Convert a document to a UTF-8 byte sequence.
-
Field Details
-
ENC
Standard character encoding we prefer (UTF-8). -
HTML_STRICT
DOCTYPE for a standards mode HTML document.- See Also:
-
-
Constructor Details
-
HtmlDomUtil
public HtmlDomUtil()
-
-
Method Details
-
toUTF8
Convert a document to a UTF-8 byte sequence.- Throws:
IOException
-
compress
Compress the document.- Throws:
IOException
-
toString
Convert a document to a String, assuming later encoding to UTF-8.- Throws:
IOException
-
find
Find an element by its "id" attribute; null if no element is found. -
addHidden
Append an HTML <input type="hidden"> to the form. -
newDocument
Construct a new empty document. -
clone
Clone a document so it can be safely modified on a per-request basis.- Throws:
IOException
-
parseFile
Parse an XHTML file from our CLASSPATH and return the instance.- Throws:
IOException
-
readFile
Read a Read a UTF-8 text file from our CLASSPATH and return it.- Throws:
IOException
-
parseFile
Parse an XHTML file from the local drive and return the instance.- Throws:
IOException
-
readFile
Read a UTF-8 text file from the local drive.- Throws:
IOException
-
attachNonce
Attaches nonce to all script elements in html.The returned html is not guaranteed to have the same formatting as the input.
- Returns:
- Updated html or {#link Optional.empty()} if parsing failed.
-