Example usage for org.jdom2 Element getValue

List of usage examples for org.jdom2 Element getValue

Introduction

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

Prototype

@Override
public String getValue() 

Source Link

Document

Returns the XPath 1.0 string value of this element, which is the complete, ordered content of all text node descendants of this element (i.e. the text that's left after all references are resolved and all other markup is stripped out.)

Usage

From source file:org.esa.snap.dataio.netcdf.metadata.profiles.hdfeos.HdfEosUtils.java

License:Open Source License

static String getValue(Element root, String... childs) {
    Element element = root;
    int index = 0;
    while (element != null && index < childs.length) {
        String childName = childs[index++];
        element = element.getChild(childName);
    }//from  w w w  .ja  v a2 s .  c o  m
    return element != null ? element.getValue() : null;

}

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
 *///from  www  .j  a  va  2s  . com
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.janusproject.acl.encoding.xml.XMLACLCodecHelper.java

License:Open Source License

/**
 * Retrieves the String value of a basic tag
 * /*w  w  w  .  ja  v a 2s  .c  o  m*/
 * @param element a JDOM Element which represents a basic tag
 * @return the value of the tag
 */
public static String decodeStringMsgParam(Element element) {
    if (element == null || element.getValue() == null) {
        return null;
    }

    return element.getValue();
}

From source file:org.janusproject.acl.encoding.xml.XMLACLCodecHelper.java

License:Open Source License

/**
 * Retrieves the content of the content/*from  www.  j  a va  2  s .co  m*/
 * 
 * @param element a JDOM Element wich represents the content tag
 * @return the content of the content in a StringBuffer
 */
public static StringBuffer decodeContent(Element element) {
    if (element == null || element.getValue() == null) {
        return null;
    }

    return new StringBuffer(element.getValue());
}

From source file:org.janusproject.acl.encoding.xml.XMLACLCodecHelper.java

License:Open Source License

/**
 * Retrieves the conversation ID/*from   w w w.j  a  v  a  2 s.  co  m*/
 * @param element a JDOM Element which represents a conversation-id tag
 * @return the UUID of the conversation
 */
public static UUID decodeConversationId(Element element) {
    if (element == null || element.getValue() == null) {
        return null;
    }

    try {
        return UUID.fromString(element.getValue());
    } catch (IllegalArgumentException e) {
        return null;
    }
}

From source file:org.jpos.q2.iso.ContextMaker.java

License:Open Source License

public void run() {
    Thread.currentThread().setName(getName());
    while (running()) {

        Object o = sp.in(in, timeout);

        if (o != null) {
            Context ctx = new Context();
            ctx.put(contextName, o);//  ww  w  .  j  a  v a 2 s . c o m

            if (contextValues != null) {
                for (Element e : contextValues) {
                    ctx.put(e.getName(), e.getValue());
                }
            }

            sp.out(out, ctx);
        }
    }
}

From source file:org.jpos.q2.iso.ContextMaker.java

License:Open Source License

public void dump(PrintStream p, String indent) {
    String inner = indent + "  ";
    p.println(indent + "<ContextMaker name='" + getName() + "'>");
    for (Element e : contextValues) {
        p.println(indent + "<" + indent + e.getName() + ">" + e.getValue() + "</" + indent + e.getName() + ">");
    }//from   w w w .j av  a 2s. c  o  m
    p.println(indent + "</ContextMaker>");
}

From source file:org.jpos.qrest.ValidateParams.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from  ww  w  .j  a  v a 2 s.c  o m
public void setConfiguration(Element cfg) throws ConfigurationException {
    mandatory = new HashMap<>();
    mandatoryJson = new HashMap<>();
    Element m = cfg.getChild("mandatory");
    if (m != null) {
        for (Element e : m.getChildren("param")) {
            if ("json-schema".equals(e.getAttributeValue("type"))) {
                try {
                    String json = e.getValue();
                    JsonNode nodeSchema = JsonLoader.fromString(json);
                    JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema(nodeSchema);
                    mandatoryJson.put(e.getAttributeValue("name"), schema);
                } catch (Exception ex) {
                    throw new ConfigurationException(ex);
                }
            } else {
                mandatory.put(e.getAttributeValue("name"), Pattern.compile(e.getValue()));
            }
        }
    }
    optional = new HashMap<>();
    optionalJson = new HashMap<>();
    Element o = cfg.getChild("optional");
    if (o != null) {
        for (Element e : o.getChildren("param")) {
            if ("json-schema".equals(e.getAttributeValue("type"))) {
                String json = e.getValue();
                JsonNode nodeSchema;
                try {
                    nodeSchema = JsonLoader.fromString(json);
                    JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema(nodeSchema);
                    optionalJson.put(e.getAttributeValue("name"), schema);
                } catch (IOException | ProcessingException ex) {
                    throw new ConfigurationException(ex);
                }
            } else {
                optional.put(e.getAttributeValue("name"), Pattern.compile(e.getValue()));
            }
        }
    }
}

From source file:org.jpos.rest.ValidateParams.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   www.j  a  v a 2  s  .  c  o  m*/
public void setConfiguration(Element cfg) throws ConfigurationException {
    mandatory = new HashMap<>();
    mandatoryJson = new HashMap<>();
    Element m = cfg.getChild("mandatory");
    if (m != null) {
        for (Element e : (List<Element>) m.getChildren("param")) {
            if ("json-schema".equals(e.getAttributeValue("type"))) {
                try {
                    String json = e.getValue();
                    JsonNode nodeSchema = JsonLoader.fromString(json);
                    JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema(nodeSchema);
                    mandatoryJson.put(e.getAttributeValue("name"), schema);
                } catch (Exception ex) {
                    //todo: change this
                    ex.printStackTrace();
                }
            } else {
                mandatory.put(e.getAttributeValue("name"), Pattern.compile(e.getValue()));
            }
        }
    }
    optional = new HashMap<>();
    optionalJson = new HashMap<>();
    Element o = cfg.getChild("optional");
    if (o != null) {
        for (Element e : (List<Element>) o.getChildren("param")) {
            if ("json-schema".equals(e.getAttributeValue("type"))) {
                String json = e.getValue();
                JsonNode nodeSchema;
                try {
                    nodeSchema = JsonLoader.fromString(json);
                    JsonSchema schema = JsonSchemaFactory.byDefault().getJsonSchema(nodeSchema);
                    optionalJson.put(e.getAttributeValue("name"), schema);
                } catch (IOException | ProcessingException ex) {
                    throw new ConfigurationException(ex);
                }
            } else {
                optional.put(e.getAttributeValue("name"), Pattern.compile(e.getValue()));
            }
        }
    }
}

From source file:org.knoxcraft.database.xml.XmlDatabase.java

License:Open Source License

/**
 * Add data to a data set from the given xml element and type
 *
 * @param child/*w ww .  j  a  v a2 s  . co m*/
 * @param dataSet
 * @param type
 */
private void addTypeToMap(Element child, HashMap<String, Object> dataSet, DataType type, DataAccess template) {
    boolean isList = false;
    try {
        isList = tableProperties.get(template.getName()).getChild(child.getName()).getAttribute("is-list")
                .getBooleanValue();
    } catch (DataConversionException dcex) {
    }
    switch (type) {
    case BYTE:
        if (isList) {
            ArrayList<Byte> values = new ArrayList<Byte>();

            for (Element el : child.getChildren()) {
                try {
                    values.add((Byte) typeParse(el.getValue(), child.getName(), type, template.getInstance()));
                } catch (IllegalAccessException e) {
                    log.debug("XML Database - Byte - List", e);
                } catch (NoSuchFieldException e) {
                    log.debug("XML Database - Byte - List", e);
                }
            }
            dataSet.put(child.getName(), values);
        } else {
            try {
                dataSet.put(child.getName(),
                        typeParse(child.getValue(), child.getName(), type, template.getInstance()));
            } catch (IllegalAccessException e) {
                log.debug("XML Database - Byte - NonList", e);
            } catch (NoSuchFieldException e) {
                log.debug("XML Database - Byte - NonList", e);
            }
        }
        break;

    case SHORT:
        if (isList) {
            ArrayList<Short> values = new ArrayList<Short>();

            for (Element el : child.getChildren()) {
                try {
                    values.add((Short) typeParse(el.getValue(), child.getName(), type, template.getInstance()));
                } catch (IllegalAccessException e) {
                    log.debug("XML Database - Short - List", e);
                } catch (NoSuchFieldException e) {
                    log.debug("XML Database - Short - List", e);
                }
            }
            dataSet.put(child.getName(), values);
        } else {
            try {
                dataSet.put(child.getName(),
                        typeParse(child.getValue(), child.getName(), type, template.getInstance()));
            } catch (IllegalAccessException e) {
                log.debug("XML Database - Short - NonList", e);
            } catch (NoSuchFieldException e) {
                log.debug("XML Database - Short - NonList", e);
            }
        }
        break;

    case INTEGER:
        if (isList) {
            ArrayList<Integer> values = new ArrayList<Integer>();

            for (Element el : child.getChildren()) {
                try {
                    values.add(
                            (Integer) typeParse(el.getValue(), child.getName(), type, template.getInstance()));
                } catch (IllegalAccessException e) {
                    log.debug("XML Database - Integer - List", e);
                } catch (NoSuchFieldException e) {
                    log.debug("XML Database - Integer - List", e);
                }
            }
            dataSet.put(child.getName(), values);
        } else {
            try {
                dataSet.put(child.getName(),
                        typeParse(child.getValue(), child.getName(), type, template.getInstance()));
            } catch (IllegalAccessException e) {
                log.debug("XML Database - Integer - NonList", e);
            } catch (NoSuchFieldException e) {
                log.debug("XML Database - Integer - NonList", e);
            }
        }
        break;

    case LONG:
        if (isList) {
            ArrayList<Long> values = new ArrayList<Long>();

            for (Element el : child.getChildren()) {
                try {
                    values.add((Long) typeParse(el.getValue(), child.getName(), type, template.getInstance()));
                } catch (IllegalAccessException e) {
                    log.debug("XML Database - Long - List", e);
                } catch (NoSuchFieldException e) {
                    log.debug("XML Database - Long - List", e);
                }
            }
            dataSet.put(child.getName(), values);
        } else {
            try {
                dataSet.put(child.getName(),
                        typeParse(child.getValue(), child.getName(), type, template.getInstance()));
            } catch (IllegalAccessException e) {
                log.debug("XML Database - Long - NonList", e);
            } catch (NoSuchFieldException e) {
                log.debug("XML Database - Long - NonList", e);
            }
        }
        break;

    case FLOAT:
        if (isList) {
            ArrayList<Float> values = new ArrayList<Float>();

            for (Element el : child.getChildren()) {
                try {
                    values.add((Float) typeParse(el.getValue(), child.getName(), type, template.getInstance()));
                } catch (IllegalAccessException e) {
                    log.debug("XML Database - Float - List", e);
                } catch (NoSuchFieldException e) {
                    log.debug("XML Database - Float - List", e);
                }
            }
            dataSet.put(child.getName(), values);
        } else {
            try {
                dataSet.put(child.getName(),
                        typeParse(child.getValue(), child.getName(), type, template.getInstance()));
            } catch (IllegalAccessException e) {
                log.debug("XML Database - Float - NonList", e);
            } catch (NoSuchFieldException e) {
                log.debug("XML Database - Float - NonList", e);
            }
        }
        break;

    case DOUBLE:
        if (isList) {
            ArrayList<Double> values = new ArrayList<Double>();

            for (Element el : child.getChildren()) {
                try {
                    values.add(
                            (Double) typeParse(el.getValue(), child.getName(), type, template.getInstance()));
                } catch (IllegalAccessException e) {
                    log.debug("XML Database - Double - List", e);
                } catch (NoSuchFieldException e) {
                    log.debug("XML Database - Double - List", e);
                }
            }
            dataSet.put(child.getName(), values);
        } else {
            try {
                dataSet.put(child.getName(),
                        typeParse(child.getValue(), child.getName(), type, template.getInstance()));
            } catch (IllegalAccessException e) {
                log.debug("XML Database - Double - NonList", e);
            } catch (NoSuchFieldException e) {
                log.debug("XML Database - Double - NonList", e);
            }
        }
        break;

    case STRING:
        if (isList) {
            ArrayList<String> values = new ArrayList<String>();

            for (Element el : child.getChildren()) {
                values.add(el.getText());
            }
            dataSet.put(child.getName(), values);
        } else {
            dataSet.put(child.getName(), child.getText());
        }
        break;

    case BOOLEAN:
        if (isList) {
            ArrayList<Boolean> values = new ArrayList<Boolean>();

            for (Element el : child.getChildren()) {
                values.add(Boolean.valueOf(el.getText()));
            }
            dataSet.put(child.getName(), values);
        } else {
            dataSet.put(child.getName(), Boolean.valueOf(child.getText()));
        }
        break;

    default:
        break;
    }
}