List of usage examples for org.jdom2 Element getValue
@Override
public String getValue()
From source file:msk.drugbank4.DrugBankParser.java
License:Apache License
/** * reads groups for current drug/*from ww w . j a va 2s . c o m*/ */ private Set<String> getGroups(Element drug) { Set<String> set = new HashSet<String>(); Element groups = drug.getChild("groups", nsDrugBank); if (groups != null) { List<Element> groupList = groups.getChildren("group", nsDrugBank); for (Element group : groupList) { set.add(group.getValue()); } } return set; }
From source file:msk.drugbank4.DrugBankParser.java
License:Apache License
/** * reads inchikey for current drug//ww w. ja v a 2 s.c om */ private String getInchiKey(Element drug) { Element props = drug.getChild("calculated-properties", nsDrugBank); if (props != null) { List<Element> typeList = props.getChildren("property", nsDrugBank); for (Element type : typeList) { Element kind = type.getChild("kind", nsDrugBank); if (kind.getValue().equals("InChIKey")) { Element value = type.getChild("value", nsDrugBank); return value.getValue().substring(9); } } } return ""; }
From source file:org.apache.marmotta.ldclient.provider.mediawiki.MediawikiProvider.java
License:Apache License
protected List<String> parseRevision(URI resource, String requestUrl, Model model, ValueFactory valueFactory, Element revisions, Context context) throws RepositoryException { List<String> followUp = Collections.emptyList(); if (revisions == null) return followUp; final Element rev = revisions.getChild("rev"); if (rev == null) return followUp; final Resource subject = resource; if (context == Context.META && "0".equals(rev.getAttributeValue("parentid"))) { // This is the first revision, so we use the creation date addLiteralTriple(subject, Namespaces.NS_DC_TERMS + "created", rev.getAttributeValue("timestamp"), Namespaces.NS_XSD + "dateTime", model, valueFactory); }/*from ww w. j av a2s . co m*/ if (context == Context.CONTENT && rev.getValue() != null && rev.getValue().trim().length() > 0) { final String content = rev.getValue().trim(); final Matcher m = REDIRECT_PATTERN.matcher(content); if (((Element) revisions.getParent()).getAttribute("redirect") != null && m.find()) { followUp = Collections.singletonList(buildApiPropQueryUrl(requestUrl, m.group(1), "info", getDefaultParams("info", null), Context.REDIRECT)); } else { addLiteralTriple(subject, Namespaces.NS_RSS_CONTENT + "encoded", content, Namespaces.NS_XSD + "string", model, valueFactory); } } return followUp; }
From source file:org.artifactory.update.md.v130beta6.ChecksumsConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element root = doc.getRootElement(); Element extension = root.getChild("extension"); // rename the extensions to additionalInfo extension.setName("additionalInfo"); // now get the sha1 and md5 values Element sha1Node = extension.getChild("sha1"); String sha1 = null;//w w w .j a v a 2s. c o m if (sha1Node != null) { sha1 = sha1Node.getValue(); extension.removeContent(sha1Node); } else { log.debug("SHA1 checksum not found, setting it to {}", sha1); } Element md5Node = extension.getChild("md5"); String md5 = null; if (md5Node != null) { md5 = md5Node.getValue(); extension.removeContent(md5Node); } else { log.debug("MD5 checksum not found, setting it to {}", md5); } // create the new checksums nodes Element checksumsInfo = new Element("checksumsInfo"); extension.addContent(checksumsInfo); Element checksums = new Element("checksums"); checksumsInfo.addContent(checksums); addChecksum(checksums, ChecksumType.sha1, sha1); addChecksum(checksums, ChecksumType.md5, md5); }
From source file:org.artifactory.version.converter.v144.MultiLdapXmlConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); Element securityElement = rootElement.getChild("security", namespace); if (securityElement != null) { Element ldapSettings = securityElement.getChild("ldapSettings", namespace); if (ldapSettings != null) { String firstLdapKey = null; String ldapKeyToUse = null; List ldapSettingList = ldapSettings.getChildren("ldapSetting", namespace); if (ldapSettingList != null && !ldapSettingList.isEmpty()) { for (Object ldapSettingObject : ldapSettingList) { Element ldapSetting = (Element) ldapSettingObject; Element key = ldapSetting.getChild("key", namespace); if (firstLdapKey == null) { firstLdapKey = key.getValue(); }//from ww w . java 2 s .c o m Element enabledElement = ldapSetting.getChild("enabled", namespace); if (Boolean.parseBoolean(enabledElement.getValue())) { ldapKeyToUse = ldapSetting.getChild("key", namespace).getValue(); } } } if (ldapKeyToUse == null && firstLdapKey != null) { ldapKeyToUse = firstLdapKey; } if (ldapKeyToUse != null) { Element ldapGroupSettings = securityElement.getChild("ldapGroupSettings", namespace); if (ldapGroupSettings != null) { List ldapGroupList = ldapGroupSettings.getChildren("ldapGroupSetting", namespace); if (ldapGroupList != null && !ldapGroupList.isEmpty()) { for (Object ldapGroupSettingObject : ldapGroupList) { Element ldapGroupSetting = (Element) ldapGroupSettingObject; Element enabledLdapElement = new Element("enabledLdap", namespace); enabledLdapElement.setText(ldapKeyToUse); Element enabledContent = ldapGroupSetting.getChild("enabled", namespace); int index = ldapGroupSetting.indexOf(enabledContent); ldapGroupSetting.addContent(index, enabledLdapElement); ldapGroupSetting.removeContent(enabledContent); } } } } } } }
From source file:org.esa.nest.dataio.radarsat2.Radarsat2ProductReader.java
License:Open Source License
private void readCalibrationLUT(final String lutName, final MetadataElement root, final boolean flipLUT) throws IOException { InputStream is;/*from w w w. j a v a2s . co m*/ if (dataDir.exists(dataDir.getRootFolder() + lutName + ".xml")) { is = dataDir.getInputStream(dataDir.getRootFolder() + lutsigma + ".xml"); } else if (dataDir.exists(dataDir.getRootFolder() + lutName.toLowerCase() + ".xml")) { is = dataDir.getInputStream(dataDir.getRootFolder() + lutsigma.toLowerCase() + ".xml"); } else { return; } final Document xmlDoc = XMLSupport.LoadXML(is); final Element rootElement = xmlDoc.getRootElement(); final Element offsetElem = rootElement.getChild("offset"); final double offset = Double.parseDouble(offsetElem.getValue()); final Element gainsElem = rootElement.getChild("gains"); final String gainsValue = gainsElem.getValue().trim().replace(" ", " "); final double[] gainsArray = StringUtils.toDoubleArray(gainsValue, " "); if (flipLUT) { double tmp; for (int i = 0; i < gainsArray.length / 2; i++) { tmp = gainsArray[i]; gainsArray[i] = gainsArray[gainsArray.length - i - 1]; gainsArray[gainsArray.length - i - 1] = tmp; } } final MetadataElement lut = new MetadataElement(lutName); root.addElement(lut); final MetadataAttribute offsetAttrib = new MetadataAttribute("offset", ProductData.TYPE_FLOAT64); offsetAttrib.getData().setElemDouble(offset); lut.addAttribute(offsetAttrib); final MetadataAttribute gainsAttrib = new MetadataAttribute("gains", ProductData.TYPE_FLOAT64, gainsArray.length); gainsAttrib.getData().setElems(gainsArray); lut.addAttribute(gainsAttrib); }
From source file:org.esa.nest.dataio.terrasarx.TerraSarXProductDirectory.java
License:Open Source License
private static void readGeoRef(final Product product, final File georefFile) throws IOException { final Document xmlDoc = XMLSupport.LoadXML(georefFile.getAbsolutePath()); final Element root = xmlDoc.getRootElement(); final Element geoGrid = root.getChild("geolocationGrid"); final Element numGridPnt = geoGrid.getChild("numberOfGridPoints"); final Element numAzimuth = numGridPnt.getChild("azimuth"); final int numAz = Integer.parseInt(numAzimuth.getValue()); final Element numRange = numGridPnt.getChild("range"); final int numRg = Integer.parseInt(numRange.getValue()); final Element gridReferenceTime = geoGrid.getChild("gridReferenceTime"); final Element tReferenceTimeUTC = gridReferenceTime.getChild("tReferenceTimeUTC"); final int size = numAz * numRg; final double[] latList = new double[size]; final double[] lonList = new double[size]; final double[] incList = new double[size]; final double[] timeList = new double[size]; final int[] row = new int[size]; final int[] col = new int[size]; //final boolean flip = !isSLC(); int i = 0;/*from w w w. j a va 2 s . c om*/ int r = numRg - 1; int c = 0; boolean regridNeeded = false; final List<Element> grdPntList = geoGrid.getChildren("gridPoint"); for (Element pnt : grdPntList) { int index = i; /* if(flip) { index = (numRg * c) + r; --r; if(r < 0) { r = numRg-1; ++c; } } */ final Element tElem = pnt.getChild("tau"); timeList[index] = Double.parseDouble(tElem.getValue()); final Element latElem = pnt.getChild("lat"); latList[index] = Double.parseDouble(latElem.getValue()); final Element lonElem = pnt.getChild("lon"); lonList[index] = Double.parseDouble(lonElem.getValue()); final Element rowElem = pnt.getChild("row"); if (rowElem != null) { row[index] = Integer.parseInt(rowElem.getValue()) - 1; regridNeeded = true; } final Element colElem = pnt.getChild("col"); if (colElem != null) { col[index] = Integer.parseInt(colElem.getValue()) - 1; } final Element incElem = pnt.getChild("inc"); incList[index] = Double.parseDouble(incElem.getValue()); ++i; } final int gridWidth = numRg; final int gridHeight = numAz; final int newGridWidth = gridWidth; final int newGridHeight = gridHeight; float[] newLatList = new float[newGridWidth * newGridHeight]; float[] newLonList = new float[newGridWidth * newGridHeight]; float[] newIncList = new float[newGridWidth * newGridHeight]; final int sceneRasterWidth = product.getSceneRasterWidth(); final int sceneRasterHeight = product.getSceneRasterHeight(); final double subSamplingX = sceneRasterWidth / (double) (newGridWidth - 1); final double subSamplingY = sceneRasterHeight / (double) (newGridHeight - 1); if (regridNeeded) { getListInEvenlySpacedGrid(sceneRasterWidth, sceneRasterHeight, gridWidth, gridHeight, col, row, latList, newGridWidth, newGridHeight, subSamplingX, subSamplingY, newLatList); getListInEvenlySpacedGrid(sceneRasterWidth, sceneRasterHeight, gridWidth, gridHeight, col, row, lonList, newGridWidth, newGridHeight, subSamplingX, subSamplingY, newLonList); getListInEvenlySpacedGrid(sceneRasterWidth, sceneRasterHeight, gridWidth, gridHeight, col, row, incList, newGridWidth, newGridHeight, subSamplingX, subSamplingY, newIncList); } else { for (int m = 0; m < newLatList.length; ++m) { newLatList[m] = (float) latList[m]; newLonList[m] = (float) lonList[m]; newIncList[m] = (float) incList[m]; } } final TiePointGrid latGrid = new TiePointGrid(OperatorUtils.TPG_LATITUDE, newGridWidth, newGridHeight, 0.5f, 0.5f, subSamplingX, subSamplingY, newLatList); latGrid.setUnit(Unit.DEGREES); product.addTiePointGrid(latGrid); final TiePointGrid lonGrid = new TiePointGrid(OperatorUtils.TPG_LONGITUDE, newGridWidth, newGridHeight, 0.5f, 0.5f, subSamplingX, subSamplingY, newLonList, TiePointGrid.DISCONT_AT_180); lonGrid.setUnit(Unit.DEGREES); product.addTiePointGrid(lonGrid); final TiePointGrid incidentAngleGrid = new TiePointGrid(OperatorUtils.TPG_INCIDENT_ANGLE, newGridWidth, newGridHeight, 0.5f, 0.5f, subSamplingX, subSamplingY, newIncList); incidentAngleGrid.setUnit(Unit.DEGREES); product.addTiePointGrid(incidentAngleGrid); final TiePointGeoCoding tpGeoCoding = new TiePointGeoCoding(latGrid, lonGrid, Datum.WGS_84); product.setGeoCoding(tpGeoCoding); // final TiePointGrid timeGrid = new TiePointGrid("Time", gridWidth, gridHeight, 0, 0, // subSamplingX, subSamplingY, timeList); // timeGrid.setUnit(Unit.NANOSECONDS); // product.addTiePointGrid(timeGrid); }
From source file:org.esa.s1tbx.io.terrasarx.TerraSarXProductDirectory.java
License:Open Source License
private static void readGeoRef(final Product product, final File georefFile) throws IOException { final Document xmlDoc = XMLSupport.LoadXML(georefFile.getAbsolutePath()); final Element root = xmlDoc.getRootElement(); final Element geoGrid = root.getChild("geolocationGrid"); final Element numGridPnt = geoGrid.getChild("numberOfGridPoints"); final Element numAzimuth = numGridPnt.getChild("azimuth"); final int numAz = Integer.parseInt(numAzimuth.getValue()); final Element numRange = numGridPnt.getChild("range"); final int numRg = Integer.parseInt(numRange.getValue()); final Element gridReferenceTime = geoGrid.getChild("gridReferenceTime"); final Element tReferenceTimeUTC = gridReferenceTime.getChild("tReferenceTimeUTC"); final int size = numAz * numRg; final double[] latList = new double[size]; final double[] lonList = new double[size]; final double[] incList = new double[size]; final double[] timeList = new double[size]; final int[] row = new int[size]; final int[] col = new int[size]; //final boolean flip = !isSLC(); int i = 0;/*w ww . j av a 2 s . com*/ int r = numRg - 1; int c = 0; boolean regridNeeded = false; final List<Element> grdPntList = geoGrid.getChildren("gridPoint"); for (Element pnt : grdPntList) { int index = i; /* if(flip) { index = (numRg * c) + r; --r; if(r < 0) { r = numRg-1; ++c; } } */ final Element tElem = pnt.getChild("tau"); timeList[index] = Double.parseDouble(tElem.getValue()); final Element latElem = pnt.getChild("lat"); latList[index] = Double.parseDouble(latElem.getValue()); final Element lonElem = pnt.getChild("lon"); lonList[index] = Double.parseDouble(lonElem.getValue()); final Element rowElem = pnt.getChild("row"); if (rowElem != null) { row[index] = Integer.parseInt(rowElem.getValue()) - 1; regridNeeded = true; } final Element colElem = pnt.getChild("col"); if (colElem != null) { col[index] = Integer.parseInt(colElem.getValue()) - 1; } final Element incElem = pnt.getChild("inc"); incList[index] = Double.parseDouble(incElem.getValue()); ++i; } final int gridWidth = numRg; final int gridHeight = numAz; final int newGridWidth = gridWidth; final int newGridHeight = gridHeight; float[] newLatList = new float[newGridWidth * newGridHeight]; float[] newLonList = new float[newGridWidth * newGridHeight]; float[] newIncList = new float[newGridWidth * newGridHeight]; final int sceneRasterWidth = product.getSceneRasterWidth(); final int sceneRasterHeight = product.getSceneRasterHeight(); final double subSamplingX = sceneRasterWidth / (double) (newGridWidth - 1); final double subSamplingY = sceneRasterHeight / (double) (newGridHeight - 1); if (regridNeeded) { getListInEvenlySpacedGrid(sceneRasterWidth, sceneRasterHeight, gridWidth, gridHeight, col, row, latList, newGridWidth, newGridHeight, subSamplingX, subSamplingY, newLatList); getListInEvenlySpacedGrid(sceneRasterWidth, sceneRasterHeight, gridWidth, gridHeight, col, row, lonList, newGridWidth, newGridHeight, subSamplingX, subSamplingY, newLonList); getListInEvenlySpacedGrid(sceneRasterWidth, sceneRasterHeight, gridWidth, gridHeight, col, row, incList, newGridWidth, newGridHeight, subSamplingX, subSamplingY, newIncList); } else { for (int m = 0; m < newLatList.length; ++m) { newLatList[m] = (float) latList[m]; newLonList[m] = (float) lonList[m]; newIncList[m] = (float) incList[m]; } } final TiePointGrid latGrid = new TiePointGrid(OperatorUtils.TPG_LATITUDE, newGridWidth, newGridHeight, 0.5f, 0.5f, subSamplingX, subSamplingY, newLatList); latGrid.setUnit(Unit.DEGREES); product.addTiePointGrid(latGrid); final TiePointGrid lonGrid = new TiePointGrid(OperatorUtils.TPG_LONGITUDE, newGridWidth, newGridHeight, 0.5f, 0.5f, subSamplingX, subSamplingY, newLonList, TiePointGrid.DISCONT_AT_180); lonGrid.setUnit(Unit.DEGREES); product.addTiePointGrid(lonGrid); final TiePointGrid incidentAngleGrid = new TiePointGrid(OperatorUtils.TPG_INCIDENT_ANGLE, newGridWidth, newGridHeight, 0.5f, 0.5f, subSamplingX, subSamplingY, newIncList); incidentAngleGrid.setUnit(Unit.DEGREES); product.addTiePointGrid(incidentAngleGrid); final TiePointGeoCoding tpGeoCoding = new TiePointGeoCoding(latGrid, lonGrid); product.setSceneGeoCoding(tpGeoCoding); // final TiePointGrid timeGrid = new TiePointGrid("Time", gridWidth, gridHeight, 0, 0, // subSamplingX, subSamplingY, timeList); // timeGrid.setUnit(Unit.NANOSECONDS); // product.addTiePointGrid(timeGrid); }
From source file:org.esa.snap.dataio.netcdf.metadata.profiles.hdfeos.HdfEosGridInfo.java
License:Open Source License
static HdfEosGridInfo createGridInfo(Element gridElem) { Element gridNameElem = gridElem.getChild("GridName"); Element projectionElem = gridElem.getChild("Projection"); Element ulPointElem = gridElem.getChild("UpperLeftPointMtrs"); Element lrPointElem = gridElem.getChild("LowerRightMtrs"); Element projParamsElem = gridElem.getChild("ProjParams"); if (gridNameElem == null || projectionElem == null || ulPointElem == null || lrPointElem == null) { return null; }/*from ww w. j a va 2 s . co m*/ String gridName = gridNameElem.getValue(); if (gridName.isEmpty()) { return null; } List<Element> ulList = ulPointElem.getChildren(); String ulLon = ulList.get(0).getValue(); String ulLat = ulList.get(1).getValue(); double upperLeftLon = Double.parseDouble(ulLon); double upperLeftLat = Double.parseDouble(ulLat); List<Element> lrList = lrPointElem.getChildren(); String lrLon = lrList.get(0).getValue(); String lrLat = lrList.get(1).getValue(); double lowerRightLon = Double.parseDouble(lrLon); double lowerRightLat = Double.parseDouble(lrLat); String projection = projectionElem.getValue(); HdfEosGridInfo hdfEosGridInfo = new HdfEosGridInfo(gridName, upperLeftLon, upperLeftLat, lowerRightLon, lowerRightLat, projection); if (projParamsElem != null) { List<Element> children = projParamsElem.getChildren(); double[] projParameterValues = new double[children.size()]; for (int i = 0; i < children.size(); i++) { Element child = children.get(i); projParameterValues[i] = Double.parseDouble(child.getValue()); } hdfEosGridInfo.setProjectionParameter(projParameterValues); } return hdfEosGridInfo; }
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);//from w ww . j a v a 2 s. co 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); } }