Search in sources :

Example 51 with SAXReader

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);
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) XMLUtil(net.sf.eclipsecs.core.util.XMLUtil) Document(org.dom4j.Document) DocumentException(org.dom4j.DocumentException) MissingResourceException(java.util.MissingResourceException) IOException(java.io.IOException) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) CheckstyleException(com.puppycrawl.tools.checkstyle.api.CheckstyleException)

Example 52 with SAXReader

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();
}
Also used : SAXReader(org.dom4j.io.SAXReader) Node(org.dom4j.Node) Document(org.dom4j.Document) URL(java.net.URL)

Example 53 with SAXReader

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;
    }
}
Also used : ErrorHandler(org.xml.sax.ErrorHandler) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) StringReader(java.io.StringReader)

Example 54 with SAXReader

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);
    }
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) SAXReader(org.dom4j.io.SAXReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ConfigurationException(org.osgi.service.cm.ConfigurationException) GenericOperation(org.talend.esb.job.controller.GenericOperation) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) Map(java.util.Map)

Example 55 with SAXReader

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()));
}
Also used : StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXReader(org.dom4j.io.SAXReader) Document(org.dom4j.Document) Source(javax.xml.transform.Source) Test(org.junit.Test)

Aggregations

SAXReader (org.dom4j.io.SAXReader)322 Document (org.dom4j.Document)256 Element (org.dom4j.Element)195 StringReader (java.io.StringReader)120 DocumentException (org.dom4j.DocumentException)74 Test (org.junit.jupiter.api.Test)74 File (java.io.File)54 List (java.util.List)49 IOException (java.io.IOException)48 InputStream (java.io.InputStream)48 ArrayList (java.util.ArrayList)47 Node (org.dom4j.Node)28 FileInputStream (java.io.FileInputStream)25 HashMap (java.util.HashMap)24 XMLWriter (org.dom4j.io.XMLWriter)22 ByteArrayInputStream (java.io.ByteArrayInputStream)20 URL (java.net.URL)18 OutputFormat (org.dom4j.io.OutputFormat)18 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)17 Test (org.junit.Test)14