@Test
public void testJobIdXML() throws Exception {
WebResource r = resource();
Map<JobId, Job> jobsMap = appContext.getAllJobs();
for (JobId id : jobsMap.keySet()) {
String jobId = MRApps.toString(id);
ClientResponse response = r.path("ws").path("v1").path("mapreduce")
.path("jobs").path(jobId).accept(MediaType.APPLICATION_XML)
.get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
String xml = response.getEntity(String.class);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is);
NodeList job = dom.getElementsByTagName("job");
verifyAMJobXML(job, appContext);
}
}
java类javax.xml.parsers.DocumentBuilderFactory的实例源码
TestAMWebServicesJobs.java 文件源码
项目:hadoop
阅读 25
收藏 0
点赞 0
评论 0
FormatFactory.java 文件源码
项目:javaide
阅读 23
收藏 0
点赞 0
评论 0
private static String formatXml(Context context, String src) throws TransformerException,
ParserConfigurationException, IOException, SAXException {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(src)));
AppSetting setting = new AppSetting(context);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", setting.getTab().length() + "");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
//initialize StreamResult with File object to save to file
StreamResult result = new StreamResult(new StringWriter());
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);
return result.getWriter().toString();
}
SOAPDocumentImpl.java 文件源码
项目:openjdk-jdk10
阅读 45
收藏 0
点赞 0
评论 0
private Document createDocument() {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance("com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl", SAAJUtil.getSystemClassLoader());
try {
final DocumentBuilder documentBuilder = docFactory.newDocumentBuilder();
return documentBuilder.newDocument();
} catch (ParserConfigurationException e) {
throw new RuntimeException("Error creating xml document", e);
}
}
CoTAdapterInbound.java 文件源码
项目:defense-solutions-proofs-of-concept
阅读 22
收藏 0
点赞 0
评论 0
private NodeList unpackXML(String xml, String targetTag) throws Exception {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource source = new InputSource();
source.setCharacterStream(new StringReader(xml));
Document doc = db.parse(source);
NodeList nodeList = doc.getElementsByTagName(targetTag);
return nodeList;
} catch (Exception e) {
log.error(e);
log.error(e.getStackTrace());
throw (e);
}
}
PathRuleWithMultipleNamespacesExpressionTest.java 文件源码
项目:redirector
阅读 17
收藏 0
点赞 0
评论 0
private static Document fromString(String xmlString) {
try {
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(xmlString.getBytes()));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
EpubParser.java 文件源码
项目:r2-streamer-java
阅读 20
收藏 0
点赞 0
评论 0
private String containerXmlParser(String containerData) throws EpubParserException { //parsing container.xml
try {
String xml = containerData.replaceAll("[^\\x20-\\x7e]", "").trim(); //in case encoding problem
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(xml)));
document.getDocumentElement().normalize();
if (document == null) {
throw new EpubParserException("Error while parsing container.xml");
}
Element rootElement = (Element) ((Element) document.getDocumentElement().getElementsByTagName("rootfiles").item(0)).getElementsByTagName("rootfile").item(0);
if (rootElement != null) {
String opfFile = rootElement.getAttribute("full-path");
if (opfFile == null) {
throw new EpubParserException("Missing root file element in container.xml");
}
//Log.d(TAG, "Root file: " + opfFile);
return opfFile; //returns opf file
}
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
}
return null;
}
WSDLTrimmer.java 文件源码
项目:jaffa-framework
阅读 19
收藏 0
点赞 0
评论 0
/**
* Trims the sourceWSDL based on the excludedFields that are declared for the graphClass associated with the input WebService implementation class.
* The targetWSDL will be generated as a result.
* @param sourceWSDL a source WSDL.
* @param targetWSDLToGenerate the WSDL to generate.
* @param webServiceImplementationClassName the WebService implementation class that may have an annotation declaring the need for WSDL trimming.
*/
public static void trim(File sourceWSDL, File targetWSDLToGenerate, String webServiceImplementationClassName) throws ParserConfigurationException, SAXException, IOException, TransformerConfigurationException, TransformerException, ClassNotFoundException {
Map<Class, Collection<String>> excludedFields = getExcludedFields(webServiceImplementationClassName);
if (excludedFields != null && excludedFields.size() > 0) {
if (log.isDebugEnabled())
log.debug("Trimming '" + sourceWSDL + "' by excluding " + excludedFields);
//Parse the source WSDL
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse(sourceWSDL);
//Trim the source WSDL
trim(document.getDocumentElement(), excludedFields);
//Generate the target WSDL
if (log.isDebugEnabled())
log.debug("Generating: " + targetWSDLToGenerate);
Source source = new DOMSource(document);
Result result = new StreamResult(targetWSDLToGenerate);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
//transformerFactory.setAttribute("indent-number", 2);
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
transformer.transform(source, result);
} else if (!sourceWSDL.equals(targetWSDLToGenerate)) {
if (log.isDebugEnabled())
log.debug("None of the fields are excluded. '" + targetWSDLToGenerate + "' will be created as a copy of '" + sourceWSDL + '\'');
copy(sourceWSDL, targetWSDLToGenerate);
}
}
TestQueuePlacementPolicy.java 文件源码
项目:hadoop
阅读 16
收藏 0
点赞 0
评论 0
private QueuePlacementPolicy parse(String str) throws Exception {
// Read and parse the allocations file.
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
.newInstance();
docBuilderFactory.setIgnoringComments(true);
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
Document doc = builder.parse(IOUtils.toInputStream(str));
Element root = doc.getDocumentElement();
return QueuePlacementPolicy.fromXml(root, configuredQueues, conf);
}
DocumentBuilderSafeProperty.java 文件源码
项目:Android_Code_Arbiter
阅读 19
收藏 0
点赞 0
评论 0
public static void unsafeNoSpecialSettings() throws ParserConfigurationException, IOException, SAXException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(getInputFile());
print(doc);
}
DOMForest.java 文件源码
项目:OpenJSharp
阅读 23
收藏 0
点赞 0
评论 0
public DOMForest( InternalizationLogic logic, Options opt ) {
if (opt == null) throw new AssertionError("Options object null");
this.options = opt;
try {
DocumentBuilderFactory dbf = XmlFactory.createDocumentBuilderFactory(opt.disableXmlSecurity);
this.documentBuilder = dbf.newDocumentBuilder();
this.parserFactory = XmlFactory.createParserFactory(opt.disableXmlSecurity);
} catch( ParserConfigurationException e ) {
throw new AssertionError(e);
}
this.logic = logic;
}