use of org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.
the class RollingStockAttribute method load.
public void load(Element root, String eNames, String eName, String oldName) {
// new format using elements starting version 3.3.1
if (root.getChild(eNames) != null) {
@SuppressWarnings("unchecked") List<Element> l = root.getChild(eNames).getChildren(eName);
Attribute a;
String[] names = new String[l.size()];
for (int i = 0; i < l.size(); i++) {
Element name = l.get(i);
if ((a = name.getAttribute(Xml.NAME)) != null) {
names[i] = a.getValue();
}
// lengths use "VALUE"
if ((a = name.getAttribute(Xml.VALUE)) != null) {
names[i] = a.getValue();
}
}
setNames(names);
} else // try old format
if (root.getChild(oldName) != null) {
// NOI18N
String[] names = root.getChildText(oldName).split("%%");
setNames(names);
}
}
use of org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.
the class EngineManager method load.
public void load(Element root) {
// new format using elements starting version 3.3.1
if (root.getChild(Xml.NEW_CONSISTS) != null) {
@SuppressWarnings("unchecked") List<Element> consists = root.getChild(Xml.NEW_CONSISTS).getChildren(Xml.CONSIST);
log.debug("Engine manager sees {} consists", consists.size());
Attribute a;
for (Element consist : consists) {
if ((a = consist.getAttribute(Xml.NAME)) != null) {
newConsist(a.getValue());
}
}
} else // old format
if (root.getChild(Xml.CONSISTS) != null) {
String names = root.getChildText(Xml.CONSISTS);
if (!names.equals(NONE)) {
// NOI18N
String[] consistNames = names.split("%%");
log.debug("consists: {}", names);
for (String name : consistNames) {
newConsist(name);
}
}
}
if (root.getChild(Xml.ENGINES) != null) {
@SuppressWarnings("unchecked") List<Element> engines = root.getChild(Xml.ENGINES).getChildren(Xml.ENGINE);
log.debug("readFile sees {} engines", engines.size());
for (Element e : engines) {
register(new Engine(e));
}
}
}
use of org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.
the class TrainManifestText method load.
public static void load(Element e) {
Element emts = e.getChild(Xml.MANIFEST_TEXT_STRINGS);
if (emts == null) {
return;
}
Attribute a;
if (emts.getChild(Xml.MANIFEST_FOR_TRAIN) != null) {
if ((a = emts.getChild(Xml.MANIFEST_FOR_TRAIN).getAttribute(Xml.TEXT)) != null) {
setStringManifestForTrain(a.getValue());
}
}
if (emts.getChild(Xml.VALID) != null) {
if ((a = emts.getChild(Xml.VALID).getAttribute(Xml.TEXT)) != null) {
setStringValid(a.getValue());
}
}
if (emts.getChild(Xml.SCHEDULED_WORK) != null) {
if ((a = emts.getChild(Xml.SCHEDULED_WORK).getAttribute(Xml.TEXT)) != null) {
setStringScheduledWork(a.getValue());
}
}
if (emts.getChild(Xml.WORK_DEPARTURE_TIME) != null) {
if ((a = emts.getChild(Xml.WORK_DEPARTURE_TIME).getAttribute(Xml.TEXT)) != null) {
setStringWorkDepartureTime(a.getValue());
}
}
if (emts.getChild(Xml.WORK_ARRIVAL_TIME) != null) {
if ((a = emts.getChild(Xml.WORK_ARRIVAL_TIME).getAttribute(Xml.TEXT)) != null) {
setStringWorkArrivalTime(a.getValue());
}
}
if (emts.getChild(Xml.NO_SCHEDULED_WORK) != null) {
if ((a = emts.getChild(Xml.NO_SCHEDULED_WORK).getAttribute(Xml.TEXT)) != null) {
setStringNoScheduledWork(a.getValue());
}
}
if (emts.getChild(Xml.NO_SCHEDULED_WORK_ROUTE_COMMENT) != null) {
if ((a = emts.getChild(Xml.NO_SCHEDULED_WORK_ROUTE_COMMENT).getAttribute(Xml.TEXT)) != null) {
setStringNoScheduledWorkWithRouteComment(a.getValue());
}
}
if (emts.getChild(Xml.DEPART_TIME) != null) {
if ((a = emts.getChild(Xml.DEPART_TIME).getAttribute(Xml.TEXT)) != null) {
setStringDepartTime(a.getValue());
}
}
if (emts.getChild(Xml.TRAIN_DEPARTS_CARS) != null) {
if ((a = emts.getChild(Xml.TRAIN_DEPARTS_CARS).getAttribute(Xml.TEXT)) != null) {
setStringTrainDepartsCars(a.getValue());
}
}
if (emts.getChild(Xml.TRAIN_DEPARTS_LOADS) != null) {
if ((a = emts.getChild(Xml.TRAIN_DEPARTS_LOADS).getAttribute(Xml.TEXT)) != null) {
setStringTrainDepartsLoads(a.getValue());
}
}
if (emts.getChild(Xml.TRAIN_TERMINATES) != null) {
if ((a = emts.getChild(Xml.TRAIN_TERMINATES).getAttribute(Xml.TEXT)) != null) {
setStringTrainTerminates(a.getValue());
}
}
if (emts.getChild(Xml.DESTINATION) != null) {
if ((a = emts.getChild(Xml.DESTINATION).getAttribute(Xml.TEXT)) != null) {
setStringDestination(a.getValue());
}
}
if (emts.getChild(Xml.TO) != null) {
if ((a = emts.getChild(Xml.TO).getAttribute(Xml.TEXT)) != null) {
setStringTo(a.getValue());
}
}
if (emts.getChild(Xml.FROM) != null) {
if ((a = emts.getChild(Xml.FROM).getAttribute(Xml.TEXT)) != null) {
setStringFrom(a.getValue());
}
}
if (emts.getChild(Xml.DEST) != null) {
if ((a = emts.getChild(Xml.DEST).getAttribute(Xml.TEXT)) != null) {
setStringDest(a.getValue());
}
}
if (emts.getChild(Xml.FINAL_DEST) != null) {
if ((a = emts.getChild(Xml.FINAL_DEST).getAttribute(Xml.TEXT)) != null) {
setStringFinalDestination(a.getValue());
}
}
if (emts.getChild(Xml.ADD_HELPERS) != null) {
if ((a = emts.getChild(Xml.ADD_HELPERS).getAttribute(Xml.TEXT)) != null) {
setStringAddHelpers(a.getValue());
}
}
if (emts.getChild(Xml.REMOVE_HELPERS) != null) {
if ((a = emts.getChild(Xml.REMOVE_HELPERS).getAttribute(Xml.TEXT)) != null) {
setStringRemoveHelpers(a.getValue());
}
}
if (emts.getChild(Xml.LOCO_CHANGE) != null) {
if ((a = emts.getChild(Xml.LOCO_CHANGE).getAttribute(Xml.TEXT)) != null) {
setStringLocoChange(a.getValue());
}
}
if (emts.getChild(Xml.CABOOSE_CHANGE) != null) {
if ((a = emts.getChild(Xml.CABOOSE_CHANGE).getAttribute(Xml.TEXT)) != null) {
setStringCabooseChange(a.getValue());
}
}
if (emts.getChild(Xml.LOCO_CABOOSE_CHANGE) != null) {
if ((a = emts.getChild(Xml.LOCO_CABOOSE_CHANGE).getAttribute(Xml.TEXT)) != null) {
setStringLocoAndCabooseChange(a.getValue());
}
}
}
use of org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.
the class RosterEntry method loadFunctions.
/**
* Loads function names from a JDOM element. Does not change values that are
* already present!
*
* @param e3 the XML element containing the functions
* @param source "family" if source is the decoder definition, or "model" if
* source is the roster entry itself
*/
public void loadFunctions(Element e3, String source) {
/*Load flag once, means that when the roster entry is edited only the first set of function labels are displayed
ie those saved in the roster file, rather than those being left blank
rather than being over-written by the defaults linked to the decoder def*/
if (loadedOnce) {
return;
}
if (e3 != null) {
// load function names
List<Element> l = e3.getChildren(RosterEntry.FUNCTION_LABEL);
for (Element fn : l) {
int num = Integer.parseInt(fn.getAttribute("num").getValue());
String lock = fn.getAttribute("lockable").getValue();
String val = fn.getText();
if ((this.getFunctionLabel(num) == null) || (source.equalsIgnoreCase("model"))) {
this.setFunctionLabel(num, val);
this.setFunctionLockable(num, lock.equals("true"));
Attribute a;
if ((a = fn.getAttribute("functionImage")) != null && !a.getValue().isEmpty()) {
try {
if (FileUtil.getFile(a.getValue()).isFile()) {
this.setFunctionImage(num, FileUtil.getAbsoluteFilename(a.getValue()));
}
} catch (FileNotFoundException ex) {
try {
if (FileUtil.getFile(FileUtil.getUserResourcePath() + a.getValue()).isFile()) {
this.setFunctionImage(num, FileUtil.getUserResourcePath() + a.getValue());
}
} catch (FileNotFoundException ex1) {
this.setFunctionImage(num, null);
}
}
}
if ((a = fn.getAttribute("functionImageSelected")) != null && !a.getValue().isEmpty()) {
try {
if (FileUtil.getFile(a.getValue()).isFile()) {
this.setFunctionSelectedImage(num, FileUtil.getAbsoluteFilename(a.getValue()));
}
} catch (FileNotFoundException ex) {
try {
if (FileUtil.getFile(FileUtil.getUserResourcePath() + a.getValue()).isFile()) {
this.setFunctionSelectedImage(num, FileUtil.getUserResourcePath() + a.getValue());
}
} catch (FileNotFoundException ex1) {
this.setFunctionSelectedImage(num, null);
}
}
}
}
}
}
if (source.equalsIgnoreCase("RosterEntry")) {
loadedOnce = true;
}
}
use of org.bouncycastle.asn1.x509.Attribute in project JMRI by JMRI.
the class PaneProgPane method newGridItem.
/**
* Create a grid item from the JDOM Element
*
* @param element element containing grid item contents
* @param showStdName show the name following the rules for the
* <em>nameFmt</em> element
* @param modelElem element containing the decoder model
* @param globs properties to configure the layout
* @return a panel containing the group
*/
public JPanel newGridItem(Element element, boolean showStdName, Element modelElem, GridGlobals globs) {
// get item-level attributes
List<Attribute> itemAttList = element.getAttributes();
List<Attribute> attList = new ArrayList<>(globs.gridAttList);
// merge grid and item-level attributes
attList.addAll(itemAttList);
// log.info("New gridtiem -----------------------------------------------");
// log.info("Attribute list:"+attList);
attList.add(new Attribute(LAST_GRIDX, ""));
attList.add(new Attribute(LAST_GRIDY, ""));
// log.info("Previous gridxCurrent="+globs.gridxCurrent+";gridyCurrent="+globs.gridyCurrent);
for (int j = 0; j < attList.size(); j++) {
Attribute attrib = attList.get(j);
String attribName = attrib.getName();
String attribRawValue = attrib.getValue();
Field constraint = null;
String constraintType = null;
// make sure we only process the last gridx or gridy attribute in the list
if (attribName.equals("gridx")) {
Attribute a = new Attribute(LAST_GRIDX, attribRawValue);
attList.set(attList.size() - 2, a);
//. don't process now
continue;
}
if (attribName.equals("gridy")) {
Attribute a = new Attribute(LAST_GRIDY, attribRawValue);
attList.set(attList.size() - 1, a);
//. don't process now
continue;
}
if (attribName.equals(LAST_GRIDX)) {
// we must be at end of original list, restore last gridx
attribName = "gridx";
if (attribRawValue.equals("")) {
// don't process blank (unused)
continue;
}
}
if (attribName.equals(LAST_GRIDY)) {
// we must be at end of original list, restore last gridy
attribName = "gridy";
if (attribRawValue.equals("")) {
// don't process blank (unused)
continue;
}
}
if ((attribName.equals("gridx") || attribName.equals("gridy")) && attribRawValue.equals("RELATIVE")) {
// NEXT is a synonym for RELATIVE
attribRawValue = "NEXT";
}
if (attribName.equals("gridx") && attribRawValue.equals("CURRENT")) {
attribRawValue = String.valueOf(Math.max(0, globs.gridxCurrent));
}
if (attribName.equals("gridy") && attribRawValue.equals("CURRENT")) {
attribRawValue = String.valueOf(Math.max(0, globs.gridyCurrent));
}
if (attribName.equals("gridx") && attribRawValue.equals("NEXT")) {
attribRawValue = String.valueOf(++globs.gridxCurrent);
}
if (attribName.equals("gridy") && attribRawValue.equals("NEXT")) {
attribRawValue = String.valueOf(++globs.gridyCurrent);
}
// log.info("attribName="+attribName+";attribRawValue="+attribRawValue);
try {
constraint = globs.gridConstraints.getClass().getDeclaredField(attribName);
constraintType = constraint.getType().toString();
constraint.setAccessible(true);
} catch (NoSuchFieldException ex) {
log.error("Unrecognised attribute \"" + attribName + "\", skipping");
continue;
}
switch(constraintType) {
case "int":
{
int attribValue;
try {
attribValue = Integer.valueOf(attribRawValue);
constraint.set(globs.gridConstraints, attribValue);
} catch (IllegalAccessException ey) {
log.error("Unable to set constraint \"" + attribName + ". IllegalAccessException error thrown.");
} catch (NumberFormatException ex) {
try {
Field constant = globs.gridConstraints.getClass().getDeclaredField(attribRawValue);
constant.setAccessible(true);
attribValue = (Integer) GridBagConstraints.class.getField(attribRawValue).get(constant);
constraint.set(globs.gridConstraints, attribValue);
} catch (NoSuchFieldException ey) {
log.error("Invalid value \"" + attribRawValue + "\" for attribute \"" + attribName + "\"");
} catch (IllegalAccessException ey) {
log.error("Unable to set constraint \"" + attribName + ". IllegalAccessException error thrown.");
}
}
break;
}
case "double":
{
double attribValue;
try {
attribValue = Double.valueOf(attribRawValue);
constraint.set(globs.gridConstraints, attribValue);
} catch (IllegalAccessException ey) {
log.error("Unable to set constraint \"" + attribName + ". IllegalAccessException error thrown.");
} catch (NumberFormatException ex) {
log.error("Invalid value \"" + attribRawValue + "\" for attribute \"" + attribName + "\"");
}
break;
}
case "class java.awt.Insets":
try {
String[] insetStrings = attribRawValue.split(",");
if (insetStrings.length == 4) {
Insets attribValue = new Insets(Integer.valueOf(insetStrings[0]), Integer.valueOf(insetStrings[1]), Integer.valueOf(insetStrings[2]), Integer.valueOf(insetStrings[3]));
constraint.set(globs.gridConstraints, attribValue);
} else {
log.error("Invalid value \"" + attribRawValue + "\" for attribute \"" + attribName + "\"");
log.error("Value should be four integers of the form \"top,left,bottom,right\"");
}
} catch (IllegalAccessException ey) {
log.error("Unable to set constraint \"" + attribName + ". IllegalAccessException error thrown.");
} catch (NumberFormatException ex) {
log.error("Invalid value \"" + attribRawValue + "\" for attribute \"" + attribName + "\"");
log.error("Value should be four integers of the form \"top,left,bottom,right\"");
}
break;
default:
log.error("Required \"" + constraintType + "\" handler for attribute \"" + attribName + "\" not defined in JMRI code");
log.error("Please file a JMRI bug report at https://sourceforge.net/p/jmri/bugs/new/");
break;
}
}
// log.info("Updated globs.GridBagConstraints.gridx="+globs.gridConstraints.gridx+";globs.GridBagConstraints.gridy="+globs.gridConstraints.gridy);
// create a panel to add as a new grid item
final JPanel c = new JPanel();
panelList.add(c);
GridBagLayout g = new GridBagLayout();
GridBagConstraints cs = new GridBagConstraints();
c.setLayout(g);
// handle the xml definition
// for all elements in the grid item
List<Element> elemList = element.getChildren();
log.trace("newGridItem starting with {} elements", elemList.size());
for (int i = 0; i < elemList.size(); i++) {
// update the grid position
cs.gridy = 0;
cs.gridx++;
Element e = elemList.get(i);
String name = e.getName();
log.trace("newGridItem processing {} element", name);
// decode the type
if (name.equals("display")) {
// its a variable
// load the variable
newVariable(e, c, g, cs, showStdName);
} else if (name.equals("separator")) {
// its a separator
JSeparator j = new JSeparator(javax.swing.SwingConstants.VERTICAL);
cs.fill = GridBagConstraints.BOTH;
cs.gridheight = GridBagConstraints.REMAINDER;
g.setConstraints(j, cs);
c.add(j);
cs.fill = GridBagConstraints.NONE;
cs.gridheight = 1;
} else if (name.equals("label")) {
cs.gridheight = GridBagConstraints.REMAINDER;
makeLabel(e, c, g, cs);
} else if (name.equals("soundlabel")) {
cs.gridheight = GridBagConstraints.REMAINDER;
makeSoundLabel(e, c, g, cs);
} else if (name.equals("cvtable")) {
makeCvTable(cs, g, c);
} else if (name.equals("indxcvtable")) {
log.debug("starting to build IndexedCvTable pane");
JTable indxcvTable = new JTable(_indexedCvModel);
JScrollPane cvScroll = new JScrollPane(indxcvTable);
indxcvTable.setDefaultRenderer(JTextField.class, new ValueRenderer());
indxcvTable.setDefaultRenderer(JButton.class, new ValueRenderer());
indxcvTable.setDefaultEditor(JTextField.class, new ValueEditor());
indxcvTable.setDefaultEditor(JButton.class, new ValueEditor());
indxcvTable.setRowHeight(new JButton("X").getPreferredSize().height);
indxcvTable.setPreferredScrollableViewportSize(new Dimension(700, indxcvTable.getRowHeight() * 14));
cvScroll.setColumnHeaderView(indxcvTable.getTableHeader());
// don't want a horizontal scroll bar
// Need to see the whole row at one time
// indxcvTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
cs.gridwidth = GridBagConstraints.REMAINDER;
g.setConstraints(cvScroll, cs);
c.add(cvScroll);
cs.gridwidth = 1;
// remember which indexed CVs to read/write
for (int j = 0; j < _indexedCvModel.getRowCount(); j++) {
String sz = "CV" + _indexedCvModel.getName(j);
int in = _varModel.findVarIndex(sz);
indexedCvList.add(in);
}
_cvTable = true;
log.debug("end of building IndexedCvTable pane");
} else if (name.equals("fnmapping")) {
pickFnMapPanel(c, g, cs, modelElem);
} else if (name.equals("dccaddress")) {
JPanel l = addDccAddressPanel(e);
if (l.getComponentCount() > 0) {
cs.gridheight = GridBagConstraints.REMAINDER;
g.setConstraints(l, cs);
c.add(l);
cs.gridheight = 1;
}
} else if (name.equals("column")) {
// nested "column" elements ...
cs.gridheight = GridBagConstraints.REMAINDER;
JPanel l = newColumn(e, showStdName, modelElem);
if (l.getComponentCount() > 0) {
panelList.add(l);
g.setConstraints(l, cs);
c.add(l);
cs.gridheight = 1;
}
} else if (name.equals("row")) {
// nested "row" elements ...
cs.gridwidth = GridBagConstraints.REMAINDER;
JPanel l = newRow(e, showStdName, modelElem);
if (l.getComponentCount() > 0) {
panelList.add(l);
g.setConstraints(l, cs);
c.add(l);
cs.gridwidth = 1;
}
} else if (name.equals("grid")) {
// nested "grid" elements ...
cs.gridwidth = GridBagConstraints.REMAINDER;
JPanel l = newGrid(e, showStdName, modelElem);
if (l.getComponentCount() > 0) {
panelList.add(l);
g.setConstraints(l, cs);
c.add(l);
cs.gridwidth = 1;
}
} else if (name.equals("group")) {
// nested "group" elements ...
JPanel l = newGroup(e, showStdName, modelElem);
if (l.getComponentCount() > 0) {
panelList.add(l);
g.setConstraints(l, cs);
c.add(l);
}
} else if (!name.equals("qualifier")) {
// its a mistake
log.error("No code to handle element of type " + e.getName() + " in newGridItem");
}
}
globs.gridxCurrent = globs.gridConstraints.gridx;
globs.gridyCurrent = globs.gridConstraints.gridy;
// add glue to the bottom to allow resize
if (c.getComponentCount() > 0) {
c.add(Box.createVerticalGlue());
}
// handle qualification if any
QualifierAdder qa = new QualifierAdder() {
@Override
protected Qualifier createQualifier(VariableValue var, String relation, String value) {
return new JComponentQualifier(c, var, Integer.parseInt(value), relation);
}
@Override
protected void addListener(java.beans.PropertyChangeListener qc) {
c.addPropertyChangeListener(qc);
}
};
qa.processModifierElements(element, _varModel);
return c;
}
Aggregations