Example usage for org.dom4j Node selectSingleNode

List of usage examples for org.dom4j Node selectSingleNode

Introduction

In this page you can find the example usage for org.dom4j Node selectSingleNode.

Prototype

Node selectSingleNode(String xpathExpression);

Source Link

Document

selectSingleNode evaluates an XPath expression and returns the result as a single Node instance.

Usage

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

private List<AssessmentStatusItem> deserializeXMLToListOfAssessmentStatusItems(InputStream xmlStream)
        throws ParseException, DocumentException {
    List<AssessmentStatusItem> result = new ArrayList<AssessmentStatusItem>();

    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);

    String lElem = "//loi:ArrayOfAssessmentStatusItem";

    doc.getRootElement().setQName(new QName(doc.getRootElement().getQName().getName(),
            new Namespace("loi", doc.getRootElement().getNamespaceURI())));
    Element root = doc.getRootElement();

    List<Node> nodes = root.selectNodes(lElem + "/loi:AssessmentStatusItem");

    for (Node node : nodes) {
        AssessmentStatusItem assessmentStatusItem = new AssessmentStatusItem();
        Node n = node.selectSingleNode("loi:AssessmentStatusId");
        if (n.hasContent()) {
            assessmentStatusItem.setAssessmentStatusId(Integer.parseInt(n.getStringValue()));
        }//  w w  w.jav a 2s  . c om
        n = node.selectSingleNode("loi:AssessmentStatusItemId");
        if (n.hasContent()) {
            assessmentStatusItem.setAssessmentStatusItemId(Integer.parseInt(n.getStringValue()));
        }
        n = node.selectSingleNode("loi:Title");
        if (n.hasContent()) {
            assessmentStatusItem.setTitle(n.getStringValue());
        }
        result.add(assessmentStatusItem);
    }

    return result;
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

/**
 * xml looks like this//from   w  ww . jav  a2  s .co  m
<EntityList xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<CurrentPageIndex>0</CurrentPageIndex>
<EntityArray>
<Organization>
  <HierarchyId>1</HierarchyId>
  <LegalId>FK</LegalId>
  <Title>Fylkeskommune</Title>
  <Type>Site</Type>
</Organization>
<Organization>
  <HierarchyId>6</HierarchyId>
  <LegalId>S-B</LegalId>
  <Title>School B</Title>
  <Type>School</Type>
</Organization>
</EntityArray>
<PageSize>2</PageSize>
<Total>2</Total>
</EntityList>
 *
 * @param responseBodyAsStream
 * @return
 */
private List<Organisation> deserializeXMLToOrganisations(InputStream xmlStream) throws DocumentException {
    List<Organisation> result = new ArrayList<Organisation>();

    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);

    String lElem = "//org:ArrayOfOrganization";
    doc.getRootElement().setQName(new QName(doc.getRootElement().getQName().getName(),
            new Namespace("org", doc.getRootElement().getNamespaceURI())));

    Element root = doc.getRootElement();

    List<Node> nodes = root.selectNodes(lElem + "/org:Organization");

    for (Node n : nodes) {
        Organisation organisation = new Organisation();
        Node node = n.selectSingleNode("org:HierarchyId");
        if (node.hasContent()) {
            organisation.setHierarchyId(Integer.parseInt(node.getStringValue()));
        }
        node = n.selectSingleNode("org:SyncLocationId");
        if (node.hasContent()) {
            organisation.setSyncLocationId(node.getStringValue());
        }
        node = n.selectSingleNode("org:LegalId");
        if (node.hasContent()) {
            organisation.setLegalId(node.getStringValue());
        }
        node = n.selectSingleNode("org:Title");
        if (node.hasContent()) {
            organisation.setTitle(node.getStringValue());
        }
        node = n.selectSingleNode("org:Type");
        if (node.hasContent()) {
            try {
                organisation.setType(OrganisationType.valueOf(node.getStringValue()));
            } catch (IllegalArgumentException iea) {
                organisation.setType(OrganisationType.Unknown);
            }
        }
        result.add(organisation);
    }

    return result;
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

