Java Code Examples for org.dom4j.Document#addComment()
The following examples show how to use
org.dom4j.Document#addComment() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimetableXMLSaver.java From cpsolver with GNU Lesser General Public License v3.0 | 6 votes |
public Document saveDocument() { Document document = DocumentHelper.createDocument(); document.addComment("University Course Timetabling"); if (iSaveCurrent && getAssignment().nrAssignedVariables() != 0) { StringBuffer comments = new StringBuffer("Solution Info:\n"); Map<String, String> solutionInfo = (getSolution() == null ? getModel().getExtendedInfo(getAssignment()) : getSolution().getExtendedInfo()); for (String key : new TreeSet<String>(solutionInfo.keySet())) { String value = solutionInfo.get(key); comments.append(" " + key + ": " + value + "\n"); } document.addComment(comments.toString()); } Element root = document.addElement("timetable"); doSave(root); return document; }
Example 2
Source File: WriteXml.java From Crawer with MIT License | 6 votes |
/** * 写数据到xml * * @param datas * @throws Exception */ public static void witeXml(@SuppressWarnings("rawtypes") Map map,String xmlFilePath) throws Exception { Document doc = DomHelper.createDomFJ(); doc.addComment("以utf-8的编码"); Element books = DomHelper.appendChile("books", doc); /* 格式化输出 */ OutputFormat format = OutputFormat.createPrettyPrint();// 紧缩 format.setEncoding("utf-8"); // 设置utf-8编码 Element book = DomHelper.appendChile("book", books); //构建树形结构 rescue(book, map); //输出 FileOutputStream fos = new FileOutputStream(xmlFilePath); XMLWriter writer=new XMLWriter(fos,format); //写结构 writer.write(doc); //关闭流 writer.close(); }
Example 3
Source File: StudentSectioningXMLSaver.java From cpsolver with GNU Lesser General Public License v3.0 | 5 votes |
public Document saveDocument() { Document document = DocumentHelper.createDocument(); document.addComment("Student Sectioning"); populate(document); return document; }
Example 4
Source File: StudentSectioningXMLSaver.java From cpsolver with GNU Lesser General Public License v3.0 | 5 votes |
/** * Fill in all the data into the given document * @param document document to be populated */ protected void populate(Document document) { if (iSaveCurrent || iSaveBest) { StringBuffer comments = new StringBuffer("Solution Info:\n"); Map<String, String> solutionInfo = (getSolution() == null ? getModel().getExtendedInfo(getAssignment()) : getSolution().getExtendedInfo()); for (String key : new TreeSet<String>(solutionInfo.keySet())) { String value = solutionInfo.get(key); comments.append(" " + key + ": " + value + "\n"); } document.addComment(comments.toString()); } Element root = document.addElement("sectioning"); root.addAttribute("version", "1.0"); root.addAttribute("initiative", getModel().getProperties().getProperty("Data.Initiative")); root.addAttribute("term", getModel().getProperties().getProperty("Data.Term")); root.addAttribute("year", getModel().getProperties().getProperty("Data.Year")); root.addAttribute("created", String.valueOf(new Date())); saveOfferings(root); saveStudents(root); saveLinkedSections(root); saveTravelTimes(root); if (iShowNames) { Progress.getInstance(getModel()).save(root); } }
Example 5
Source File: ConfigurationWriter.java From eclipse-cs with GNU Lesser General Public License v2.1 | 4 votes |
/** * Writes the modules of the configuration to the output stream. * * @param out * the ouput stream. * @param modules * the modules * @param checkConfig * the Check configuration object * @throws CheckstylePluginException * error writing the checkstyle configuration */ public static void write(OutputStream out, List<Module> modules, ICheckConfiguration checkConfig) throws CheckstylePluginException { try { // pass the configured modules through the save filters SaveFilters.process(modules); Document doc = DocumentHelper.createDocument(); doc.addDocType(XMLTags.MODULE_TAG, "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN", "https://checkstyle.org/dtds/configuration_1_3.dtd"); String lineSeperator = System.getProperty("line.separator"); //$NON-NLS-1$ String comment = lineSeperator + " This configuration file was written by the eclipse-cs plugin configuration editor" //$NON-NLS-1$ + lineSeperator; doc.addComment(comment); // write out name and description as comment String description = lineSeperator + " Checkstyle-Configuration: " //$NON-NLS-1$ + checkConfig.getName() + lineSeperator + " Description: " //$NON-NLS-1$ + (Strings.emptyToNull(checkConfig.getDescription()) != null ? lineSeperator + checkConfig.getDescription() + lineSeperator : "none" + lineSeperator); //$NON-NLS-1$ doc.addComment(description); // find the root module (Checker) // the root module is the only module that has no parent List<Module> rootModules = getChildModules(null, modules); if (rootModules.size() < 1) { throw new CheckstylePluginException(Messages.errorNoRootModule); } if (rootModules.size() > 1) { throw new CheckstylePluginException(Messages.errorMoreThanOneRootModule); } writeModule(rootModules.get(0), doc, null, modules); out.write(XMLUtil.toByteArray(doc)); } catch (IOException e) { CheckstylePluginException.rethrow(e); } }
Example 6
Source File: XmlExport.java From openmeetings with Apache License 2.0 | 4 votes |
public static Document createDocument() { Document document = DocumentHelper.createDocument(); document.setXMLEncoding(UTF_8.name()); document.addComment(XmlExport.FILE_COMMENT); return document; }
Example 7
Source File: DomHelper.java From Crawer with MIT License | 2 votes |
/** * 根目录添加注释 * @param explain 说明文字 * @param doc */ public static void addCommend(String explain,Document doc){ doc.addComment(explain); }