Example usage for org.w3c.dom Element getTextContent

List of usage examples for org.w3c.dom Element getTextContent

Introduction

In this page you can find the example usage for org.w3c.dom Element getTextContent.

Prototype

public String getTextContent() throws DOMException;

Source Link

Document

This attribute returns the text content of this node and its descendants.

Usage

From source file:cz.incad.kramerius.rest.api.k5.client.search.SearchResource.java

public static void changeMasterPidInDOM(Element docElem) {
    // <str name="PID">uuid:2ad31d65-50ca-11e1-916e-001b63bd97ba</str>
    Element elm = XMLUtils.findElement(docElem, new XMLUtils.ElementsFilter() {

        @Override//from   w w w  .  j a  v a  2  s  .c om
        public boolean acceptElement(Element element) {
            if (element.getNodeName().equals("str")) {
                if (element.hasAttribute("name") && (element.getAttribute("name").equals("PID"))) {
                    return true;
                }
            }
            return false;
        }
    });
    if (elm != null) {
        String pid = elm.getTextContent();
        if (pid.contains("/")) {
            pid = pid.replace("/", "");
            elm.setTextContent(pid);
        }
    }
}

From source file:Main.java

/**
 * If there is no <profiles> section, create one with relevant profile with given profileId
 * If <profiles> already contains a <profile> with given profileId, delete all of its plugins
 * @param document// ww w . ja v a2  s . c  o  m
 * @param pomRoot
 * @param profileIdVal
 * @return the <plugins> node (under profiles/profile/build), or null for any error
 */
public static Element initiateProfile(Document document, Element pomRoot, String profileIdVal) {
    //If <profiles> section does not exist, then create and get out
    NodeList childrenRoot = pomRoot.getChildNodes();
    int numProfileNodes = childrenRoot.getLength();
    Node profiles = null;
    for (int index = 0; index < numProfileNodes; index++) {
        Node currNode = childrenRoot.item(index);
        if (currNode.getNodeName().equals(PROFILES_NODE_NAME)) {
            profiles = currNode;
            break;
        }
    }
    if (profiles == null) {
        //no <profiles> section was found.
        //create <profiles>
        Element profilesNew = addProfilesSection(document, pomRoot);

        //Create <profile>, add to <profiles>, and get out
        return addNewProfileSection(document, profilesNew, profileIdVal);
    }

    //the <profiles> section already exists, go over all profiles to determine if the specific profile (with given profileIdVal) exists
    NodeList profileNodes = profiles.getChildNodes();
    numProfileNodes = profileNodes.getLength();
    boolean isProblem = false;
    Element profile = null;
    Element plugins = null;
    for (int profileIndex = 0; profileIndex < numProfileNodes; profileIndex++) {
        //Convert to Element if possible, otherwise it is not relevant
        Node profileNode = profileNodes.item(profileIndex);
        if (!(profileNode instanceof Element)) {
            continue;
        }
        Element currProfile = (Element) profileNode;

        NodeList profileChildren = currProfile.getChildNodes();
        int numProfileChildren = profileChildren.getLength();
        Element profileId = null;
        for (int indexProfileChildren = 0; indexProfileChildren < numProfileChildren; indexProfileChildren++) {
            if (!(profileChildren.item(indexProfileChildren) instanceof Element)) {
                continue;
            }

            if (profileChildren.item(indexProfileChildren).getNodeName().equals(PROFILE_ID_NAME)) {
                profileId = (Element) profileChildren.item(indexProfileChildren);
                break;
            }
        }
        if (profileId == null) {
            //we have a profile without an id, ignore it and move to the next one
            continue;
        }

        //Check if its id is the one we are interested in
        String currProfileIdVal = profileId.getTextContent();
        if (currProfileIdVal.equals(profileIdVal)) {
            profile = currProfile;
            //A profile was found with id = profileId
            //get/create the <build> element
            Element build = getChildElement(document, currProfile, BUILD_NAME);
            if (build == null) {
                isProblem = true;
                break;
            }

            //get/create the <plugins> element
            plugins = getChildElement(document, build, PLUGINS_NAME);
            if (plugins == null) {
                isProblem = true;
                break;
            }

            //remove all children from the <plugins> element (whether or not they are <plugin>'s)
            NodeList pluginNodes = plugins.getChildNodes();
            int numPluginsChildren = pluginNodes.getLength();
            for (int pluginIndex = numPluginsChildren - 1; pluginIndex >= 0; pluginIndex--) {
                plugins.removeChild(pluginNodes.item(pluginIndex));
            }

            //whatever happened above, we are done now, don't check any other profiles
            break;
        }
        //else continue to the next profile
    }

    if (isProblem)
        return null;

    if (profile == null) {
        //the required profile was never found.  Create it now, add to profiles, and get out
        return addNewProfileSection(document, (Element) profiles, profileIdVal);
    } else {
        //we did find the profile, so return the plugins element
        return plugins;
    }
}

