Example usage for org.jdom2 Element getChild

List of usage examples for org.jdom2 Element getChild

Introduction

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

Prototype

public Element getChild(final String cname) 

Source Link

Document

This returns the first child element within this element with the given local name and belonging to no namespace.

Usage

From source file:com.ohnosequences.xml.model.uniprot.ProteinXML.java

License:Open Source License

public List<GoTermXML> getBiologicalProcessGoTerms() {
    Element goTerms = root.getChild(GO_TERMS_TAG_NAME);
    if (goTerms != null) {
        Element bioProc = goTerms.getChild(PROCESS_GO_TERMS_TAG_NAME);
        if (bioProc != null) {
            List<Element> gos = bioProc.getChildren(GoTermXML.TAG_NAME);
            ArrayList<GoTermXML> result = new ArrayList<GoTermXML>();
            for (Element elem : gos) {
                result.add(new GoTermXML(elem));
            }/*from   w w  w. j a v  a2  s  .  c  o  m*/
            return result;
        } else {
            return null;
        }
    } else {
        return null;
    }
}

From source file:com.ohnosequences.xml.model.uniprot.ProteinXML.java

License:Open Source License

public List<GoTermXML> getCellularComponentGoTerms() {
    Element goTerms = root.getChild(GO_TERMS_TAG_NAME);
    if (goTerms != null) {
        Element cellComp = goTerms.getChild(COMPONENT_GO_TERMS_TAG_NAME);
        if (cellComp != null) {
            List<Element> gos = cellComp.getChildren(GoTermXML.TAG_NAME);
            ArrayList<GoTermXML> result = new ArrayList<GoTermXML>();
            for (Element elem : gos) {
                result.add(new GoTermXML(elem));
            }/*from  w  w  w .  ja  va 2s  .  c o m*/
            return result;
        } else {
            return null;
        }
    } else {
        return null;
    }
}

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

public static void processProperties(URL configs, String contextGateway) throws Exception {
    loadInternals(); //this code organization is weird but it's from iterations of design

    if (contextGateway != null) {
        //Overrides a default set by internal properties
        Server.setDefaultGateway(contextGateway);
    }//  w  w  w .j a va 2  s .c om

    Document properties = loadDocument(configs);
    if (properties == null) {
        return;
    }

    Element louie = properties.getRootElement();

    //Check for alternate loading point 
    boolean resetRoot = false;
    for (Element elem : louie.getChildren()) {
        if (ALT_PATH.equalsIgnoreCase(elem.getName())) {
            String altPath = elem.getTextTrim();
            LoggerFactory.getLogger(LouieProperties.class).info("Loading Louie configs from alternate file: {}",
                    altPath);
            //overwrite document with values from alternate config 
            properties = loadDocument(new File(altPath).toURI().toURL());
            if (properties == null)
                return;
            resetRoot = true;
        }
    }
    if (resetRoot) {
        //reset root to new properties obj root
        louie = properties.getRootElement();
    }

    Element groups = louie.getChild(GROUPS);
    if (groups != null) {
        AccessManager.loadGroups(groups);
    }

    boolean serversConfigured = false;
    for (Element elem : louie.getChildren()) {
        String elemName = elem.getName().toLowerCase();

        if (null != elemName)
            switch (elemName) {
            case ALT_PATH:
                LoggerFactory.getLogger(LouieProperties.class)
                        .warn("Extra config_path alternate loading point specified. "
                                + "Only one file-switch can be performed.\n"
                                + "  Please verify what is specified in the embedded xml file.\n"
                                + "  Found: {}", elem.getText());
                break;
            case SERVER_PARENT:
                processServers(elem);
                serversConfigured = true;
                break;
            case SERVICE_PARENT:
                processServices(elem, false);
                break;
            case MESSAGING:
                MessagingProperties.processMessaging(elem);
                break;
            case MAIL:
                MailProperties.processProperties(elem);
                break;
            case SCHEDULER:
                TaskSchedulerProperties.processProperties(elem);
                break;
            case ALERTS:
                AlertProperties.processProperties(elem);
                break;
            case CUSTOM:
                processCustomProperties(elem);
                break;
            case GROUPS:
                break;
            default:
                LoggerFactory.getLogger(LouieProperties.class).warn("Unexpected top level property  {}",
                        elemName);
                break;
            }
    }
    if (!serversConfigured)
        processServers(null); //ugly bootstrapping workflow
}

From source file:com.rhythm.louie.server.LouieProperties.java

License:Apache License

