本文整理汇总了Java中org.w3c.dom.bootstrap.DOMImplementationRegistry类的典型用法代码示例。如果您正苦于以下问题:Java DOMImplementationRegistry类的具体用法?Java DOMImplementationRegistry怎么用?Java DOMImplementationRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DOMImplementationRegistry类属于org.w3c.dom.bootstrap包,在下文中一共展示了DOMImplementationRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SchemaLoader
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入依赖的package包/类
/**
* Constructor to build a Schema instance around a given nodeName
*
* @param schemaFileURI a schema file URI.
* @param nodeName the local name of the target node.
* @throws Exception if there is an error loading the schema or if the root element count in the schema is less than
* one.
*/
public SchemaLoader(String schemaFileURI, String nodeName) throws Exception {
this.setSchemaFileURI(schemaFileURI);
targetNode = nodeName;
// get DOM Implementation using DOM Registry
System.setProperty(DOMImplementationRegistry.PROPERTY, DOMXSImplementationSourceImpl.class.getName());
impRegistry = DOMImplementationRegistry.newInstance();
XSImplementation impl = (XSImplementation) impRegistry.getDOMImplementation("XS-Loader");
XSLoader schemaLoader = impl.createXSLoader(null);
// schemaLoader.getConfig().setParameter("validate", Boolean.TRUE);
String[] soapenvSchemaPath = { schemaFileURI, this.getClass().getResource(SOAP_11_SCHEMA_PATH).toExternalForm() };
StringList schemaList = new StringListImpl(soapenvSchemaPath, 2);
xsModel = schemaLoader.loadURIList(schemaList);
this.referenceNodes = new SchemaHelper(xsModel);
if (nodeName != null && 0 < nodeName.trim().length()) {
nodeChoiceList = referenceNodes.getAncestors(nodeName);
}
}
示例2: 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);
}
示例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
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: testCreateNewItem2SellRetry
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入依赖的package包/类
/**
* Check for DOMErrorHandler handling DOMError. Before fix of bug 4896132
* test throws DOM Level 1 node error.
*
* @throws Exception If any errors occur.
*/
@Test
public void testCreateNewItem2SellRetry() throws Exception {
String xmlFile = XML_DIR + "accountInfo.xml";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document document = dbf.newDocumentBuilder().parse(xmlFile);
DOMConfiguration domConfig = document.getDomConfig();
MyDOMErrorHandler errHandler = new MyDOMErrorHandler();
domConfig.setParameter("error-handler", errHandler);
DOMImplementationLS impl =
(DOMImplementationLS) DOMImplementationRegistry.newInstance()
.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
MyDOMOutput domoutput = new MyDOMOutput();
domoutput.setByteStream(System.out);
writer.write(document, domoutput);
document.normalizeDocument();
writer.write(document, domoutput);
assertFalse(errHandler.isError());
}
示例5: 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);
}
示例6: testCreateNewItem2SellRetry
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入依赖的package包/类
/**
* Check for DOMErrorHandler handling DOMError. Before fix of bug 4896132
* test throws DOM Level 1 node error.
*
* @throws Exception If any errors occur.
*/
@Test(groups = {"readLocalFiles"})
public void testCreateNewItem2SellRetry() throws Exception {
String xmlFile = XML_DIR + "accountInfo.xml";
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
Document document = dbf.newDocumentBuilder().parse(xmlFile);
DOMConfiguration domConfig = document.getDomConfig();
MyDOMErrorHandler errHandler = new MyDOMErrorHandler();
domConfig.setParameter("error-handler", errHandler);
DOMImplementationLS impl =
(DOMImplementationLS) DOMImplementationRegistry.newInstance()
.getDOMImplementation("LS");
LSSerializer writer = impl.createLSSerializer();
MyDOMOutput domoutput = new MyDOMOutput();
domoutput.setByteStream(System.out);
writer.write(document, domoutput);
document.normalizeDocument();
writer.write(document, domoutput);
assertFalse(errHandler.isError());
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: 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);
}
}
示例10: 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;
}
}
示例11: 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);
}
示例12: 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);
}
}
示例13: configure
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入依赖的package包/类
/**
* This method configures the CEP.
*
* @return It returns a well configured esper service provider instance.
*/
private EPServiceProvider configure() {
// configure logging
System.setProperty(DOMImplementationRegistry.PROPERTY,
"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl");
// configure supported event ids
Configuration config = new Configuration();
config.addEventTypeAutoName(LogEvent.class.getPackage().getName());
// create provider
EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config);
// discover schema url
URL schemaURL = ComplexEventProcessor.class.getClassLoader().getResource(eventLogFile);
logger.info("xsd path is: " + schemaURL.toString());
// configure default xml stream
ConfigurationEventTypeXMLDOM sensorcfg = new ConfigurationEventTypeXMLDOM();
sensorcfg.setRootElementName("log");
sensorcfg.setSchemaResource(schemaURL.toString());
epService.getEPAdministrator().getConfiguration()
.addEventType(LogEvent.LogEventStream, sensorcfg);
return epService;
}
示例14: 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);
}
示例15: marshall
import org.w3c.dom.bootstrap.DOMImplementationRegistry; //导入依赖的package包/类
/**
* Marshall a SAML XML object into a W3C DOM and then into a String
*
* @param pXMLObject SAML Object to marshall
* @return XML version of the SAML Object in string form
*/
private String marshall(XMLObject pXMLObject) {
try {
MarshallerFactory lMarshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory();
Marshaller lMarshaller = lMarshallerFactory.getMarshaller(pXMLObject);
Element lElement = lMarshaller.marshall(pXMLObject);
DOMImplementationLS lDOMImplementationLS = (DOMImplementationLS) DOMImplementationRegistry.newInstance().getDOMImplementation("LS");
LSSerializer lSerializer = lDOMImplementationLS.createLSSerializer();
LSOutput lOutput = lDOMImplementationLS.createLSOutput();
lOutput.setEncoding("UTF-8");
Writer lStringWriter = new StringWriter();
lOutput.setCharacterStream(lStringWriter);
lSerializer.write(lElement, lOutput);
return lStringWriter.toString();
}
catch (Exception e) {
throw new ExInternal("Error Serializing the SAML Response", e);
}
}