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 String serializeNotificationToXML(Notification notification) {
    Document document = DocumentHelper.createDocument();

    Element root = document.addElement("Notification");
    root.setQName(new QName("Notification", new Namespace("", EntityConstants.NAMESPACE_ENTITIES)));
    root.add(new Namespace("i", "http://www.w3.org/2001/XMLSchema-instance"));

    if (notification.getLaunchParameter() != null) {
        root.addElement("LaunchParameter").addText(notification.getLaunchParameter().toString());
    }/*from  w  w w  .jav a  2 s.c o  m*/
    if (notification.getLocalizedMessages() != null) {
        Element n = root.addElement("LocalizedMessages");
        n.add(new Namespace("a", EntityConstants.NAMESPACE_ARRAYS));

        HashMap<String, String> messages = notification.getLocalizedMessages();
        for (String lang : messages.keySet()) {
            Element messageKeyValuePair = n.addElement("a:KeyValueOfstringstring");
            messageKeyValuePair.addElement("a:Key").addText(lang);
            messageKeyValuePair.addElement("a:Value").addText(messages.get(lang));
        }
    }
    if (notification.getMessage() != null) {
        root.addElement("Message").addText(notification.getMessage());
    }
    if (notification.getReciverPermission() != null) {
        root.addElement("ReciverPermission").addText(notification.getReciverPermission().toString());
    }

    return root.asXML();
}

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

private String serializeLearningObjectInstanceUserReportsToXML(
        List<LearningObjectInstanceUserReport> userReports) {
    Document document = DocumentHelper.createDocument();

    Element root = document.addElement("ArrayOfLearningObjectInstanceUserReport");
    root.setQName(new QName("ArrayOfLearningObjectInstanceUserReport",
            new Namespace("", EntityConstants.NAMESPACE_ENTITIES)));
    root.add(new Namespace("i", "http://www.w3.org/2001/XMLSchema-instance"));

    for (LearningObjectInstanceUserReport userReport : userReports) {
        Element n = root.addElement("LearningObjectInstanceUserReport");
        fillLearningObjectInstanceUserReportXmlElement(n, userReport);
    }//from w w  w .  j a va 2s .c  o  m
    return root.asXML();
}

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

private String serializeLearningObjectInstanceToXML(LearningObjectInstance instance) {
    Document document = DocumentHelper.createDocument();

    Element root = document.addElement("LearningObjectInstance");
    root.setQName(new QName("LearningObjectInstance", new Namespace("", EntityConstants.NAMESPACE_ENTITIES)));
    root.add(new Namespace("i", "http://www.w3.org/2001/XMLSchema-instance"));

    if (instance.getActiveFromUTC() != null) {
        String activeFromUTCText = sdf.format(instance.getActiveFromUTC());
        root.addElement("ActiveFromUtc").addText(activeFromUTCText);
    }//  w  w  w  .j av a 2  s . co  m
    if (instance.getActiveToUTC() != null) {
        String activeToUTCText = sdf.format(instance.getActiveToUTC());
        root.addElement("ActiveToUtc").addText(activeToUTCText);
    }

    root.addElement("AssessmentId").addText(instance.getAssessmentId().toString());
    root.addElement("AssessmentStatusId").addText(instance.getAssessmentStatusId().toString());
    root.addElement("IsAssessmentVisible").addText(String.valueOf(instance.getIsAssessmentVisible()));
    root.addElement("CreatedByUserId").addText("" + instance.getCreatedByUserId());

    if (instance.getCreatedUTC() != null) {
        String createdUTCText = sdf.format(instance.getCreatedUTC());
        root.addElement("CreatedUtc").addText(createdUTCText);
    }
    root.addElement("CourseCode").addText("" + instance.getCourseCode());
    root.addElement("CourseId").addText("" + instance.getCourseId());
    root.addElement("CourseSyncKey").addText("" + instance.getCourseSyncKey());
    root.addElement("CourseOrganisationId").addText("" + instance.getCourseOrganisationId());
    root.addElement("CourseOrganisationSyncKey").addText("" + instance.getCourseOrganisationSyncKey());
    if (instance.getMaxScore() != null) {
        root.addElement("MaxScore").addText("" + instance.getMaxScore());
    }
    if (instance.getDeadLineUTC() != null) {
        String deadlineUTCText = sdf.format(instance.getDeadLineUTC());
        root.addElement("DeadlineUtc").addText(deadlineUTCText);
    }

    root.addElement("IsObligatory").addText(String.valueOf(instance.isIsObligatory()));

    root.addElement("LearningObjectId").addText("" + instance.getLearningObjectId());
    root.addElement("LearningObjectInstanceId").addText("" + instance.getLearningObjectInstanceId());

    if (instance.getModifiedUTC() != null) {
        String modifiedUTCText = sdf.format(instance.getModifiedUTC());
        root.addElement("ModifiedUtc").addText(modifiedUTCText);
    }

    root.addElement("Title").addText(instance.getTitle());

    return root.asXML();
}

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