From source file:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamInt object/*w w  w .j a v a 2  s  .c o  m*/
 *
 * @param parameterElement
 * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter)
 * @return
 */
private static LicenseParamInt createLicenseParamInt(Element parameterElement, String parameterClass) {
    LicenseParamInt lpInt = new LicenseParamInt();
    lpInt.setParameterClass(parameterClass);

    NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes();

    for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) {
        Attr attrs = (Attr) parameterElementAttributeMap.item(i);

        if (attrs.getNodeName().equals("name")) {
            lpInt.setName(attrs.getNodeValue());
        }

    }

    Element parameterTitleElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0);

    if (parameterTitleElement != null) {
        lpInt.setTitle(parameterTitleElement.getTextContent());
    }

    Element valueElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value").item(0);

    if (valueElement != null) {
        lpInt.setValue(Integer.parseInt(valueElement.getTextContent()));
    }

    return lpInt;
}

From source file:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamDisplay object/* www .j a  v a 2  s . c  om*/
 *
 * @param parameterElement
 * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter)
 * @return
 */
private static LicenseParamDisplay createLicenseParamDisplay(Element parameterElement, String parameterClass) {
    LicenseParamDisplay lpd = new LicenseParamDisplay();
    lpd.setParameterClass(parameterClass);

    NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes();

    for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) {
        Attr attrs = (Attr) parameterElementAttributeMap.item(i);

        if (attrs.getNodeName().equals("name")) {
            lpd.setName(attrs.getNodeValue());
        }

    }

    Element parameterTitleElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0);

    if (parameterTitleElement != null) {
        lpd.setTitle(parameterTitleElement.getTextContent());
    }

    NodeList valueElementList = parameterElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1",
            "value");

    for (int j = 0; j < valueElementList.getLength(); j++) {
        Element valueElement = (Element) valueElementList.item(j);

        lpd.addValue(valueElement.getTextContent());

    }

    return lpd;
}

From source file:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamText object//from   w w w . ja va  2s  .c o  m
 *
 * @param parameterElement
 * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter)
 * @return
 */
private static LicenseParamText createLicenseParamText(Element parameterElement, String parameterClass) {
    LicenseParamText lpt = new LicenseParamText();
    lpt.setParameterClass(parameterClass);

    NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes();

    for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) {
        Attr attrs = (Attr) parameterElementAttributeMap.item(i);

        if (attrs.getNodeName().equals("name")) {
            lpt.setName(attrs.getNodeValue());
        }

    }

    Element parameterTitleElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0);

    if (parameterTitleElement != null) {
        lpt.setTitle(parameterTitleElement.getTextContent());
    }

    NodeList valueElementList = parameterElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1",
            "value");

    for (int j = 0; j < valueElementList.getLength(); j++) {
        Element valueElement = (Element) valueElementList.item(j);

        lpt.addValue(valueElement.getTextContent());

    }

    return lpt;
}

From source file:BarAdapter.java

@Override
public Bar unmarshal(Object v) throws Exception {
    Bar bar = new Bar();
    Element element = (Element) v;
    bar.value = element.getTextContent();
    return bar;//from  ww  w.j a  v a2s. co m
}

From source file:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamBln object//from   w  ww.  ja  v a2s.  c  o m
 *
 * @param parameterElement
 * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter)
 * @return
 */
private static LicenseParamBln createLicenseParamBln(Element parameterElement, String parameterClass) {
    LicenseParamBln lpbln = new LicenseParamBln();
    lpbln.setParameterClass(parameterClass);

    NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes();

    for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) {
        Attr attrs = (Attr) parameterElementAttributeMap.item(i);

        if (attrs.getNodeName().equals("name")) {
            lpbln.setName(attrs.getNodeValue());
        }

    }

    Element parameterTitleElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0);

    if (parameterTitleElement != null) {
        lpbln.setTitle(parameterTitleElement.getTextContent());
    }

    Element parameterValueElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "value").item(0);

    if (parameterValueElement != null) {
        if (parameterValueElement.getTextContent().equals("true")) {
            lpbln.setValue(true);
        } else {
            lpbln.setValue(false);
        }
    }

    return lpbln;
}

From source file:isl.FIMS.utils.Utils.java

