use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class DecoderFile method processVariablesElement.
public void processVariablesElement(Element variablesElement, VariableTableModel variableModel, String extraInclude, String extraExclude) {
// handle include, exclude on this element
extraInclude = extraInclude + (variablesElement.getAttributeValue("include") != null ? "," + variablesElement.getAttributeValue("include") : "");
extraExclude = extraExclude + (variablesElement.getAttributeValue("exclude") != null ? "," + variablesElement.getAttributeValue("exclude") : "");
log.debug("extraInclude /{}/, extraExclude /{}/", extraInclude, extraExclude);
// load variables to table
for (Element e : variablesElement.getChildren("variable")) {
try {
// skip creating it
if (getNumFunctions() >= 0 && e.getAttribute("minFn") != null && getNumFunctions() < e.getAttribute("minFn").getIntValue()) {
continue;
}
// skip creating it
if (getNumOutputs() >= 0 && e.getAttribute("minOut") != null && getNumOutputs() < Integer.parseInt(e.getAttribute("minOut").getValue())) {
continue;
}
// if not correct productID, skip
if (!isProductIDok(e, extraInclude, extraExclude)) {
continue;
}
} catch (NumberFormatException | DataConversionException ex) {
log.warn("Problem parsing minFn or minOut in decoder file, variable " + e.getAttribute("item") + " exception: " + ex);
}
// load each row
variableModel.setRow(nextCvStoreIndex++, e);
}
// load constants to table
for (Element e : variablesElement.getChildren("constant")) {
try {
// skip creating it
if (getNumFunctions() >= 0 && e.getAttribute("minFn") != null && getNumFunctions() < e.getAttribute("minFn").getIntValue()) {
continue;
}
// skip creating it
if (getNumOutputs() >= 0 && e.getAttribute("minOut") != null && getNumOutputs() < e.getAttribute("minOut").getIntValue()) {
continue;
}
// if not correct productID, skip
if (!isProductIDok(e, extraInclude, extraExclude)) {
continue;
}
} catch (DataConversionException ex) {
log.warn("Problem parsing minFn or minOut in decoder file, variable " + e.getAttribute("item") + " exception: " + ex);
}
// load each row
variableModel.setConstant(e);
}
for (Element e : variablesElement.getChildren("ivariable")) {
try {
if (log.isDebugEnabled()) {
log.debug("process iVar " + e.getAttribute("CVname"));
}
// skip creating it
if (getNumFunctions() >= 0 && e.getAttribute("minFn") != null && getNumFunctions() < e.getAttribute("minFn").getIntValue()) {
log.debug("skip due to num functions");
continue;
}
// skip creating it
if (getNumOutputs() >= 0 && e.getAttribute("minOut") != null && getNumOutputs() < e.getAttribute("minOut").getIntValue()) {
log.debug("skip due to num outputs");
continue;
}
// if not correct productID, skip
if (!isProductIDok(e, extraInclude, extraExclude)) {
continue;
}
} catch (DataConversionException ex) {
log.warn("Problem parsing minFn or minOut in decoder file, variable " + e.getAttribute("item") + " exception: " + ex);
}
// load each row
if (variableModel.setIndxRow(nextICvStoreIndex, e, _productID, _model, _family) == nextICvStoreIndex) {
// if this one existed, we will not update the row count.
nextICvStoreIndex++;
} else {
if (log.isDebugEnabled()) {
log.debug("skipping entry for " + e.getAttribute("CVname"));
}
}
}
for (Element e : variablesElement.getChildren("variables")) {
processVariablesElement(e, variableModel, extraInclude, extraExclude);
}
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class JmriJTablePersistenceManager method initialize.
@Override
public void initialize(Profile profile) throws InitializationException {
try {
Element element = JDOMUtil.toJDOMElement(ProfileUtils.getUserInterfaceConfiguration(ProfileManager.getDefault().getActiveProfile()).getConfigurationFragment(TABLES_ELEMENT, TABLES_NAMESPACE, false));
element.getChildren("table").stream().forEach((table) -> {
String tableName = table.getAttributeValue("name");
int sortColumn = -1;
SortOrder sortOrder = SortOrder.UNSORTED;
Element sortElement = table.getChild(SORT_ORDER);
if (sortElement != null) {
List<SortKey> keys = new ArrayList<>();
for (Element sortKey : sortElement.getChildren()) {
sortOrder = SortOrder.valueOf(sortKey.getAttributeValue(SORT_ORDER));
try {
sortColumn = sortKey.getAttribute("column").getIntValue();
SortKey key = new SortKey(sortColumn, sortOrder);
keys.add(key);
} catch (DataConversionException ex) {
log.error("Unable to get sort column as integer");
}
}
this.sortKeys.put(tableName, keys);
}
log.debug("Table {} column {} is sorted {}", tableName, sortColumn, sortOrder);
for (Element column : table.getChild("columns").getChildren()) {
String columnName = column.getAttribute("name").getValue();
int order = -1;
int width = -1;
boolean hidden = false;
try {
if (column.getAttributeValue("order") != null) {
order = column.getAttribute("order").getIntValue();
}
if (column.getAttributeValue("width") != null) {
width = column.getAttribute("width").getIntValue();
}
if (column.getAttribute("hidden") != null) {
hidden = column.getAttribute("hidden").getBooleanValue();
}
} catch (DataConversionException ex) {
log.error("Unable to parse column \"{}\"", columnName);
continue;
}
if (sortColumn == order) {
this.setPersistedState(tableName, columnName, order, width, sortOrder, hidden);
} else {
this.setPersistedState(tableName, columnName, order, width, SortOrder.UNSORTED, hidden);
}
}
});
} catch (NullPointerException ex) {
log.info("Table preferences not found.\nThis is expected on the first time the \"{}\" profile is used on this computer.", ProfileManager.getDefault().getActiveProfile().getName());
}
this.setInitialized(profile, true);
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class WebServerPreferences method load.
public void load(Element child) {
Attribute a;
a = child.getAttribute(CLICK_DELAY);
if (a != null) {
try {
setClickDelay(a.getIntValue());
} catch (DataConversionException e) {
log.debug(e.getLocalizedMessage(), e);
}
}
a = child.getAttribute(REFRESH_DELAY);
if (a != null) {
try {
setRefreshDelay(a.getIntValue());
} catch (DataConversionException e) {
log.debug(e.getLocalizedMessage(), e);
}
}
a = child.getAttribute(USE_AJAX);
if (a != null) {
setUseAjax(Boolean.parseBoolean(a.getValue()));
}
a = child.getAttribute(SIMPLE);
if (a != null) {
setSimple(Boolean.parseBoolean(a.getValue()));
}
a = child.getAttribute(ALLOW_REMOTE_CONFIG);
if (a != null) {
setAllowRemoteConfig(Boolean.parseBoolean(a.getValue()));
}
a = child.getAttribute(READONLY_POWER);
if (a != null) {
setReadonlyPower(Boolean.parseBoolean(a.getValue()));
}
a = child.getAttribute(PORT);
if (a != null) {
try {
setPort(a.getIntValue());
} catch (DataConversionException ex) {
setPort(12080);
log.error("Unable to read port. Setting to default value.", ex);
}
}
a = child.getAttribute(RAILROAD_NAME);
if (a != null) {
setRailRoadName(a.getValue());
}
Element df = child.getChild(DISALLOWED_FRAMES);
if (df != null) {
this.disallowedFrames.clear();
df.getChildren(FRAME).stream().forEach((f) -> {
this.disallowedFrames.add(f.getText().trim());
});
}
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class ControlPanel method setXml.
/**
* Set the preferences based on the XML Element.
* <ul>
* <li> Window prefs
* </ul>
*
*
* @param e The Element for this object.
*/
public void setXml(Element e) {
internalAdjust = true;
try {
this.setSpeedController(e.getAttribute("displaySpeedSlider").getIntValue());
} catch (org.jdom2.DataConversionException ex) {
log.error("DataConverstionException in setXml: " + ex);
} catch (Exception em) {
// in this case, recover by displaying the speed slider.
this.setSpeedController(SLIDERDISPLAY);
}
Attribute tsAtt = e.getAttribute("trackSlider");
if (tsAtt != null) {
try {
trackSlider = tsAtt.getBooleanValue();
} catch (org.jdom2.DataConversionException ex) {
trackSlider = trackSliderDefault;
}
} else {
trackSlider = trackSliderDefault;
}
Attribute tsmiAtt = e.getAttribute("trackSliderMinInterval");
if (tsmiAtt != null) {
try {
trackSliderMinInterval = tsmiAtt.getLongValue();
} catch (org.jdom2.DataConversionException ex) {
trackSliderMinInterval = trackSliderMinIntervalDefault;
}
if (trackSliderMinInterval < trackSliderMinIntervalMin) {
trackSliderMinInterval = trackSliderMinIntervalMin;
} else if (trackSliderMinInterval > trackSliderMinIntervalMax) {
trackSliderMinInterval = trackSliderMinIntervalMax;
}
} else {
trackSliderMinInterval = trackSliderMinIntervalDefault;
}
if ((prevShuntingFn == null) && (e.getAttribute("switchSliderOnFunction") != null)) {
setSwitchSliderFunction(e.getAttribute("switchSliderOnFunction").getValue());
}
internalAdjust = false;
Element window = e.getChild("window");
WindowPreferences.setPreferences(this, window);
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class PositionableShapeXml method loadCommonAttributes.
public void loadCommonAttributes(PositionableShape ps, int defaultLevel, Element element) {
int x = getInt(element, "x");
int y = getInt(element, "y");
ps.setLocation(x, y);
ps.setDisplayLevel(getInt(element, "level"));
Attribute a = element.getAttribute("hidden");
if ((a != null) && a.getValue().equals("yes")) {
ps.setHidden(true);
ps.setVisible(false);
}
a = element.getAttribute("positionable");
if ((a != null) && a.getValue().equals("true")) {
ps.setPositionable(true);
} else {
ps.setPositionable(false);
}
a = element.getAttribute("showtooltip");
if ((a != null) && a.getValue().equals("true")) {
ps.setShowTooltip(true);
} else {
ps.setShowTooltip(false);
}
a = element.getAttribute("editable");
if ((a != null) && a.getValue().equals("true")) {
ps.setEditable(true);
} else {
ps.setEditable(false);
}
Element elem = element.getChild("toolTip");
if (elem != null) {
ToolTip tip = ps.getTooltip();
if (tip != null) {
tip.setText(elem.getText());
}
}
ps.setLineWidth(getInt(element, "lineWidth"));
int alpha = -1;
try {
a = element.getAttribute("alpha");
if (a != null) {
alpha = a.getIntValue();
}
} catch (DataConversionException ex) {
log.warn("invalid 'alpha' value (non integer)");
}
ps.setLineColor(getColor(element, "lineColor", alpha));
ps.setFillColor(getColor(element, "fillColor", alpha));
ps.makeShape();
ps.rotate(getInt(element, "degrees"));
a = element.getAttribute("hideOnSensor");
boolean hide = false;
if (a != null) {
hide = a.getValue().equals("true");
}
int changeLevel = -1;
try {
changeLevel = getInt(element, "changeLevelOnSensor");
} catch (Exception e) {
log.error("failed to get changeLevel attribute ex= " + e);
}
try {
Attribute attr = element.getAttribute("controlSensor");
if (attr != null) {
ps.setControlSensor(attr.getValue(), hide, changeLevel);
}
} catch (NullPointerException e) {
log.error("incorrect information for controlSensor of PositionableShape");
}
ps.updateSize();
}
Aggregations