private String serializeLearningObjectiveAssessmentsToXml(
        List<LearningObjectiveAssessment> learningObjectiveAssessments) {
    Document document = DocumentHelper.createDocument();

    Element root = document.addElement("ArrayOfLearningObjectiveAssessment");
    root.setQName(new QName("ArrayOfLearningObjectiveAssessment",
            new Namespace("", EntityConstants.NAMESPACE_ENTITIES)));
    root.add(new Namespace("i", "http://www.w3.org/2001/XMLSchema-instance"));

    for (LearningObjectiveAssessment loAssessment : learningObjectiveAssessments) {
        Element n = root.addElement("LearningObjectiveAssessment");

        n.addElement("LearningObjectiveId").addText(Integer.toString(loAssessment.getLearningObjectiveId()));
        n.addElement("UserId").addText(Integer.toString(loAssessment.getUserId()));
        n.addElement("RubricCriteriaItemId").addText(Integer.toString(loAssessment.getRubricCriteriaItemId()));
        n.addElement("PercentScore").addText(Double.toString(loAssessment.getPercentScore()));
        if (loAssessment.getComment() != null) {
            n.addElement("Comment").addText(loAssessment.getComment());
        }/*from  w  w w  . j a va 2  s  .c  o  m*/
        n.addElement("Mastery").addText(Boolean.toString(loAssessment.getMastery()));
        n.addElement("Override").addText(Boolean.toString(loAssessment.getOverride()));
        if (loAssessment.getAssessedAchievementLevelId() != null) {
            n.addElement("AssessedAchievementLevelId")
                    .addText(loAssessment.getAssessedAchievementLevelId().toString());
        }
        n.addElement("Reportable").addText(Boolean.toString(loAssessment.getReportable()));
    }
    return root.asXML();
}

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

private List<AssessmentItem> deserializeXMLToListOfAssessmentItems(InputStream xmlStream)
        throws ParseException, DocumentException {
    List<AssessmentItem> result = new ArrayList<AssessmentItem>();
    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);

    String lElem = "//loi:ArrayOfAssessmentItem";

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

    for (Node node : nodes) {
        AssessmentItem assessmentItem = new AssessmentItem();
        Node n = node.selectSingleNode("loi:AssessmentId");
        if (n.hasContent()) {
            assessmentItem.setAssessmentId(Integer.parseInt(n.getStringValue()));
        }//from w ww.j  av  a2s  .  co  m
        n = node.selectSingleNode("loi:AssessmentItemId");
        if (n.hasContent()) {
            assessmentItem.setAssessmentItemId(Integer.parseInt(n.getStringValue()));
        }
        n = node.selectSingleNode("loi:Description");
        if (n.hasContent()) {
            assessmentItem.setDescription(n.getStringValue());
        }
        n = node.selectSingleNode("loi:PercentFromAndIncl");
        if (n.hasContent()) {
            assessmentItem.setPercentFromAndIncl(Double.parseDouble(n.getStringValue()));
        }
        n = node.selectSingleNode("loi:PercentTo");
        if (n.hasContent()) {
            assessmentItem.setPercentTo(Double.parseDouble(n.getStringValue()));
        }
        n = node.selectSingleNode("loi:Title");
        if (n.hasContent()) {
            assessmentItem.setTitle(n.getStringValue());
        }
        result.add(assessmentItem);
    }
    return result;
}

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

