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:it.eng.qbe.datasource.configuration.dao.fileimpl.CalculatedFieldsDAOFileImpl.java

License:Mozilla Public License

private String loadExpression(Node calculatedFieldNode) {
    String expression;/*  w w  w. j a  v  a  2s . co m*/

    expression = null;

    Node expressionNode = calculatedFieldNode.selectSingleNode(EXPRESSION_TAG);
    if (expressionNode != null) {
        expression = expressionNode.getStringValue();
    } else { // for back compatibility
        expression = calculatedFieldNode.getStringValue();
    }

    return expression;
}

From source file:it.unibz.inf.xmlssd.metadator.xml.XMLProcessor.java

License:Apache License

/**
 * Method which returns only a simple list of photos for displaying it in the
 * deletion dialog./*from   w  w w.  j  a  v  a 2s.co  m*/
 * @return
 * @throws IOException 
 */
public String getListOfPhotos() throws IOException {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("metadator");

    List list = backend.get().selectNodes("//metadator/photo");
    for (Iterator i = list.iterator(); i.hasNext();) {
        Element element = (Element) i.next();

        Node author = element.selectSingleNode("//author");
        Node title = element.selectSingleNode("//title");

        root.addElement("photo").addAttribute("id", element.attributeValue("id"))
                .addAttribute("author", author.getStringValue())
                .addAttribute("filename", element.attributeValue("filename"))
                .addAttribute("title", title.getStringValue());
    }

    return UIHelper.prettyPrintString(document.asXML());
}

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()));
        }/*from   ww  w  .j av  a  2 s  .c  o  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/*from  w w  w .  j a v a  2 s  .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/*from  w  w  w  . ja  v  a2 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.ja  va  2  s  . 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;/* ww w. ja v a2s.c o  m*/

    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());
        }//from   www .  jav a  2 s .  c o m
        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   ww w. j a v a  2  s  .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 . jav a2 s .co  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;
}