本文整理汇总了Java中groovy.util.XmlParser类的典型用法代码示例。如果您正苦于以下问题:Java XmlParser类的具体用法?Java XmlParser怎么用?Java XmlParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlParser类属于groovy.util包,在下文中一共展示了XmlParser类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import groovy.util.XmlParser; //导入依赖的package包/类
@RequestMapping(value = "/rpc/execute")
public ModelAndView execute(RpcCommand rpc, BindingResult errors) {
rpcCommandValidator.validate(rpc, errors);
if (errors.hasErrors()) {
throw new IllegalArgumentException("RPC request is invalid", new BindException(errors));
}
try {
RpcResponse response = null;
if (rpc.getParams().isEmpty()) {
response = rpcTemplate.execute(getRpcUrl(rpc));
} else {
response = rpcTemplate.execute(getRpcUrl(rpc), getParams(rpc));
}
if (rpc.getFormat().equals("xml")) {
StringWriter stringWriter = new StringWriter();
Node node = new XmlParser().parseText(response.toString());
new XmlNodePrinter(new PrintWriter(stringWriter)).print(node);
return ModelAndViewFactory.stringModelAndView("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + stringWriter.toString(), "application/xml");
} else if (rpc.getFormat().equals("json")) {
JsonNode jsonNode = jsonRpcResponseExtractor.extractData(response);
String result = jsonRpcResponseExtractor.getJsonMapper().writerWithDefaultPrettyPrinter().writeValueAsString(jsonNode);
return ModelAndViewFactory.stringModelAndView(result, "application/json");
} else {
return ModelAndViewFactory.stringModelAndView(response.toString(), "text/plain");
}
} catch (Exception e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
return ModelAndViewFactory.stringModelAndView(sw.toString(), "text/plain");
}
}
示例2: createParser
import groovy.util.XmlParser; //导入依赖的package包/类
private static XmlParser createParser() {
try {
XmlParser parser = new XmlParser(false, true, true);
try {
// If not set for >= JAXP 1.5 / Java8 won't allow referencing DTDs, e.g.
// using http URLs, because Groovy's XmlParser requests FEATURE_SECURE_PROCESSING
parser.setProperty(ACCESS_EXTERNAL_DTD, ALLOW_ANY_EXTERNAL_DTD);
} catch (SAXNotRecognizedException ignore) {
// property requires >= JAXP 1.5 / Java8
}
return parser;
} catch (Exception ex) {
throw new UncheckedException(ex);
}
}
示例3: asNode
import groovy.util.XmlParser; //导入依赖的package包/类
public Node asNode() {
if (node == null) {
try {
node = new XmlParser().parseText(toString());
} catch (Exception e) {
throw UncheckedException.throwAsUncheckedException(e);
}
builder = null;
element = null;
}
return node;
}
示例4: getGPathParamValue
import groovy.util.XmlParser; //导入依赖的package包/类
private Object getGPathParamValue(String varName, String varType) throws ActivityException {
Object value = super.getVariableValue(varName);
com.centurylink.mdw.variable.VariableTranslator translator = VariableTranslator.getTranslator(getPackage(), varType);
if (translator instanceof DocumentReferenceTranslator) {
try {
DocumentReferenceTranslator docRefTranslator = (DocumentReferenceTranslator) translator;
outputDocumentWriter = new StringWriter();
if (isOutputDocument(varName)) {
if (value == null) {
MarkupBuilder builder = new MarkupBuilder(outputDocumentWriter);
builder.setDoubleQuotes(true);
value = builder;
}
else {
value = new XmlParser().parseText(docRefTranslator.realToString(value));
}
}
else {
value = new XmlSlurper().parseText(docRefTranslator.realToString(value));
}
}
catch (Exception ex) {
logger.severeException(ex.getMessage(), ex);
throw new ActivityException(ex.getMessage(), ex);
}
}
return value;
}
示例5: realToObject
import groovy.util.XmlParser; //导入依赖的package包/类
public Object realToObject(String str) throws TranslationException {
try {
return new XmlParser().parseText(str);
} catch (Exception e) {
throw new TranslationException(e.getMessage(), e);
}
}
示例6: load
import groovy.util.XmlParser; //导入依赖的package包/类
@Override
public void load(InputStream inputStream) throws Exception {
xml = new XmlParser().parse(inputStream);
load(xml);
}
示例7: newParser
import groovy.util.XmlParser; //导入依赖的package包/类
private XmlParser newParser() throws Exception {
XmlParser xmlParser = new XmlParser(newSaxParser());
xmlParser.setErrorHandler(getErrorHandler());
xmlParser.setTrimWhitespace(!isKeepWhitespace());
return xmlParser;
}
示例8: XmlTemplateEngine
import groovy.util.XmlParser; //导入依赖的package包/类
public XmlTemplateEngine(String indentation, boolean validating) throws SAXException, ParserConfigurationException {
this(new XmlParser(validating, true), new GroovyShell());
this.xmlParser.setTrimWhitespace(true);
setIndentation(indentation);
}