List of usage examples for org.jdom2 Element getValue
@Override
public String getValue()
From source file:org.transitime.avl.ZonarAvlModule.java
License:Open Source License
@Override protected void extractAvlData(Document doc) throws NumberFormatException { logger.info("Extracting data from xml file"); // Get root of doc Element rootNode = doc.getRootElement(); List<Element> assets = rootNode.getChildren("asset"); for (Element asset : assets) { String vehicleId = asset.getAttributeValue("id"); // Only need 5 digits of precision for lat & lon. Anything more // than that is silly. String latStr = asset.getChild("lat").getValue(); double lat = MathUtils.round(Double.parseDouble(latStr), 5); String lonStr = asset.getChild("long").getValue(); double lon = MathUtils.round(Double.parseDouble(lonStr), 5); String headingStr = asset.getChild("heading").getValue(); float heading = Float.parseFloat(headingStr); Element speedElement = asset.getChild("speed"); String speedStr = speedElement.getValue(); float speed = Float.parseFloat(speedStr); String unitsStr = speedElement.getAttributeValue("unit"); if (unitsStr.equals("Km/Hour")) { speed *= KM_PER_HOUR_TO_METERS_PER_SEC; } else {//from ww w .jav a 2 s . c o m logger.error("Cannot handle units of \"{}\" for Zonar feed.", unitsStr); } String timeStr = asset.getChild("time").getValue(); long time = Long.parseLong(timeStr) * Time.MS_PER_SEC; // Power and odometer are currently not used but are processed // here just in case they are helpful in the future @SuppressWarnings("unused") String power = asset.getChild("power").getValue(); // on or off @SuppressWarnings("unused") String odometer = asset.getChild("odometer").getValue(); // Create and process the AVL report. AvlReport avlReport = new AvlReport(vehicleId, time, MathUtils.round(lat, 5), MathUtils.round(lon, 5), speed, heading, "Zonar"); processAvlReport(avlReport); } }
From source file:org.universaal.tools.configurationEditor.editors.ConfigurationEditor.java
License:Apache License
private void showSimpleConfigItem(Element el) { for (Control wi : selectedItemGroup.getChildren()) { wi.dispose();/* w ww . ja va 2s. c om*/ } List<Attribute> tiAtts = el.getAttributes(); Label l1; Text t1; for (Attribute att : tiAtts) { l1 = new Label(selectedItemGroup, SWT.NONE); l1.setText(att.getName() + ":"); t1 = new Text(selectedItemGroup, SWT.SINGLE | SWT.BORDER); t1.setEditable(true); t1.setText(att.getValue()); // ------------- <Listener> -------------- WidgetMapping.put(t1, att); t1.addModifyListener(widgetListener); // ------------- </Listener> -------------- GridData gd = new GridData(); gd.horizontalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; t1.setLayoutData(gd); } // TI's children List<Element> tiEls = el.getChildren(); for (Element tiEl : tiEls) { if (tiEl.getName().equals("validators")) { //DO NOTHING! } else { l1 = new Label(selectedItemGroup, SWT.NONE); l1.setText(tiEl.getName() + ":"); t1 = new Text(selectedItemGroup, SWT.SINGLE | SWT.BORDER); t1.setEditable(true); t1.setText(tiEl.getValue()); // ------------- <Listener> -------------- WidgetMapping.put(t1, tiEl); t1.addModifyListener(widgetListener); // ------------- </Listener> -------------- GridData gd = new GridData(); gd.horizontalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; t1.setLayoutData(gd); } } }
From source file:org.universaal.tools.configurationEditor.editors.ConfigurationEditor.java
License:Apache License
private void showMapConfigItem(Element el) { for (Control wi : selectedItemGroup.getChildren()) { wi.dispose();/*from w ww . java2 s . c om*/ } List<Attribute> tiAtts = el.getAttributes(); Label l1; Text t1; for (Attribute att : tiAtts) { l1 = new Label(selectedItemGroup, SWT.NONE); l1.setText(att.getName() + ":"); t1 = new Text(selectedItemGroup, SWT.SINGLE | SWT.BORDER); t1.setEditable(true); t1.setText(att.getValue()); // ------------- <Listener> -------------- WidgetMapping.put(t1, att); t1.addModifyListener(widgetListener); // ------------- </Listener> -------------- GridData gd = new GridData(); gd.horizontalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; t1.setLayoutData(gd); } // TI's children List<Element> tiEls = el.getChildren(); for (Element tiEl : tiEls) { // mapConfigItem if (tiEl.getName().equals("options")) { // l1 = new Label(selectedItemGroup, SWT.NONE); // l1.setText(tiEl.getName() + ":"); // Combo combo = new Combo(selectedItemGroup, SWT.NONE | SWT.READ_ONLY); List<Element> opt = tiEl.getChildren(); for (Element e : opt) { l1 = new Label(selectedItemGroup, SWT.NONE); l1.setText(e.getName() + ":"); t1 = new Text(selectedItemGroup, SWT.SINGLE | SWT.BORDER); t1.setEditable(true); t1.setText(e.getValue()); // ------------- <Listener> -------------- WidgetMapping.put(t1, e); t1.addModifyListener(widgetListener); // ------------- </Listener> -------------- GridData gd = new GridData(); gd.horizontalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; t1.setLayoutData(gd); } // GridData gd = new GridData(); // gd.horizontalAlignment = GridData.FILL; // gd.grabExcessHorizontalSpace = true; // combo.setLayoutData(gd); // Validators } else if (tiEl.getName().equals("validators")) { //DO NOTHING! } else { l1 = new Label(selectedItemGroup, SWT.NONE); l1.setText(tiEl.getName() + ":"); t1 = new Text(selectedItemGroup, SWT.SINGLE | SWT.BORDER); t1.setEditable(true); t1.setText(tiEl.getValue()); // ------------- <Listener> -------------- WidgetMapping.put(t1, tiEl); t1.addModifyListener(widgetListener); // ------------- </Listener> -------------- GridData gd = new GridData(); gd.horizontalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; t1.setLayoutData(gd); } } }
From source file:org.universaal.tools.configurationEditor.editors.ConfigurationEditor.java
License:Apache License
private void showValidator(Element e) { for (Control wi : selectedItemGroup.getChildren()) { wi.dispose();/* w w w . jav a 2s . c o m*/ } Label l1; Text t1; l1 = new Label(selectedItemGroup, SWT.NONE); l1.setText("class:"); l1.pack(); t1 = new Text(selectedItemGroup, SWT.SINGLE | SWT.BORDER); t1.setEditable(true); t1.setText(e.getAttributeValue("class")); t1.pack(); // ------------- <Listener> -------------- WidgetMapping.put(t1, e.getAttribute("class")); t1.addModifyListener(widgetListener); // ------------- </Listener> -------------- GridData gd = new GridData(); gd.horizontalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; t1.setLayoutData(gd); // Validator attributs List<Element> vAtts = e.getChildren(); for (Element vAt : vAtts) { l1 = new Label(selectedItemGroup, SWT.NONE); l1.setText(vAt.getName() + ":"); t1 = new Text(selectedItemGroup, SWT.SINGLE | SWT.BORDER); t1.setEditable(true); t1.setText(vAt.getValue()); // ------------- <Listener> -------------- WidgetMapping.put(t1, vAt); t1.addModifyListener(widgetListener); // ------------- </Listener> -------------- gd = new GridData(); gd.horizontalAlignment = GridData.FILL; gd.grabExcessHorizontalSpace = true; t1.setLayoutData(gd); } }
From source file:org.yawlfoundation.yawl.engine.YWorkItem.java
License:Open Source License
private YLogDataItemList assembleLogDataItemList(Element data, boolean input) { YLogDataItemList result = new YLogDataItemList(); if (data != null) { Map<String, YParameter> params = _engine.getParameters(_specID, getTaskID(), input); String descriptor = (input ? "Input" : "Output") + "VarAssignment"; for (Element child : data.getChildren()) { String name = child.getName(); String value = child.getValue(); YParameter param = params.get(name); if (param != null) { String dataType = param.getDataTypeNameUnprefixed(); // if a complex type, store the structure with the value if (child.getContentSize() > 1) { value = JDOMUtil.elementToString(child); }/*ww w. ja va2 s . c o m*/ result.add(new YLogDataItem(descriptor, name, value, dataType)); // add any configurable logging predicates for this parameter YLogDataItem dataItem = getDataLogPredicate(param, input); if (dataItem != null) result.add(dataItem); } } } return result; }
From source file:org.yawlfoundation.yawl.procletService.blockType.BlockCP.java
License:Open Source License
public static List<EntityMID> getEntityMIDsFromData(Element dataList) { List<EntityMID> returnList = new ArrayList<EntityMID>(); Element eidData = dataList.getChild("entities"); if (eidData != null) { List<Element> children = eidData.getChildren("entity"); for (Element child : children) { Element emid = child.getChild("entity_id"); String value = emid.getValue().trim(); returnList.add(new EntityMID(value)); }/*from w w w. java2s . com*/ } return returnList; }
From source file:org.yawlfoundation.yawl.procletService.blockType.BlockPI.java
License:Open Source License
public static void calculateDataPassing(List<EntityID> eids, WorkItemRecord wir) { myLog.debug("CALCULATEDATAPASSING"); // get datalist Element dl = wir.getDataList(); Element eidData = dl.getChild("entities"); // get relevant perfs List<Performative> relPerfs = new ArrayList<Performative>(); for (EntityID eid : eids) { for (Performative perf : Performatives.getInstance().getPerformatives()) { for (EntityID eidPerf : perf.getEntityIDs()) { if (eidPerf.toString().equals(eid.toString())) { // 20022010 // check if perf not already in boolean alreadyIn = false; for (Performative perfCheck : relPerfs) { if (perfCheck.equalContent(perf)) { alreadyIn = true; }/*from w ww . j a v a 2 s. c o m*/ } if (!alreadyIn) { relPerfs.add(perf); } break; } } } } myLog.debug("relPerfs:" + relPerfs); if (eidData != null) { for (Performative perf : relPerfs) { // go through content of performative String content = perf.getContent(); myLog.debug("eids:" + perf.getEntityIDs().toString()); myLog.debug("content:" + content); Element eltContent = JDOMUtil.stringToElement(content); List<Element> entitiesElts = eltContent.getChildren("entity"); for (Element entityElt : entitiesElts) { // get the name Element emid = entityElt.getChild("entity_id"); String value = emid.getValue().trim(); myLog.debug("value:" + value); // check if the data of the wir we also have an emid with the same name // also check if entityElt is RELEVANT!!! so is it contained in eids // 20022010 boolean found = false; for (EntityID eid : eids) { if (value.equals(eid.getEmid().getValue())) { found = true; } } if (eidData != null && found) { boolean match = false; List<Element> children = eidData.getChildren("entity"); for (Element child : children) { myLog.debug("have entity"); Element emidData = child.getChild("entity_id"); String valueData = emidData.getValue().trim(); myLog.debug("entity_id:" + valueData); if (valueData.equals(value)) { // match match = true; // add the data List<Element> nvsPerf = entityElt.getChildren("name_value_pair"); for (Element nvPerf : nvsPerf) { String nameNvPerf = nvPerf.getChild("name").getValue().trim(); String valueNvPerf = nvPerf.getChild("value").getValue().trim(); // find out whether I have an nv in the wir with the same name List<Element> nvsWir = child.getChildren("name_value_pair"); boolean match2 = false; for (Element nvWir : nvsWir) { String nameNvWir = nvWir.getChild("name").getValue().trim(); String valueNvWir = nvWir.getChild("value").getValue().trim(); if (nameNvWir.equals(nameNvPerf)) { // have a match match2 = true; nvWir.getChild("value").setText(valueNvPerf); break; } } if (!match2) { // no nv pair with such a name exists myLog.debug("no nv pair with such a name exists!"); // add one Element newElt = new Element("name_value_pair"); Element nameElt = new Element("name"); nameElt.setText(nameNvPerf); Element valueElt = new Element("value"); valueElt.setText(valueNvPerf); newElt.addContent(nameElt); newElt.addContent(valueElt); myLog.debug("newElt:" + JDOMUtil.elementToString(newElt)); child.addContent(newElt); } } break; } } if (!match) { // no emid with same name in the data of the wir myLog.debug("no emid with the same name in data of wir!"); // eid Element newEntityElt = new Element("entity"); String eid = entityElt.getChild("entity_id").getValue(); Element eidElt = new Element("entity_id"); eidElt.setText(eid); newEntityElt.addContent(eidElt); // nv pairs List<Element> elts = entityElt.getChildren("name_value_pair"); for (Element elt : elts) { String name = elt.getChild("name").getValue(); String valueElt = elt.getChild("value").getValue(); Element nvElt = new Element("name_value_pair"); Element newNameElt = new Element("name"); newNameElt.setText(name); Element newValueElt = new Element("value"); newValueElt.setText(valueElt); nvElt.addContent(newNameElt); nvElt.addContent(newValueElt); newEntityElt.addContent(nvElt); } myLog.debug("newEntityElt:" + JDOMUtil.elementToString(newEntityElt)); eidData.addContent(newEntityElt); } } } } } // done myLog.debug("dl:" + JDOMUtil.elementToString(dl)); wir.setDataList(dl); myLog.debug("data wir:" + wir.getDataListString()); }
From source file:org.yawlfoundation.yawl.procletService.blockType.BlockPICreate.java
License:Open Source License
private String removeUnneededData(String s, List<EntityID> eids) { myLog.debug("REMOVEUNNEEDEDDATA"); List<Element> eltsRemove = new ArrayList<Element>(); Element dataList = JDOMUtil.stringToElement(s).clone(); myLog.debug("dataList:" + JDOMUtil.elementToString(dataList)); //Element eidData = dataList.getChild("entity"); Element eidData = dataList;// ww w .ja v a2s . c o m if (eidData != null) { myLog.debug("have entities"); List<Element> children = eidData.getChildren("entity"); for (Element child : children) { myLog.debug("have entity"); Element emid = child.getChild("entity_id"); String value = emid.getValue().trim(); myLog.debug("value:" + value); // check if this one occurs in eids boolean match = false; for (EntityID eid : eids) { if (eid.getEmid().getValue().equals(value)) { // match myLog.debug("found match"); match = true; break; } } if (!match) { eltsRemove.add(child); } } } myLog.debug("eltsRemove:" + eltsRemove.toString()); Element eidData2 = dataList; if (eidData != null) { myLog.debug("have entities"); for (Element eltSave : eltsRemove) { eidData2.removeContent(eltSave); } } String outputStr = JDOMUtil.elementToString(eidData2); myLog.debug("outputStr:" + outputStr); return outputStr; }
From source file:org.yawlfoundation.yawl.procletService.state.Performatives.java
License:Open Source License
public static String calculateContent(List<EntityID> eids, WorkItemRecord wir) { myLog.debug("CALCULATECONTENT"); myLog.debug("eids:" + eids); Element dataList = wir.getDataList(); if (dataList != null) { dataList = dataList.clone();//w ww. j a v a 2 s . c o m myLog.debug("dataList:" + JDOMUtil.elementToString(dataList)); Element eidData = dataList.getChild("entities"); List<Element> eltsRemove = new ArrayList<Element>(); if (eidData != null) { myLog.debug("have entities"); List<Element> children = eidData.getChildren("entity"); for (Element child : children) { myLog.debug("have entity"); Element emid = child.getChild("entity_id"); String value = emid.getValue().trim(); myLog.debug("value:" + value); // check if this one occurs in eids boolean match = false; for (EntityID eid : eids) { if (eid.getEmid().getValue().equals(value)) { // match myLog.debug("found match"); match = true; break; } } if (!match) { eltsRemove.add(child); } } } // remove what is not needed myLog.debug("eltsRemove:" + eltsRemove.toString()); Element eidData2 = dataList.getChild("entities"); if (eidData != null) { myLog.debug("have entities"); for (Element eltSave : eltsRemove) { eidData2.removeContent(eltSave); } } // // create output // Element output = new Element("entities"); // for (Element elt : eltsSave) { // output.addContent(elt); // } String outputStr = JDOMUtil.elementToString(eidData2); myLog.debug("outputStr:" + outputStr); return outputStr; } else { // get from the graphs which entities it concerns List<EntityMID> emids = new ArrayList<EntityMID>(); myLog.debug("wir:" + wir); List<InteractionGraph> graphs = InteractionGraphs.getInstance().getGraphs(); for (InteractionGraph graph : graphs) { if (!graph.getEntityMID().getValue().contains("TEMP")) { for (InteractionArc arc : graph.getArcs()) { myLog.debug("arc:" + arc); // check the tail if (arc.getTail().getClassID().equals(wir.getSpecURI()) && arc.getTail().getProcletID().equals(wir.getCaseID()) && arc.getTail().getBlockID().equals(wir.getTaskID())) { myLog.debug("in loop"); EntityMID emid = arc.getEntityID().getEmid(); // check if not already in emids boolean check = false; for (EntityMID emidC : emids) { if (emidC.getValue().equals(emid.getValue())) { check = true; } } if (!check) { emids.add(emid); myLog.debug("emid added:" + emid); } } } } } // have the relevant emids Element newEntsElt = new Element("entities"); for (EntityMID emid : emids) { Element newEntElt = new Element("entity"); Element newEidElt = new Element("entity_id"); newEidElt.setText(emid.getValue()); newEntElt.addContent(newEidElt); newEntsElt.addContent(newEntElt); } String outputStr = JDOMUtil.elementToString(newEntsElt); myLog.debug("outputStr:" + outputStr); return outputStr; } }
From source file:password.pwm.config.PwmSetting.java
License:Open Source License
public Map<String, String> getOptions() { final Element settingElement = PwmSettingXml.readSettingXml(this); final Element optionsElement = settingElement.getChild("options"); final Map<String, String> returnList = new LinkedHashMap<>(); if (optionsElement != null) { final List<Element> optionElements = optionsElement.getChildren("option"); if (optionElements != null) { for (Element optionElement : optionElements) { if (optionElement.getAttribute("value") == null) { throw new IllegalStateException( "option element is missing 'value' attribute for key " + this.getKey()); }//from w ww. j a va 2 s. c o m returnList.put(optionElement.getAttribute("value").getValue(), optionElement.getValue()); } } } return Collections.unmodifiableMap(returnList); }