Search in sources :

Example 11 with Element

use of org.neo4j.ogm.domain.gh806.Element in project gocd by gocd.

the class StageCctrayPresentationModelTest method shouldContainBuilds.

private void shouldContainBuilds(Element root) {
    Element buildProject = findChildByName(root, "cruise :: ft :: firefox");
    assertThat(buildProject, hasAttribute("activity", "Sleeping"));
    assertThat(buildProject, hasAttribute("lastBuildStatus", "Success"));
    assertThat(buildProject, hasAttribute("lastBuildLabel", String.valueOf(LABEL)));
    assertThat(buildProject, hasAttribute("lastBuildTime", DATE_STR));
    assertThat(buildProject, hasAttribute("webUrl", buildDetailUrl()));
}
Also used : Element(org.jdom2.Element)

Example 12 with Element

use of org.neo4j.ogm.domain.gh806.Element in project gocd by gocd.

the class StageCctrayPresentationModelTest method shouldGetGoodCctrayXml.

@Test
public void shouldGetGoodCctrayXml() throws Exception {
    Element root = new Element("Projects");
    cctrayXmlPresenter.toCctrayXml(root, CONTEXT_PATH);
    assertThat(root.getChildren().size(), is(2));
    shouldContainStage(root);
    shouldContainBuilds(root);
}
Also used : Element(org.jdom2.Element) Test(org.junit.Test)

Example 13 with Element

use of org.neo4j.ogm.domain.gh806.Element in project gocd by gocd.

the class StageCctrayPresentationModel method createProjectElement.

private void createProjectElement(Element parent, String name, String activity, String lastBuildStatus, String lastBuildLabel, String lastBuildTime, String webUrl) {
    Element project = new Element("Project");
    project.setAttribute("name", name);
    project.setAttribute("activity", activity);
    project.setAttribute("lastBuildStatus", lastBuildStatus);
    project.setAttribute("lastBuildLabel", lastBuildLabel);
    project.setAttribute("lastBuildTime", lastBuildTime);
    project.setAttribute("webUrl", webUrl);
    parent.addContent(project);
}
Also used : Element(org.jdom2.Element)

Example 14 with Element

use of org.neo4j.ogm.domain.gh806.Element in project dq-easy-cloud by dq-open-cloud.

the class DqXMLUtils method getMapFromInputStream.

/**
 * <p>
 * 将xml流中的信息放入map中
 * </p>
 *
 * @param inputStream
 *            : InputStream : xml输入流
 * @param paramsMap
 *            : Map<String, Object> : xml结果容器
 * @return Map<String, Object>
 * @throws IOException
 * @author daiqi 创建时间 2018年2月23日 下午12:49:06
 */
public static Map<String, Object> getMapFromInputStream(InputStream inputStream, Map<String, Object> paramsMap) throws IOException {
    if (null == paramsMap) {
        paramsMap = new HashMap<>();
    }
    SAXBuilder builder = new SAXBuilder();
    try {
        Document doc = builder.build(inputStream);
        Element root = doc.getRootElement();
        List<Element> list = root.getChildren();
        Iterator<Element> it = list.iterator();
        while (it.hasNext()) {
            Element e = (Element) it.next();
            String k = e.getName();
            Object v = DqStringUtils.EMPTY;
            List<Element> children = e.getChildren();
            if (children.isEmpty()) {
                v = e.getTextNormalize();
            } else {
                v = getChildren(children);
            }
            paramsMap.put(k, v);
        }
    } catch (JDOMException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
    return paramsMap;
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 15 with Element

use of org.neo4j.ogm.domain.gh806.Element in project dq-easy-cloud by dq-open-cloud.

the class XmlUtilsTest method deleteXmlElement.

/**
 * 删除节点和属性
 * @param doc
 * @throws Exception
 */
public static void deleteXmlElement(Document doc) throws Exception {
    // 获取根元素
    Element root = doc.getRootElement();
    List<Element> personList = root.getChildren("person");
    // 循环person元素,删除person的id为1的id属性以及username子节点
    for (Element el : personList) {
        if (null != el.getAttribute("id") && "1".equals(el.getAttribute("id").getValue())) {
            el.removeAttribute("id");
            el.removeChild("username");
        }
    }
    // 循环person元素,删除person的id为2的节点
    for (int i = 0; i < personList.size(); i++) {
        Element el = personList.get(i);
        if (null != el.getAttribute("id") && "2".equals(el.getAttribute("id").getValue())) {
            // 从root节点上删除该节点
            root.removeContent(el);
        // 警告:此处删除了节点可能会使personList的长度发生变化而发生越界错误,故不能写成for(int i=0,len=personList.size(); i<len; i++)
        }
    }
    XMLOutputter out = new XMLOutputter();
    // 设置UTF-8编码,理论上来说应该不会有乱码,但是出现了乱码,故设置为GBK
    out.setFormat(Format.getCompactFormat().setEncoding("GBK"));
    // 写文件
    out.output(doc, new FileWriter("src/test.xml"));
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) Element(org.jdom2.Element) FileWriter(java.io.FileWriter)

Aggregations

Element (org.jdom2.Element)3327 Document (org.jdom2.Document)502 Test (org.junit.Test)457 ArrayList (java.util.ArrayList)327 IOException (java.io.IOException)268 Attribute (org.jdom2.Attribute)207 JDOMException (org.jdom2.JDOMException)202 Element (org.osate.aadl2.Element)143 Namespace (org.jdom2.Namespace)136 Test (org.junit.jupiter.api.Test)131 List (java.util.List)130 SAXBuilder (org.jdom2.input.SAXBuilder)125 File (java.io.File)124 HashMap (java.util.HashMap)117 XMLOutputter (org.jdom2.output.XMLOutputter)103 XConfiguration (org.apache.oozie.util.XConfiguration)98 Configuration (org.apache.hadoop.conf.Configuration)96 NamedElement (org.osate.aadl2.NamedElement)77 StringReader (java.io.StringReader)67 Iterator (java.util.Iterator)63