Java Code Examples for org.jdom2.Element#getChildTextTrim()

The following examples show how to use org.jdom2.Element#getChildTextTrim() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Checks if website protection is currently active.
 * If current user is super user this method always returns false.
 * 
 * @return true if write access is currently active, false if not
 */
public static boolean isActive() {
    // if superuser is online, return false
    String superUser = MCRSystemUserInformation.getSuperUserInstance().getUserID();
    if (MCRSessionMgr.getCurrentSession().getUserInformation().getUserID().equals(superUser)) {
        return false;
    }
    // init, if impossible return false
    Element config = getConfiguration();
    if (config == null) {
        return false;
    }
    // return value contained in config
    String protection = config.getChildTextTrim("protectionEnabled");
    return Boolean.valueOf(protection);
}
 
Example 2
/**
 * This method reads the XML input stream part from a DOM part for the
 * metadata of the document.
 * 
 * @param element
 *            a relevant DOM element for the metadata
 */
@Override
public void setFromDOM(Element element) {
    super.setFromDOM(element);
    fullname = element.getChildTextTrim("fullname");

    if (fullname == null) {
        fullname = "";
    }

    nickname = element.getChildTextTrim("nickname");

    if (nickname == null) {
        nickname = "";
    }

    property = element.getChildTextTrim("property");

    if (property == null) {
        property = "";
    }
}
 
Example 3
/** Sets the work's properties from the pre-processed, transformed works XML */
private void setFromWorkXML(MCRWork work, Element workXML) {
    Element mods = workXML.getChild("mods", MCRConstants.MODS_NAMESPACE).detach();

    String bibTeX = workXML.getChildTextTrim("bibTeX");
    Optional<Element> modsFromBibTeX = bibTeX2MODS(bibTeX);
    modsFromBibTeX.ifPresent(m -> MCRMergeTool.merge(mods, m));

    work.setMODS(mods);
    String sourceID = workXML.getAttributeValue("source");
    work.setSource(MCRWorkSource.getInstance(sourceID));

    if (work.getSource().isThisApplication()) {
        String oid = workXML.getAttributeValue("oid");
        work.setObjectID(MCRObjectID.getInstance(oid));
    }
}
 
Example 4
private String getChannelImageUrl(Element channelElement) {
    String result = getITunesAttribute(channelElement, "image", "href");
    if (result == null) {
        Element imageElement = channelElement.getChild("image");
        if (imageElement != null) {
            result = imageElement.getChildTextTrim("url");
        }
    }
    return result;
}
 
Example 5
private String getITunesElement(Element element, String childName) {
    for (Namespace ns : ITUNES_NAMESPACES) {
        String value = element.getChildTextTrim(childName, ns);
        if (value != null) {
            return value;
        }
    }
    return null;
}
 
Example 6
Source Project: emissary   File: DirectoryEntry.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Build an entry from the supplied xml fragment
 * 
 * @param e a JDOM Element
 */
public static DirectoryEntry fromXML(final Element e) {
    final String key = e.getChildTextTrim(KEY);
    final String desc = e.getChildTextTrim(DESC);
    final int cost = JDOMUtil.getChildIntValue(e, COST);
    final int quality = JDOMUtil.getChildIntValue(e, QUALITY);
    final DirectoryEntry d = new DirectoryEntry(key, desc, cost, quality);
    return d;
}
 
Example 7
Source Project: emissary   File: JDOMUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Like Element.getChildTextTrim but for an int
 */
public static int getChildIntValue(final Element el, final String childName) {
    final String val = el.getChildTextTrim(childName);
    int x = -1;
    try {
        x = Integer.parseInt(val);
    } catch (NumberFormatException ex) {
        logger.debug("Unable to parse {} as an integer", val);
    }
    return x;
}
 
Example 8
Source Project: emissary   File: JDOMUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Like Element.getChildTextTrim but for an long
 */
