Example usage for org.jdom2 Element getChildren

List of usage examples for org.jdom2 Element getChildren

Introduction

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

Prototype

public List<Element> getChildren(final String cname) 

Source Link

Document

This returns a List of all the child elements nested directly (one level deep) within this element with the given local name and belonging to no namespace, returned as Element objects.

Usage

From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a User object from a JDOM element.
 *
 * @param element The User JDOM element.
 * @return A User object.//from   w  w  w .  j  av  a  2  s .com
 * @throws ReaderException
 */
protected final User getUser(Element element) throws ReaderException {
    User user = new User();

    // id
    Element internalIDElement = element.getChild(INTERNAL_ID);
    if (internalIDElement != null) {
        setInternalID(user, internalIDElement);
    }

    // identities
    Element identitiesElement = element.getChild(IDENTITIES);
    if (identitiesElement != null) {
        List<Element> identityElements = identitiesElement.getChildren(IDENTITY);
        for (Element identityElement : identityElements) {
            user.getIdentities().add(getPrincipal(identityElement));
        }
    }

    // personalDetails
    Element personalDetailsElement = element.getChild(PERSONAL_DETAILS);
    if (personalDetailsElement != null) {
        user.personalDetails = getPersonalDetails(personalDetailsElement);
    }

    // posixDetails
    Element posixDetailsElement = element.getChild(POSIX_DETAILS);
    if (posixDetailsElement != null) {
        user.posixDetails = getPosixDetails(posixDetailsElement);
    }

    return user;
}

From source file:ca.nrc.cadc.ac.xml.AbstractReaderWriter.java

License:Open Source License

/**
 * Get a UserRequest object from a JDOM element.
 *
 * @param element The UserRequest JDOM element.
 * @return A UserRequest object.//from  w  ww.  j av a2 s  .com
 * @throws ReaderException
 */
protected final Group getGroup(Element element) throws ReaderException {
    String uri = element.getAttributeValue(URI);
    if (uri == null) {
        String error = "group missing required uri attribute";
        throw new ReaderException(error);
    }

    // Group owner
    User user = null;
    Element ownerElement = element.getChild(OWNER);
    if (ownerElement != null) {
        // Owner user
        Element userElement = ownerElement.getChild(USER);
        if (userElement == null) {
            String error = "owner missing required user element";
            throw new ReaderException(error);
        }
        user = getUser(userElement);
    }

    GroupURI groupURI = new GroupURI(uri);
    Group group = new Group(groupURI);

    // set owner field
    setField(group, user, OWNER);

    // description
    Element descriptionElement = element.getChild(DESCRIPTION);
    if (descriptionElement != null) {
        group.description = descriptionElement.getText();
    }

    // lastModified
    Element lastModifiedElement = element.getChild(LAST_MODIFIED);
    if (lastModifiedElement != null) {
        try {
            DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
            group.lastModified = df.parse(lastModifiedElement.getText());
        } catch (ParseException e) {
            String error = "Unable to parse group lastModified because " + e.getMessage();

            throw new ReaderException(error);
        }
    }

    // properties
    Element propertiesElement = element.getChild(PROPERTIES);
    if (propertiesElement != null) {
        List<Element> propertyElements = propertiesElement.getChildren(PROPERTY);
        for (Element propertyElement : propertyElements) {
            group.getProperties().add(getGroupProperty(propertyElement));
        }
    }

    // groupMembers
    Element groupMembersElement = element.getChild(GROUP_MEMBERS);
    if (groupMembersElement != null) {
        List<Element> groupElements = groupMembersElement.getChildren(GROUP);
        for (Element groupMember : groupElements) {
            group.getGroupMembers().add(getGroup(groupMember));
        }
    }

    // userMembers
    Element userMembersElement = element.getChild(USER_MEMBERS);
    if (userMembersElement != null) {
        List<Element> userElements = userMembersElement.getChildren(USER);
        for (Element userMember : userElements) {
            group.getUserMembers().add(getUser(userMember));
        }
    }

    // groupAdmins
    Element groupAdminsElement = element.getChild(GROUP_ADMINS);
    if (groupAdminsElement != null) {
        List<Element> groupElements = groupAdminsElement.getChildren(GROUP);
        for (Element groupMember : groupElements) {
            group.getGroupAdmins().add(getGroup(groupMember));
        }
    }

    // userAdmins
    Element userAdminsElement = element.getChild(USER_ADMINS);
    if (userAdminsElement != null) {
        List<Element> userElements = userAdminsElement.getChildren(USER);
        for (Element userMember : userElements) {
            group.getUserAdmins().add(getUser(userMember));
        }
    }

    return group;
}

