本文整理汇总了Java中org.w3c.dom.bootstrap.DOMImplementationRegistry.getDOMImplementation方法的典型用法代码示例。如果您正苦于以下问题:Java DOMImplementationRegistry.getDOMImplementation方法的具体用法?Java DOMImplementationRegistry.getDOMImplementation怎么用?Java DOMImplementationRegistry.getDOMImplementation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.bootstrap.DOMImplementationRegistry
的用法示例。
在下文中一共展示了DOMImplementationRegistry.getDOMImplementation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String format = "javax_imageio_1.0";
BufferedImage img =
new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
ImageWriter iw = ImageIO.getImageWritersByMIMEType("image/png").next();
IIOMetadata meta =
iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
DOMImplementationRegistry registry;
registry = DOMImplementationRegistry.newInstance();
DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
Document doc = impl.createDocument(null, format, null);
Element root, text, entry;
root = doc.getDocumentElement();
root.appendChild(text = doc.createElement("Text"));
text.appendChild(entry = doc.createElement("TextEntry"));
// keyword isn't #REQUIRED by the standard metadata format.
// However, it is required by the PNG format, so we include it here.
entry.setAttribute("keyword", "Comment");
entry.setAttribute("value", "Some demo comment");
meta.mergeTree(format, root);
}
示例2: testCreateNewItem2Sell
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
/**
* Check for DOMErrorHandler handling DOMError. Before fix of bug 4890927
* DOMConfiguration.setParameter("well-formed",true) throws an exception.
*
* @throws Exception If any errors occur.
*/
@Test
public void testCreateNewItem2Sell() throws Exception {
String xmlFile = XML_DIR + "novelsInvalid.xml";
Document document = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(xmlFile);
document.getDomConfig().setParameter("well-formed", true);
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
MyDOMOutput domOutput = new MyDOMOutput();
domOutput.setByteStream(System.out);
LSSerializer writer = impl.createLSSerializer();
writer.write(document, domOutput);
}
示例3: testCreateNewItem2Sell
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
/**
* Check for DOMErrorHandler handling DOMError. Before fix of bug 4890927
* DOMConfiguration.setParameter("well-formed",true) throws an exception.
*
* @throws Exception If any errors occur.
*/
@Test(groups = {"readLocalFiles"})
public void testCreateNewItem2Sell() throws Exception {
String xmlFile = XML_DIR + "novelsInvalid.xml";
Document document = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(xmlFile);
document.getDomConfig().setParameter("well-formed", true);
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
MyDOMOutput domOutput = new MyDOMOutput();
domOutput.setByteStream(System.out);
LSSerializer writer = impl.createLSSerializer();
writer.write(document, domOutput);
}
示例4: marshall
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
/**
* `
* Serialize XML objects
*
* @param xmlObject : XACML or SAML objects to be serialized
* @return serialized XACML or SAML objects
* @throws EntitlementException
*/
private String marshall(XMLObject xmlObject) throws EntitlementException {
try {
doBootstrap();
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
"org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
Marshaller marshaller = marshallerFactory.getMarshaller(xmlObject);
Element element = marshaller.marshall(xmlObject);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl =
(DOMImplementationLS) registry.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
LSOutput output = impl.createLSOutput();
output.setByteStream(byteArrayOutputStream);
writer.write(element, output);
return byteArrayOutputStream.toString();
} catch (Exception e) {
log.error("Error Serializing the SAML Response");
throw new EntitlementException("Error Serializing the SAML Response", e);
}
}
示例5: marshall
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
/**
* Serializes the specified SAML 2.0 based XML content representation to its corresponding actual XML syntax
* representation.
*
* @param xmlObject the SAML 2.0 based XML content object
* @return a {@link String} representation of the actual XML representation of the SAML 2.0 based XML content
* representation
* @throws SSOException if an error occurs during the marshalling process
*/
public static String marshall(XMLObject xmlObject) throws SSOException {
try {
Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(xmlObject);
Element element = null;
if (marshaller != null) {
element = marshaller.marshall(xmlObject);
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS implementation = (DOMImplementationLS) registry.getDOMImplementation("LS");
LSSerializer writer = implementation.createLSSerializer();
LSOutput output = implementation.createLSOutput();
output.setByteStream(byteArrayOutputStream);
writer.write(element, output);
return new String(byteArrayOutputStream.toByteArray(), StandardCharsets.UTF_8);
} catch (ClassNotFoundException | InstantiationException | MarshallingException | IllegalAccessException e) {
throw new SSOException("Error in marshalling SAML 2.0 Assertion", e);
}
}
示例6: DomDocumentBuilderFactory
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
public DomDocumentBuilderFactory()
{
try
{
DOMImplementationRegistry reg =
DOMImplementationRegistry.newInstance();
impl = reg.getDOMImplementation("LS 3.0");
if (impl == null)
{
throw new FactoryConfigurationError("no LS implementations found");
}
ls = (DOMImplementationLS) impl;
}
catch (Exception e)
{
throw new FactoryConfigurationError(e);
}
}
示例7: format
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
public static String format(String xml) {
try {
final InputSource src = new InputSource(new StringReader(xml));
final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
final Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("<?xml"));
//May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
final LSSerializer writer = impl.createLSSerializer();
writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.
return writer.writeToString(document);
} catch (Exception e) {
return xml;
}
}
示例8: transformNonTextNodeToOutputStream
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
/**
* Serializes a node using a certain character encoding.
*
* @param node
* DOM node to serialize
* @param os
* output stream, to which the node is serialized
* @param omitXmlDeclaration
* indicator whether to omit the XML declaration or not
* @param encoding
* character encoding, can be <code>null</code>, if
* <code>null</code> then "UTF-8" is used
* @throws Exception
*/
public static void transformNonTextNodeToOutputStream(Node node, OutputStream os, boolean omitXmlDeclaration, String encoding)
throws Exception { //NOPMD
// previously we used javax.xml.transform.Transformer, however the JDK xalan implementation did not work correctly with a specified encoding
// therefore we switched to DOMImplementationLS
if (encoding == null) {
encoding = "UTF-8";
}
DOMImplementationRegistry domImplementationRegistry = DOMImplementationRegistry.newInstance();
DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementationRegistry.getDOMImplementation("LS");
LSOutput lsOutput = domImplementationLS.createLSOutput();
lsOutput.setEncoding(encoding);
lsOutput.setByteStream(os);
LSSerializer lss = domImplementationLS.createLSSerializer();
lss.getDomConfig().setParameter("xml-declaration", !omitXmlDeclaration);
lss.write(node, lsOutput);
}
示例9: formatHtml
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
protected String formatHtml(String html) throws MojoExecutionException {
try {
InputSource src = new InputSource(new StringReader(html));
Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
Boolean keepDeclaration = Boolean.valueOf(html.startsWith("<?xml"));
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
writer.getDomConfig().setParameter("xml-declaration", keepDeclaration);
return writer.writeToString(document);
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
示例10: testEvent
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
public void testEvent() throws Exception {
//URL url = ResourceLoader.resolveClassPathOrURLResource("schema", "regression/typeTestSchema.xsd");
URL url = ResourceLoader.resolveClassPathOrURLResource("schema", "regression/simpleSchema.xsd", this.getClass().getClassLoader());
String uri = url.toURI().toString();
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
registry.addSource(new DOMXSImplementationSourceImpl());
XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader");
XSLoader schemaLoader = impl.createXSLoader(null);
XSModel xsModel = schemaLoader.loadURI(uri);
XSNamedMap elements = xsModel.getComponents(XSConstants.ELEMENT_DECLARATION);
for (int i = 0; i < elements.getLength(); i++) {
XSObject object = elements.item(i);
//System.out.println("name '" + object.getName() + "' namespace '" + object.getNamespace());
}
XSElementDeclaration dec = (XSElementDeclaration) elements.item(0);
XSComplexTypeDefinition complexActualElement = (XSComplexTypeDefinition) dec.getTypeDefinition();
printSchemaDef(complexActualElement, 2);
}
示例11: indentXML
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
/**
* Method to generated idented XML
* Credit: Steve McLeod and DaoWen.
* Code from http://stackoverflow.com/a/11519668
* @param xml input xml in string format
* @return indented xml in string format
*/
public static String indentXML(String xml) {
try {
final InputSource src = new InputSource(new StringReader(xml));
final Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement();
final Boolean keepDeclaration = xml.startsWith("<?xml");
//May need this: System.setProperty(DOMImplementationRegistry.PROPERTY,"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS");
final LSSerializer writer = impl.createLSSerializer();
writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified.
writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted.
return writer.writeToString(document);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例12: XSParser
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
public XSParser(LSResourceResolver entityResolver, DOMErrorHandler errorHandler){
System.setProperty(DOMImplementationRegistry.PROPERTY, DOMXSImplementationSourceImpl.class.getName());
DOMImplementationRegistry registry;
try{
registry = DOMImplementationRegistry.newInstance();
}catch(Exception ex){
throw new ImpossibleException(ex);
}
XSImplementationImpl xsImpl = (XSImplementationImpl)registry.getDOMImplementation("XS-Loader");
xsLoader = xsImpl.createXSLoader(null);
DOMConfiguration config = xsLoader.getConfig();
config.setParameter(Constants.DOM_VALIDATE, Boolean.TRUE);
if(entityResolver!=null)
config.setParameter(Constants.DOM_RESOURCE_RESOLVER, entityResolver);
if(errorHandler!=null)
config.setParameter(Constants.DOM_ERROR_HANDLER, errorHandler);
}
示例13: setUp
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
super.setUp();
DOMImplementationRegistry registry =
DOMImplementationRegistry.newInstance();
DOMImplementation domImpl = registry.getDOMImplementation(
"XML 1.0 Traversal 2.0");
String qname = "html";
String systemId = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
String publicId = "-//W3C//DTD XHTML 1.0 Transitional//EN";
DocumentType documentType = domImpl.createDocumentType(
qname, publicId, systemId);
Document doc = domImpl.createDocument(null, null, documentType);
mq = new SimpleMessageQueue();
stack = new Html5ElementStack(doc, false, mq);
stack.open(false);
}
示例14: getXmlString
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
private String getXmlString(Node node) {
try {
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS implementationLS = (DOMImplementationLS)registry.getDOMImplementation("LS");
LSOutput output = implementationLS.createLSOutput();
output.setEncoding(this.xmlEncoding);
output.setCharacterStream(new StringWriter());
LSSerializer serializer = implementationLS.createLSSerializer();
serializer.write(node, output);
return output.getCharacterStream().toString();
} catch (Exception e1) {
e1.printStackTrace();
}
return null;
}
示例15: writeXmlDocumentToFile
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入方法依赖的package包/类
/** Utility methods */
private void writeXmlDocumentToFile(Node node, String filename) {
try {
// find file or create one and save all info
File file = new File(filename);
if(!file.exists()) {
file.createNewFile();
}
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementationLS implementationLS = (DOMImplementationLS)registry.getDOMImplementation("LS");
LSOutput output = implementationLS.createLSOutput();
output.setEncoding("UTF-8");
output.setCharacterStream(new FileWriter(file));
LSSerializer serializer = implementationLS.createLSSerializer();
serializer.getDomConfig().setParameter("format-pretty-print", true);
serializer.write(node, output);
} catch (Exception e1) {
e1.printStackTrace();
}
}