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

The following examples show how to use org.jdom2.Element#getChildTextTrim() . 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
Source File: MCRWorksFetcher.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
/** 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 2
Source File: MCRMetaInstitutionName.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
Source File: MCRWebsiteWriteProtection.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 4
Source File: PodcastService.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: SvnCommand.java    From gocd with 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 6
Source File: MCRMetaAddress.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 7
Source File: MCRBasketXMLParser.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 8
Source File: PodcastService.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: PodcastService.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: JDOMUtil.java    From emissary with 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 11
Source File: JDOMUtil.java    From emissary with 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 12
Source File: DirectoryEntry.java    From emissary with 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 13
Source File: PodcastService.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
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 14
Source File: ExtractionTest.java    From emissary with 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 15
Source File: MCRNameMerger.java    From mycore with GNU General Public License v3.0 4 votes vote down vote up
private void setFromDisplayForm(Element element) {
    String displayForm = element.getChildTextTrim("displayForm", MCRConstants.MODS_NAMESPACE);
    if (displayForm != null) {
        setFromCombinedName(displayForm.replaceAll("\\s+", " "));
    }
}
 
Example 16
Source File: JDOMUtil.java    From emissary with 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 17
Source File: WorkBundle.java    From emissary with 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;
}