From source file:ca.nrc.cadc.ac.xml.GroupListReader.java

License:Open Source License

/**
 * Get a List of Groups from a JDOM element.
 *
 * @param element The Group's JDOM element.
 * @return A List of Group objects.//from www.  ja  v  a2  s .  c o  m
 * @throws URISyntaxException
 * @throws ReaderException
 */
protected final List<Group> getGroupList(Element element) throws URISyntaxException, ReaderException {
    ;
    List<Group> groups = new ArrayList<Group>();

    List<Element> groupElements = element.getChildren(GROUP);
    for (Element groupElement : groupElements) {
        groups.add(getGroup(groupElement));
    }

    return groups;
}

From source file:ca.nrc.cadc.ac.xml.UserListReader.java

License:Open Source License

/**
 * Get a List of Users from a JDOM element.
 *
 * @param element The Users JDOM element.
 * @return A List of User objects./*from   w  ww .j av a 2s. c o m*/
 * @throws ReaderException
 */
protected final List<User> getUserList(Element element) throws ReaderException {
    List<User> users = new ArrayList<User>();

    List<Element> userElements = element.getChildren(USER);
    for (Element userElement : userElements) {
        users.add(getUser(userElement));
    }

    return users;
}

From source file:ca.nrc.cadc.caom2.xml.ArtifactAccessReader.java

License:Open Source License

public ArtifactAccess read(Reader reader) throws IOException {
    if (reader == null) {
        throw new IllegalArgumentException("reader must not be null");
    }//from  www.  j  a  v a  2s  . c o  m

    Document document;
    try {
        document = XmlUtil.buildDocument(reader);
    } catch (JDOMException ex) {
        throw new IllegalArgumentException("invalid input document", ex);
    }

    // Root element and namespace of the Document
    Element root = document.getRootElement();
    if (!ENAMES.artifactAccess.name().equals(root.getName())) {
        throw new IllegalArgumentException(
                "invalid root element: " + root.getName() + " expected: " + ENAMES.artifactAccess);
    }

    Artifact a = getArtifact(root.getChild(ENAMES.artifact.name()));
    ArtifactAccess ret = new ArtifactAccess(a);

    ret.isPublic = getBoolean(root.getChildTextTrim(ENAMES.isPublic.name()));

    getGroupList(ret.getReadGroups(), ENAMES.readGroups.name(), root.getChildren(ENAMES.readGroups.name()));

    return ret;
}

From source file:ca.nrc.cadc.reg.CapabilitiesReader.java

License:Open Source License

private Capability buildCapability(final Element capElement) {
    Capability cap = new Capability(this.parseStandardID(capElement));
    List<Element> intfElementList = capElement.getChildren("interface");
    for (Element intfElement : intfElementList) {
        Interface intf = this.buildInterface(intfElement);
        cap.getInterfaces().add(intf);// w  w  w. j a  v  a2 s. c  o m
    }

    return cap;
}

From source file:ca.nrc.cadc.vosi.TableReader.java

License:Open Source License

