Example usage for org.dom4j Element add

List of usage examples for org.dom4j Element add

Introduction

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

Prototype

void add(Namespace namespace);

Source Link

Document

Adds the given Namespace to this element.

Usage

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

private String serializeNotificationToWrappedXML(Notification notification) {
    Document document = DocumentHelper.createDocument();

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

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

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

    return root.asXML();
}

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

private String serializeUserIdsToWrappedXML(int[] receiverUserIds) {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("receiverUserIds");
    root.add(new Namespace("i", "http://www.w3.org/2001/XMLSchema-instance"));
    root.add(new Namespace("a", EntityConstants.NAMESPACE_ARRAYS));

    for (int id : receiverUserIds) {
        Element idElement = root.addElement("a:int");
        idElement.setText(Integer.toString(id));
    }/*from w w  w.  j a v  a  2s  .  c  om*/

    return root.asXML();
}

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

private String serializeListOfIntToWrappedXML(int[] ids) {
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement("ArrayOfint");
    root.add(new Namespace("i", "http://www.w3.org/2001/XMLSchema-instance"));
    root.add(new Namespace("a", EntityConstants.NAMESPACE_ARRAYS));

    for (int id : ids) {
        Element idElement = root.addElement("a:int");
        idElement.setText(Integer.toString(id));
    }/*from   w  w  w .  jav a 2  s.co m*/

    return root.asXML();
}

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());
    }//  w w  w. j  av a2  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   ww w .  j a  v a 2  s .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);
    }//from   w  w w  . j a v  a2s .c om
    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   www  .  j  a  v  a2 s.  co  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:jetsennet.orm.executor.resultset.RowsResultSetXmlExtractor.java

License:Apache License

@Override
public Document handle(ResultSet rs) throws SQLException {
    Document results = DocumentHelper.createDocument();
    Element rootElement = results.addElement(rootName);
    ResultSetMetaData rsmd = rs.getMetaData();
    int pos = 0;/*from  w  w  w .  java2 s  .  c  o m*/
    int len = 0;
    while (rs.next()) {
        if (pos >= offset) {
            try {
                rootElement.add(this.xmlReader.read(itemName, rs, rsmd));
                len++;
            } catch (Exception e) {
                throw new SQLException(e);
            }
        }
        if (len >= max) {
            break;
        }
        pos++;
    }
    return results;
}

From source file:lost.tok.AuthorsHandler.java

License:Open Source License

/**
 * Adding an author to the xml file//from  ww w.  j  av  a 2 s  .  c  o m
 * 
 * @param author - the author to add
 * @param rank
 * @throws CoreException
 */
public void addAuthor(Author author, Integer rank) throws CoreException {

    if (!myToK.getProject().exists() || author == null) {
        throwCoreException("problem with atributes to addAuthor");
        return;
    }

    Document doc = readFromXML();

    // creating the xPath
    XPath xpathSelector = DocumentHelper.createXPath("//authorsGroup[id='" + rank + "']");
    List result = xpathSelector.selectNodes(doc);
    if (result.size() == 1) {
        Element authorsGroup = (Element) result.get(0);
        author.setID(++id);
        authorsGroup.add(author.toXML());

        writeToXml(doc);
    }
}

From source file:lost.tok.AuthorsHandler.java

License:Open Source License

/**
 * Relocate author to target rank/*from  w  ww.  j av a2  s .c o  m*/
 * 
 * @param srcRank
 * @param trgtRank
 */
public void relocateAuthor(String authName, Integer trgtRank) {

    Document doc = readFromXML();

    // If the author and the target rank can be found,
    // the author will move to the target rank
    XPath xpathSelector1 = DocumentHelper.createXPath("//author[.='" + authName + "']");
    List result = xpathSelector1.selectNodes(doc);
    if (result.size() == 1) {
        Element element = (Element) result.get(0);
        XPath xpathSelector2 = DocumentHelper
                .createXPath("//authorsGroup[id='" + java.lang.Integer.toString(trgtRank) + "']");
        List targets = xpathSelector2.selectNodes(doc);
        if (targets.size() == 1) {
            Element target = (Element) targets.get(0);
            element.detach();
            target.add(element);
        }
    }

    writeToXml(doc);
}