use of org.neo4j.ogm.domain.gh806.Element in project dq-easy-cloud by dq-open-cloud.
the class XmlUtilsTest method updateXmlElement.
/**
* 更新节点
* @param doc
* @throws Exception
*/
public static void updateXmlElement(Document doc) throws Exception {
// 获取根元素
Element root = doc.getRootElement();
// 循环person元素并修改其id属性的值
for (Element el : root.getChildren("person")) {
el.setAttribute("id", "haha");
}
// 循环设置username和password的文本值和添加属性
for (Element el : root.getChildren()) {
el.getChild("username").setAttribute("nameVal", "add_val").setText("update_text");
el.getChild("password").setAttribute("passVal", "add_val").setText("update_text");
}
XMLOutputter out = new XMLOutputter();
// 设置UTF-8编码,理论上来说应该不会有乱码,但是出现了乱码,故设置为GBK
out.setFormat(Format.getCompactFormat().setEncoding("GBK"));
// 写文件
out.output(doc, new FileWriter("src/test.xml"));
}
use of org.neo4j.ogm.domain.gh806.Element in project dq-easy-cloud by dq-open-cloud.
the class XmlUtilsTest method testReadXml.
@Test
public void testReadXml() {
// 获取根元素
Element root = doc.getRootElement();
System.out.println("---获取第一个子节点和子节点下面的节点信息------");
List<Element> rmElements = root.getChildren();
Element rmElement = root.getChild("resultMap");
System.out.println("resultMap属性的值列表" + rmElement.getChildren("result").size());
// 第一次输入张三 第二次输出123123
System.out.println("getContentSize:" + rmElement.getChildren("result").size());
// for (Content content : rmElement.getContent()) {
// System.out.println("content" + content);
// }
// System.out.println("result:" + rmElement.getChild("result").getAttributes());
// for(Element el: rmElement.getChildren()){
// System.out.println("attribute:" + el.getAttributes());//第一次输入张三 第二次输出123123
// }
//
// System.out.println("---直接在根节点下就遍历所有的子节点---");
// for(Element el: root.getChildren()){
// System.out.println(el.getText());//这里输出4行空格
// System.out.println(el.getChildText("username"));//输出张三 & 1111111112
// System.out.println(el.getChildText("password"));//输出123123 & password2
// }
}
use of org.neo4j.ogm.domain.gh806.Element in project ddf by codice.
the class OpenSearchSource method createResponseFromEntry.
/**
* Creates a single response from input parameters. Performs XPath operations on the document to
* retrieve data not passed in.
*
* @param entry a single Atom entry
* @return single response
* @throws ddf.catalog.source.UnsupportedQueryException
*/
private List<Result> createResponseFromEntry(SyndEntry entry) throws UnsupportedQueryException {
String id = entry.getUri();
if (id != null && !id.isEmpty()) {
id = id.substring(id.lastIndexOf(':') + 1);
}
List<SyndContent> contents = entry.getContents();
List<SyndCategory> categories = entry.getCategories();
List<Metacard> metacards = new ArrayList<>();
List<Element> foreignMarkup = entry.getForeignMarkup();
String relevance = "";
String source = "";
for (Element element : foreignMarkup) {
if (element.getName().equals("score")) {
relevance = element.getContent(0).getValue();
}
}
//we currently do not support downloading content via an RSS enclosure, this support can be added at a later date if we decide to include it
for (SyndContent content : contents) {
MetacardImpl metacard = getMetacardImpl(parseContent(content.getValue(), id));
metacard.setSourceId(this.shortname);
String title = metacard.getTitle();
if (StringUtils.isEmpty(title)) {
metacard.setTitle(entry.getTitle());
}
if (!source.isEmpty()) {
metacard.setSourceId(source);
}
metacards.add(metacard);
}
for (int i = 0; i < categories.size() && i < metacards.size(); i++) {
SyndCategory category = categories.get(i);
Metacard metacard = metacards.get(i);
if (StringUtils.isBlank(metacard.getContentTypeName())) {
((MetacardImpl) metacard).setContentTypeName(category.getName());
}
}
List<Result> results = new ArrayList<>();
for (Metacard metacard : metacards) {
ResultImpl result = new ResultImpl(metacard);
if (relevance == null || relevance.isEmpty()) {
LOGGER.debug("couldn't find valid relevance. Setting relevance to 0");
relevance = "0";
}
result.setRelevanceScore(new Double(relevance));
results.add(result);
}
return results;
}
use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class AbstractSignalHeadManagerXml method store.
/**
* Default implementation for storing the contents of a SignalHeadManager.
* <P>
* Unlike most other managers, the individual SignalHead objects are stored
* separately via the configuration system so they can have separate type
* information.
*
* @param o Object to store, of type SignalHeadManager
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
Element signalheads = new Element("signalheads");
setStoreElementClass(signalheads);
SignalHeadManager sm = (SignalHeadManager) o;
if (sm != null) {
java.util.Iterator<String> iter = sm.getSystemNameList().iterator();
// don't return an element if there are not signalheads to include
if (!iter.hasNext()) {
return null;
}
// store the signalheads
while (iter.hasNext()) {
String sname = iter.next();
if (sname == null) {
log.error("System name null during store, skipped");
continue;
}
log.debug("system name is " + sname);
SignalHead sub = sm.getBySystemName(sname);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
signalheads.addContent(e);
}
} catch (Exception e) {
log.error("Error storing signalhead: {}", e, e);
}
}
}
return signalheads;
}
use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class AbstractTurnoutManagerConfigXML method loadTurnouts.
/**
* Utility method to load the individual Turnout objects. If there's no
* additional info needed for a specific turnout type, invoke this with the
* parent of the set of Turnout elements.
*
* @param shared Element containing the Turnout elements to load.
* @param perNode Element containing per-node Turnout data.
* @return true if succeeded
*/
@SuppressWarnings("unchecked")
public boolean loadTurnouts(Element shared, Element perNode) {
boolean result = true;
List<Element> operationList = shared.getChildren("operations");
if (operationList.size() > 1) {
log.warn("unexpected extra elements found in turnout operations list");
result = false;
}
if (operationList.size() > 0) {
TurnoutOperationManagerXml tomx = new TurnoutOperationManagerXml();
tomx.load(operationList.get(0), null);
}
List<Element> turnoutList = shared.getChildren("turnout");
if (log.isDebugEnabled()) {
log.debug("Found " + turnoutList.size() + " turnouts");
}
TurnoutManager tm = InstanceManager.turnoutManagerInstance();
try {
if (shared.getChild("defaultclosedspeed") != null) {
String closedSpeed = shared.getChild("defaultclosedspeed").getText();
if (closedSpeed != null && !closedSpeed.equals("")) {
tm.setDefaultClosedSpeed(closedSpeed);
}
}
} catch (jmri.JmriException ex) {
log.error(ex.toString());
}
try {
if (shared.getChild("defaultthrownspeed") != null) {
String thrownSpeed = shared.getChild("defaultthrownspeed").getText();
if (thrownSpeed != null && !thrownSpeed.equals("")) {
tm.setDefaultThrownSpeed(thrownSpeed);
}
}
} catch (jmri.JmriException ex) {
log.error(ex.toString());
}
for (int i = 0; i < turnoutList.size(); i++) {
Element elem = turnoutList.get(i);
String sysName = getSystemName(elem);
if (sysName == null) {
log.error("unexpected null in systemName " + elem);
result = false;
break;
}
String userName = getUserName(elem);
checkNameNormalization(sysName, userName, tm);
if (log.isDebugEnabled()) {
log.debug("create turnout: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")");
}
Turnout t = tm.getBySystemName(sysName);
if (t == null) {
t = tm.newTurnout(sysName, userName);
//Nothing is logged in the console window as the newTurnoutFunction already does this.
} else if (userName != null) {
t.setUserName(userName);
}
// Load common parts
loadCommon(t, elem);
// now add feedback if needed
Attribute a;
a = elem.getAttribute("feedback");
if (a != null) {
try {
t.setFeedbackMode(a.getValue());
} catch (IllegalArgumentException e) {
log.error("Can not set feedback mode: '" + a.getValue() + "' for turnout: '" + sysName + "' user name: '" + (userName == null ? "" : userName) + "'");
result = false;
}
}
a = elem.getAttribute("sensor1");
if (a != null) {
try {
t.provideFirstFeedbackSensor(a.getValue());
} catch (jmri.JmriException e) {
result = false;
}
}
a = elem.getAttribute("sensor2");
if (a != null) {
try {
t.provideSecondFeedbackSensor(a.getValue());
} catch (jmri.JmriException e) {
result = false;
}
}
// check for turnout inverted
t.setInverted(getAttributeBool(elem, "inverted", false));
// check for turnout decoder
a = turnoutList.get(i).getAttribute("decoder");
if (a != null) {
t.setDecoderName(a.getValue());
}
// check for turnout lock mode
a = turnoutList.get(i).getAttribute("lockMode");
if (a != null) {
if (a.getValue().equals("both")) {
t.enableLockOperation(Turnout.CABLOCKOUT + Turnout.PUSHBUTTONLOCKOUT, true);
}
if (a.getValue().equals("cab")) {
t.enableLockOperation(Turnout.CABLOCKOUT, true);
t.enableLockOperation(Turnout.PUSHBUTTONLOCKOUT, false);
}
if (a.getValue().equals("pushbutton")) {
t.enableLockOperation(Turnout.PUSHBUTTONLOCKOUT, true);
t.enableLockOperation(Turnout.CABLOCKOUT, false);
}
}
// check for turnout locked
a = turnoutList.get(i).getAttribute("locked");
if (a != null) {
t.setLocked(Turnout.CABLOCKOUT + Turnout.PUSHBUTTONLOCKOUT, a.getValue().equals("true"));
}
// number of bits, if present - if not, defaults to 1
a = turnoutList.get(i).getAttribute("numBits");
if (a == null) {
t.setNumberOutputBits(1);
} else {
int iNum = Integer.parseInt(a.getValue());
if ((iNum == 1) || (iNum == 2)) {
t.setNumberOutputBits(iNum);
} else {
log.warn("illegal number of output bits for control of turnout " + sysName);
t.setNumberOutputBits(1);
result = false;
}
}
// control type, if present - if not, defaults to 0
a = turnoutList.get(i).getAttribute("controlType");
if (a == null) {
t.setControlType(0);
} else {
int iType = Integer.parseInt(a.getValue());
if (iType >= 0) {
t.setControlType(iType);
} else {
log.warn("illegal control type for control of turnout " + sysName);
t.setControlType(0);
result = false;
}
}
// operation stuff
List<Element> myOpList = turnoutList.get(i).getChildren("operation");
if (myOpList.size() > 0) {
if (myOpList.size() > 1) {
log.warn("unexpected extra elements found in turnout-specific operations");
result = false;
}
TurnoutOperation toper = TurnoutOperationXml.loadOperation(myOpList.get(0));
t.setTurnoutOperation(toper);
} else {
a = turnoutList.get(i).getAttribute("automate");
if (a != null) {
String str = a.getValue();
if (str.equals("Off")) {
t.setInhibitOperation(true);
} else if (!str.equals("Default")) {
t.setInhibitOperation(false);
TurnoutOperation toper = TurnoutOperationManager.getInstance().getOperation(str);
t.setTurnoutOperation(toper);
} else {
t.setInhibitOperation(false);
}
}
}
// set initial state from sensor feedback if appropriate
t.setInitialKnownStateFromFeedback();
try {
t.setDivergingSpeed("Global");
if (elem.getChild("divergingSpeed") != null) {
String speed = elem.getChild("divergingSpeed").getText();
if (speed != null && !speed.equals("") && !speed.contains("Global")) {
t.setDivergingSpeed(speed);
}
}
} catch (jmri.JmriException ex) {
log.error(ex.toString());
}
try {
t.setStraightSpeed("Global");
if (elem.getChild("straightSpeed") != null) {
String speed = elem.getChild("straightSpeed").getText();
if (speed != null && !speed.equals("") && !speed.contains("Global")) {
t.setStraightSpeed(speed);
}
}
} catch (jmri.JmriException ex) {
log.error(ex.toString());
}
}
return result;
}
Aggregations