Example usage for org.jdom2 Attribute getValue

List of usage examples for org.jdom2 Attribute getValue

Introduction

In this page you can find the example usage for org.jdom2 Attribute getValue.

Prototype

public String getValue() 

Source Link

Document

This will return the actual textual value of this Attribute.

Usage

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());
                }/*w ww.j a va  2  s.  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.nest.dataio.binary.BinaryDBReader.java

License:Open Source License

private static void DecodeElement(final BinaryFileReader reader, final Map metaMap, final Element child,
        final String suffix) {

    String name = "";
    try {/*from ww w.jav a2 s. c om*/
        final Attribute nameAttrib = child.getAttribute("name");
        final Attribute typeAttrib = child.getAttribute("type");
        final Attribute numAttrib = child.getAttribute("num");
        if (nameAttrib != null && typeAttrib != null && numAttrib != null) {

            name = nameAttrib.getValue();
            if (suffix != null)
                name += suffix;
            final int type = Integer.parseInt(typeAttrib.getValue());
            final int num = Integer.parseInt(numAttrib.getValue());

            switch (type) {
            case Skip: {
                reader.skipBytes(num); // blank
                break;
            }
            case An: {
                metaMap.put(name, reader.readAn(num));
                break;
            }
            case In: {
                metaMap.put(name, (int) reader.readIn(num));
                break;
            }
            case B1: {
                metaMap.put(name, reader.readB1());
                break;
            }
            case B2: {
                metaMap.put(name, reader.readB2());
                break;
            }
            case B4: {
                metaMap.put(name, reader.readB4());
                break;
            }
            case B8: {
                metaMap.put(name, reader.readB8());
                break;
            }
            case Fn: {
                metaMap.put(name, reader.readFn(num));
                break;
            }
            case En: {
                metaMap.put(name, reader.readEn(num));
                break;
            }
            case Debug: {
                System.out.print(" = ");
                for (int i = 0; i < num; ++i) {
                    final String tmp = reader.readAn(1);
                    if (!tmp.isEmpty() && !tmp.equals(" "))
                        System.out.print(tmp);
                }
                System.out.println();
                break;
            }
            default: {
                throw new IllegalBinaryFormatException("Unknown type " + type, reader.getCurrentPos());
            }
            }
        }

    } catch (Exception e) {
        if (e.getCause() != null)
            System.out.println(' ' + e.toString() + ':' + e.getCause().toString() + " for " + name);
        else
            System.out.println(' ' + e.toString() + ':' + " for " + name);
    }
}

From source file:org.esa.nest.dataio.binary.BinaryDBReader.java

License:Open Source License