public static long getChildLongValue(final Element el, final String childName) {
    final String val = el.getChildTextTrim(childName);
    long x = -1L;
    try {
        x = Long.parseLong(val);
    } catch (NumberFormatException ex) {
        logger.debug("Unable to parse {} as an long", val);
    }
    return x;
}
 
Example 9
private String getChannelImageUrl(Element channelElement) {
    String result = getITunesAttribute(channelElement, "image", "href");
    if (result == null) {
        Element imageElement = channelElement.getChild("image");
        if (imageElement != null) {
            result = imageElement.getChildTextTrim("url");
        }
    }
    return result;
}
 
Example 10
private String getITunesElement(Element element, String childName) {
    for (Namespace ns : ITUNES_NAMESPACES) {
        String value = element.getChildTextTrim(childName, ns);
        if (value != null) {
            return value;
        }
    }
    return null;
}
 
Example 11
/**
 * Parses an XML element that represents a basket entry.
 */
public MCRBasketEntry parseXML(Element xml) {
    String id = xml.getAttributeValue("id");
    String uri = xml.getAttributeValue("uri");
    MCRBasketEntry entry = new MCRBasketEntry(id, uri);

    String comment = xml.getChildTextTrim("comment");
    if (comment != null) {
        entry.setComment(comment);
    }

    return entry;
}
 
Example 12
/**
 * This method reads the XML input stream part from a DOM part for the
 * metadata of the document.
 * 
 * @param element
 *            a relevant JDOM element for the metadata
 */
@Override
public void setFromDOM(final Element element) {
    super.setFromDOM(element);
    country = element.getChildTextTrim("country");
    state = element.getChildTextTrim("state");
    zipCode = element.getChildTextTrim("zipcode");
    city = element.getChildTextTrim("city");
    street = element.getChildTextTrim("street");
    number = element.getChildTextTrim("number");
}
 
Example 13
Source Project: gocd   File: SvnCommand.java    License: Apache License 2.0 5 votes vote down vote up
private void parseDOMTree(Document document) throws UnsupportedEncodingException {
    Element infoElement = document.getRootElement();
    Element entryElement = infoElement.getChild("entry");
    String encodedUrl = entryElement.getChildTextTrim("url");

    Element repositoryElement = entryElement.getChild("repository");
    String root = repositoryElement.getChildTextTrim("root");
    String encodedPath = StringUtils.replace(encodedUrl, root, "");

    this.path = URLDecoder.decode(encodedPath, ENCODING);
    this.root = root;
    this.encodedUrl = encodedUrl;
}
 
Example 14
Source Project: emissary   File: WorkBundle.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Build a WorkBundle object from a jdom document
 * 
 * @param jdom the jdom document representing a work bundle object
 * @return the constructed WorkBundle or null on error
 */
private static WorkBundle buildWorkBundle(Document jdom) {
    Element root = jdom.getRootElement();
    if (root == null) {
        logger.error("Document does not have a root element!");
        return null;
    }

    WorkBundle wb = new WorkBundle();
    wb.setBundleId(root.getChildTextTrim("bundleId"));
    String s = root.getChildTextTrim("outputRoot");
    if (s != null && s.length() > 0) {
        wb.setOutputRoot(s);
    } else {
        wb.setOutputRoot(null);
    }

    s = root.getChildTextTrim("eatPrefix");
    if (s != null && s.length() > 0) {
        wb.setEatPrefix(s);
    } else {
        wb.setEatPrefix(null);
    }

    s = root.getChildTextTrim("caseId");
    if (s != null && s.length() > 0) {
        wb.setCaseId(s);
    } else {
        wb.setCaseId(null);
    }

    s = root.getChildTextTrim("sentTo");
    if (s != null && s.length() > 0) {
        wb.setSentTo(s);
    } else {
        wb.setSentTo(null);
    }

    wb.setPriority(JDOMUtil.getChildIntValue(root, "priority"));
    wb.setSimpleMode(JDOMUtil.getChildBooleanValue(root, "simpleMode"));
    wb.setOldestFileModificationTime(JDOMUtil.getChildLongValue(root, "oldestFileModificationTime"));
    wb.setYoungestFileModificationTime(JDOMUtil.getChildLongValue(root, "youngestFileModificationTime"));
    wb.setTotalFileSize(JDOMUtil.getChildLongValue(root, "totalFileSize"));
    String serr = root.getChildTextTrim("errorCount");
    if (serr != null && serr.length() > 0) {
        wb.setErrorCount(Integer.parseInt(serr));
    }

    for (Element wu : root.getChildren("workUnit")) {
        String filename = wu.getChildTextTrim("workFileName");
        String transactionId = wu.getChildTextTrim("transactionId");
        boolean failedToParse = Boolean.valueOf(wu.getChildTextTrim("failedToParse"));
        boolean failedToProcess = Boolean.valueOf(wu.getChildTextTrim("failedToProcess"));
        wb.addWorkUnit(new WorkUnit(filename, transactionId, failedToParse, failedToProcess));
    }

    return wb;
}
 
