Example usage for org.dom4j Node getStringValue

List of usage examples for org.dom4j Node getStringValue

Introduction

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

Prototype

String getStringValue();

Source Link

Document

Returns the XPath string-value of this node.

Usage

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()));
        }// www  .  java 2 s.c  om
        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());
    }/*w  w  w. j a  v a2s . c om*/
    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()));
    }/*from w  w  w  . j a v  a  2  s.c om*/
    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()));
        }/* www.j  a  v a  2 s  . co  m*/
        n = node.selectSingleNode("loi:Title");
        if (n.hasContent()) {
            assessmentStatus.setTitle(n.getStringValue());
        }
        result.add(assessmentStatus);
    }

    return result;
}

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

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

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

    String lElem = "//loi:ArrayOfCollaborationParticipant";

    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:CollaborationParticipant");

    for (Node node : nodes) {
        CollaborationParticipant collaborationParticipant = new CollaborationParticipant();
        Node n = node.selectSingleNode("loi:FirstName");
        if (n.hasContent()) {
            collaborationParticipant.setFirstName(n.getStringValue());
        }/*from  w ww  .  j  a  va 2  s  .  com*/
        n = node.selectSingleNode("loi:LastName");
        if (n.hasContent()) {
            collaborationParticipant.setFirstName(n.getStringValue());
        }
        n = node.selectSingleNode("loi:CollaborationId");
        if (n.hasContent()) {
            collaborationParticipant.setUserId(Integer.parseInt(n.getStringValue()));
        }
        n = node.selectSingleNode("loi:UserId");
        if (n.hasContent()) {
            collaborationParticipant.setUserId(Integer.parseInt(n.getStringValue()));
        }
        result.add(collaborationParticipant);
    }

    return result;
}

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