private List<Assessment> deserializeXMLToListOfAssessments(InputStream xmlStream)
        throws ParseException, DocumentException {
    List<Assessment> result = new ArrayList<Assessment>();
    SAXReader reader = new SAXReader();
    Document doc = reader.read(xmlStream);

    String lElem = "//loi:ArrayOfAssessment";

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

    for (Node node : nodes) {
        Assessment assessment = new Assessment();
        Node n = node.selectSingleNode("loi:AssessmentId");
        if (n.hasContent()) {
            assessment.setAssessmentId(Integer.parseInt(n.getStringValue()));
        }//  w  w  w . jav a  2  s  . c  o m
        n = node.selectSingleNode("loi:Description");
        if (n.hasContent()) {
            assessment.setDescription(n.getStringValue());
        }
        n = node.selectSingleNode("loi:Title");
        if (n.hasContent()) {
            assessment.setTitle(n.getStringValue());
        }
        result.add(assessment);
    }
    return result;
}

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

private LearningObjectInstance deserializeXMLToLearningObjectInstance(InputStream xmlStream)
        throws ParseException, DocumentException {
    LearningObjectInstance loi = null;//from www . java  2s. c o  m

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

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

        Node node = root.selectSingleNode(lElem + "/loi:ActiveToUtc");
        if (node != null && node.hasContent()) {
            loi.setActiveToUTC(sdf.parse(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:DeadlineUtc");
        if (node != null && node.hasContent()) {
            loi.setDeadLineUTC(sdf.parse(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:ActiveFromUtc");
        if (node != null && node.hasContent()) {
            loi.setActiveFromUTC(sdf.parse(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:CreatedUtc");
        if (node != null && node.hasContent()) {
            loi.setCreatedUTC(sdf.parse(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:ModifiedUtc");
        if (node != null && node.hasContent()) {
            loi.setModifiedUTC(sdf.parse(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:Title");
        if (node != null && node.hasContent()) {
            loi.setTitle(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:LearningObjectInstanceId");
        if (node != null && node.hasContent()) {
            loi.setLearningObjectInstanceId(Integer.parseInt(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:LearningObjectId");
        if (node != null && node.hasContent()) {
            loi.setLearningObjectId(Integer.parseInt(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:ModifiedUtc");
        if (node != null && node.hasContent()) {
            loi.setModifiedUTC(sdf.parse(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:CreatedUtc");
        if (node != null && node.hasContent()) {
            loi.setCreatedUTC(sdf.parse(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:CreatedByUserId");
        if (node != null && node.hasContent()) {
            loi.setCreatedByUserId(Integer.parseInt(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:IsObligatory");
        if (node != null && node.hasContent()) {
            loi.setIsObligatory(Boolean.parseBoolean(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:AssessmentId");
        if (node != null && node.hasContent()) {
            loi.setAssessmentId(Integer.parseInt(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:AssessmentStatusId");
        if (node != null && node.hasContent()) {
            loi.setAssessmentStatusId(Integer.parseInt(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:IsAssessmentVisible");
        if (node != null && node.hasContent()) {
            loi.setIsAssessmentVisible(Boolean.parseBoolean(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:CourseCode");
        if (node != null && node.hasContent()) {
            loi.setCourseCode(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:CourseId");
        if (node != null && node.hasContent()) {
            loi.setCourseId(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:CourseSyncKey");
        if (node != null && node.hasContent()) {
            loi.setCourseSyncKey(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:CourseOrganisationId");
        if (node != null && node.hasContent()) {
            loi.setCourseOrganisationId(Integer.parseInt(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:CourseOrganisationSyncKey");
        if (node != null && node.hasContent()) {
            loi.setCourseOrganisationSyncKey(node.getStringValue());
        }
        node = root.selectSingleNode(lElem + "/loi:MaxScore");
        if (node != null && node.hasContent()) {
            loi.setMaxScore(Double.parseDouble(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:SubmissionType");
        if (node != null && node.hasContent()) {
            try {
                loi.setSubmissionType(SubmissionType.valueOf(node.getStringValue()));
            } catch (IllegalArgumentException iea) {
                loi.setSubmissionType(SubmissionType.NotInUse);
            }
        }
        node = root.selectSingleNode(lElem + "/loi:UsePlagiarism");
        if (node != null && node.hasContent()) {
            loi.setUsePlagiarism(Boolean.parseBoolean(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:UseAnonymousSubmission");
        if (node != null && node.hasContent()) {
            loi.setUseAnonymousSubmission(Boolean.parseBoolean(node.getStringValue()));
        }
        node = root.selectSingleNode(lElem + "/loi:HasLearningObjectiveAssessmentCriteria");
        if (node != null && node.hasContent()) {
            loi.setHasLearningObjectiveAssessmentCriteria(Boolean.parseBoolean(node.getStringValue()));
        }
    }
    return loi;
}

From source file:nc.noumea.mairie.organigramme.services.exportGraphML.impl.AbstractExportGraphMLService.java

License:Open Source License

/**
 * Initialise l entete du graphML/* w w  w  . ja va  2 s .  c o  m*/
 * 
 * @param root
 *            Element
 */
protected void initHeader(Element root) {

    root.addAttribute("xmlns", "http://graphml.graphdrawing.org/xmlns");
    root.addAttribute("xsi:schemaLocation",
            "http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd");
    root.add(new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"));
    root.add(new Namespace("y", "http://www.yworks.com/xml/graphml"));
    root.addElement("key").addAttribute("yfiles.type", "nodegraphics").addAttribute("for", "node")
            .addAttribute("id", "d6");
    root.addElement("key").addAttribute("yfiles.type", "edgegraphics").addAttribute("for", "edge")
            .addAttribute("id", "d7");
    root.addElement("key").addAttribute("yfiles.type", "resources").addAttribute("for", "graphml")
            .addAttribute("id", "d13");
}

From source file:nc.noumea.mairie.organigramme.services.impl.ExportGraphMLServiceImpl.java

License:Open Source License

private void initHeader(Element root) {
    root.addAttribute("xmlns", "http://graphml.graphdrawing.org/xmlns");
    root.addAttribute("xsi:schemaLocation",
            "http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd");
    root.add(new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"));
    root.add(new Namespace("y", "http://www.yworks.com/xml/graphml"));
    root.addElement("key").addAttribute("attr.name", "sigle").addAttribute("attr.type", "string")
            .addAttribute("for", "node").addAttribute("id", "d4");
    root.addElement("key").addAttribute("attr.name", "label").addAttribute("attr.type", "string")
            .addAttribute("for", "node").addAttribute("id", "d5");
    root.addElement("key").addAttribute("yfiles.type", "nodegraphics").addAttribute("for", "node")
            .addAttribute("id", "d6");
    root.addElement("key").addAttribute("yfiles.type", "edgegraphics").addAttribute("for", "edge")
            .addAttribute("id", "d7");
}

From source file:net.sf.saxon.option.dom4j.DOM4JWriter.java

License:Mozilla Public License

/**
* Start of an element./*from  w w w. ja v  a 2s.  c o m*/
*/

public void startElement(NodeName nameCode, SchemaType typeCode, int locationId, int properties)
        throws XPathException {
    flush();
    String local = nameCode.getLocalPart();
    String uri = nameCode.getURI();
    String prefix = nameCode.getPrefix();
    Element element;
    if (ancestors.isEmpty()) {
        startDocument(0);
        implicitDocumentNode = true;
    }
    QName name = new QName(local, new Namespace(prefix, uri));
    if (ancestors.size() == 1) {
        element = new DefaultElement(name);
        document.setRootElement(element);
    } else {
        element = ((Element) ancestors.peek()).addElement(name);
    }
    ancestors.push(element);
}