List of usage examples for org.dom4j DocumentHelper createDocument
public static Document createDocument()
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 ww w . j a va 2s .c o m 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)); }// w w w . ja va 2s .c o 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()); }/*from w w w. j a v a 2s . co 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); }/* 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. java2 s. c o 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 ww.java 2 s.c om*/ 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;/* w w w. j a v a2 s .c om*/ 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.wizards.NewSourceFolder.java
License:Open Source License
protected Document orderSkeleton(IFolder folder) { Document orderDoc = DocumentHelper.createDocument(); // Create the Skeleton of the order file Element e = orderDoc.addElement("order"); //$NON-NLS-1$ e.addElement("dir").addText(folder.getName()); return orderDoc; }
From source file:main.FrevoMain.java
License:Open Source License
/** * Starts a saving procedure calling the method's own saveResults function. * Run-specific data will be added to the end of the file. * /* w ww . j a v a 2 s. c o m*/ * @param fileName * Name of the saved file without the extension. (E.g. * solution_generation_13) * @param method * The corresponding method instance to be called for saving. */ public static File saveResult(String fileName, final Element representationRootElement, long startSeed, long currentActiveSeed) { // create new document for output Document doc = DocumentHelper.createDocument(); doc.addDocType("frevo", null, System.getProperty("user.dir") + "//Components//ISave.dtd"); Element dfrevo = doc.addElement("frevo"); String fileLocation = "Undefined"; // export sessionconfig Element sessionconfig = dfrevo.addElement("sessionconfig"); // custom name Element configentry = sessionconfig.addElement("configentry"); configentry.addAttribute("key", "CustomName"); configentry.addAttribute("type", "STRING"); configentry.addAttribute("value", customName); // number of runs Element runentry = sessionconfig.addElement("configentry"); runentry.addAttribute("key", "NumberofRuns"); runentry.addAttribute("type", "INT"); runentry.addAttribute("value", Integer.toString(getNumberOfSimulationRuns())); // starting seed Element seedentry = sessionconfig.addElement("configentry"); seedentry.addAttribute("key", "StartingSeed"); seedentry.addAttribute("type", "LONG"); // seedentry.addAttribute("value", Long.toString(getSeed())); seedentry.addAttribute("value", Long.toString(startSeed)); // active seed Element aseedentry = sessionconfig.addElement("configentry"); aseedentry.addAttribute("key", "CurrentSeed"); aseedentry.addAttribute("type", "LONG"); aseedentry.addAttribute("value", Long.toString(currentActiveSeed)); try { // export problem Element problemsettings = dfrevo.addElement("problem"); ComponentXMLData problem = FrevoMain.SELECTED_PROBLEM; problemsettings.addAttribute("class", problem.getClassName()); Vector<String> keys = new Vector<String>(problem.getProperties().keySet()); for (String k : keys) { Element entry = problemsettings.addElement("problementry"); entry.addAttribute("key", k); entry.addAttribute("type", problem.getTypeOfProperty(k).toString()); entry.addAttribute("value", problem.getValueOfProperty(k)); } // export method Element methodsettings = dfrevo.addElement("method"); ComponentXMLData method = FrevoMain.SELECTED_METHOD; methodsettings.addAttribute("class", method.getClassName()); keys = new Vector<String>(method.getProperties().keySet()); for (String k : keys) { Element entry = methodsettings.addElement("methodentry"); entry.addAttribute("key", k); entry.addAttribute("type", method.getTypeOfProperty(k).toString()); entry.addAttribute("value", method.getValueOfProperty(k)); } // export ranking Element rankingsettings = dfrevo.addElement("ranking"); ComponentXMLData ranking = FrevoMain.SELECTED_RANKING; rankingsettings.addAttribute("class", ranking.getClassName()); keys = new Vector<String>(ranking.getProperties().keySet()); for (String k : keys) { Element entry = rankingsettings.addElement("rankingentry"); entry.addAttribute("key", k); entry.addAttribute("type", ranking.getTypeOfProperty(k).toString()); entry.addAttribute("value", ranking.getValueOfProperty(k)); } // export representation Element repsettings = dfrevo.addElement("representation"); ComponentXMLData representation = FrevoMain.SELECTED_REPRESENTATION; repsettings.addAttribute("class", representation.getClassName()); keys = new Vector<String>(representation.getProperties().keySet()); for (String k : keys) { Element entry = repsettings.addElement("representationentry"); entry.addAttribute("key", k); entry.addAttribute("type", representation.getTypeOfProperty(k).toString()); entry.addAttribute("value", representation.getValueOfProperty(k)); } // call method's own save solution dfrevo.add(representationRootElement); // save contents to file String location = FREVO_INSTALL_DIRECTORY + File.separator + "Results" + File.separator + customName; File rootSaveDir = new File(location); // remove spaces from filename fileName.replaceAll(" ", "_"); // create save directory based on given custom name rootSaveDir.mkdirs(); // create sub-directories for different seeds if (FrevoMain.getNumberOfSimulationRuns() > 1) { // create seed directory if there are more than one run File seedDir = new File(location + File.separator + "seed_" + startSeed); seedDir.mkdir(); fileLocation = seedDir + File.separator + fileName + ".zre"; } else { // save it the root location fileLocation = rootSaveDir + File.separator + fileName + ".zre"; } File saveFile = new File(fileLocation); OutputFormat format = OutputFormat.createPrettyPrint(); format.setLineSeparator(System.getProperty("line.separator")); saveFile.createNewFile(); FileWriter out = new FileWriter(saveFile); BufferedWriter bw = new BufferedWriter(out); XMLWriter wr = new XMLWriter(bw, format); wr.write(doc); wr.close(); System.out.println("XML Writing Completed: " + fileLocation); if (isFrevoWithGraphics()) { mainWindow.addRecentResult(saveFile); } return saveFile; } catch (OutOfMemoryError mem) { System.err.println("Could not export! (Out of memory)"); } catch (IOException e) { System.err.println("IOException while writing to XML! Check path at: " + fileLocation); e.printStackTrace(); } return null; }
From source file:main.FrevoMain.java
License:Open Source License
/** * Saves FREVO settings to the configuration file. Initiates file writing to * store data./*from ww w . ja v a 2 s . c o m*/ */ public static void saveSettings() { Document doc; File configfile = new File(FREVO_INSTALL_DIRECTORY + "/frevo_config.xml"); if (configfile.exists()) { // load data if it already exists doc = SafeSAX.read(configfile, true); Node windowsizes = doc.selectSingleNode("/frevo/window-sizes"); List<?> items = windowsizes.selectNodes(".//window"); Iterator<?> it = items.iterator(); while (it.hasNext()) { Element el = (Element) it.next(); String name = el.valueOf("./@name"); // save main data if (name.equals("main")) { el.addAttribute("width", Integer.toString(FrevoMain.mainWindowParameters[0])); el.addAttribute("height", Integer.toString(FrevoMain.mainWindowParameters[1])); } // save component browser data if (name.equals("componentbrowser")) { el.addAttribute("width", Integer.toString(FrevoMain.componentBrowserParameters[0])); el.addAttribute("height", Integer.toString(FrevoMain.componentBrowserParameters[1])); el.addAttribute("topsplit", Integer.toString(FrevoMain.componentBrowserParameters[2])); el.addAttribute("bigsplit", Integer.toString(FrevoMain.componentBrowserParameters[3])); } } } else { try { configfile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } // file does not exist doc = DocumentHelper.createDocument(); doc.addDocType("frevo", null, "config.dtd"); Element dfrevo = doc.addElement("frevo"); dfrevo.addElement("tags"); Element windowsizes = dfrevo.addElement("window-sizes"); Element mainwindow = windowsizes.addElement("window"); mainwindow.addAttribute("name", "main"); mainwindow.addAttribute("width", Integer.toString(FrevoMain.mainWindowParameters[0])); mainwindow.addAttribute("height", Integer.toString(FrevoMain.mainWindowParameters[1])); Element compwindow = windowsizes.addElement("window"); compwindow.addAttribute("name", "componentbrowser"); compwindow.addAttribute("width", Integer.toString(FrevoMain.componentBrowserParameters[0])); compwindow.addAttribute("height", Integer.toString(FrevoMain.componentBrowserParameters[1])); compwindow.addAttribute("topsplit", Integer.toString(FrevoMain.componentBrowserParameters[2])); compwindow.addAttribute("bigsplit", Integer.toString(FrevoMain.componentBrowserParameters[3])); } // write to file try { OutputFormat format = OutputFormat.createPrettyPrint(); format.setLineSeparator(System.getProperty("line.separator")); configfile.createNewFile(); FileWriter out = new FileWriter(configfile); BufferedWriter bw = new BufferedWriter(out); XMLWriter wr = new XMLWriter(bw, format); wr.write(doc); wr.close(); } catch (IOException e) { e.printStackTrace(); System.exit(1); } }