List of usage examples for org.jdom2 Attribute getValue
public String getValue()
Attribute
. From source file:org.esa.snap.core.dataop.downloadable.XMLSupport.java
License:Open Source License
public static String getAttrib(final Element elem, final String tag) { final Attribute attrib = elem.getAttribute(tag); if (attrib != null) return attrib.getValue(); return ""; }
From source file:org.esa.snap.dataio.netcdf.metadata.profiles.hdfeos.HdfEosMetadataPart.java
License:Open Source License
private static void addDomToMetadata(Element childDE, String name, MetadataElement parentME) { if (childDE.getChildren().size() > 0 || childDE.getAttributes().size() > 0) { final MetadataElement childME = new MetadataElement(name); addDomToMetadata(childDE, childME); parentME.addElement(childME);// w w w . j av a2 s . c o m if (childDE.getAttributes().size() != 0) { List attrList = childDE.getAttributes(); for (Object o : attrList) { Attribute attribute = (Attribute) o; String attributeName = attribute.getName(); String attributeValue = attribute.getValue(); final ProductData valueMEAtrr = ProductData.createInstance(attributeValue); final MetadataAttribute mdAttribute = new MetadataAttribute(attributeName, valueMEAtrr, true); childME.addAttribute(mdAttribute); } } } else { String valueDE = childDE.getValue(); if (valueDE == null) { valueDE = ""; } final ProductData valueME = ProductData.createInstance(valueDE); final MetadataAttribute attribute = new MetadataAttribute(name, valueME, true); parentME.addAttribute(attribute); } }
From source file:org.esa.snap.datamodel.metadata.AbstractMetadataIO.java
License:Open Source License
private static void loadAttribute(final Element domElem, final MetadataElement rootElem) { final Attribute nameAttrib = domElem.getAttribute(NAME); if (nameAttrib == null) return;// w w w. jav a2 s.c o m final String name = nameAttrib.getValue(); if (name == null) return; final Attribute valueAttrib = domElem.getAttribute(VALUE); if (valueAttrib == null) return; final Attribute typeAttrib = domElem.getAttribute(TYPE); Integer typeFromFile = null; if (typeAttrib != null) { typeFromFile = Integer.parseInt(typeAttrib.getValue()); } MetadataAttribute metaAttrib = rootElem.getAttribute(name); if (metaAttrib == null) { if (typeFromFile != null) { metaAttrib = new MetadataAttribute(name, typeFromFile); rootElem.addAttribute(metaAttrib); } else { return; } } final int type = metaAttrib.getDataType(); if (type == ProductData.TYPE_ASCII) { String valStr = valueAttrib.getValue(); if (valStr == null || valStr.isEmpty()) valStr = " "; metaAttrib.getData().setElems(valStr); } else if (type == ProductData.TYPE_UTC || typeFromFile == ProductData.TYPE_UTC) { metaAttrib.getData().setElems(AbstractMetadata.parseUTC(valueAttrib.getValue()).getArray()); } else if (type == ProductData.TYPE_FLOAT64 || type == ProductData.TYPE_FLOAT32) { metaAttrib.getData().setElemDouble(Double.parseDouble(valueAttrib.getValue())); } else if (type == ProductData.TYPE_INT8 && typeFromFile != null && typeFromFile == ProductData.TYPE_ASCII) { metaAttrib.getData().setElems(valueAttrib.getValue()); } else { metaAttrib.getData().setElemInt(Integer.parseInt(valueAttrib.getValue())); } final Attribute unitAttrib = domElem.getAttribute("unit"); final Attribute descAttrib = domElem.getAttribute("desc"); if (descAttrib != null) metaAttrib.setDescription(descAttrib.getValue()); if (unitAttrib != null) metaAttrib.setUnit(unitAttrib.getValue()); }
From source file:org.esa.snap.datamodel.metadata.AbstractMetadataIO.java
License:Open Source License
private static void parseTiePointGrids(final Product product, final Element tpgElem) throws IOException { final List tpgElements = tpgElem.getContent(); for (Object o : tpgElements) { if (!(o instanceof Element)) continue; final Element elem = (Element) o; final String name = elem.getName(); final List content = elem.getContent(); final List<Float> valueList = new ArrayList<>(); int columnCount = 0; int rowCount = 0; for (Object row : content) { if (!(row instanceof Element)) continue; final Element rowElem = (Element) row; final Attribute value = rowElem.getAttribute("value"); int columns = parseTiePointGirdRow(value.getValue(), valueList); if (columnCount == 0) columnCount = columns;/*from w w w . j a v a 2s . c om*/ else if (columnCount != columns) throw new IOException( "Metadata for tie-point-grid " + name + " has incorrect number of columns"); ++rowCount; } addTiePointGrid(product, name, valueList, columnCount, rowCount); } // update GeoCoding setGeoCoding(product); }
From source file:org.esa.snap.datamodel.metadata.AbstractMetadataIO.java
License:Open Source License
/** * Add metadata from an XML file into the Metadata of the product * * @param xmlRoot root element of xml file * @param metadataRoot MetadataElement to place it into */// w ww . ja va 2s . c o m public static void AddXMLMetadata(final Element xmlRoot, final MetadataElement metadataRoot) { final String rootName = xmlRoot.getName(); final boolean rootChildrenEmpty = xmlRoot.getChildren().isEmpty(); if (rootChildrenEmpty && xmlRoot.getAttributes().isEmpty()) { if (!xmlRoot.getValue().isEmpty()) { addAttribute(metadataRoot, rootName, xmlRoot.getValue()); } } else if (rootChildrenEmpty) { final MetadataElement metaElem = new MetadataElement(rootName); if (!xmlRoot.getValue().isEmpty()) addAttribute(metaElem, rootName, xmlRoot.getValue()); final List<Attribute> xmlAttribs = xmlRoot.getAttributes(); for (Attribute aChild : xmlAttribs) { addAttribute(metaElem, aChild.getName(), aChild.getValue()); } metadataRoot.addElement(metaElem); } else { final MetadataElement metaElem = new MetadataElement(rootName); final List children = xmlRoot.getContent(); for (Object aChild : children) { if (aChild instanceof Element) { AddXMLMetadata((Element) aChild, metaElem); } else if (aChild instanceof Attribute) { final Attribute childAtrrib = (Attribute) aChild; addAttribute(metaElem, childAtrrib.getName(), childAtrrib.getValue()); } } final List<Attribute> xmlAttribs = xmlRoot.getAttributes(); for (Attribute aChild : xmlAttribs) { addAttribute(metaElem, aChild.getName(), aChild.getValue()); } metadataRoot.addElement(metaElem); } }
From source file:org.esa.snap.db.DBQuery.java
License:Open Source License
private static GregorianCalendar getCalendarDate(final Element elem) { final Attribute y = elem.getAttribute("year"); final Attribute m = elem.getAttribute("month"); final Attribute d = elem.getAttribute("day"); if (y != null && m != null && d != null) { return new GregorianCalendar(Integer.parseInt(y.getValue()), Integer.parseInt(m.getValue()), Integer.parseInt(d.getValue())); }//from www. j ava2s . co m return null; }
From source file:org.esa.snap.framework.dataop.downloadable.ftpUtils.java
License:Open Source License
public static Map<String, Long> readRemoteFileList(final ftpUtils ftp, final String server, final String remotePath) { boolean useCachedListing = true; final String tmpDirUrl = SystemUtils.getApplicationDataDir().getAbsolutePath(); final File listingFile = new File(tmpDirUrl + "//" + server + ".listing.xml"); if (!listingFile.exists()) useCachedListing = false;// w w w.j a v a 2 s . c om final Map<String, Long> fileSizeMap = new HashMap<>(900); if (useCachedListing) { Document doc = null; try { doc = XMLSupport.LoadXML(listingFile.getAbsolutePath()); } catch (IOException e) { useCachedListing = false; } if (useCachedListing) { final Element root = doc.getRootElement(); boolean listingFound = false; final List children1 = root.getContent(); for (Object c1 : children1) { if (!(c1 instanceof Element)) continue; final Element remotePathElem = (Element) c1; final Attribute pathAttrib = remotePathElem.getAttribute("path"); if (pathAttrib != null && pathAttrib.getValue().equalsIgnoreCase(remotePath)) { listingFound = true; final List children2 = remotePathElem.getContent(); for (Object c2 : children2) { if (!(c2 instanceof Element)) continue; final Element fileElem = (Element) c2; final Attribute attrib = fileElem.getAttribute("size"); if (attrib != null) { try { fileSizeMap.put(fileElem.getName(), attrib.getLongValue()); } catch (Exception e) { // } } } } } if (!listingFound) useCachedListing = false; } } if (!useCachedListing) { try { final FTPFile[] remoteFileList = ftp.getRemoteFileList(remotePath); if (remoteFileList != null) { writeRemoteFileList(remoteFileList, server, remotePath, listingFile); for (FTPFile ftpFile : remoteFileList) { fileSizeMap.put(ftpFile.getName(), ftpFile.getSize()); } } } catch (Exception e) { System.out.println("Unable to get remote file list " + e.getMessage()); } } return fileSizeMap; }
From source file:org.esa.snap.productlibrary.rcp.toolviews.AOIMonitoring.model.AOI.java
License:Open Source License
private boolean load(final File file) { Document doc;/*from w w w . j a va 2 s .com*/ try { doc = XMLSupport.LoadXML(file.getAbsolutePath()); final Element root = doc.getRootElement(); final Attribute nameAttrib = root.getAttribute("name"); if (nameAttrib != null) this.name = nameAttrib.getValue(); final List<GeoPos> geoPosList = new ArrayList<GeoPos>(); final List<Content> children = root.getContent(); for (Object aChild : children) { if (aChild instanceof Element) { final Element child = (Element) aChild; if (child.getName().equals("param")) { inputFolder = XMLSupport.getAttrib(child, "inputFolder"); outputFolder = XMLSupport.getAttrib(child, "outputFolder"); processingGraph = XMLSupport.getAttrib(child, "graph"); lastProcessed = XMLSupport.getAttrib(child, "lastProcessed"); final Attribute findSlavesAttrib = child.getAttribute("findSlaves"); if (findSlavesAttrib != null) findSlaves = Boolean.parseBoolean(findSlavesAttrib.getValue()); final Attribute maxSlavesAttrib = child.getAttribute("maxSlaves"); if (maxSlavesAttrib != null) maxSlaves = Integer.parseInt(maxSlavesAttrib.getValue()); } else if (child.getName().equals("points")) { final List<Content> pntsList = child.getContent(); for (Object o : pntsList) { if (o instanceof Element) { final Element pntElem = (Element) o; final String latStr = XMLSupport.getAttrib(pntElem, "lat"); final String lonStr = XMLSupport.getAttrib(pntElem, "lon"); if (!latStr.isEmpty() && !lonStr.isEmpty()) { final float lat = Float.parseFloat(latStr); final float lon = Float.parseFloat(lonStr); geoPosList.add(new GeoPos(lat, lon)); } } } } else if (child.getName().equals(DBQuery.DB_QUERY)) { slaveDBQuery = new DBQuery(); //todo slaveDBQuery.fromXML(child); } } } aoiPoints = geoPosList.toArray(new GeoPos[geoPosList.size()]); } catch (IOException e) { SnapApp.getDefault().handleError("Unable to load AOI", e); return false; } return true; }
From source file:org.esa.snap.util.ftpUtils.java
License:Open Source License
public static Map<String, Long> readRemoteFileList(final ftpUtils ftp, final String server, final String remotePath) { boolean useCachedListing = true; final String tmpDirUrl = ResourceUtils.getApplicationUserTempDataDir().getAbsolutePath(); final File listingFile = new File(tmpDirUrl + "//" + server + ".listing.xml"); if (!listingFile.exists()) useCachedListing = false;// w w w . ja v a 2 s . c o m final Map<String, Long> fileSizeMap = new HashMap<>(900); if (useCachedListing) { Document doc = null; try { doc = XMLSupport.LoadXML(listingFile.getAbsolutePath()); } catch (IOException e) { useCachedListing = false; } if (useCachedListing) { final Element root = doc.getRootElement(); boolean listingFound = false; final List children1 = root.getContent(); for (Object c1 : children1) { if (!(c1 instanceof Element)) continue; final Element remotePathElem = (Element) c1; final Attribute pathAttrib = remotePathElem.getAttribute("path"); if (pathAttrib != null && pathAttrib.getValue().equalsIgnoreCase(remotePath)) { listingFound = true; final List children2 = remotePathElem.getContent(); for (Object c2 : children2) { if (!(c2 instanceof Element)) continue; final Element fileElem = (Element) c2; final Attribute attrib = fileElem.getAttribute("size"); if (attrib != null) { try { fileSizeMap.put(fileElem.getName(), attrib.getLongValue()); } catch (Exception e) { // } } } } } if (!listingFound) useCachedListing = false; } } if (!useCachedListing) { try { final FTPFile[] remoteFileList = ftp.getRemoteFileList(remotePath); writeRemoteFileList(remoteFileList, server, remotePath, listingFile); for (FTPFile ftpFile : remoteFileList) { fileSizeMap.put(ftpFile.getName(), ftpFile.getSize()); } } catch (Exception e) { System.out.println("Unable to get remote file list " + e.getMessage()); } } return fileSizeMap; }
From source file:org.fnppl.opensdx.xml.Element.java
License:Open Source License
public Vector<String[]> getAttributes() { Vector<String[]> atts = new Vector<String[]>(); List<Attribute> l = (List<Attribute>) base.getAttributes(); if (l != null) { for (Attribute a : l) { atts.add(new String[] { a.getName(), a.getValue() }); }//from w w w . j a v a 2 s . c om } return atts; }