private LearningObjectiveReportSettings deserializeXMLToLearningObjectiveReportSettings(InputStream xmlStream)
        throws ParseException, DocumentException {
    LearningObjectiveReportSettings result = null;
    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);

    String lElem = "//loi:LearningObjectiveReportSettings";

    doc.getRootElement().setQName(new QName(doc.getRootElement().getQName().getName(),
            new Namespace("loi", doc.getRootElement().getNamespaceURI())));
    Element root = doc.getRootElement();
    if (root.getName().equals("LearningObjectiveReportSettings")) {
        result = new LearningObjectiveReportSettings();

        Node node = root.selectSingleNode(lElem + "/loi:AchievementLevelOrder");
        if (node.hasContent()) {
            try {
                result.setAchievementLevelOrder(AchievementLevelOrder.valueOf(node.getStringValue()));
            } catch (IllegalArgumentException iea) {
                result.setAchievementLevelOrder(AchievementLevelOrder.HighestToLowest);
            }/*from  w w w .  j  av a  2  s . com*/
        }
        node = root.selectSingleNode(lElem + "/loi:UseMastery");
        if (node.hasContent()) {
            result.setUseMastery(Boolean.parseBoolean(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:LearningObjectiveMasteryRecurrenceType");
        if (node.hasContent()) {
            try {
                result.setLearningObjectiveMasteryRecurrenceType(
                        LearningObjectiveMasteryRecurrenceType.valueOf(node.getStringValue()));
            } catch (IllegalArgumentException iea) {
                result.setLearningObjectiveMasteryRecurrenceType(LearningObjectiveMasteryRecurrenceType.None);
            }
        }
        node = root.selectSingleNode(lElem + "/loi:Statuses");
        if (node.hasContent()) {
            result.setStatuses(getLearningObjectiveAssessmentStatusesFromXml(
                    node.selectNodes("loi:LearningObjectiveAssessmentStatus")));
        }
        node = root.selectSingleNode(lElem + "/loi:ClientMasterySettings");
        if (node.hasContent()) {
            result.setClientMasterySettings(
                    getClientMasterySettingsHashMapFromXml(node.selectNodes("loi:MasterySettingsItem")));
        }
        node = root.selectSingleNode(lElem + "/loi:ShowReportStatusForStudents");
        if (node.hasContent()) {
            result.setShowReportStatusForStudents(Boolean.parseBoolean(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:ConnectAssessmentCriteriaToScale");
        if (node.hasContent()) {
            result.setConnectAssessmentCriteriaToScale(Boolean.parseBoolean(node.getStringValue()));
        }
    }
    return result;
}

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

private List<LearningObjectiveAssessmentStatus> getLearningObjectiveAssessmentStatusesFromXml(
        List<Node> nodes) {
    List<LearningObjectiveAssessmentStatus> result = new ArrayList<LearningObjectiveAssessmentStatus>();

    for (Node n : nodes) {
        LearningObjectiveAssessmentStatus status = new LearningObjectiveAssessmentStatus();
        Node node = n.selectSingleNode("loi:LearningObjectiveAssessmentStatusId");
        if (node.hasContent()) {
            status.setLearningObjectiveAssessmentStatusId(Integer.parseInt(node.getStringValue()));
        }//from  w  ww  .j  a va  2 s  . c o m
        node = n.selectSingleNode("loi:Enabled");
        if (node.hasContent()) {
            status.setEnabled(Boolean.parseBoolean(node.getStringValue()));
        }
        node = n.selectSingleNode("loi:StartsAtPercentage");
        if (node.hasContent()) {
            status.setStartsAtPercentage(Integer.parseInt(node.getStringValue()));
        }
        node = n.selectSingleNode("loi:Label");
        if (node.hasContent()) {
            status.setLabel(node.getStringValue());
        }
        node = n.selectSingleNode("loi:Type");
        if (node.hasContent()) {
            try {
                status.setType(LearningObjectiveAssessmentStatusType.valueOf(node.getStringValue()));
            } catch (IllegalArgumentException iea) {
                status.setType(LearningObjectiveAssessmentStatusType.NotAssessed);
            }
        }
        node = n.selectSingleNode("loi:MasteryThreshold");
        if (node.hasContent()) {
            status.setMasteryThreshold(Boolean.parseBoolean(node.getStringValue()));
        }
        result.add(status);
    }

    return result;
}

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

private HashMap<Integer, LearningObjectiveMasteryClientSettings> getClientMasterySettingsHashMapFromXml(
        List<Node> nodes) {
    HashMap<Integer, LearningObjectiveMasteryClientSettings> result = new HashMap<Integer, LearningObjectiveMasteryClientSettings>();

    for (Node n : nodes) {
        Node node = n.selectSingleNode("loi:LearningObjectiveId");
        if (node.hasContent()) {
            Integer learningObjectiveId = Integer.parseInt(node.getStringValue());

            node = n.selectSingleNode("loi:LearningObjectiveMasterySettings");
            if (node.hasContent()) {
                result.put(learningObjectiveId, getClientMasterySettingsFromXml(node));
            }/*from   ww w. j  a  va  2  s .c  om*/
        }
    }
    return result;
}

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

private LearningObjectiveMasteryClientSettings getClientMasterySettingsFromXml(Node n) {
    LearningObjectiveMasteryClientSettings masterySettings = new LearningObjectiveMasteryClientSettings();

    Node node = n.selectSingleNode("loi:AffectsByLevel");
    if (node.hasContent()) {
        masterySettings.setAffectsByLevel(Boolean.parseBoolean(node.getStringValue()));
    }/* ww w.ja v  a  2  s .  c  om*/
    node = n.selectSingleNode("loi:AffectsByResettingMastery");
    if (node.hasContent()) {
        masterySettings.setAffectsByResettingMastery(Boolean.parseBoolean(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:MasteredWithoutOverride");
    if (node.hasContent()) {
        masterySettings.setMasteredWithoutOverride(Boolean.parseBoolean(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:BreaksRecurrence");
    if (node.hasContent()) {
        masterySettings.setBreaksRecurrence(Boolean.parseBoolean(node.getStringValue()));
    }
    node = n.selectSingleNode("loi:IsReportMastered");
    if (node.hasContent()) {
        masterySettings.setIsReportMastered(Boolean.parseBoolean(node.getStringValue()));
    }
    return masterySettings;
}

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

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

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

    String lElem = "//loi:ArrayOfLearningObjectiveAssessment";

    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:LearningObjectiveAssessment");

    for (Node node : nodes) {
        LearningObjectiveAssessment learningObjectiveAssessment = new LearningObjectiveAssessment();
        Node n = node.selectSingleNode("loi:LearningObjectiveId");
        if (n.hasContent()) {
            learningObjectiveAssessment.setLearningObjectiveId(Integer.parseInt(n.getStringValue()));
        }//from w w  w. jav a2  s.c om
        n = node.selectSingleNode("loi:UserId");
        if (n.hasContent()) {
            learningObjectiveAssessment.setUserId(Integer.parseInt(n.getStringValue()));
        }
        n = node.selectSingleNode("loi:RubricCriteriaItemId");
        if (n.hasContent()) {
            learningObjectiveAssessment.setRubricCriteriaItemId(Integer.parseInt(n.getStringValue()));
        }
        n = node.selectSingleNode("loi:PercentScore");
        if (n.hasContent()) {
            learningObjectiveAssessment.setPercentScore(Double.parseDouble(n.getStringValue()));
        }
        n = node.selectSingleNode("loi:Comment");
        if (n.hasContent()) {
            learningObjectiveAssessment.setComment(n.getStringValue());
        }
        n = node.selectSingleNode("loi:Mastery");
        if (n.hasContent()) {
            learningObjectiveAssessment.setMastery(Boolean.parseBoolean(n.getStringValue()));
        }
        n = node.selectSingleNode("loi:Override");
        if (n.hasContent()) {
            learningObjectiveAssessment.setOverride(Boolean.parseBoolean(n.getStringValue()));
        }
        n = node.selectSingleNode("loi:AssessedAchievementLevelId");
        if (n.hasContent()) {
            learningObjectiveAssessment.setAssessedAchievementLevelId(Integer.parseInt(n.getStringValue()));
        }
        n = node.selectSingleNode("loi:Reportable");
        if (n.hasContent()) {
            learningObjectiveAssessment.setReportable(Boolean.parseBoolean(n.getStringValue()));
        }
        result.add(learningObjectiveAssessment);
    }
    return result;
}