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.nest.dat.toolviews.Projects.ProductSet.java

License:Open Source License

boolean Load(final File file) {

    if (!file.exists())
        return false;
    Document doc;/*from  w  ww.  j  a v a  2s . c  o m*/
    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);//from  w  w  w  . j  a v a 2 s .  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);
                    }//www. j  av  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 w ww. ja v  a 2s . co 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.s1tbx.dat.toolviews.Projects.ProductSet.java

License:Open Source License

boolean Load(final File file) {

    if (!file.exists())
        return false;
    Document doc;//w w w.  ja va 2 s .  c  om
    try {
        doc = XMLSupport.LoadXML(file.getAbsolutePath());
    } catch (IOException e) {
        Dialogs.showError("Unable to load " + file.toString() + ": " + 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.s1tbx.dat.toolviews.Projects.Project.java

License:Open Source License

public void LoadProject(final File file) {

    initProject(file);/* ww w  .ja  va 2  s. c o  m*/

    Document doc;
    try {
        doc = XMLSupport.LoadXML(file.getAbsolutePath());
    } catch (IOException e) {
        Dialogs.showError("Unable to load " + file.toString() + ": " + 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.snap.core.dataop.downloadable.FtpDownloader.java

License:Open Source License

public static Map<String, Long> readRemoteFileList(final FtpDownloader ftp, final String server,
        final String remotePath) {

    boolean useCachedListing = true;
    final File listingFile = new File(SystemUtils.getCacheDir(), server + ".listing.xml");
    if (!listingFile.exists())
        useCachedListing = false;// w  w w.j av  a2 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<Content> 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<Content> 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(getFileName(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) {
            SystemUtils.LOG.warning("Unable to get remote file list " + e.getMessage());
        }
    }

    return fileSizeMap;
}

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

License:Open Source License

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

    final List<Content> children = domElem.getContent();
    for (Object aChild : children) {
        if (aChild instanceof Element) {
            final Element child = (Element) aChild;
            final List<Content> grandChildren = child.getContent();
            if (!grandChildren.isEmpty()) {
                final MetadataElement newElem = new MetadataElement(child.getName());
                domElementToMetadataElement(child, newElem);
                metadataElem.addElement(newElem);
            }/*from w  ww  .ja v  a2s. c o m*/

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

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

License:Open Source License

public static Element getElement(final Element root, final String name) throws IOException {
    final List<Content> 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 .ja  va  2s . c  om
    }
    throw new IOException("Element " + name + " not found");
}

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

License:Open Source License

public static Text getElementText(final Element root) throws IOException {
    final List<Content> children = root.getContent();
    for (Object aChild : children) {
        if (aChild instanceof Text) {
            return (Text) aChild;
        }// w  w w .jav  a  2 s . c o  m
    }
    throw new IOException("Element Text not found");
}