Example usage for org.dom4j Node hasContent

List of usage examples for org.dom4j Node hasContent

Introduction

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

Prototype

boolean hasContent();

Source Link

Document

hasContent returns true if this node is a Branch (either an Element or a Document) and it contains at least one content node such as a child Element or Text node.

Usage

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

/**
 * xml looks like this/*  ww  w . ja  va2s  .c  o 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()));
        }/*from w w  w.  j a va  2  s.com*/
        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 w w.  ja v a  2s . com*/
        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 ww  w.  j a v  a 2s  .  c  o m
    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 ww  .j  ava2s  .  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()));
        }/*from w w  w. j a va 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());
        }/*  ww w .j a va2s  .c o  m*/
        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);
            }// ww w.  j a va  2 s.c  o m
        }
        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  ww  w.j a  v  a  2  s .co 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 w  ww .  j a  v a  2  s. c  o  m*/
        }
    }
    return result;
}