use of org.dom4j.io.SAXReader in project eclipse-cs by checkstyle.
the class MetadataFactory method parseMetadata.
@SuppressWarnings("unchecked")
private static void parseMetadata(InputStream metadataStream, ResourceBundle metadataBundle) throws DocumentException, CheckstylePluginException {
SAXReader reader = new SAXReader();
reader.setEntityResolver(new XMLUtil.InternalDtdEntityResolver(PUBLIC2INTERNAL_DTD_MAP));
Document document = reader.read(metadataStream);
List<Element> groupElements = document.getRootElement().elements(XMLTags.RULE_GROUP_METADATA_TAG);
for (Element groupEl : groupElements) {
String groupName = groupEl.attributeValue(XMLTags.NAME_TAG).trim();
groupName = localize(groupName, metadataBundle);
// process description
String groupDesc = groupEl.elementTextTrim(XMLTags.DESCRIPTION_TAG);
groupDesc = localize(groupDesc, metadataBundle);
RuleGroupMetadata group = getRuleGroupMetadata(groupName);
if (group == null) {
boolean hidden = Boolean.valueOf(groupEl.attributeValue(XMLTags.HIDDEN_TAG)).booleanValue();
int priority = 0;
try {
priority = Integer.parseInt(groupEl.attributeValue(XMLTags.PRIORITY_TAG));
} catch (Exception e) {
CheckstyleLog.log(e);
priority = Integer.MAX_VALUE;
}
group = new RuleGroupMetadata(groupName, groupDesc, hidden, priority);
sRuleGroupMetadata.put(groupName, group);
}
// process the modules
processModules(groupEl, group, metadataBundle);
}
}
use of org.dom4j.io.SAXReader in project summer-mis by cn-cerc.
the class AlipayJs method query_timestamp.
// 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数 注意:远程解析XML出错,与服务器是否支持SSL等配置有关
public String query_timestamp() throws MalformedURLException, DocumentException, IOException {
String strUrl = AlipayConfig.ALIPAY_GATEWAY_NEW + "service=query_timestamp&partner=" + this.partner + "&_input_charset" + AlipayConfig.input_charset;
StringBuffer result = new StringBuffer();
SAXReader reader = new SAXReader();
Document doc = reader.read(new URL(strUrl).openStream());
List<Node> nodeList = doc.selectNodes("//alipay/*");
for (Node node : nodeList) {
if (node.getName().equals("is_success") && node.getText().equals("T")) {
List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
for (Node node1 : nodeList1) {
result.append(node1.getText());
}
}
}
return result.toString();
}
use of org.dom4j.io.SAXReader in project tesb-rt-se by Talend.
the class RuntimeESBConsumerTest method getDocumentFromString.
private Document getDocumentFromString(String xmlString) {
SAXReader reader = new SAXReader();
reader.setValidation(false);
reader.setErrorHandler(createNiceMock(ErrorHandler.class));
try {
return reader.read(new StringReader(xmlString));
} catch (DocumentException e) {
return null;
}
}
use of org.dom4j.io.SAXReader in project tesb-rt-se by Talend.
the class GenericServiceProviderImpl method invoke.
// @javax.jws.WebMethod(exclude=true)
public final Source invoke(Source request) {
QName operationQName = (QName) context.getMessageContext().get(MessageContext.WSDL_OPERATION);
LOG.info("Invoke operation '" + operationQName + "'");
GenericOperation esbProviderCallback = getESBProviderCallback(operationQName.getLocalPart());
if (esbProviderCallback == null) {
throw new RuntimeException("Handler for operation " + operationQName + " cannot be found");
}
try {
ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();
StaxUtils.copy(request, os);
org.dom4j.Document requestDoc = new SAXReader().read(new ByteArrayInputStream(os.toByteArray()));
Object payload;
if (extractHeaders) {
Map<String, Object> esbRequest = new HashMap<String, Object>();
esbRequest.put(ESBProviderCallback.HEADERS_SOAP, context.getMessageContext().get(Header.HEADER_LIST));
esbRequest.put(ESBProviderCallback.HEADERS_HTTP, context.getMessageContext().get(MessageContext.HTTP_REQUEST_HEADERS));
esbRequest.put(ESBProviderCallback.REQUEST, requestDoc);
esbRequest.put(CorrelationIDFeature.MESSAGE_CORRELATION_ID, context.getMessageContext().get(CorrelationIDFeature.MESSAGE_CORRELATION_ID));
payload = esbRequest;
} else {
payload = requestDoc;
}
LOG.fine("Generic provider invoked with payload: " + payload);
Object result = esbProviderCallback.invoke(payload, isOperationRequestResponse(operationQName.getLocalPart()));
// oneway
if (result == null) {
return null;
}
LOG.fine("Generic provider callback returns: " + result);
if (result instanceof Map<?, ?>) {
Map<String, Object> map = CastUtils.cast((Map<?, ?>) result);
return processResult(map.get(ESBEndpointConstants.REQUEST_PAYLOAD));
} else {
return processResult(result);
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.dom4j.io.SAXReader in project tesb-rt-se by Talend.
the class DOM4JMarshallerTest method documentToSource.
@Test
public void documentToSource() throws Exception {
SAXReader reader = new SAXReader();
Document doc = reader.read(new ByteArrayInputStream(XML.getBytes()));
Source source = DOM4JMarshaller.documentToSource(doc);
StringWriter writer = new StringWriter();
TransformerFactory.newInstance().newTransformer().transform(source, new StreamResult(writer));
// TESB-5237
assertTrue(writer.toString().contains("xmlns=\"\""));
// TESB-12665
TransformerFactory.newInstance().newTransformer().transform(source, new StreamResult(new StringWriter()));
}
Aggregations