private static void loadInternals() throws JDOMException, IOException {
    Document internals;/*from w  w w .  j a v a 2  s.  c  om*/
    SAXBuilder docBuilder = new SAXBuilder();

    URL xmlURL = LouieProperties.class.getResource("/config/louie-internal.xml");
    internals = docBuilder.build(xmlURL);

    Element louie = internals.getRootElement();

    //Load internal defaults into Server
    Element serverDef = louie.getChild("server_defaults");

    Server.setDefaultHost(serverDef.getChildText(HOST));
    Server.setDefaultGateway(serverDef.getChildText(GATEWAY));
    Server.setDefaultDisplay(serverDef.getChildText(DISPLAY));
    Server.setDefaultIP(serverDef.getChildText(IP));
    Server.setDefaultTimezone(serverDef.getChildText(TIMEZONE));
    Server.setDefaultLocation(serverDef.getChildText(LOCATION));
    Server.setDefaultPort(Integer.parseInt(serverDef.getChildText(PORT)));
    Server.setDefaultSecure(Boolean.parseBoolean(serverDef.getChildText(SECURE)));

    //Load internal defaults into ServiceProperties
    Element serviceDef = louie.getChild("service_defaults");

    ServiceProperties.setDefaultCaching(Boolean.parseBoolean(serviceDef.getChildText(CACHING)));
    ServiceProperties.setDefaultEnable(Boolean.parseBoolean(serviceDef.getChildText(ENABLE)));
    ServiceProperties.setDefaultReadOnly(Boolean.parseBoolean(serviceDef.getChildText(READ_ONLY)));

    //Load internal services into ServiceProperties
    Element coreServices = louie.getChild("core_services");
    processServices(coreServices, true);

    Element schedDef = louie.getChild("scheduler_defaults");
    TaskSchedulerProperties.setThreadPoolSize(Integer.parseInt(schedDef.getChildText(POOL_SIZE)));

    Element accessDef = louie.getChild("group_defaults");
    AccessManager.loadGroups(accessDef);

}

From source file:com.rometools.opml.io.impl.OPML10Parser.java

License:Apache License

/**
 * Inspects an XML Document (JDOM) to check if it can parse it.
 * <p>/*from   w w  w.j a  v  a 2 s  . c  om*/
 * It checks if the given document if the type of feeds the parser understands.
 * <p>
 *
 * @param document XML Document (JDOM) to check if it can be parsed by this parser.
 * @return <b>true</b> if the parser know how to parser this feed, <b>false</b> otherwise.
 */
@Override
public boolean isMyType(final Document document) {
    final Element e = document.getRootElement();

    if (e.getName().equals("opml")
            && (e.getChild("head") == null || e.getChild("head").getChild("docs") == null)
            && (e.getAttributeValue("version") == null || e.getAttributeValue("version").equals("1.0"))) {
        return true;
    }

    return false;
}

From source file:com.rometools.opml.io.impl.OPML10Parser.java

License:Apache License

/**
 * Parses an XML document (JDOM Document) into a feed bean.
 * <p>/*  w  ww.  jav  a2  s  .  c o m*/
 *
 * @param document XML document (JDOM) to parse.
 * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED).
 * @return the resulting feed bean.
 * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type.
 * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM).
 */
@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale)
        throws IllegalArgumentException, FeedException {
    final Opml opml = new Opml();
    opml.setFeedType("opml_1.0");

    final Element root = document.getRootElement();
    final Element head = root.getChild("head");

    if (head != null) {
        opml.setTitle(head.getChildText("title"));

        if (head.getChildText("dateCreated") != null) {
            opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"), Locale.US));
        }

        if (head.getChildText("dateModified") != null) {
            opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"), Locale.US));
        }

        opml.setOwnerName(head.getChildTextTrim("ownerName"));
        opml.setOwnerEmail(head.getChildTextTrim("ownerEmail"));
        opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState")));

        try {
            opml.setWindowBottom(readInteger(head.getChildText("windowBottom")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowBottom", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowBottom", nfe);
            }
        }

        try {
            opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowLeft", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowLeft", nfe);
            }
        }

        try {
            opml.setWindowRight(readInteger(head.getChildText("windowRight")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowRight", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowRight", nfe);
            }
        }

        try {
            opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowLeft", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowLeft", nfe);
            }
        }

        try {
            opml.setWindowTop(readInteger(head.getChildText("windowTop")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse windowTop", nfe);
            if (validate) {
                throw new FeedException("Unable to parse windowTop", nfe);
            }
        }

        try {
            opml.setExpansionState(readIntArray(head.getChildText("expansionState")));
        } catch (final NumberFormatException nfe) {
            LOG.warn("Unable to parse expansionState", nfe);
            if (validate) {
                throw new FeedException("Unable to parse expansionState", nfe);
            }
        }
    }

    opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate, locale));
    opml.setModules(parseFeedModules(root, locale));

    return opml;
}

From source file:com.rometools.opml.io.impl.OPML20Parser.java

License:Apache License

/**
 * Inspects an XML Document (JDOM) to check if it can parse it.
 * <p>//ww w  .  j av a 2  s . c  o m
 * It checks if the given document if the type of feeds the parser understands.
 * <p>
 *
 * @param document XML Document (JDOM) to check if it can be parsed by this parser.
 * @return <b>true</b> if the parser know how to parser this feed, <b>false</b> otherwise.
 */
@Override
public boolean isMyType(final Document document) {
    final Element e = document.getRootElement();

    if (e.getName().equals("opml") && (e.getChild("head") != null && e.getChild("head").getChild("docs") != null
            || e.getAttributeValue("version") != null && e.getAttributeValue("version").equals("2.0")
            || e.getChild("head") != null && e.getChild("head").getChild("ownerId") != null)) {
        return true;
    }

    return false;
}