private void DecodeElementDebug(final BinaryFileReader reader, final Map metaMap, final Element child,
        final String suffix) {

    String name = "";
    try {//from  w  w w  .  j a v  a 2 s.  co m
        final Attribute nameAttrib = child.getAttribute("name");
        final Attribute typeAttrib = child.getAttribute("type");
        final Attribute numAttrib = child.getAttribute("num");
        if (nameAttrib != null && typeAttrib != null && numAttrib != null) {

            name = nameAttrib.getValue();
            if (suffix != null)
                name += suffix;
            final int type = Integer.parseInt(typeAttrib.getValue());
            final int num = Integer.parseInt(numAttrib.getValue());

            System.out.print(" " + reader.getCurrentPos() + ' ' + (reader.getCurrentPos() - startPos + 1) + ' '
                    + name + ' ' + type + ' ' + num);

            switch (type) {
            case Skip: {
                reader.skipBytes(num); // blank
                break;
            }
            case An: {

                final String tmp = reader.readAn(num);
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case In: {

                final int tmp = (int) reader.readIn(num);
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case B1: {

                final int tmp = reader.readB1();
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case B2: {

                final int tmp = reader.readB2();
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case B4: {

                final int tmp = reader.readB4();
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case B8: {

                final long tmp = reader.readB8();
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case Fn: {

                double tmp = reader.readFn(num);
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case En: {

                double tmp = reader.readEn(num);
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case Debug: {

                System.out.print(" = ");
                for (int i = 0; i < num; ++i) {
                    final String tmp = reader.readAn(1);
                    if (!tmp.isEmpty() && !tmp.equals(" "))
                        System.out.print(tmp);
                }
                System.out.println();
                break;
            }
            default: {
                throw new IllegalBinaryFormatException("Unknown type " + type, reader.getCurrentPos());
            }
            }
            System.out.println();
        }

    } catch (Exception e) {
        if (e.getCause() != null)
            System.out.println(' ' + e.toString() + ':' + e.getCause().toString() + " for " + name);
        else
            System.out.println(' ' + e.toString() + ':' + " for " + name);
        //throw new IllegalBinaryFormatException(e.toString(), reader.getCurrentPos());
    }
}

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  ww  .  ja  va 2s.com*/
    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);//  w  w w.  j  ava2s.c  om

    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.s1tbx.dataio.binary.BinaryDBReader.java

License:Open Source License

private static void DecodeElement(final BinaryFileReader reader, final Map metaMap, final Element child,
        final String suffix) {

    String name = "";
    try {//from   ww  w  . j av a 2 s  .  c om
        final Attribute nameAttrib = child.getAttribute("name");
        final Attribute typeAttrib = child.getAttribute("type");
        final Attribute numAttrib = child.getAttribute("num");
        if (nameAttrib != null && typeAttrib != null && numAttrib != null) {

            name = nameAttrib.getValue();
            if (suffix != null)
                name += suffix;
            final int type = Integer.parseInt(typeAttrib.getValue());
            final int num = Integer.parseInt(numAttrib.getValue());

            switch (type) {
            case Skip: {
                reader.skipBytes(num); // blank
                break;
            }
            case An: {
                metaMap.put(name, reader.readAn(num));
                break;
            }
            case In: {
                metaMap.put(name, (int) reader.readIn(num));
                break;
            }
            case B1: {
                metaMap.put(name, reader.readB1());
                break;
            }
            case B2: {
                metaMap.put(name, reader.readB2());
                break;
            }
            case B4: {
                metaMap.put(name, reader.readB4());
                break;
            }
            case B8: {
                metaMap.put(name, reader.readB8());
                break;
            }
            case Fn: {
                metaMap.put(name, reader.readFn(num));
                break;
            }
            case En: {
                metaMap.put(name, reader.readEn(num));
                break;
            }
            case Debug: {
                System.out.print(" = ");
                for (int i = 0; i < num; ++i) {
                    final String tmp = reader.readAn(1);
                    if (!tmp.isEmpty() && !tmp.equals(" "))
                        System.out.print(tmp);
                }
                System.out.println();
                break;
            }
            default: {
                throw new IllegalBinaryFormatException("Unknown type " + type, reader.getCurrentPos());
            }
            }
        }

    } catch (Exception e) {
        if (e.getCause() != null)
            SystemUtils.LOG.severe(' ' + e.toString() + ':' + e.getCause().toString() + " for " + name);
        else
            SystemUtils.LOG.severe(' ' + e.toString() + ':' + " for " + name);
    }
}

From source file:org.esa.s1tbx.dataio.binary.BinaryDBReader.java

License:Open Source License

private void DecodeElementDebug(final BinaryFileReader reader, final Map metaMap, final Element child,
        final String suffix) {

    String name = "";
    try {/*from  w  ww . j  a v  a2s .c  o m*/
        final Attribute nameAttrib = child.getAttribute("name");
        final Attribute typeAttrib = child.getAttribute("type");
        final Attribute numAttrib = child.getAttribute("num");
        if (nameAttrib != null && typeAttrib != null && numAttrib != null) {

            name = nameAttrib.getValue();
            if (suffix != null)
                name += suffix;
            final int type = Integer.parseInt(typeAttrib.getValue());
            final int num = Integer.parseInt(numAttrib.getValue());

            System.out.print(" " + reader.getCurrentPos() + ' ' + (reader.getCurrentPos() - startPos + 1) + ' '
                    + name + ' ' + type + ' ' + num);

            switch (type) {
            case Skip: {
                reader.skipBytes(num); // blank
                break;
            }
            case An: {

                final String tmp = reader.readAn(num);
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case In: {

                final int tmp = (int) reader.readIn(num);
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case B1: {

                final int tmp = reader.readB1();
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case B2: {

                final int tmp = reader.readB2();
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case B4: {

                final int tmp = reader.readB4();
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case B8: {

                final long tmp = reader.readB8();
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case Fn: {

                double tmp = reader.readFn(num);
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case En: {

                double tmp = reader.readEn(num);
                System.out.print(" = " + tmp);
                metaMap.put(name, tmp);
                break;
            }
            case Debug: {

                System.out.print(" = ");
                for (int i = 0; i < num; ++i) {
                    final String tmp = reader.readAn(1);
                    if (!tmp.isEmpty() && !tmp.equals(" "))
                        System.out.print(tmp);
                }
                System.out.println();
                break;
            }
            default: {
                throw new IllegalBinaryFormatException("Unknown type " + type, reader.getCurrentPos());
            }
            }
            System.out.println();
        }

    } catch (Exception e) {
        if (e.getCause() != null)
            SystemUtils.LOG.severe(' ' + e.toString() + ':' + e.getCause().toString() + " for " + name);
        else
            SystemUtils.LOG.severe(' ' + e.toString() + ':' + " for " + name);
        //throw new IllegalBinaryFormatException(e.toString(), reader.getCurrentPos());
    }
}

From source file:org.esa.s2tbx.dataio.s2.gml.GmlFilter.java

License:Open Source License

public Pair<String, List<EopPolygon>> parse(InputStream stream) {
    SAXBuilder builder = new SAXBuilder();
    Document jdomDoc = null;//from ww  w .jav a2s  . c  o  m

    try {
        jdomDoc = builder.build(stream);

        //get the root element
        Element web_app = jdomDoc.getRootElement();
        String maskEpsg = "";

        Namespace gml = Namespace.getNamespace("http://www.opengis.net/gml/3.2");
        Namespace eop = Namespace.getNamespace("http://www.opengis.net/eop/2.0");

        List<Element> targeted = web_app.getChildren("boundedBy", gml);
        if (!targeted.isEmpty()) {
            Element aEnvelope = targeted.get(0).getChild("Envelope", gml);
            if (aEnvelope != null) {
                maskEpsg = aEnvelope.getAttribute("srsName").getValue();
            }
        }

        List<EopPolygon> recoveredGeometries = new ArrayList<>();

        IteratorIterable<Content> contents = web_app.getDescendants();
        while (contents.hasNext()) {
            Content web_app_content = contents.next();
            if (!web_app_content.getCType().equals(CType.Text)
                    && !web_app_content.getCType().equals(CType.Comment)) {
                boolean withGml = (web_app_content.getNamespacesInScope().get(0).getPrefix().contains("gml"));
                if (withGml) {
                    boolean parentNotGml = !(web_app_content.getParentElement().getNamespace().getPrefix()
                            .contains("gml"));
                    if (parentNotGml) {
                        Element capturedElement = (Element) web_app_content;
                        Attribute attr = null;
                        String polygonId = "";
                        String typeId = "";
                        if (capturedElement.getName().contains("Polygon")) {
                            attr = capturedElement.getAttribute("id", gml);
                            if (attr != null) {
                                polygonId = attr.getValue();
                                if (polygonId.indexOf('.') != -1) {
                                    typeId = polygonId.substring(0, polygonId.indexOf('.'));
                                }
                            }
                        }

                        Document newDoc = new Document(capturedElement.clone().detach());

                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        xmlOutput.output(newDoc, baos);
                        String replacedContent = baos.toString().replace("/www.opengis.net/gml/3.2",
                                "/www.opengis.net/gml");

                        InputStream ois = new ByteArrayInputStream(replacedContent.getBytes());

                        List<Polygon> pols = streamParseGML3(ois);
                        for (Polygon pol : pols) {
                            recoveredGeometries.add(new EopPolygon(polygonId, typeId, pol));
                        }
                    }
                }

            }
        }

        return new Pair<String, List<EopPolygon>>(maskEpsg, recoveredGeometries);
    } catch (JDOMException e) {
        // {@report "parse xml problem !"}
    } catch (IOException e) {
        // {@report "IO problem !"}
    }

    return new Pair<String, List<EopPolygon>>("", new ArrayList<>());
}

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;//from w w  w  . ja  v a2s .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<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 addAttribute(final MetadataElement root, final Element domElem) {

    final Attribute nameAttrib = domElem.getAttribute("name");
    final Attribute valueAttrib = domElem.getAttribute("value");
    final Attribute typeAttrib = domElem.getAttribute("type");
    final Attribute unitAttrib = domElem.getAttribute("unit");
    final Attribute descAttrib = domElem.getAttribute("desc");

    if (nameAttrib == null || valueAttrib == null)
        return;/*from  w  w w.  ja v  a2s.  c  o  m*/

    final MetadataAttribute attribute = new MetadataAttribute(nameAttrib.getName(), ProductData.TYPE_ASCII, 1);
    attribute.getData().setElems(valueAttrib.getValue());

    if (unitAttrib != null)
        attribute.setUnit(unitAttrib.getValue());
    if (descAttrib != null)
        attribute.setDescription(descAttrib.getValue());

    root.addAttribute(attribute);
}