/**
 * xml looks like this//from  w w w  . j  a  v  a  2s .c  om
<ArrayOfOrganizationRole xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<OrganizationRole>
  <HierarchyId>1</HierarchyId>
  <HomeOrganization>false</HomeOrganization>
  <Role>Administrator</Role>
</OrganizationRole>
<OrganizationRole>
  <HierarchyId>2</HierarchyId>
  <HomeOrganization>false</HomeOrganization>
  <Role>Administrator</Role>
</OrganizationRole>
<OrganizationRole>
  <HierarchyId>3</HierarchyId>
  <HomeOrganization>false</HomeOrganization>
  <Role>Administrator</Role>
</OrganizationRole>
<OrganizationRole>
  <HierarchyId>5</HierarchyId>
  <HomeOrganization>false</HomeOrganization>
  <Role>Administrator</Role>
</OrganizationRole>
<OrganizationRole>
  <HierarchyId>6</HierarchyId>
  <HomeOrganization>true</HomeOrganization>
  <Role>Administrator</Role>
</OrganizationRole>
</ArrayOfOrganizationRole>
 *
 * @param responseBodyAsStream
 * @return
 */
private List<OrganisationRole> deserializeXMLToOrganisationRoles(InputStream xmlStream)
        throws DocumentException {
    List<OrganisationRole> result = new ArrayList<OrganisationRole>();

    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);

    String lElem = "//org:ArrayOfOrganizationRole";
    doc.getRootElement().setQName(new QName(doc.getRootElement().getQName().getName(),
            new Namespace("org", doc.getRootElement().getNamespaceURI())));

    Element root = doc.getRootElement();

    List<Node> nodes = root.selectNodes(lElem + "/org:OrganizationRole");

    for (Node n : nodes) {
        OrganisationRole organisationRole = new OrganisationRole();
        Node node = n.selectSingleNode("org:HierarchyId");
        if (node.hasContent()) {
            organisationRole.setHierarchyId(Integer.parseInt(node.getStringValue()));
        }
        node = n.selectSingleNode("org:HomeOrganization");
        if (node.hasContent()) {
            organisationRole.setHomeOrganization(Boolean.parseBoolean(node.getStringValue()));
        }
        node = n.selectSingleNode("org:Role");
        if (node.hasContent()) {
            organisationRole.setRole(node.getStringValue());
        }
        result.add(organisationRole);
    }

    return result;
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

private List<AppLicense> deserializeXMLToAppLicenses(InputStream xmlStream) throws DocumentException {
    List<AppLicense> result = new ArrayList<AppLicense>();

    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);

    String lElem = "//loi:ArrayOfAppLicense";
    doc.getRootElement().setQName(new QName(doc.getRootElement().getQName().getName(),
            new Namespace("loi", doc.getRootElement().getNamespaceURI())));

    Element root = doc.getRootElement();

    List<Node> nodes = root.selectNodes(lElem + "/loi:AppLicense");

    for (Node n : nodes) {
        AppLicense appLicense = new AppLicense();
        Node node = n.selectSingleNode("loi:LicenseId");
        if (node.hasContent()) {
            appLicense.setLicenseId(Integer.parseInt(node.getStringValue()));
        }//from w  ww .java  2s.c om
        node = n.selectSingleNode("loi:ExternalLicenseId");
        if (node.hasContent()) {
            appLicense.setExternalLicenseId(node.getStringValue());
        }
        result.add(appLicense);
    }
    return result;
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

/**
 * xml looks like this/*from www.ja v  a2 s.co  m*/
<ArrayOfRubricCriteriaItem xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<RubricCriteriaItem>
<Id>1</Id>
<Title>First criteria item</Title>
<LearningObjectiveId>33</LearningObjectiveId>
<AchievementLevels>
    <RubricAchievementLevel>
        <Id>1</Id>
        <Text>Advanced</Text>
        <OrderNo>1</OrderNo>
    </RubricAchievementLevel>
    <RubricAchievementLevel>
        <Id>2</Id>
        <Text>Proficient</Text>
        <OrderNo>2</OrderNo>
    </RubricAchievementLevel>
    <RubricAchievementLevel>
        <Id>3</Id>
        <Text>Basic</Text>
        <OrderNo>4</OrderNo>
    </RubricAchievementLevel>
    <RubricAchievementLevel>
        <Id>4</Id>
        <Text>Below basic</Text>
        <OrderNo>4</OrderNo>
    </RubricAchievementLevel>
</AchievementLevels>
<UniqueId>12341234</UniqueId>
</RubricCriteriaItem>
</ArrayOfRubricCriteriaItem>
 *
 * @param responseBodyAsStream
 * @return
 */
