use of org.jdom2.Comment in project Douya by DreaminginCodeZH.
the class CommentListResource method onCommentDeleted.
@Subscribe(threadMode = ThreadMode.MAIN)
public void onCommentDeleted(CommentDeletedEvent event) {
if (event.isFromMyself(this) || isEmpty()) {
return;
}
List<Comment> commentList = get();
for (int i = 0, size = commentList.size(); i < size; ) {
Comment comment = commentList.get(i);
if (comment.id == event.commentId) {
commentList.remove(i);
getListener().onCommentRemoved(getRequestCode(), i);
--size;
} else {
++i;
}
}
}
use of org.jdom2.Comment in project JMRI by JMRI.
the class OBlockManagerXml method store.
/**
* Store the contents of a OBlockManager.
*
* @param o Object to store, of type BlockManager
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
Element blocks = new Element("oblocks");
blocks.setAttribute("class", "jmri.jmrit.logix.configurexml.OBlockManagerXml");
OBlockManager manager = (OBlockManager) o;
Iterator<String> iter = manager.getSystemNameList().iterator();
while (iter.hasNext()) {
String sname = iter.next();
OBlock block = manager.getBySystemName(sname);
String uname = block.getUserName();
if (log.isDebugEnabled()) {
log.debug("OBlock: sysName= " + sname + ", userName= " + uname);
}
Element elem = new Element("oblock");
elem.setAttribute("systemName", sname);
if (uname != null && uname.length() > 0) {
// doing this for compatibility during 2.9.* series
elem.setAttribute("userName", uname);
elem.addContent(new Element("userName").addContent(uname));
}
String comment = block.getComment();
if (comment != null) {
Element c = new Element("comment");
c.addContent(comment);
elem.addContent(c);
}
elem.setAttribute("length", "" + block.getLengthMm());
elem.setAttribute("units", block.isMetric() ? "true" : "false");
elem.setAttribute("curve", "" + block.getCurvature());
if (block.getNamedSensor() != null) {
Element se = new Element("sensor");
se.setAttribute("systemName", block.getNamedSensor().getName());
elem.addContent(se);
}
if (block.getNamedErrorSensor() != null) {
Element se = new Element("errorSensor");
se.setAttribute("systemName", block.getNamedErrorSensor().getName());
elem.addContent(se);
}
if (block.getReporter() != null) {
Element se = new Element("reporter");
se.setAttribute("systemName", block.getReporter().getSystemName());
se.setAttribute("reportCurrent", block.isReportingCurrent() ? "true" : "false");
elem.addContent(se);
}
elem.setAttribute("permissive", block.getPermissiveWorking() ? "true" : "false");
elem.setAttribute("speedNotch", block.getBlockSpeed());
List<Path> paths = block.getPaths();
for (int j = 0; j < paths.size(); j++) {
elem.addContent(storePath((OPath) paths.get(j)));
}
List<Portal> portals = block.getPortals();
for (int i = 0; i < portals.size(); i++) {
elem.addContent(storePortal(portals.get(i)));
}
// and put this element out
blocks.addContent(elem);
}
return blocks;
}
use of org.jdom2.Comment in project JMRI by JMRI.
the class WarrantManagerXml method store.
/**
* Store the contents of a WarrantManager.
*
* @param o Object to store, of type warrantManager
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
Element warrants = new Element("warrants");
warrants.setAttribute("class", "jmri.jmrit.logix.configurexml.WarrantManagerXml");
WarrantManager manager = (WarrantManager) o;
Iterator<String> iter = manager.getSystemNameList().iterator();
while (iter.hasNext()) {
String sname = iter.next();
Warrant warrant = manager.getBySystemName(sname);
String uname = warrant.getUserName();
if (log.isDebugEnabled())
log.debug("Warrant: sysName= {}, userName= {}", sname, uname);
Element elem = new Element("warrant");
elem.setAttribute("systemName", sname);
if (uname == null)
uname = "";
if (uname.length() > 0) {
elem.setAttribute("userName", uname);
}
if (warrant instanceof SCWarrant) {
elem.setAttribute("wtype", "SC");
elem.setAttribute("timeToPlatform", "" + ((SCWarrant) warrant).getTimeToPlatform());
elem.setAttribute("forward", ((SCWarrant) warrant).getForward() ? "true" : "false");
} else {
elem.setAttribute("wtype", "normal");
}
String comment = warrant.getComment();
if (comment != null) {
Element c = new Element("comment");
c.addContent(comment);
elem.addContent(c);
}
List<BlockOrder> orders = warrant.getSavedOrders();
for (int j = 0; j < orders.size(); j++) {
elem.addContent(storeOrder(orders.get(j), "blockOrder"));
}
BlockOrder viaOrder = warrant.getViaOrder();
if (viaOrder != null) {
elem.addContent(storeOrder(viaOrder, "viaOrder"));
}
BlockOrder avoidOrder = warrant.getAvoidOrder();
if (avoidOrder != null) {
elem.addContent(storeOrder(avoidOrder, "avoidOrder"));
}
List<ThrottleSetting> throttleCmds = warrant.getThrottleCommands();
for (int j = 0; j < throttleCmds.size(); j++) {
elem.addContent(storeCommand(throttleCmds.get(j), "throttleCommand"));
}
elem.addContent(storeTrain(warrant, "train"));
// and put this element out
warrants.addContent(elem);
}
return warrants;
}
use of org.jdom2.Comment in project JMRI by JMRI.
the class MatrixSignalMastXml method load.
@Override
public boolean load(Element shared, Element perNode) {
// from XML to mast m
MatrixSignalMast m;
String sys = getSystemName(shared);
try {
m = new jmri.implementation.MatrixSignalMast(sys);
} catch (Exception e) {
log.error("An error occured while trying to create the signal '" + sys + "' " + e.toString());
return false;
}
if (getUserName(shared) != null) {
m.setUserName(getUserName(shared));
}
// username & comment
loadCommon(m, shared);
if (shared.getChild("unlit") != null) {
Element unlit = shared.getChild("unlit");
if (unlit.getAttribute("allowed") != null) {
if (unlit.getAttribute("allowed").getValue().equals("no")) {
m.setAllowUnLit(false);
} else {
m.setAllowUnLit(true);
String bits = unlit.getChild("bitString").getText();
m.setUnLitBits(bits);
}
}
}
// multiple
Element outps = shared.getChild("outputs");
if (outps != null) {
// singular
List<Element> list = outps.getChildren("output");
int i = 0;
for (Element outp : list) {
// count outputs
i++;
}
// set char[] size before creating outputs
m.setBitNum(i);
for (Element outp : list) {
String outputname = outp.getAttribute("matrixCol").getValue();
String turnoutname = outp.getText();
m.setOutput(outputname, turnoutname);
}
}
// multiple
Element bss = shared.getChild("bitStrings");
if (bss != null) {
// singular
List<Element> list = bss.getChildren("bitString");
for (Element bs : list) {
// OK if value is null
m.setBitstring(bs.getAttribute("aspect").getValue(), bs.getText());
}
}
// multiple
Element disabled = shared.getChild("disabledAspects");
if (disabled != null) {
// singular
List<Element> list = disabled.getChildren("disabledAspect");
for (Element asp : list) {
m.setAspectDisabled(asp.getText());
}
}
InstanceManager.getDefault(jmri.SignalMastManager.class).register(m);
return true;
}
use of org.jdom2.Comment in project JMRI by JMRI.
the class BlockBossLogicXml method load.
@Override
public boolean load(Element shared, Element perNode) {
boolean result = true;
List<Element> l = shared.getChildren("signalelement");
// this is for backward compatibility only
if (l.size() == 0) {
l = shared.getChildren("block");
}
// process each item
for (int i = 0; i < l.size(); i++) {
Element block = l.get(i);
BlockBossLogic bb = null;
try {
bb = BlockBossLogic.getStoppedObject(block.getAttributeValue("signal"));
} catch (java.lang.Exception e) {
log.error("An error occured trying to find the signal for the signal elements for " + block.getAttributeValue("signal"));
result = false;
}
if (bb != null) {
if (block.getAttribute("approachsensor1") != null) {
try {
bb.setApproachSensor1(block.getAttributeValue("approachsensor1"));
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured loading the approach sensor for the signal elements for " + bb.getDrivenSignal());
result = false;
}
}
if (block.getAttribute("watchedsensor") != null) {
// for older XML files
try {
bb.setSensor1(block.getAttributeValue("watchedsensor"));
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured loading the watched sensor in the SSL for " + bb.getDrivenSignal());
result = false;
}
}
// old form of sensors with system names
List<Element> sl = block.getChildren("sensor");
try {
if (sl.size() >= 1 && sl.get(0) != null) {
bb.setSensor1(sl.get(0).getAttributeValue("systemName"));
}
if (sl.size() >= 2 && sl.get(1) != null) {
bb.setSensor2(sl.get(1).getAttributeValue("systemName"));
}
if (sl.size() >= 3 && sl.get(2) != null) {
bb.setSensor3(sl.get(2).getAttributeValue("systemName"));
}
if (sl.size() >= 4 && sl.get(3) != null) {
bb.setSensor4(sl.get(3).getAttributeValue("systemName"));
}
if (sl.size() >= 5 && sl.get(4) != null) {
bb.setSensor5(sl.get(4).getAttributeValue("systemName"));
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured loading the sensors list in the SSL");
result = false;
}
// new form of sensors with system names
sl = block.getChildren("sensorname");
try {
if (sl.size() >= 1 && sl.get(0) != null) {
bb.setSensor1(sl.get(0).getText());
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured loading the sensor1 list in the SSL for " + bb.getDrivenSignal());
result = false;
}
try {
if (sl.size() >= 2 && sl.get(1) != null) {
bb.setSensor2(sl.get(1).getText());
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured loading the sensor2 list in the SSL for " + bb.getDrivenSignal());
result = false;
}
try {
if (sl.size() >= 3 && sl.get(2) != null) {
bb.setSensor3(sl.get(2).getText());
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured loading the sensor3 list in the SSL for " + bb.getDrivenSignal());
result = false;
}
try {
if (sl.size() >= 4 && sl.get(3) != null) {
bb.setSensor4(sl.get(3).getText());
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured loading the sensor4 list in the SSL for " + bb.getDrivenSignal());
result = false;
}
try {
if (sl.size() >= 5 && sl.get(4) != null) {
bb.setSensor5(sl.get(4).getText());
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured loading the sensor5 list in the SSL for " + bb.getDrivenSignal());
result = false;
}
try {
bb.setMode(block.getAttribute("mode").getIntValue());
if (block.getAttribute("distantsignal") != null) {
bb.setDistantSignal(block.getAttribute("distantsignal").getBooleanValue());
}
if (block.getAttribute("limitspeed1") != null) {
bb.setLimitSpeed1(block.getAttribute("limitspeed1").getBooleanValue());
}
if (block.getAttribute("limitspeed2") != null) {
bb.setLimitSpeed2(block.getAttribute("limitspeed2").getBooleanValue());
}
try {
if (block.getAttribute("watchedturnout") != null) {
bb.setTurnout(block.getAttributeValue("watchedturnout"));
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured in retrieving the watched turnout (" + block.getAttributeValue("watchedturnout") + ")element attribute list for " + bb.getDrivenSignal());
result = false;
}
try {
if (block.getAttribute("watchedsignal1") != null) {
bb.setWatchedSignal1(block.getAttributeValue("watchedsignal1"), block.getAttribute("useflashyellow").getBooleanValue());
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured in retrieving the watched signal 1 (" + block.getAttributeValue("watchedsignal1") + ")element attribute list for " + bb.getDrivenSignal());
result = false;
}
try {
if (block.getAttribute("watchedsignal1alt") != null) {
bb.setWatchedSignal1Alt(block.getAttributeValue("watchedsignal1alt"));
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured in retrieving the watched signal 1 alt (" + block.getAttributeValue("watchedsignal1alt") + ")element attribute list for " + bb.getDrivenSignal());
result = false;
}
try {
if (block.getAttribute("watchedsignal2") != null) {
bb.setWatchedSignal2(block.getAttributeValue("watchedsignal2"));
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured in retrieving the watched signal 2 (" + block.getAttributeValue("watchedsignal2") + ")element attribute list for " + bb.getDrivenSignal());
result = false;
}
try {
if (block.getAttribute("watchedsignal2alt") != null) {
bb.setWatchedSignal2Alt(block.getAttributeValue("watchedsignal2alt"));
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured in retrieving the watched signal 2 alt (" + block.getAttributeValue("watchedsignal2alt") + ") element attribute list for " + bb.getDrivenSignal());
result = false;
}
try {
if (block.getAttribute("watchedsensor1") != null) {
bb.setWatchedSensor1(block.getAttributeValue("watchedsensor1"));
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured in retrieving the watched sensor 1 (" + block.getAttributeValue("watchedsensor1") + ") element attribute list for " + bb.getDrivenSignal());
result = false;
}
try {
if (block.getAttribute("watchedsensor1alt") != null) {
bb.setWatchedSensor1Alt(block.getAttributeValue("watchedsensor1alt"));
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured in retrieving the watched sensor 1 alt (" + block.getAttributeValue("watchedsensor1alt") + ") element attribute list for " + bb.getDrivenSignal());
result = false;
}
try {
if (block.getAttribute("watchedsensor2") != null) {
bb.setWatchedSensor2(block.getAttributeValue("watchedsensor2"));
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured in retrieving the watched sensor 2 (" + block.getAttributeValue("watchedsensor2") + ") element attribute list for " + bb.getDrivenSignal());
result = false;
}
try {
if (block.getAttribute("watchedsensor2alt") != null) {
bb.setWatchedSensor2Alt(block.getAttributeValue("watchedsensor2alt"));
}
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured in retrieving the watched sensor 2 alt (" + block.getAttributeValue("watchedsensor2alt") + ")element attribute list for " + bb.getDrivenSignal());
result = false;
}
// load comment, if present
String c = block.getChildText("comment");
if (c != null) {
bb.setComment(c);
}
} catch (org.jdom2.DataConversionException e) {
log.warn("error reading blocks from file" + e);
result = false;
} catch (java.lang.IllegalArgumentException e) {
log.error("An error occured in the signal element attribute list");
result = false;
}
try {
bb.retain();
bb.start();
} catch (java.lang.NullPointerException e) {
log.error("An error occured trying to start the signal logic " + bb.getDrivenSignal());
result = false;
}
}
}
return result;
}
Aggregations