本文整理汇总了Java中org.w3c.dom.ls.LSParser.getDomConfig方法的典型用法代码示例。如果您正苦于以下问题:Java LSParser.getDomConfig方法的具体用法?Java LSParser.getDomConfig怎么用?Java LSParser.getDomConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.ls.LSParser
的用法示例。
在下文中一共展示了LSParser.getDomConfig方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.w3c.dom.ls.LSParser; //导入方法依赖的package包/类
private static Document parse(LSInput input, boolean validateIfSchema) {
DOMImplementationLS impl = getDOMImpl();
LSParser parser = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
DOMConfiguration config = parser.getDomConfig();
config.setParameter("element-content-whitespace", false);
config.setParameter("namespaces", true);
config.setParameter("validate-if-schema", validateIfSchema);
return parser.parse(input);
}
示例2: testDOMConfiguration
import org.w3c.dom.ls.LSParser; //导入方法依赖的package包/类
@Test
public void testDOMConfiguration() {
final DOMErrorHandler handler = new DOMErrorHandler() {
public boolean handleError(final DOMError error) {
return false;
}
};
final LSResourceResolver resolver = new LSResourceResolver() {
public LSInput resolveResource(final String type, final String namespaceURI, final String publicId, final String systemId, final String baseURI) {
return null;
}
};
final Object[][] values = {
// parameter, value
{ "canonical-form", Boolean.FALSE }, { "cdata-sections", Boolean.FALSE }, { "cdata-sections", Boolean.TRUE },
{ "check-character-normalization", Boolean.FALSE }, { "comments", Boolean.FALSE }, { "comments", Boolean.TRUE },
{ "datatype-normalization", Boolean.FALSE }, { "entities", Boolean.FALSE }, { "entities", Boolean.TRUE }, { "error-handler", handler },
{ "infoset", Boolean.TRUE }, { "namespaces", Boolean.TRUE }, { "namespace-declarations", Boolean.TRUE },
{ "namespace-declarations", Boolean.FALSE }, { "normalize-characters", Boolean.FALSE }, { "split-cdata-sections", Boolean.TRUE },
{ "split-cdata-sections", Boolean.FALSE }, { "validate", Boolean.FALSE }, { "validate-if-schema", Boolean.FALSE },
{ "well-formed", Boolean.TRUE }, { "element-content-whitespace", Boolean.TRUE },
{ "charset-overrides-xml-encoding", Boolean.TRUE }, { "charset-overrides-xml-encoding", Boolean.FALSE }, { "disallow-doctype", Boolean.FALSE },
{ "ignore-unknown-character-denormalizations", Boolean.TRUE }, { "resource-resolver", resolver }, { "resource-resolver", null },
{ "supported-media-types-only", Boolean.FALSE }, };
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException parserConfigurationException) {
parserConfigurationException.printStackTrace();
Assert.fail(parserConfigurationException.toString());
}
DOMImplementationLS lsImpl = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");
LSParser lsParser = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
DOMConfiguration config = lsParser.getDomConfig();
for (int i = values.length; --i >= 0;) {
Object val = values[i][1];
String param = (String) values[i][0];
try {
config.setParameter(param, val);
Object returned = config.getParameter(param);
Assert.assertEquals(val, returned, "'" + param + "' is set to " + returned + ", but expected " + val);
System.out.println("set '" + param + "'" + " to '" + val + "'" + " and returned '" + returned + "'");
} catch (DOMException e) {
String settings = "setting '" + param + "' to " + val;
System.err.println(settings);
e.printStackTrace();
Assert.fail(settings + ", " + e.toString());
}
}
}
示例3: testCheckCharNorm001
import org.w3c.dom.ls.LSParser; //导入方法依赖的package包/类
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: the root element has one Text node with not fully
* normalized characters, the 'check-character-normalization' parameter set
* to true, <br>
* <b>name</b>: error-handler <br>
* <b>value</b>: DOMErrorHandler. <br>
* <b>Expected results</b>: LSParser calls the specified error handler
*/
@Test
public void testCheckCharNorm001() {
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException pce) {
Assert.fail(pce.toString());
} catch (FactoryConfigurationError fce) {
Assert.fail(fce.toString());
}
DOMImplementationLS lsImpl = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");
if (lsImpl == null) {
System.out.println("OK, the DOM implementation does not support the LS 3.0");
return;
}
LSParser lsParser = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
DOMConfiguration config = lsParser.getDomConfig();
if (!config.canSetParameter("check-character-normalization", Boolean.TRUE)) {
System.out.println("OK, setting 'check-character-normalization' to true is not supported");
return;
}
config.setParameter("check-character-normalization", Boolean.TRUE);
TestHandler testHandler = new TestHandler();
config.setParameter("error-handler", testHandler);
LSInput lsInput = lsImpl.createLSInput();
lsInput.setStringData("<root>\u0073\u0075\u0063\u0327\u006F\u006E</root>");
Document doc = lsParser.parse(lsInput);
if (null == testHandler.getError()) {
Assert.fail("no error is reported, expected 'check-character-normalization-failure'");
}
return; // Status.passed("OK");
}
示例4: testCheckCharNorm002
import org.w3c.dom.ls.LSParser; //导入方法依赖的package包/类
/**
* Equivalence class partitioning with state and input values orientation
* for public void setParameter(String name, Object value) throws
* DOMException, <br>
* <b>pre-conditions</b>: the root element contains a fully-normalized text, <br>
* <b>name</b>: check-character-normalization <br>
* <b>value</b>: false. <br>
* <b>Expected results</b>: LSParser reports no errors
*/
@Test
public void testCheckCharNorm002() {
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException pce) {
Assert.fail(pce.toString());
} catch (FactoryConfigurationError fce) {
Assert.fail(fce.toString());
}
DOMImplementationLS lsImpl = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");
if (lsImpl == null) {
System.out.println("OK, the DOM implementation does not support the LS 3.0");
return;
}
LSParser lsParser = lsImpl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
DOMConfiguration config = lsParser.getDomConfig();
if (!config.canSetParameter("check-character-normalization", Boolean.FALSE)) {
Assert.fail("setting 'check-character-normalization' to false is not supported");
}
config.setParameter("check-character-normalization", Boolean.FALSE);
TestHandler testHandler = new TestHandler();
config.setParameter("error-handler", testHandler);
LSInput lsInput = lsImpl.createLSInput();
lsInput.setStringData("<root>fully-normalized</root>");
Document doc = lsParser.parse(lsInput);
if (null != testHandler.getError()) {
Assert.fail("no error is expected, but reported: " + testHandler.getError());
}
return; // Status.passed("OK");
}