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()));
}
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);
}
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);
}
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;
}
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"));
}
Aggregations