use of com.zhan_dui.utils.m3u8.Element in project pcgen by PCGen.
the class DiceBagModel method saveToDocument.
/**
* <p>Loads the current dicebag's information into the
* given JDOM document.</p>
*
* @param doc
*/
private void saveToDocument(Document doc) {
Element party = new Element("dice-bag");
party.setAttribute("name", m_name);
for (String dieString : m_dice) {
Element die = new Element("dice-roll");
die.addContent(dieString);
party.addContent(die);
}
doc.setRootElement(party);
}
use of com.zhan_dui.utils.m3u8.Element in project pcgen by PCGen.
the class Localized method update.
/**
*
* @param e
* @param attribute if {@code null}, use the trimmed text.
*/
private void update(Element e, String attribute) {
List<?> children = e.getChildren(ELEMENT_LOC);
for (Object object : children) {
if (object instanceof Element) {
Element child = (Element) object;
String lang = child.getAttributeValue(ATTRIBUTE_LANGUAGE);
String name;
if (attribute == null)
name = child.getTextTrim();
else
name = child.getAttributeValue(attribute);
if (lang != null && !lang.isEmpty())
addName(lang, name);
}
}
}
use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.
the class BlockManagerXml method addBeanSetting.
void addBeanSetting(Element e, BeanSetting bs) {
if (bs.getBean() == null) {
log.error("Invalid BeanSetting - did not save");
return;
}
// persist bean name, type and value
Element bse = new Element("beansetting");
// for now, assume turnout
bse.setAttribute("setting", "" + bs.getSetting());
Element be = new Element("turnout");
be.setAttribute("systemName", bs.getBeanName());
bse.addContent(be);
e.addContent(bse);
}
use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.
the class BlockManagerXml method loadPath.
/**
* Load path into an existing Block from XML.
*
* @param block Block to receive path
* @param element Element containing path information
* @return true if path added to block; false otherwise
* @throws jmri.configurexml.JmriConfigureXmlException if element contains
* malformed or
* schematically invalid
* XMl
*/
public boolean loadPath(Block block, Element element) throws JmriConfigureXmlException {
// load individual path
int toDir = 0;
int fromDir = 0;
try {
toDir = element.getAttribute("todir").getIntValue();
fromDir = element.getAttribute("fromdir").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("Could not parse path attribute");
} catch (NullPointerException e) {
handleException("Block Path entry in file missing required attribute", null, block.getSystemName(), block.getUserName(), null);
}
Block toBlock = null;
if (element.getAttribute("block") != null) {
String name = element.getAttribute("block").getValue();
toBlock = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(name);
}
Path path = new Path(toBlock, toDir, fromDir);
List<Element> settings = element.getChildren("beansetting");
for (int i = 0; i < settings.size(); i++) {
Element setting = settings.get(i);
loadBeanSetting(path, setting);
}
// check if path already in block
if (!block.hasPath(path)) {
block.addPath(path);
return true;
} else {
log.debug("Skipping load of duplicate path {}", path);
return false;
}
}
use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.
the class BlockManagerXml method store.
/**
* Store the contents of a BlockManager.
*
* @param o Object to store, of type BlockManager
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
Element blocks = new Element("blocks");
setStoreElementClass(blocks);
BlockManager tm = (BlockManager) o;
if (tm != null) {
java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
// don't return an element if there are not blocks to include
if (!iter.hasNext()) {
return null;
}
blocks.addContent(new Element("defaultspeed").addContent(tm.getDefaultSpeed()));
// write out first set of blocks without contents
while (iter.hasNext()) {
try {
String sname = iter.next();
if (sname == null) {
log.error("System name null during store");
} else {
Block b = tm.getBySystemName(sname);
// the following null check is to catch a null pointer exception that sometimes was found to happen
if (b == null) {
log.error("Null block during store - sname = " + sname);
} else {
Element elem = new Element("block");
elem.addContent(new Element("systemName").addContent(sname));
// the following null check is to catch a null pointer exception that sometimes was found to happen
String uname = b.getUserName();
if ((uname != null) && (!uname.equals(""))) {
elem.addContent(new Element("userName").addContent(b.getUserName()));
}
if (log.isDebugEnabled()) {
log.debug("initial store Block " + sname);
}
// and put this element out
blocks.addContent(elem);
}
}
} catch (Exception e) {
log.error(e.toString());
}
}
// write out again with contents
iter = tm.getSystemNameList().iterator();
while (iter.hasNext()) {
String sname = iter.next();
if (sname == null) {
log.error("System name null during store skipped for this block");
} else {
Block b = tm.getBySystemName(sname);
// the following null check is to catch a null pointer exception that sometimes was found to happen
if (b == null) {
log.error("Null Block during store - second store skipped for this block - " + sname);
} else {
String uname = b.getUserName();
if (uname == null) {
uname = "";
}
Element elem = new Element("block");
elem.addContent(new Element("systemName").addContent(sname));
if (log.isDebugEnabled()) {
log.debug("second store Block " + sname + ":" + uname);
}
// store length and curvature attributes
elem.setAttribute("length", Float.toString(b.getLengthMm()));
elem.setAttribute("curve", Integer.toString(b.getCurvature()));
// store common parts
storeCommon(b, elem);
if ((!b.getBlockSpeed().equals("")) && !b.getBlockSpeed().contains("Global")) {
elem.addContent(new Element("speed").addContent(b.getBlockSpeed()));
}
String perm = "no";
if (b.getPermissiveWorking()) {
perm = "yes";
}
elem.addContent(new Element("permissive").addContent(perm));
// Add content. First, the sensor.
if (b.getNamedSensor() != null) {
elem.addContent(new Element("occupancysensor").addContent(b.getNamedSensor().getName()));
}
if (b.getDeniedBlocks().size() > 0) {
Element denied = new Element("deniedBlocks");
b.getDeniedBlocks().forEach((deniedBlock) -> {
denied.addContent(new Element("block").addContent(deniedBlock));
});
elem.addContent(denied);
}
// Now the Reporter
Reporter r = b.getReporter();
if (r != null) {
Element re = new Element("reporter");
re.setAttribute("systemName", r.getSystemName());
re.setAttribute("useCurrent", b.isReportingCurrent() ? "yes" : "no");
elem.addContent(re);
}
if (tm.isSavedPathInfo()) {
// then the paths
List<Path> paths = b.getPaths();
for (int i = 0; i < paths.size(); i++) {
addPath(elem, paths.get(i));
}
// and put this element out
}
blocks.addContent(elem);
}
}
}
}
return blocks;
}
Aggregations