本文整理匯總了Java中org.w3c.dom.DOMImplementation.getFeature方法的典型用法代碼示例。如果您正苦於以下問題:Java DOMImplementation.getFeature方法的具體用法?Java DOMImplementation.getFeature怎麽用?Java DOMImplementation.getFeature使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.DOMImplementation
的用法示例。
在下文中一共展示了DOMImplementation.getFeature方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.newDocument();
DOMImplementation impl = document.getImplementation();
DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");
LSSerializer dsi = implLS.createLSSerializer();
/* We should have here incorrect document without getXmlVersion() method:
* Such Document is generated by replacing the JDK bootclasses with it's
* own Node,Document and DocumentImpl classes (see run.sh). According to
* XERCESJ-1007 the AbstractMethodError should be thrown in such case.
*/
String result = dsi.writeToString(document);
System.out.println("Result:" + result);
}
示例2: toXml
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
public static String toXml(Document domDoc) throws TransformerException {
DOMImplementation domImplementation = domDoc.getImplementation();
if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) {
DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0");
LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
if (domConfiguration.canSetParameter("xml-declaration", Boolean.TRUE))
lsSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) {
lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
LSOutput lsOutput = domImplementationLS.createLSOutput();
lsOutput.setEncoding("UTF-8");
StringWriter stringWriter = new StringWriter();
lsOutput.setCharacterStream(stringWriter);
lsSerializer.write(domDoc, lsOutput);
return stringWriter.toString();
}
}
return toXml((Node)domDoc);
}
示例3: main
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception
{
ArrayList<LineItem> items = new ArrayList<>();
items.add(new LineItem(new Product("Toaster", 29.95), 3));
items.add(new LineItem(new Product("Hair dryer", 24.95), 1));
ItemListBuilder builder = new ItemListBuilder();
Document doc = builder.build(items);
DOMImplementation impl = doc.getImplementation();
DOMImplementationLS implLS
= (DOMImplementationLS) impl.getFeature("LS", "3.0");
LSSerializer ser = implLS.createLSSerializer();
String out = ser.writeToString(doc);
System.out.println(out);
}
示例4: resolveResource
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
public LSInput resolveResource(String type,
String namespaceURI,
String publicId,
String systemId,
String baseURI) {
LSInput lsi = mDelegate.resolveResource(type, namespaceURI, publicId, systemId, baseURI);
if (lsi == null) {
//if we can not get an input from catalog, then it could that
//there as a schema in types section which refer to schema compoment from other inline schema
//so we try to check in other inline schema.
WSDLSchema schema = findSchema(namespaceURI);
if(schema != null) {
Reader in = createInlineSchemaSource(mWsdlText, mWsdlPrefixes, mWsdlLinePositions, schema);
if(in != null) {
//create LSInput object
DOMImplementation domImpl = null;
try {
domImpl = DocumentBuilderFactory.newInstance().newDocumentBuilder().getDOMImplementation();
} catch (ParserConfigurationException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "resolveResource", ex); //NOI18N
return null;
}
DOMImplementationLS dols = (DOMImplementationLS) domImpl.getFeature("LS","3.0");
lsi = dols.createLSInput();
lsi.setCharacterStream(in);
if(mWsdlSystemId != null) {
lsi.setSystemId(mWsdlSystemId);
}
return lsi;
}
}
}
return lsi;
}
示例5: getLSDOMImpl
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
/**
* Get the DOM Level 3 Load/Save {@link DOMImplementationLS} for the given node.
*
* @param node the node to evaluate
* @return the DOMImplementationLS for the given node
*/
public static DOMImplementationLS getLSDOMImpl(Node node) {
DOMImplementation domImpl;
if (node instanceof Document) {
domImpl = ((Document) node).getImplementation();
} else {
domImpl = node.getOwnerDocument().getImplementation();
}
DOMImplementationLS domImplLS = (DOMImplementationLS) domImpl.getFeature("LS", "3.0");
return domImplLS;
}
示例6: prettyPrint
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
public void prettyPrint() {
final String xml = xmlPane.getText();
final InputSource src = new InputSource(new StringReader(xml));
org.w3c.dom.Document document;
try {
document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src);
} catch (SAXException | IOException | ParserConfigurationException e) {
return;
}
final Pattern p = Pattern.compile("^<\\?xml.*\\?>");
final Matcher m = p.matcher(xml);
final String xmlDecl = (m.find()) ? m.group() : "";
// Pretty-prints a DOM document to XML using DOM Load and Save's LSSerializer.
// Note that the "format-pretty-print" DOM configuration parameter can only be set in JDK 1.6+.
final DOMImplementation domImplementation = document.getImplementation();
if (!domImplementation.hasFeature("LS", "3.0") || !domImplementation.hasFeature("Core", "2.0")) {
return;
}
final DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0");
final LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
final DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
if (domConfiguration.canSetParameter("format-pretty-print", true)) {
domConfiguration.setParameter("format-pretty-print", true);
}
if (domConfiguration.canSetParameter("xml-declaration", false)) {
domConfiguration.setParameter("xml-declaration", false);
}
final LSOutput lsOutput = domImplementationLS.createLSOutput();
lsOutput.setEncoding("UTF-8");
final StringWriter stringWriter = new StringWriter();
if (!xmlDecl.isEmpty()) {
stringWriter.write(xmlDecl);
stringWriter.write("\n");
}
lsOutput.setCharacterStream(stringWriter);
lsSerializer.write(document, lsOutput);
final String xmlOut = stringWriter.toString();
xmlPane.setText(xmlOut);
}
示例7: testDOMErrorHandler
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
@Test
public void testDOMErrorHandler() {
final String XML_DOCUMENT = "<?xml version=\"1.0\"?>" + "<hello>" + "world" + "</hello>";
StringReader stringReader = new StringReader(XML_DOCUMENT);
InputSource inputSource = new InputSource(stringReader);
Document doc = null;
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
// LSSerializer defaults to Namespace processing
// so parsing must also
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder parser = documentBuilderFactory.newDocumentBuilder();
doc = parser.parse(inputSource);
} catch (Throwable e) {
e.printStackTrace();
Assert.fail(e.toString());
}
DOMImplementation impl = doc.getImplementation();
DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");
LSSerializer writer = implLS.createLSSerializer();
System.out.println("Serializer is: " + implLS.getClass().getName() + " " + implLS);
DOMErrorHandlerImpl eh = new DOMErrorHandlerImpl();
writer.getDomConfig().setParameter("error-handler", eh);
boolean serialized = false;
try {
serialized = writer.write(doc, new Output());
// unexpected success
Assert.fail("Serialized without raising an LSException due to " + "'no-output-specified'.");
} catch (LSException lsException) {
// expected exception
System.out.println("Expected LSException: " + lsException.toString());
// continue processing
}
Assert.assertFalse(serialized, "Expected writer.write(doc, new Output()) == false");
Assert.assertTrue(eh.NoOutputSpecifiedErrorReceived, "'no-output-specified' error was expected");
}
示例8: testDOMConfiguration
import org.w3c.dom.DOMImplementation; //導入方法依賴的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());
}
}
}
示例9: testCheckCharNorm001
import org.w3c.dom.DOMImplementation; //導入方法依賴的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");
}
示例10: testCheckCharNorm002
import org.w3c.dom.DOMImplementation; //導入方法依賴的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");
}