private List<RubricCriteriaItem> deserializeXMLToCriteria(InputStream xmlStream) throws DocumentException {
    List<RubricCriteriaItem> result = new ArrayList<RubricCriteriaItem>();

    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);

    String lElem = "//loi:ArrayOfRubricCriteriaItem";
    doc.getRootElement().setQName(new QName(doc.getRootElement().getQName().getName(),
            new Namespace("loi", doc.getRootElement().getNamespaceURI())));

    Element root = doc.getRootElement();

    List<Node> nodes = root.selectNodes(lElem + "/loi:RubricCriteriaItem");

    for (Node n : nodes) {
        RubricCriteriaItem rubric = new RubricCriteriaItem();
        Node node = n.selectSingleNode("loi:Id");
        if (node.hasContent()) {
            rubric.setId(Integer.parseInt(node.getStringValue()));
        }
        node = n.selectSingleNode("loi:Title");
        if (node.hasContent()) {
            rubric.setTitle(node.getStringValue());
        }
        node = n.selectSingleNode("loi:LearningObjectiveId");
        if (node.hasContent()) {
            rubric.setLearningObjectiveId(Integer.parseInt(node.getStringValue()));
        }
        node = n.selectSingleNode("loi:AchievementLevels");
        if (node.hasContent()) {
            rubric.setAchievementLevels(
                    getRubricAchievementLevelsFromXml(n.selectNodes("loi:RubricAchievementLevel")));
        }
        node = n.selectSingleNode("loi:UniqueId");
        if (node.hasContent()) {
            rubric.setUniqueId(node.getStringValue());
        }
        result.add(rubric);
    }

    return result;
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

private List<LearningObjective> deserializeXMLToListOfLearningObjectives(InputStream xmlStream)
        throws DocumentException {
    List<LearningObjective> result = new ArrayList<LearningObjective>();

    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);

    String lElem = "//loi:ArrayOfLearningObjective";
    doc.getRootElement().setQName(new QName(doc.getRootElement().getQName().getName(),
            new Namespace("loi", doc.getRootElement().getNamespaceURI())));

    Element root = doc.getRootElement();

    List<Node> nodes = root.selectNodes(lElem + "/loi:LearningObjective");

    for (Node n : nodes) {
        LearningObjective lo = new LearningObjective();
        Node node = n.selectSingleNode("loi:Id");
        if (node.hasContent()) {
            lo.setId(Integer.parseInt(node.getStringValue()));
        }/*  w w w  .j a v  a 2 s. c o  m*/
        node = n.selectSingleNode("loi:Title");
        if (node.hasContent()) {
            lo.setTitle(node.getStringValue());
        }
        node = n.selectSingleNode("loi:Description");
        if (node.hasContent()) {
            lo.setDescription(node.getStringValue());
        }
        node = n.selectSingleNode("loi:Obsolete");
        if (node.hasContent()) {
            lo.setObsolete(Boolean.parseBoolean(node.getStringValue()));
        }
        result.add(lo);
    }

    return result;
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

