Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fn:parse-html and Validator.nu dependency #2258

Merged
merged 17 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions basex-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>nu.validator</groupId>
<artifactId>htmlparser</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
Expand Down
153 changes: 149 additions & 4 deletions basex-core/src/main/java/org/basex/build/html/HtmlOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.basex.util.options.*;

/**
* Options for parsing and serializing HTML documents with TagSoup.
* Options for parsing and serializing HTML documents with TagSoup and Validator.nu.
*
* @author BaseX Team, BSD License
* @author Christian Gruen
Expand Down Expand Up @@ -37,14 +37,56 @@ public final class HtmlOptions extends Options {
/** TagSoup option: lexical. */
public static final BooleanOption LEXICAL = new BooleanOption("lexical", false);

/** TagSoup option: method (html). */
public static final StringOption METHOD = new StringOption("method", "xml");
/** TagSoup option: doctype-system=systemid. */
public static final StringOption DOCTYPE_SYSTEM = new StringOption("doctype-system");
/** TagSoup option: doctype-public=publicid. */
public static final StringOption DOCTYPE_PUBLIC = new StringOption("doctype-public");
/** TagSoup option: encoding=encoding. */

/** Common option: encoding. */
public static final StringOption ENCODING = new StringOption("encoding");
/** Common option: method. */
public static final EnumOption<HtmlParser.Method> METHOD = new EnumOption<>("method",
HtmlParser.Method.class);

/** fn:parse-html option: html-version. */
public static final StringOption HTML_VERSION = new StringOption("html-version");
/** fn:parse-html option: include-template-content. */
public static final BooleanOption INCLUDE_TEMPLATE_CONTENT =
new BooleanOption("include-template-content");

/** Validator.nu option: unicode-normalization-checking. */
public static final BooleanOption UNICODE_NORMALIZATION_CHECKING =
new BooleanOption("unicode-normalization-checking", false);
/** Validator.nu option: mapping-lang-to-xml-lang. */
public static final BooleanOption MAPPING_LANG_TO_XML_LANG =
new BooleanOption("mapping-lang-to-xml-lang", false);
/** Validator.nu option: scripting-enabled. */
public static final BooleanOption SCRIPTING_ENABLED =
new BooleanOption("scripting-enabled", false);
/** Validator.nu option: content-space-policy. */
public static final EnumOption<XmlViolationPolicy> CONTENT_SPACE_POLICY =
new EnumOption<>("content-space-policy", XmlViolationPolicy.class);
/** Validator.nu option: content-non-xml-char-policy. */
public static final EnumOption<XmlViolationPolicy> CONTENT_NON_XML_CHAR_POLICY =
new EnumOption<>("content-non-xml-char-policy", XmlViolationPolicy.class);
/** Validator.nu option: comment-policy. */
public static final EnumOption<XmlViolationPolicy> COMMENT_POLICY =
new EnumOption<>("comment-policy", XmlViolationPolicy.class);
/** Validator.nu option: xmlns-policy. */
public static final EnumOption<XmlViolationPolicy> XMLNS_POLICY =
new EnumOption<>("xmlns-policy", XmlViolationPolicy.class);
/** Validator.nu option: name-policy. */
public static final EnumOption<XmlViolationPolicy> NAME_POLICY =
new EnumOption<>("name-policy", XmlViolationPolicy.class);
/** Validator.nu option: streamability-violation-policy. */
public static final EnumOption<XmlViolationPolicy> STREAMABILITY_VIOLATION_POLICY =
new EnumOption<>("streamability-violation-policy", XmlViolationPolicy.class);
/** Validator.nu option: xml-policy. */
public static final EnumOption<XmlViolationPolicy> XML_POLICY =
new EnumOption<>("xml-policy", XmlViolationPolicy.class);
/** Validator.nu option: heuristics. */
public static final EnumOption<Heuristics> HEURISTICS =
new EnumOption<>("heuristics", Heuristics.class);

/**
* Default constructor.
Expand All @@ -59,4 +101,107 @@ public HtmlOptions() {
public HtmlOptions(final Options opts) {
super(opts);
}

/**
* Copied from nu.validator.htmlparser.common.XmlViolationPolicy in order to avoid the
* class path dependency of HtmlOptions on Validator.nu.
*
* Copyright (c) 2007 Henri Sivonen
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

/**
* Policy for XML 1.0 violations.
*
* @version $Id$
* @author hsivonen
*/
public enum XmlViolationPolicy {
/**
* Conform to HTML 5, allow XML 1.0 to be violated.
*/
ALLOW,

/**
* Halt when something cannot be mapped to XML 1.0.
*/
FATAL,

/**
* Be non-conforming and alter the infoset to fit
* XML 1.0 when something would otherwise not be
* mappable to XML 1.0.
*/
ALTER_INFOSET
}

/**
* Copied from nu.validator.htmlparser.common.XmlViolationPolicy in order to avoid the
* class path dependency of HtmlOptions on Validator.nu.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

/**
* Indicates a request for character encoding sniffer choice.
*
* @version $Id$
* @author hsivonen
*/
public enum Heuristics {

/**
* Perform no heuristic sniffing.
*/
NONE,

/**
* Use both jchardet and ICU4J.
*/
ALL,

/**
* Use jchardet only.
*/
CHARDET,

/**
* Use ICU4J only.
*/
ICU
}

}
Loading