public static void updateVocabularies(XMLEntity xmlE, String database, String xmlId, String xmlType,
        String dbPass, String dbUser, String lang) {
    String[] vocsToCheck = xmlE.queryString("//*[@sps_vocabulary!='' and @sps_id!='' and ./text()!='']");
    for (String vocTag : vocsToCheck) {
        Element e = Utils.getElement(vocTag);
        String sps_vocabulary = e.getAttribute("sps_vocabulary");
        String sps_id = e.getAttribute("sps_id");
        String text = e.getTextContent();
        DMSConfig vocConf = new DMSConfig(Utils.DBURI, Utils.systemDbCollection + "Vocabulary/", Utils.DBuser,
                Utils.DBpassword);/*from   w ww  .  ja v  a  2 s.  c  o  m*/
        Vocabulary voc = new Vocabulary(sps_vocabulary, lang, vocConf);
        String[] terms = voc.termValues();
        String addTerm = text;
        if (!Arrays.asList(terms).contains(addTerm)) {
            int id = voc.addTerm(addTerm);
            if (text.contains("'")) {
                xmlE.xUpdate(
                        "//*[@sps_vocabulary='" + sps_vocabulary + "'and ./text()=\"" + text + "\" ]/@sps_id",
                        String.valueOf(id));

            } else {
                xmlE.xUpdate(
                        "//*[@sps_vocabulary='" + sps_vocabulary + "'and ./text()='" + text + "' ]/@sps_id",
                        String.valueOf(id));

            }

        }
    }
}

From source file:com.evolveum.midpoint.repo.sql.data.common.any.RAnyConverter.java

/**
 * This method provides transformation of {@link Element} value to its object form, e.g. <value>1</value> to
 * {@link Integer} number 1. It's based on element definition from schema registry or xsi:type attribute
 * in that element.//from  w w w  .  ja va 2s .  c o m
 *
 * @param definition
 * @param value
 * @return
 */
public static Object getRealRepoValue(ItemDefinition definition, Element value) throws SchemaException {
    ValueType willBeSaveAs = definition == null ? null : getValueType(definition.getTypeName());
    QName typeName = definition == null ? DOMUtil.resolveXsiType(value) : definition.getTypeName();

    Validate.notNull(typeName, "Definition was not defined for element value '"
            + DOMUtil.getQNameWithoutPrefix(value) + "' and it doesn't have xsi:type.");

    Object object;
    if (ValueType.STRING.equals(willBeSaveAs)) {
        if (DOMUtil.listChildElements(value).isEmpty()) {
            //simple values
            return value.getTextContent();
        } else {
            //composite elements or containers
            return DOMUtil.serializeDOMToString(value);
        }
    } else {
        object = XmlTypeConverter.toJavaValue(value, typeName);
    }

    object = getAggregatedRepoObject(object);
    if (object == null) {
        throw new IllegalStateException("Can't extract value for saving from prism property value\n" + value);
    }

    return object;
}

From source file:eu.elf.license.LicenseParser.java

/**
 * Creates LicenseParamEnum object/* w w  w  . ja v a 2 s .c  om*/
 *
 * @param parameterElement
 * @param parameterClass - parameter class (predefinedParameter || precalculatedParameter || referencedParameter || resultParameter || configurationParameter)
 * @return
 */
private static LicenseParamEnum createLicenseParamEnum(Element parameterElement, String parameterClass) {

    Boolean multiAttributeValue = false;
    LicenseParamEnum lpEnum = new LicenseParamEnum();
    lpEnum.setParameterClass(parameterClass);

    NamedNodeMap parameterElementAttributeMap = parameterElement.getAttributes();

    for (int i = 0; i < parameterElementAttributeMap.getLength(); i++) {
        Attr attrs = (Attr) parameterElementAttributeMap.item(i);

        if (attrs.getNodeName().equals("name")) {
            lpEnum.setName(attrs.getNodeValue());
        }

        if (attrs.getNodeName().equals("multi")) {

            if (attrs.getNodeValue().equals("true")) {
                multiAttributeValue = true;
            } else {
                multiAttributeValue = false;
            }
        }

    }

    lpEnum.setMulti(multiAttributeValue);

    Element parameterTitleElement = (Element) parameterElement
            .getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1", "title").item(0);

    if (parameterTitleElement != null) {
        lpEnum.setTitle(parameterTitleElement.getTextContent());
    }

    NodeList valueElementList = parameterElement.getElementsByTagNameNS("http://www.conterra.de/xcpf/1.1",
            "value");

    for (int j = 0; j < valueElementList.getLength(); j++) {
        Element valueElement = (Element) valueElementList.item(j);

        NamedNodeMap valueElementAttributeMap = valueElement.getAttributes();

        for (int k = 0; k < valueElementAttributeMap.getLength(); k++) {
            Attr attrs = (Attr) valueElementAttributeMap.item(k);

            if (attrs.getNodeName().equals("selected")) {
                if (attrs.getNodeValue().equals("true")) {
                    lpEnum.setDefaultValue(valueElement.getTextContent());
                    lpEnum.addSelection(valueElement.getTextContent());
                }
            }

        }

        lpEnum.addOption(valueElement.getTextContent());
    }

    return lpEnum;
}