void indexAttribute(String parentElementPath, MetadataAttribute attribute) { String key = (parentElementPath + "@" + attribute.getName()).toLowerCase(); if (!this.attributeMap.containsKey(key)) { this.attributeMap.put(key, new ArrayList<>()); } this.attributeMap.get(key).add(attribute); }
private String createAttributeName(MetadataAttribute attribute) { StringBuilder sb = new StringBuilder(); MetadataElement metadataElement = attribute.getParentElement(); if (metadataElement != null) { prependParentName(metadataElement, sb); } sb.append(attribute.getName()); return sb.toString(); }
private static void addMetadataAttributes(MetadataAttribute attribute, ProductData data, List<MetadataTableElement> metadataTableElementList) { final String name = attribute.getName(); final String unit = attribute.getUnit(); final String description = attribute.getDescription(); for (int j = 0; j < data.getNumElems(); j++) { String elemName = String.format("%s.%d", name, j + 1); metadataTableElementList.add(new MetadataTableArrayElemLeaf(elemName, unit, description, data, j)); } } }
public String[] getAttributeValues(String attributePath) { String[] values = null; if (attributePath != null) { attributePath = ensureAttributeTagPresent(attributePath); List<MetadataAttribute> attributes; if (attributeMap.containsKey(attributePath) && (attributes = attributeMap.get(attributePath)) != null && attributes.size() > 0) { values = new String[attributes.size()]; for (int i = 0; i < attributes.size(); i++) { values[i] = attributes.get(i).getData().getElemString(); if (values[i] == null) { warn(MISSING_ELEMENT_WARNING, attributes.get(i).getName()); } } } else { warn(NO_SUCH_PATH_WARNING, attributePath); } } return values; }
protected void validateMetadata(final Product trgProduct) throws Exception { final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(trgProduct); final MetadataAttribute[] attribs = absRoot.getAttributes(); for(MetadataAttribute attrib : attribs) { System.out.println(attrib.getName() +"= "+ attrib.getData().toString()); } } }
final String name = attrib.getName(); boolean lastDupe = true; for (int j = i + 1; j < elem.getNumAttributes(); j++) { final MetadataAttribute dupeAtrib = elem.getAttributeAt(j); if (dupeAtrib.getName().equals(name)) { Integer cnt = dupeCntAtrib.get(name); if (cnt == null) if (lastDupe) ++cnt; attrib.setName(attrib.getName() + "." + cnt); newGroup.addAttribute(new Attribute(attrib.getName(), elem.getAttributeDouble(attrib.getName(), 0))); } else if (dataType == ProductData.TYPE_UTC || attrib.getData() instanceof ProductData.UTC) { newGroup.addAttribute(new Attribute(attrib.getName(), NetcdfConstants.UTC_TYPE + elem.getAttributeString(attrib.getName(), " "))); } else if (dataType > ProductData.TYPE_INT8 && dataType < ProductData.TYPE_FLOAT32) { newGroup.addAttribute(new Attribute(attrib.getName(), elem.getAttributeInt(attrib.getName(), 0))); } else { newGroup.addAttribute(new Attribute(attrib.getName(), elem.getAttributeString(attrib.getName(), " ")));
/** * Returns the value of the attribute (or the default value) specified by its XPath expression and the given index, * when multiple such attributes are present at the same XPath location. * @param attributePath the XPath location of the attribute * @param attributeIndex the index of the attribute in the attribute array * @param defaultValue the default value if the attribute is not found or has a <code>null</code> value * @return The attribute (or default) value */ public String getAttributeValue(String attributePath, int attributeIndex, String defaultValue) { String value = defaultValue; if (attributePath != null) { attributePath = ensureAttributeTagPresent(attributePath); List<MetadataAttribute> attributes; if (attributeMap.containsKey(attributePath) && (attributes = attributeMap.get(attributePath)) != null && attributes.size() > attributeIndex) { value = attributes.get(attributeIndex).getData().getElemString(); if (value == null) { value = defaultValue; warn(MISSING_ELEMENT_WARNING, attributes.get(attributeIndex).getName()); } } else { warn(NO_SUCH_PATH_WARNING, attributePath); } } return value; }
public ArrayList<String> getBandNames() { ArrayList<String> bands = new ArrayList<>(17); MetadataElement bandGlobalListElement = getRootElement().getElement("Product_Characteristics").getElement("Band_Global_List"); for (int j = 0; j < bandGlobalListElement.getNumAttributes(); j++) { if (bandGlobalListElement.getAttributeAt(j).getName().equals("BAND_ID")) { bands.add(bandGlobalListElement.getAttributeAt(j).getData().getElemString()); } } return bands; }
public MetadataTableLeaf(MetadataAttribute attribute) { this(attribute.getName(), attribute.getDataType(), attribute.getData(), attribute.getUnit(), attribute.getDescription()); }
private static void searchMetadata(final MetadataElement resultElem, final MetadataElement elem, final String tag) { final MetadataElement[] elemList = elem.getElements(); for (MetadataElement e : elemList) { searchMetadata(resultElem, e, tag); } final MetadataAttribute[] attribList = elem.getAttributes(); for (MetadataAttribute attrib : attribList) { if (attrib.getName().toUpperCase().contains(tag)) { final MetadataAttribute newAttrib = attrib.createDeepClone(); newAttrib.setDescription(getAttributePath(attrib)); resultElem.addAttribute(newAttrib); } } }
/** * Helper method that copies the child nodes of a metadata element as child nodes * of another metadata element. * * @param source The metadata element holding the nodes to be copied * @param target The destination metadata element */ public static void CopyChildElements(MetadataElement source, MetadataElement target) { Assert.notNull(source); Assert.notNull(target); MetadataAttribute[] attributes = source.getAttributes(); if (attributes != null) { for (MetadataAttribute attribute : attributes) { if (!target.containsAttribute(attribute.getName()) && !attribute.getName().contains(":")) { target.addAttribute(attribute); } } } while (source.getNumElements() > 0) { MetadataElement currentElement = source.getElementAt(0); target.addElement(currentElement); source.removeElement(currentElement); } }
if (summaryElem != null) { for (MetadataAttribute sum : summaryElem.getAttributes()) { if (sum.getName().contains(tagInSummary)) { summaryTime = AbstractMetadata.parseUTC( summaryElem.getAttributeString(sum.getName().trim()), dateFormat2); if (workRep.getName().contains("SceneCenterDateTime")) { final ProductData.UTC centreTime = AbstractMetadata.parseUTC( workReportElem.getAttributeString(workRep.getName().trim()), dateFormat2); final double diff = centreTime.getMJD() - startTime.getMJD(); workReportTime = new ProductData.UTC(startTime.getMJD() + (diff * 2.0));
String data, attrName; for (MetadataAttribute attribute : currentElement.getAttributes()) { attrName = attribute.getName(); data = currentElement.getAttributeString(attrName, ""); if (RapidEyeConstants.TAG_LINEOFF.equals(attrName)) {
public ArrayList<String> getBandNames(String resolutionId) { ArrayList<String> bands = new ArrayList<>(13); MetadataElement bandGroupListElement = getRootElement().getElement("Product_Characteristics").getElement("Band_Group_List"); for (int i = 0; i < bandGroupListElement.getNumElements(); i++) { MetadataElement element = bandGroupListElement.getElementAt(i); if (element.getAttribute("group_id").getData().getElemString().equals(resolutionId)) { MetadataElement bandListElement = element.getElement("Band_List"); for (int j = 0; j < bandListElement.getNumAttributes(); j++) { if (bandListElement.getAttributeAt(j).getName().equals("BAND_ID")) { bands.add(bandListElement.getAttributeAt(j).getData().getElemString()); } } } } return bands; }
private void resetFlagTableModel() { flagModel.clear(); if (currentRaster != null) { for (Band band : currentFlagBands) { // currentFlagBands is already filtered for "equals size" in registerFlagDatasets final FlagCoding flagCoding = band.getFlagCoding(); final int numFlags = flagCoding.getNumAttributes(); final String bandNameDot = band.getName() + "."; for (int j = 0; j < numFlags; j++) { String name = bandNameDot + flagCoding.getAttributeAt(j).getName(); flagModel.addRow(name, "", ""); } } } }
MetadataElement bandListElement = element.getElement("Band_List"); for (int j = 0; j < bandListElement.getNumAttributes(); j++) { if (bandListElement.getAttributeAt(j).getName().equals("BAND_ID")) { bands.add(bandListElement.getAttributeAt(j).getData().getElemString()); MetadataElement bandListElement = element.getElement("Band_List"); for (int j = 0; j < bandListElement.getNumAttributes(); j++) { if (bandListElement.getAttributeAt(j).getName().equals("BAND_ID")) { bandStrings[index] = bandListElement.getAttributeAt(j).getData().getElemString(); index++;
public static void createFlagMasks(Product targetProduct) { Guardian.assertNotNull("targetProduct", targetProduct); int w = targetProduct.getSceneRasterWidth(); int h = targetProduct.getSceneRasterHeight(); MyMaskColor mColor = new MyMaskColor(); ProductNodeGroup<Mask> tarMG = targetProduct.getMaskGroup(); ProductNodeGroup<FlagCoding> tarFCG = targetProduct.getFlagCodingGroup(); for (int node=0; node<tarFCG.getNodeCount(); node++){ FlagCoding fc = tarFCG.get(node); for (int i=0; i<fc.getNumAttributes(); i++){ MetadataAttribute f = fc.getAttributeAt(i); String expr = fc.getName() + "." + f.getName(); Mask m = Mask.BandMathsType.create(f.getName(), f.getDescription(), w, h, expr, mColor.next(), 0.5); tarMG.add(m); } } }
final MetadataAttribute slaveBandsAttr = new MetadataAttribute("Slave_bands", ProductData.TYPE_ASCII); slaveProduct.addAttribute(slaveBandsAttr); slaveProduct.setAttributeString(slaveBandsAttr.getName(), slaveBands);