From source file:com.rometools.rome.io.impl.OPML10Parser.java

License:Apache License

/**
       * Parses an XML document (JDOM Document) into a feed bean.
       * <p>//from  w ww. j a  v  a  2s  .  c o  m
       *
       * @param document XML document (JDOM) to parse.
       * @param validate indicates if the feed should be strictly validated (NOT YET IMPLEMENTED).
       * @return the resulting feed bean.
       * @throws IllegalArgumentException thrown if the parser cannot handle the given feed type.
       * @throws FeedException thrown if a feed bean cannot be created out of the XML document (JDOM).
       */
@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale)
        throws IllegalArgumentException, FeedException {
    final Opml opml = new Opml();
    opml.setFeedType("opml_1.0");

    final Element root = document.getRootElement();
    final Element head = root.getChild("head");

    if (head != null) {
        opml.setTitle(head.getChildText("title"));

        if (head.getChildText("dateCreated") != null) {
            opml.setCreated(DateParser.parseRFC822(head.getChildText("dateCreated"), Locale.US));
        }

        if (head.getChildText("dateModified") != null) {
            opml.setModified(DateParser.parseRFC822(head.getChildText("dateModified"), Locale.US));
        }

        opml.setOwnerName(head.getChildTextTrim("ownerName"));
        opml.setOwnerEmail(head.getChildTextTrim("ownerEmail"));
        opml.setVerticalScrollState(readInteger(head.getChildText("vertScrollState")));
    }

    try {
        opml.setWindowBottom(readInteger(head.getChildText("windowBottom")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowBottom", nfe);
        }
    }

    try {
        opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
    } catch (final NumberFormatException nfe) {
    }

    try {
        opml.setWindowRight(readInteger(head.getChildText("windowRight")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowRight", nfe);
        }
    }

    try {
        opml.setWindowLeft(readInteger(head.getChildText("windowLeft")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowLeft", nfe);
        }
    }

    try {
        opml.setWindowTop(readInteger(head.getChildText("windowTop")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse windowTop", nfe);
        }
    }

    try {
        opml.setExpansionState(readIntArray(head.getChildText("expansionState")));
    } catch (final NumberFormatException nfe) {

        if (validate) {
            throw new FeedException("Unable to parse expansionState", nfe);
        }
    }

    opml.setOutlines(parseOutlines(root.getChild("body").getChildren("outline"), validate, locale));
    opml.setModules(parseFeedModules(root, locale));

    return opml;
}

From source file:com.rometools.rome.io.impl.OPML20Parser.java

License:Apache License

/**
 * Inspects an XML Document (JDOM) to check if it can parse it.
 * <p>/*  w  w  w .ja v  a2s  .  co m*/
 * It checks if the given document if the type of feeds the parser understands.
 * <p>
 *
 * @param document XML Document (JDOM) to check if it can be parsed by this parser.
 * @return <b>true</b> if the parser know how to parser this feed, <b>false</b> otherwise.
 */
@Override
public boolean isMyType(final Document document) {
    final Element e = document.getRootElement();
    String name = e.getName();
    if (!"opml".equals(name)) {
        return false;
    }
    String version = e.getAttributeValue("version");
    if ("2.0".equals(version)) {
        return true;
    }
    Element head = e.getChild("head");
    if (head != null) {
        Element docs = head.getChild("docs");
        if (docs != null) {
            return true;
        }
        Element ownerId = head.getChild("ownerId");
        if (ownerId != null) {
            return true;
        }
    }
    return false;
}

From source file:com.rometools.rome.io.impl.RSS091UserlandGenerator.java

License:Open Source License

@Override
protected void checkChannelConstraints(final Element eChannel) throws FeedException {

    checkNotNullAndLength(eChannel, "title", 1, 100);
    checkNotNullAndLength(eChannel, "description", 1, 500);
    checkNotNullAndLength(eChannel, "link", 1, 500);
    checkNotNullAndLength(eChannel, "language", 2, 5);
    checkLength(eChannel, "rating", 20, 500);
    checkLength(eChannel, "copyright", 1, 100);
    checkLength(eChannel, "pubDate", 1, 100);
    checkLength(eChannel, "lastBuildDate", 1, 100);
    checkLength(eChannel, "docs", 1, 500);
    checkLength(eChannel, "managingEditor", 1, 100);
    checkLength(eChannel, "webMaster", 1, 100);

    final Element skipHours = eChannel.getChild("skipHours");

    if (skipHours != null) {

        final List<Element> hours = skipHours.getChildren();
        for (final Element hour : hours) {

            final int value = Integer.parseInt(hour.getText().trim());

            if (isHourFormat24()) {
                if (value < 1 || value > 24) {
                    throw new FeedException("Invalid hour value " + value + ", it must be between 1 and 24");
                }/*  ww w.  j  ava2  s  .com*/
            } else {
                if (value < 0 || value > 23) {
                    throw new FeedException("Invalid hour value " + value + ", it must be between 0 and 23");
                }
            }

        }

    }

}