Example usage for org.jdom2 Element getContent

List of usage examples for org.jdom2 Element getContent

Introduction

In this page you can find the example usage for org.jdom2 Element getContent.

Prototype

@Override
public List<Content> getContent() 

Source Link

Document

This returns the full content of the element as a List which may contain objects of type Text, Element, Comment, ProcessingInstruction, CDATA, and EntityRef.

Usage

From source file:org.esa.snap.core.dataop.downloadable.XMLSupport.java

License:Open Source License

public static String[] getStringList(final Element elem) {
    final List<String> array = new ArrayList<>();
    final List<Content> contentList = elem.getContent();
    for (Object o : contentList) {
        if (o instanceof Element) {
            array.add(((Element) o).getName());
        }/*from w w w  .  ja v a2s.c  o  m*/
    }
    return array.toArray(new String[array.size()]);
}

From source file:org.esa.snap.datamodel.metadata.AbstractMetadataIO.java

License:Open Source License

public static boolean Load(final Product product, final MetadataElement metadataElem, final File metadataFile)
        throws IOException {

    Document doc;/*from   ww  w. ja  v  a2  s. co  m*/
    try {
        doc = XMLSupport.LoadXML(metadataFile.getAbsolutePath());
    } catch (IOException e) {
        System.out.println(e.getMessage());
        return false;
    }

    final Element root = doc.getRootElement();
    final List elements = root.getContent();
    for (Object o : elements) {
        if (o instanceof Element) {
            final Element elem = (Element) o;
            if (elem.getName().equals(AbstractMetadata.ABSTRACT_METADATA_ROOT))
                findAbstractedMetadata(elem.getContent(), metadataElem);
            else if (elem.getName().equals(TPG))
                parseTiePointGrids(product, elem);
        }
    }
    return true;
}

From source file:org.esa.snap.datamodel.metadata.AbstractMetadataIO.java

License:Open Source License

private static void findAbstractedMetadata(final List domChildren, final MetadataElement metadataElem) {
    for (Object aChild : domChildren) {
        if (aChild instanceof Element) {
            final Element child = (Element) aChild;
            final String childName = child.getName();
            if (child.getContentSize() > 0) {
                MetadataElement subElem = metadataElem.getElement(childName);
                if (subElem == null) {
                    subElem = new MetadataElement(childName);
                    metadataElem.addElement(subElem);
                }//from   www .j  av a2 s  .  co m
                findAbstractedMetadata(child.getContent(), subElem);
            } else if (childName.equals(ATTRIB)) {
                loadAttribute(child, metadataElem);
            }
        }
    }
}

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;/*www  .  j  a v  a2  s.com*/
            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
 *///  ww  w. ja  v  a  2 s .co 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.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;//from ww  w  .  ja  va 2  s  .  com

    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.framework.dataop.downloadable.XMLSupport.java

License:Open Source License

private static void domElementToMetadataElement(final Element domElem, final MetadataElement metadataElem) {

    final List children = domElem.getContent();
    for (Object aChild : children) {
        if (aChild instanceof Element) {
            final Element child = (Element) aChild;
            final List grandChildren = child.getContent();
            if (!grandChildren.isEmpty()) {
                final MetadataElement newElem = new MetadataElement(child.getName());
                domElementToMetadataElement(child, newElem);
                metadataElem.addElement(newElem);
            }/*  w ww  .  j a  va  2  s  .  c om*/

            if (child.getName().equals("attrib")) {
                addAttribute(metadataElem, child);
            }
        }
    }
}

From source file:org.esa.snap.framework.dataop.downloadable.XMLSupport.java

License:Open Source License

public static Element getElement(final Element root, final String name) throws IOException {
    final List children = root.getContent();
    for (Object aChild : children) {
        if (aChild instanceof Element) {
            final Element elem = (Element) aChild;
            if (elem.getName().equalsIgnoreCase(name))
                return elem;
        }/*from   w ww  .  j a v a  2  s. c o  m*/
    }
    throw new IOException("Element " + name + " not found");
}

From source file:org.esa.snap.framework.dataop.downloadable.XMLSupport.java

License:Open Source License

public static Text getElementText(final Element root) throws IOException {
    final List children = root.getContent();
    for (Object aChild : children) {
        if (aChild instanceof Text) {
            return (Text) aChild;
        }/*w  w  w .ja v  a2s  .  c om*/
    }
    throw new IOException("Element Text not found");
}

From source file:org.esa.snap.framework.dataop.downloadable.XMLSupport.java

License:Open Source License

public static String[] getStringList(final Element elem) {
    final List<String> array = new ArrayList<>();
    final List contentList = elem.getContent();
    for (Object o : contentList) {
        if (o instanceof Element) {
            array.add(((Element) o).getName());
        }//from  w  w  w.  j av a 2 s.com
    }
    return array.toArray(new String[array.size()]);
}