static TableDesc toTable(String schemaName, Element te, Namespace xsi) {
    String tn = te.getChildTextTrim("name");
    TableDesc td = new TableDesc(schemaName, tn);
    List<Element> cols = te.getChildren("column");
    for (Element ce : cols) {
        String cn = ce.getChildTextTrim("name");
        Element dte = ce.getChild("dataType");
        String dtt = dte.getAttributeValue("type", xsi);
        String dtv = dte.getTextTrim();
        if (TAP_TYPE.equals(dtt))
            dtv = "adql:" + dtv;
        else if (VOT_TYPE.equals(dtt))
            dtv = "vot:" + dtv;
        Integer arraysize = null;
        String as = dte.getAttributeValue("size");
        if (as != null)
            arraysize = new Integer(as);
        ColumnDesc cd = new ColumnDesc(tn, cn, dtv, arraysize);
        td.getColumnDescs().add(cd);/*  ww  w.j  a  va2s.  c o m*/
    }

    List<Element> keys = te.getChildren("foreignKey");
    int i = 1;
    for (Element fk : keys) {
        String keyID = tn + "_key" + i;
        String tt = fk.getChildTextTrim("targetTable");
        KeyDesc kd = new KeyDesc(keyID, tn, tt);
        List<Element> fkcols = fk.getChildren("fkColumn");
        for (Element fkc : fkcols) {
            String fc = fkc.getChildTextTrim("fromColumn");
            String tc = fkc.getChildTextTrim("targetColumn");
            KeyColumnDesc kcd = new KeyColumnDesc(keyID, fc, tc);
            kd.getKeyColumnDescs().add(kcd);
        }
        td.getKeyDescs().add(kd);
    }

    return td;
}

From source file:ca.nrc.cadc.vosi.TableSetReader.java

License:Open Source License

private TapSchema toTapSchema(Document doc) {
    TapSchema ret = new TapSchema();
    Element root = doc.getRootElement();
    Namespace xsi = root.getNamespace("xsi");
    if ("tableset".equals(root.getName())) {
        // content is element-form unqualified
        List<Element> sels = root.getChildren("schema");
        for (Element se : sels) {
            String sn = se.getChildTextTrim("name");
            SchemaDesc sd = new SchemaDesc(sn);
            List<Element> tabs = se.getChildren("table");
            for (Element te : tabs) {
                TableDesc td = TableReader.toTable(sn, te, xsi);
                String tn = td.getTableName();
                sd.getTableDescs().add(td);
            }//from w w  w . ja  v a2s.  c  o m
            ret.getSchemaDescs().add(sd);
        }
    }
    return ret;
}

From source file:carb.view.NewsParseur.java

static String getTexte() throws DataConversionException {

    Element elementNews = racineNews.getChild("allnews");

    Element newsTrouvee = null;//  w  w w .j  av  a  2s.  c o  m
    Element courant = null;

    // dateString = dateDuJour.date(); // quand il sera toujours  jour              
    List listNews = elementNews.getChildren("news");
    Iterator i = listNews.iterator();

    int dateTrouvee = 0;

    while (dateTrouvee != 1 & i.hasNext()) {// tant que la date n'est pas trouv et qu'il reste des news
        //  analyser
        courant = (Element) i.next();

        String dateActuelle = courant.getChild("date").getText(); // petit test de date              
        if (dateActuelle.equals(dateString)) { // si on trouve une news aujourd'hui         
            dateTrouvee = 1;
            newsTrouvee = courant.clone();

        }
    }

    if (dateTrouvee == 1) {
        return newsTrouvee.getChild("text").getText();
    } else {
        System.out.println("Il y a eu une couille");
        return null;
    }

}

From source file:carb.view.NewsParseur.java

static String getTitre() throws DataConversionException {

    Element elementNews = racineNews.getChild("allnews");
    Element newsTrouvee = null;/*  w  w w  .  j av  a2 s.c om*/
    Element courant = null;
    // dateString = dateDuJour.date(); // quand il sera toujours  jour              
    List listNews = elementNews.getChildren("news");
    Iterator i = listNews.iterator();

    int dateTrouvee = 0;

    while (dateTrouvee != 1 & i.hasNext()) {// tant que la date n'est pas trouv et qu'il reste des news
        //  analyser
        courant = (Element) i.next();
        String dateActuelle = courant.getChild("date").getText(); // petit test de date              
        if (dateActuelle.equals(dateString)) { // si on trouve une news aujourd'hui         
            dateTrouvee = 1;
            newsTrouvee = courant.clone();
        }
    }

    if (dateTrouvee == 1) {
        return newsTrouvee.getChild("title").getText();
    } else {
        System.out.println("Il y a eu une couille");
        return null;
    }
}