Example 15
Source Project: emissary   File: JDOMUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Like Element.getChildTextTrim but for a boolean
 */
public static boolean getChildBooleanValue(final Element el, final String childName) {
    final String val = el.getChildTextTrim(childName);
    return Boolean.parseBoolean(val);
}
 
Example 16
Source Project: emissary   File: ExtractionTest.java    License: Apache License 2.0 4 votes vote down vote up
protected void checkStringValue(Element meta, String data, String tname) {
    String key = meta.getChildTextTrim("name");
    String value = meta.getChildText("value");
    String matchMode = "equals";
    Attribute mm = meta.getAttribute("matchMode");

    if (value == null) {
        return; // checking the value is optional
    }

    if (mm != null) {
        matchMode = mm.getValue();
    }

    if (matchMode.equals("equals")) {
        assertEquals(meta.getName() + " element '" + key + "' problem in " + tname + " value '" + data + "' does not equal '" + value + "'",
                value, data);
    } else if (matchMode.equals("index")) {
        assertTrue(meta.getName() + " element '" + key + "' problem in " + tname + " value '" + data + "' does not index '" + value + "'",
                data.indexOf(value) > -1);
    } else if (matchMode.equals("match")) {
        assertTrue(meta.getName() + " element '" + key + "' problem in " + tname + " value '" + data + "' does not match '" + value + "'",
                data.matches(value));
    } else if (matchMode.equals("base64")) {
        // decode value as a base64 encoded byte[] array and use the string
        // representation of the byte array for comparison to the incoming value
        value = new String(DatatypeConverter.parseBase64Binary(value));
        assertEquals(meta.getName() + " element '" + key + "' problem in " + tname + " value '" + data + "' does not match '" + value + "'",
                value, data);
    } else if ("collection".equalsIgnoreCase(matchMode)) {
        Attribute separatorAttribute = meta.getAttribute("collectionSeparator");
        String separator = null != separatorAttribute ? separatorAttribute.getValue() : ","; // comma is default
        // separator
        Collection<String> expectedValues = Arrays.asList(value.split(separator));
        Collection<String> actualValues = Arrays.asList(data.split(separator));
        assertTrue(meta.getName() + " element '" + key + "' problem in " + tname + " did not have equal collection, value ' " + data
                + "' does not equal '" + value + "' split by separator '" + separator + "'",
                CollectionUtils.isEqualCollection(expectedValues, actualValues));

    } else {
        fail("Problematic matchMode specified for test '" + matchMode + "' on " + key + " in element " + meta.getName());
    }
}
 
Example 17
private void setFromDisplayForm(Element element) {
    String displayForm = element.getChildTextTrim("displayForm", MCRConstants.MODS_NAMESPACE);
    if (displayForm != null) {
        setFromCombinedName(displayForm.replaceAll("\\s+", " "));
    }
}