private List<RubricAchievementLevel> getRubricAchievementLevelsFromXml(List<Node> nodes) {
    List<RubricAchievementLevel> result = new ArrayList<RubricAchievementLevel>();

    for (Node n : nodes) {
        RubricAchievementLevel level = new RubricAchievementLevel();
        Node node = n.selectSingleNode("loi:Id");
        if (node.hasContent()) {
            level.setId(Integer.parseInt(node.getStringValue()));
        }/*from  w  ww .  ja v  a 2 s .  co m*/
        node = n.selectSingleNode("loi:Text");
        if (node.hasContent()) {
            level.setText(node.getStringValue());
        }
        node = n.selectSingleNode("loi:OrderNo");
        if (node.hasContent()) {
            level.setOrderNo(Integer.parseInt(node.getStringValue()));
        }
        result.add(level);
    }

    return result;
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

private void fillSingleLearningObjectInstanceUserEntityFromXml(LearningObjectInstanceUser singleUser,
        Element root, String lElem, Node n) {
    Node node = n.selectSingleNode("loi:FirstName");
    if (node.hasContent()) {
        singleUser.setFirstName(node.getStringValue());
    }/*from   w  w w .j a  v a  2  s  .  com*/
    node = n.selectSingleNode("loi:LastName");
    if (node.hasContent()) {
        singleUser.setLastName(node.getStringValue());
    }

    node = n.selectSingleNode("loi:UserId");
    if (node.hasContent()) {
        singleUser.setUserId(Integer.parseInt(node.getStringValue()));
    }

    // All following nodes are extended data which will only be sent if the app is allowed to receive them.
    // If one of the fields is there, all will be.
    node = root.selectSingleNode(lElem + "/loi:Custom1");
    if (node != null) {
        if (node.hasContent()) {
            singleUser.setCustom1(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Custom2");
        if (node.hasContent()) {
            singleUser.setCustom2(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Custom3");
        if (node.hasContent()) {
            singleUser.setCustom3(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Custom4");
        if (node.hasContent()) {
            singleUser.setCustom4(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Custom5");
        if (node.hasContent()) {
            singleUser.setCustom5(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Custom1Id");
        if (node.hasContent()) {
            singleUser.setCustom1Id(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Custom2Id");
        if (node.hasContent()) {
            singleUser.setCustom2Id(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Custom3Id");
        if (node.hasContent()) {
            singleUser.setCustom3Id(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Custom4Id");
        if (node.hasContent()) {
            singleUser.setCustom4Id(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Custom5Id");
        if (node.hasContent()) {
            singleUser.setCustom5Id(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Mobile");
        if (node.hasContent()) {
            singleUser.setMobile(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:SyncKey");
        if (node.hasContent()) {
            singleUser.setSyncKey(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Email");
        if (node.hasContent()) {
            singleUser.setEmail(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:ProfileImageUrl");
        if (node.hasContent()) {
            singleUser.setProfileImageUrl(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:ProfileImageSmallUrl");
        if (node.hasContent()) {
            singleUser.setProfileImageSmallUrl(node.getStringValue());
        }
    } // End of extended data.
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

private void fillSingleLearningObjectInstanceUserReportEntityFromXml(
        LearningObjectInstanceUserReport singleReport, Element root, String lElem, Node n)
        throws ParseException {
    fillSingleLearningObjectInstanceUserEntityFromXml(singleReport, root, lElem, n);

    Node node = n.selectSingleNode("loi:AssessmentItemId");
    if (node.hasContent()) {
        singleReport.setAssessmentItemId(Integer.parseInt(node.getStringValue()));
    }//w w  w  .j  av  a2  s.  c o m
    node = n.selectSingleNode("loi:AssessmentItemTitle");
    if (node.hasContent()) {
        singleReport.setAssessmentItemTitle(node.getStringValue());
    }
    node = n.selectSingleNode("loi:AssessmentStatusItemId");
    if (node.hasContent()) {
        singleReport.setAssessmentStatusItemId(Integer.parseInt(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:AssessmentStatusItemTitle");
    if (node.hasContent()) {
        singleReport.setAssessmentStatusItemTitle(node.getStringValue());
    }
    node = n.selectSingleNode("loi:Comment");
    if (node.hasContent()) {
        singleReport.setComment(node.getStringValue());
    }
    node = n.selectSingleNode("loi:NumberOfTimesRead");
    if (node.hasContent()) {
        singleReport.setNumberOfTimesRead(Integer.parseInt(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:SimplePercentScore");
    if (node.hasContent()) {
        singleReport.setSimplePercentScore(Double.parseDouble(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:Score");
    if (node.hasContent()) {
        singleReport.setScore(Double.parseDouble(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:SimpleStatus");
    if (node.hasContent()) {
        singleReport.setSimpleStatus(SimpleStatusType.valueOf(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:NumberOfAttemptsTaken");
    if (node.hasContent()) {
        singleReport.setNumberOfAttemptsTaken(Integer.parseInt(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:AttemptId");
    if (node.hasContent()) {
        singleReport.setAttemptId(Integer.parseInt(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:Reviewed");
    if (node.hasContent()) {
        singleReport.setReviewedUtc(sdf.parse(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:ReviewedBy");
    if (node.hasContent()) {
        singleReport.setReviewedBy(Integer.parseInt(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:CollaborationId");
    if (node.hasContent()) {
        singleReport.setCollaborationId(Integer.parseInt(node.getStringValue()));
    }
}

From source file:itslearning.platform.restapi.sdk.learningtoolapp.LearningObjectServicetRestClient.java

private List<AssessmentStatus> deserializeXMLToListOfPossibleAssessmentStatuses(InputStream xmlStream)
        throws ParseException, DocumentException {
    List<AssessmentStatus> result = new ArrayList<AssessmentStatus>();

    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);

    String lElem = "//loi:ArrayOfAssessmentStatus";

    doc.getRootElement().setQName(new QName(doc.getRootElement().getQName().getName(),
            new Namespace("loi", doc.getRootElement().getNamespaceURI())));
    Element root = doc.getRootElement();

    List<Node> nodes = root.selectNodes(lElem + "/loi:AssessmentStatus");

    for (Node node : nodes) {
        AssessmentStatus assessmentStatus = new AssessmentStatus();
        Node n = node.selectSingleNode("loi:AssessmentStatusId");
        if (n.hasContent()) {
            assessmentStatus.setAssessmentStatusId(Integer.parseInt(n.getStringValue()));
        }/* w  w w. j  a va 2s  .co m*/
        n = node.selectSingleNode("loi:Title");
        if (n.hasContent()) {
            assessmentStatus.setTitle(n.getStringValue());
        }
        result.add(assessmentStatus);
    }

    return result;
}