List of usage examples for org.jdom2 Element getAttribute
public Attribute getAttribute(final String attname)
This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.
From source file:org.bbsync.utility.file.Configuration.java
License:Apache License
private static boolean isNamedElement(Element elem, String name) { Attribute elemName = elem.getAttribute("name"); if (elemName.getValue().equals(name)) { return true; }//from ww w .j a va 2s . c om return false; }
From source file:org.bbsync.utility.file.Configuration.java
License:Apache License
public static String getNamedParameterValue(List<Element> parameters, String paramName) { Iterator<Element> params = parameters.iterator(); while (params.hasNext()) { Element param = params.next(); if (isNamedElement(param, paramName)) { return param.getAttribute("value").getValue(); }// ww w . java 2 s . com } return null; }
From source file:org.da4.urlminimizer.XmlConfiguration.java
License:Apache License
@Override public ConfigVO getConfig(String filename) throws ConfigException { ConfigVO config = new ConfigVO(); SAXBuilder builder = new SAXBuilder(); Document doc = null;//from ww w. j av a 2s . com try { doc = builder.build(new File(filename)); } catch (JDOMException e) { throw new ConfigException("Error Parsing Config File", e); } catch (IOException e) { // TODO Auto-generated catch block throw new ConfigException("Error Reading Config File", e); } Element rootElement = doc.getRootElement(); Attribute attribProdName = rootElement.getAttribute("productName"); if (attribProdName == null || attribProdName.getValue() == null || attribProdName.getValue().trim().isEmpty()) throw new ConfigException("No Product name,or issue with product name"); Attribute attribRootUrl = rootElement.getAttribute("rootUrl"); if (attribRootUrl == null || attribRootUrl.getValue() == null || attribRootUrl.getValue().trim().isEmpty()) throw new ConfigException("No Root Url,or issue with URL"); config.setProductName(attribProdName.getValue()); config.setRootUrl(attribRootUrl.getValue()); List<PluginVO> pluginVos = new ArrayList<PluginVO>(); List<Element> xmlPluginList = rootElement.getChildren("plugin"); for (Element xmlPlugin : xmlPluginList) { String hooksRaw = xmlPlugin.getAttributeValue("hook"); List<Hook> hooks = new ArrayList<Hook>(); if (!"".equalsIgnoreCase(hooksRaw.trim())) { String[] hooksSplit = hooksRaw.split(","); for (String hook : hooksSplit) { hooks.add(Hook.get(hook)); } } PluginVO pluginVo = new PluginVO(xmlPlugin.getAttributeValue("class"), hooks); Map<String, String> attribMap = new LinkedHashMap<String, String>(); List<Element> xmlPluginAttribs = xmlPlugin.getChildren("attribute"); for (Element xmlAttribute : xmlPluginAttribs) { attribMap.put(xmlAttribute.getAttributeValue("name"), xmlAttribute.getAttributeValue("value")); } pluginVo.setAttributes(attribMap); pluginVos.add(pluginVo); } config.setPluginConfigs(pluginVos); return config; }
From source file:org.esa.nest.dat.layersrc.ObjectDetectionLayer.java
License:Open Source License
private void LoadTargets(final File file) { if (file == null) return;//from ww w.jav a2 s . com Document doc; try { doc = XMLSupport.LoadXML(file.getAbsolutePath()); } catch (IOException e) { return; } targetList.clear(); final Element root = doc.getRootElement(); final List children = root.getContent(); for (Object aChild : children) { if (aChild instanceof Element) { final Element targetsDetectedElem = (Element) aChild; if (targetsDetectedElem.getName().equals("targetsDetected")) { final Attribute attrib = targetsDetectedElem.getAttribute("bandName"); if (attrib != null && band.getName().equalsIgnoreCase(attrib.getValue())) { final List content = targetsDetectedElem.getContent(); for (Object det : content) { if (det instanceof Element) { final Element targetElem = (Element) det; if (targetElem.getName().equals("target")) { final Attribute lat = targetElem.getAttribute("lat"); if (lat == null) continue; final Attribute lon = targetElem.getAttribute("lon"); if (lon == null) continue; final Attribute width = targetElem.getAttribute("width"); if (width == null) continue; final Attribute length = targetElem.getAttribute("length"); if (length == null) continue; final Attribute intensity = targetElem.getAttribute("intensity"); if (intensity == null) continue; targetList.add(new ObjectDiscriminationOp.ShipRecord( Double.parseDouble(lat.getValue()), Double.parseDouble(lon.getValue()), (Double.parseDouble(width.getValue()) / rangeSpacing) + border, (Double.parseDouble(length.getValue()) / azimuthSpacing) + border, Double.parseDouble(intensity.getValue()))); } } } } } } } }
From source file:org.esa.nest.dat.layersrc.WindFieldEstimationLayer.java
License:Open Source License
private void LoadTargets(final File file) { if (file == null) return;/*from ww w . ja va2s. co m*/ Document doc; try { doc = XMLSupport.LoadXML(file.getAbsolutePath()); } catch (IOException e) { return; } targetList.clear(); final Element root = doc.getRootElement(); final List children = root.getContent(); for (Object aChild : children) { if (aChild instanceof Element) { final Element targetsDetectedElem = (Element) aChild; if (targetsDetectedElem.getName().equals("windFieldEstimated")) { final Attribute attrib = targetsDetectedElem.getAttribute("bandName"); if (attrib != null && band.getName().equalsIgnoreCase(attrib.getValue())) { final List content = targetsDetectedElem.getContent(); for (Object det : content) { if (det instanceof Element) { final Element targetElem = (Element) det; if (targetElem.getName().equals("windFieldInfo")) { final Attribute lat = targetElem.getAttribute("lat"); if (lat == null) continue; final Attribute lon = targetElem.getAttribute("lon"); if (lon == null) continue; final Attribute speed = targetElem.getAttribute("speed"); if (speed == null) continue; final Attribute dx = targetElem.getAttribute("dx"); if (dx == null) continue; final Attribute dy = targetElem.getAttribute("dy"); if (dy == null) continue; final Attribute ratio = targetElem.getAttribute("ratio"); if (ratio == null) continue; targetList.add(new WindFieldEstimationOp.WindFieldRecord( Double.parseDouble(lat.getValue()), Double.parseDouble(lon.getValue()), Double.parseDouble(speed.getValue()), Double.parseDouble(dx.getValue()), Double.parseDouble(dy.getValue()), Double.parseDouble(ratio.getValue()))); } } } } } } } }
From source file:org.esa.nest.dat.toolviews.Projects.ProductSet.java
License:Open Source License
boolean Load(final File file) { if (!file.exists()) return false; Document doc;// ww w . j a va2 s .c om try { doc = XMLSupport.LoadXML(file.getAbsolutePath()); } catch (IOException e) { VisatApp.getApp().showErrorDialog(e.getMessage()); return false; } fileList = new ArrayList<File>(10); Element root = doc.getRootElement(); final List children = root.getContent(); for (Object aChild : children) { if (aChild instanceof Element) { final Element child = (Element) aChild; if (child.getName().equals("product")) { final Attribute attrib = child.getAttribute("path"); fileList.add(new File(attrib.getValue())); } } } return true; }
From source file:org.esa.nest.dat.toolviews.Projects.Project.java
License:Open Source License
public void LoadProject(final File file) { initProject(file);/* w w w . j a v a 2s. c o m*/ Document doc; try { doc = XMLSupport.LoadXML(file.getAbsolutePath()); } catch (IOException e) { VisatApp.getApp().showErrorDialog(e.getMessage()); return; } final Vector<ProjectSubFolder> folderList = new Vector<ProjectSubFolder>(30); final Vector<ProjectFile> prodList = new Vector<ProjectFile>(50); final Element root = doc.getRootElement(); final List children = root.getContent(); for (Object aChild : children) { if (aChild instanceof Element) { final Element child = (Element) aChild; if (child.getName().equals("subFolder")) { final Attribute attrib = child.getAttribute("name"); final ProjectSubFolder subFolder = projectSubFolders.addSubFolder(attrib.getValue()); subFolder.fromXML(child, folderList, prodList); } } } loadProducts(folderList, prodList); notifyEvent(false); showProjectsView(); }
From source file:org.esa.nest.dat.toolviews.Projects.ProjectSubFolder.java
License:Open Source License
public void fromXML(Element elem, Vector<ProjectSubFolder> folderList, Vector<ProjectFile> prodList) { final List children = elem.getContent(); for (Object aChild : children) { if (aChild instanceof Element) { final Element child = (Element) aChild; if (child.getName().equals("subFolder")) { final Attribute attrib = child.getAttribute("name"); final ProjectSubFolder subFolder = addSubFolder(attrib.getValue()); final Attribute attribUser = child.getAttribute("user"); if (attribUser != null && attrib.getValue().equals("true")) createdByUser = true; subFolder.fromXML(child, folderList, prodList); } else if (child.getName().equals("product")) { final Attribute pathAttrib = child.getAttribute("path"); final Attribute nameAttrib = child.getAttribute("name"); final File file = new File(pathAttrib.getValue()); if (file.exists()) { folderList.add(this); final ProjectFile newFile = new ProjectFile(file, nameAttrib.getValue()); boolean added = prodList.add(newFile); if (added) { newFile.setFolderType(this.folderType); }/*from ww w . j a v a 2 s . c om*/ } } } } }
From source file:org.esa.nest.dataio.binary.BinaryDBReader.java
License:Open Source License
public void readRecord(final BinaryFileReader reader) { final Element root = xmlDoc.getRootElement(); if (DEBUG_MODE) System.out.print("\nReading " + recName + "\n\n"); final List children = root.getContent(); for (Object aChild : children) { if (aChild instanceof Element) { final Element child = (Element) aChild; if (child.getName().equals("struct")) { final Attribute loopAttrib = child.getAttribute("loop"); int loop; if (loopAttrib != null) { final String loopName = loopAttrib.getValue(); loop = getAttributeInt(loopName); } else { final Attribute nloopAttrib = child.getAttribute("nloop"); loop = Integer.parseInt(nloopAttrib.getValue()); }/*from ww w . ja v a 2 s.c o m*/ final List structChildren = child.getChildren(); for (int l = 1; l <= loop; ++l) { final String suffix = " " + l; for (Object aStructChild : structChildren) { if (aStructChild instanceof Element) { if (DEBUG_MODE) { DecodeElementDebug(reader, metaMap, (Element) aStructChild, suffix); } else { DecodeElement(reader, metaMap, (Element) aStructChild, suffix); } } } } } if (DEBUG_MODE) { DecodeElementDebug(reader, metaMap, child, null); } else { DecodeElement(reader, metaMap, child, null); } } } }
From source file:org.esa.nest.dataio.binary.BinaryDBReader.java
License:Open Source License
private static void DecodeElement(final BinaryFileReader reader, final Map metaMap, final Element child, final String suffix) { String name = ""; try {//from w w w. j a v a 2 s. co m final Attribute nameAttrib = child.getAttribute("name"); final Attribute typeAttrib = child.getAttribute("type"); final Attribute numAttrib = child.getAttribute("num"); if (nameAttrib != null && typeAttrib != null && numAttrib != null) { name = nameAttrib.getValue(); if (suffix != null) name += suffix; final int type = Integer.parseInt(typeAttrib.getValue()); final int num = Integer.parseInt(numAttrib.getValue()); switch (type) { case Skip: { reader.skipBytes(num); // blank break; } case An: { metaMap.put(name, reader.readAn(num)); break; } case In: { metaMap.put(name, (int) reader.readIn(num)); break; } case B1: { metaMap.put(name, reader.readB1()); break; } case B2: { metaMap.put(name, reader.readB2()); break; } case B4: { metaMap.put(name, reader.readB4()); break; } case B8: { metaMap.put(name, reader.readB8()); break; } case Fn: { metaMap.put(name, reader.readFn(num)); break; } case En: { metaMap.put(name, reader.readEn(num)); break; } case Debug: { System.out.print(" = "); for (int i = 0; i < num; ++i) { final String tmp = reader.readAn(1); if (!tmp.isEmpty() && !tmp.equals(" ")) System.out.print(tmp); } System.out.println(); break; } default: { throw new IllegalBinaryFormatException("Unknown type " + type, reader.getCurrentPos()); } } } } catch (Exception e) { if (e.getCause() != null) System.out.println(' ' + e.toString() + ':' + e.getCause().toString() + " for " + name); else System.out.println(' ' + e.toString() + ':' + " for " + name); } }