private void validateXmlResult(Element resultXml) throws KalturaApiException {
Element resultElement = null;
try {
resultElement = XmlUtils.getElementByXPath(resultXml, "/xml/result");
} catch (XPathExpressionException xee) {
// AZ (unicon) - necessary in order to debug
String resultXmlStr;
try {
Document document = resultXml.getOwnerDocument();
DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation();
LSSerializer serializer = domImplLS.createLSSerializer();
resultXmlStr = serializer.writeToString(resultXml);
} catch (Exception e) {
resultXmlStr = "Unable to get XML result: "+e;
}
throw new KalturaApiException("XPath expression exception ("+xee+") evaluating result:"+resultXmlStr);
}
if (resultElement != null) {
return;
} else {
throw new KalturaApiException("Invalid result");
}
}
java类org.w3c.dom.ls.DOMImplementationLS的实例源码
KalturaClientBase.java 文件源码
项目:kaltura-ce-sakai-extension
阅读 31
收藏 0
点赞 0
评论 0
XMLHelper.java 文件源码
项目:lams
阅读 16
收藏 0
点赞 0
评论 0
/**
* Obtain a the DOM, level 3, Load/Save serializer {@link LSSerializer} instance from the
* given {@link DOMImplementationLS} instance.
*
* <p>
* The serializer instance will be configured with the parameters passed as the <code>serializerParams</code>
* argument. It will also be configured with an {@link LSSerializerFilter} that shows all nodes to the filter,
* and accepts all nodes shown.
* </p>
*
* @param domImplLS the DOM Level 3 Load/Save implementation to use
* @param serializerParams parameters to pass to the {@link DOMConfiguration} of the serializer
* instance, obtained via {@link LSSerializer#getDomConfig()}. May be null.
*
* @return a new LSSerializer instance
*/
public static LSSerializer getLSSerializer(DOMImplementationLS domImplLS, Map<String, Object> serializerParams) {
LSSerializer serializer = domImplLS.createLSSerializer();
serializer.setFilter(new LSSerializerFilter() {
public short acceptNode(Node arg0) {
return FILTER_ACCEPT;
}
public int getWhatToShow() {
return SHOW_ALL;
}
});
if (serializerParams != null) {
DOMConfiguration serializerDOMConfig = serializer.getDomConfig();
for (String key : serializerParams.keySet()) {
serializerDOMConfig.setParameter(key, serializerParams.get(key));
}
}
return serializer;
}
AbstractMethodErrorTest.java 文件源码
项目:openjdk-jdk10
阅读 30
收藏 0
点赞 0
评论 0
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);
}
AuctionController.java 文件源码
项目:openjdk-jdk10
阅读 39
收藏 0
点赞 0
评论 0
/**
* 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);
}
AuctionController.java 文件源码
项目:openjdk-jdk10
阅读 38
收藏 0
点赞 0
评论 0
/**
* 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());
}
DocumentLSTest.java 文件源码
项目:openjdk-jdk10
阅读 15
收藏 0
点赞 0
评论 0
@Test
public void testLSInputParsingByteStream() throws Exception {
DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation();
LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null);
LSInput src = impl.createLSInput();
try (InputStream is = new FileInputStream(ASTROCAT)) {
src.setByteStream(is);
assertNotNull(src.getByteStream());
// set certified accessor methods
boolean origCertified = src.getCertifiedText();
src.setCertifiedText(true);
assertTrue(src.getCertifiedText());
src.setCertifiedText(origCertified); // set back to orig
src.setSystemId(filenameToURL(ASTROCAT));
Document doc = domParser.parse(src);
Element result = doc.getDocumentElement();
assertEquals(result.getTagName(), "stardb");
}
}
DocumentLSTest.java 文件源码
项目:openjdk-jdk10
阅读 16
收藏 0
点赞 0
评论 0
@Test
public void testLSInputParsingString() throws Exception {
DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation();
String xml = "<?xml version='1.0'?><test>runDocumentLS_Q6</test>";
LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null);
LSSerializer domSerializer = impl.createLSSerializer();
// turn off xml decl in serialized string for comparison
domSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
LSInput src = impl.createLSInput();
src.setStringData(xml);
assertEquals(src.getStringData(), xml);
Document doc = domParser.parse(src);
String result = domSerializer.writeToString(doc);
assertEquals(result, "<test>runDocumentLS_Q6</test>");
}
AbstractMethodErrorTest.java 文件源码
项目:openjdk9
阅读 23
收藏 0
点赞 0
评论 0
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);
}
AuctionController.java 文件源码
项目:openjdk9
阅读 14
收藏 0
点赞 0
评论 0
/**
* 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);
}
AuctionController.java 文件源码
项目:openjdk9
阅读 40
收藏 0
点赞 0
评论 0
/**
* 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());
}
DocumentLSTest.java 文件源码
项目:openjdk9
阅读 15
收藏 0
点赞 0
评论 0
@Test
public void testLSInputParsingByteStream() throws Exception {
DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation();
LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null);
LSInput src = impl.createLSInput();
try (InputStream is = new FileInputStream(ASTROCAT)) {
src.setByteStream(is);
assertNotNull(src.getByteStream());
// set certified accessor methods
boolean origCertified = src.getCertifiedText();
src.setCertifiedText(true);
assertTrue(src.getCertifiedText());
src.setCertifiedText(origCertified); // set back to orig
src.setSystemId(filenameToURL(ASTROCAT));
Document doc = domParser.parse(src);
Element result = doc.getDocumentElement();
assertEquals(result.getTagName(), "stardb");
}
}
DocumentLSTest.java 文件源码
项目:openjdk9
阅读 21
收藏 0
点赞 0
评论 0
@Test
public void testLSInputParsingString() throws Exception {
DOMImplementationLS impl = (DOMImplementationLS) getDocumentBuilder().getDOMImplementation();
String xml = "<?xml version='1.0'?><test>runDocumentLS_Q6</test>";
LSParser domParser = impl.createLSParser(MODE_SYNCHRONOUS, null);
LSSerializer domSerializer = impl.createLSSerializer();
// turn off xml decl in serialized string for comparison
domSerializer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE);
LSInput src = impl.createLSInput();
src.setStringData(xml);
assertEquals(src.getStringData(), xml);
Document doc = domParser.parse(src);
String result = domSerializer.writeToString(doc);
assertEquals(result, "<test>runDocumentLS_Q6</test>");
}
WSXACMLMessageReceiver.java 文件源码
项目:carbon-identity-framework
阅读 21
收藏 0
点赞 0
评论 0
/**
* `
* 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);
}
}
ConfigurationController.java 文件源码
项目:c2mon
阅读 24
收藏 0
点赞 0
评论 0
/**
* Saves the process configuration.
*/
private void saveConfiguration(Document docXMLConfig) {
String fileToSaveConf = properties.getSaveRemoteConfig();
if (fileToSaveConf.length() > 0 && docXMLConfig != null) {
log.info("saveConfiguration - saving the process configuration XML in a file " + fileToSaveConf + " due to user request");
File file = new File(fileToSaveConf);
if (file.isDirectory() || !fileToSaveConf.endsWith(".xml")) {
throw new RuntimeException("Path to which to save remote config must end with '.xml'");
}
try {
DOMImplementationLS domImplementation = (DOMImplementationLS) docXMLConfig.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
lsSerializer.writeToURI(docXMLConfig, file.toURI().toURL().toString());
} catch (java.io.IOException ex) {
log.error("saveConfiguration - Could not save the configuration to the file " + fileToSaveConf, ex);
}
}
}
SSOUtils.java 文件源码
项目:tomcat-extension-samlsso
阅读 21
收藏 0
点赞 0
评论 0
/**
* 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);
}
}
DomHelper.java 文件源码
项目:mdw
阅读 26
收藏 0
点赞 0
评论 0
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);
}
AbstractFileTypeWizardIterator.java 文件源码
项目:oblivion-netbeans-plugin
阅读 18
收藏 0
点赞 0
评论 0
/**
* Creates the metadata file for the file that was created by the wizard.
*
* @param targetFolder The folder on which the metadata file will be created.
*/
private void createMetadataFile(FileObject targetFolder) {
try {
Document newXmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element rootElement = newXmlDocument.createElementNS(SALESFORCE_METADATA_NAMESPACE, getMetadataName());
Element childElement;
for (Map.Entry<String, String> node : getMetadataParameters().entrySet()) {
childElement = newXmlDocument.createElement(node.getKey());
childElement.setTextContent(node.getValue());
rootElement.appendChild(childElement);
}
FileObject createdData = targetFolder.createData(getMetadataFileName());
DOMImplementationLS domImplementation = (DOMImplementationLS) newXmlDocument.getImplementation();
LSSerializer serializer = domImplementation.createLSSerializer();
serializer.writeToURI(rootElement, createdData.toURI().toString());
} catch (ParserConfigurationException | IOException ex) {
Exceptions.printStackTrace(ex);
}
}
DomDocumentBuilderFactory.java 文件源码
项目:javify
阅读 19
收藏 0
点赞 0
评论 0
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);
}
}
DomLSParser.java 文件源码
项目:javify
阅读 22
收藏 0
点赞 0
评论 0
public DomLSParser(short mode, String schemaType)
throws DOMException
{
switch (mode)
{
case DOMImplementationLS.MODE_ASYNCHRONOUS:
async = true;
break;
case DOMImplementationLS.MODE_SYNCHRONOUS:
async = false;
break;
default:
throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR);
}
// TODO schemaType
this.schemaType = schemaType;
factory = SAXParserFactory.newInstance();
}
Utils.java 文件源码
项目:SI
阅读 14
收藏 0
点赞 0
评论 0
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;
}
}
ItemListBuilderDemo.java 文件源码
项目:code-similarity
阅读 23
收藏 0
点赞 0
评论 0
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);
}
XmlSignatureHelper.java 文件源码
项目:Camel
阅读 20
收藏 0
点赞 0
评论 0
/**
* 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);
}
ConfigPersister.java 文件源码
项目:spike.x
阅读 19
收藏 0
点赞 0
评论 0
public void load(File f) throws ConfigPersisterException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(f);
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
String configString = lsSerializer.writeToString(doc);
_config = (Config) _xstream.fromXML(convertToCurrent(configString));
setConfigPath(f);
} catch (Exception e) {
throw new ConfigPersisterException(e);
}
}
ConfigPersister.java 文件源码
项目:spike.x
阅读 20
收藏 0
点赞 0
评论 0
public void load(File f) throws ConfigPersisterException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(f);
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
String configString = lsSerializer.writeToString(doc);
_config = (Config) _xstream.fromXML(convertToCurrent(configString));
setConfigPath(f);
} catch (Exception e) {
throw new ConfigPersisterException(e);
}
}
ConfigPersister.java 文件源码
项目:spike.x
阅读 21
收藏 0
点赞 0
评论 0
public void load(File f) throws ConfigPersisterException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(f);
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
String configString = lsSerializer.writeToString(doc);
_config = (Config) _xstream.fromXML(convertToCurrent(configString));
setConfigPath(f);
} catch (Exception e) {
throw new ConfigPersisterException(e);
}
}
UnitTestsIndexMojo.java 文件源码
项目:tibco-fcunit
阅读 19
收藏 0
点赞 0
评论 0
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);
}
}
XMLIO.java 文件源码
项目:automation_engine
阅读 27
收藏 0
点赞 0
评论 0
/**
* Returns a textual representation of an XML Object.
*
* @param doc XML Dom Document
* @return String containing a textual representation of the object
*/
public static String asString(Document doc) {
try {
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
LSOutput lsOutput = domImplementation.createLSOutput();
lsOutput.setEncoding("UTF-8");
return lsSerializer.writeToString(doc);
} catch (Exception e) {
e.printStackTrace();
try {
DOMSource domSource = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
return writer.toString();
} catch(Exception ex) {
logger.error(ex);
return StackTrace.asString(ex);
}
}
}
DomDocumentBuilderFactory.java 文件源码
项目:jvm-stm
阅读 24
收藏 0
点赞 0
评论 0
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);
}
}
DomLSParser.java 文件源码
项目:jvm-stm
阅读 22
收藏 0
点赞 0
评论 0
public DomLSParser(short mode, String schemaType)
throws DOMException
{
switch (mode)
{
case DOMImplementationLS.MODE_ASYNCHRONOUS:
async = true;
break;
case DOMImplementationLS.MODE_SYNCHRONOUS:
async = false;
break;
default:
throw new DomDOMException(DOMException.NOT_SUPPORTED_ERR);
}
// TODO schemaType
this.schemaType = schemaType;
factory = SAXParserFactory.newInstance();
}
ConfigPersister.java 文件源码
项目:beast-mcmc
阅读 21
收藏 0
点赞 0
评论 0
public void load(File f) throws ConfigPersisterException {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(f);
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
String configString = lsSerializer.writeToString(doc);
_config = (Config) _xstream.fromXML(convertToCurrent(configString));
setConfigPath(f);
} catch (Exception e) {
throw new ConfigPersisterException(e);
}
}