Example usage for org.dom4j Namespace Namespace

List of usage examples for org.dom4j Namespace Namespace

Introduction

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

Prototype

public Namespace(String prefix, String uri) 

Source Link

Document

DOCUMENT ME!

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  ww  . j a  va2s.co  m*/
        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//w  ww. j  ava 2s.c  o  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/*w ww .j  a v  a  2  s.c  o  m*/
<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 ww w.  j a va  2s.com
        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

private Site deserializeXMLToSite(InputStream xmlStream) throws ParseException, DocumentException {
    Site site = null;/* w  ww.  jav a2  s  . c om*/

    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);
    String lElem = "//loi:Site";

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

        Node node = root.selectSingleNode(lElem + "/loi:Segment");
        if (node.hasContent()) {
            try {
                site.setSegment(EducationSegment.valueOf(node.getStringValue()));
            } catch (IllegalArgumentException iea) {
                site.setSegment(EducationSegment.Other);
            }
        }
        node = root.selectSingleNode(lElem + "/loi:CountryCode");
        if (node.hasContent()) {
            site.setCountryCode(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:Name");
        if (node.hasContent()) {
            site.setName(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:ShortName");
        if (node.hasContent()) {
            site.setShortName(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:BaseUrl");
        if (node.hasContent()) {
            site.setBaseUrl(node.getStringValue());
        }
    }
    return site;
}

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

private CustomerSettings deserializeXMLToCustomerSettings(InputStream xmlStream)
        throws ParseException, DocumentException {
    CustomerSettings customerSettings = null;

    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);
    String lElem = "//loi:CustomerSettings";

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

        Node node = doc.selectSingleNode("loi:PlagiarismCode");
        if (node.hasContent()) {
            customerSettings.setPlagiarismCode(node.getStringValue());
        }//  ww w .ja  v  a2  s.  c om
        node = doc.selectSingleNode("loi:PlagiarismEmail");
        if (node.hasContent()) {
            customerSettings.setPlagiarismEmail(node.getStringValue());
        }
        node = doc.selectSingleNode("loi:PlagiarismShowStudentName");
        if (node.hasContent()) {
            customerSettings.setPlagiarismShowStudentName(node.getStringValue());
        }
        node = doc.selectSingleNode("loi:UsePlagiarism");
        if (node.hasContent()) {
            customerSettings.setUsePlagiarism(Boolean.parseBoolean(node.getStringValue()));
        }
    }
    return customerSettings;
}

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

/**
 * xml looks like this/*from  www.j  a v  a  2s  . 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   www .j a va 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<LearningObjectInstanceUserReport> deserializeXMLToListOfLearningObjectInstanceUserReport(
        InputStream xmlStream) throws ParseException, DocumentException {
    List<LearningObjectInstanceUserReport> result = new ArrayList<LearningObjectInstanceUserReport>();

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

    String lElem = "//loi:ArrayOfLearningObjectInstanceUserReport";

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

    for (Node n : nodes) {
        LearningObjectInstanceUserReport singleReport = new LearningObjectInstanceUserReport();
        fillSingleLearningObjectInstanceUserReportEntityFromXml(singleReport, root, lElem, n);
        result.add(singleReport);//from   www .  j  a v  a 2  s.c o m
    }

    return result;
}

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

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

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

    String lElem = "//loi:ArrayOfLearningObjectInstanceUser";

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

    for (Node n : nodes) {
        LearningObjectInstanceUser singleUser = new LearningObjectInstanceUser();
        fillSingleLearningObjectInstanceUserEntityFromXml(singleUser, root, lElem, n);
        result.add(singleUser);//  ww  w  .j a  va 2s  . c o m
    }

    return result;
}