List of usage examples for org.dom4j Element addComment
Element addComment(String comment);
Comment
node with the given text to this element. From source file:architecture.ee.component.RepositoryImpl.java
License:Apache License
public ApplicationProperties getSetupApplicationProperties() { if (setupProperties == null) { if (initailized.get()) { File file = getFile(ApplicationConstants.DEFAULT_STARTUP_FILENAME); if (!file.exists()) { boolean error = false; // create default file... log.debug(CommonLogLocalizer.format("003012", file.getAbsolutePath())); Writer writer = null; try { lock.lock();/*from w w w . j a v a 2 s.c o m*/ writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8); XMLWriter xmlWriter = new XMLWriter(writer, OutputFormat.createPrettyPrint()); StringBuilder sb = new StringBuilder(); org.dom4j.Document document = org.dom4j.DocumentHelper.createDocument(); org.dom4j.Element root = document.addElement("startup-config"); // setup start // ------------------------------------------------------------ org.dom4j.Element setupNode = root.addElement("setup"); setupNode.addElement("complete").setText("false"); // setup end // license start root.addComment("LICENSE SETTING"); org.dom4j.Element licenseNode = root.addElement("license"); // license end // view start /* org.dom4j.Element viewNode = root.addElement("view"); org.dom4j.Element renderNode = viewNode.addElement("render"); org.dom4j.Element freemarkerNode = renderNode.addElement("freemarker"); freemarkerNode.addElement("enabled").setText("true"); freemarkerNode.addElement("source").addElement("location"); org.dom4j.Element velocityNode = renderNode.addElement("velocity"); velocityNode.addElement("enabled").setText("false"); */ // view end // security start root.addComment("SECURITY SETTING"); org.dom4j.Element securityNode = root.addElement("security"); org.dom4j.Element encrpptNode = securityNode.addElement("encrypt"); encrpptNode.addElement("algorithm").setText("Blowfish"); encrpptNode.addElement("key").addElement("current"); org.dom4j.Element encrpptPropertyNode = encrpptNode.addElement("property"); encrpptPropertyNode.addElement("name").setText("username"); encrpptPropertyNode.addElement("name").setText("password"); securityNode.addElement("authentication").addElement("encoding").addElement("algorithm") .setText("SHA-256"); // security end // services start root.addComment("SERVICES SETTING"); org.dom4j.Element servicesNode = root.addElement("services"); servicesNode.addElement("sql").addElement("location").addText("sql"); // services end // database start root.addComment("DATABASE SETTING"); org.dom4j.Element databaseNode = root.addElement("database"); org.dom4j.Element databaseDefaultNode = databaseNode.addElement("default"); databaseDefaultNode.addComment(" 1. jndi datasource "); databaseDefaultNode.addComment((new StringBuilder()).append("\n").append(" ") .append("<jndiDataSourceProvider>").append("\n").append(" ") .append(" <jndiName></jndiName>").append("\n").append(" ") .append("</jndiDataSourceProvider>").append("\n").toString()); databaseDefaultNode.addComment(" 2. connection pool datasource using dbcp "); databaseDefaultNode.addComment((new StringBuilder()).append("\n").append(" ") .append("<pooledDataSourceProvider> ").append("\n").append(" ") .append(" <driverClassName></driverClassName> ").append("\n").append(" ") .append(" <url></url>").append("\n").append(" ") .append(" <username></username>").append("\n").append(" ") .append(" <password></password>").append("\n").append(" ") .append(" <connectionProperties>").append("\n").append(" ") .append(" <initialSize>1</initialSize>").append("\n").append(" ") .append(" <maxActive>8</maxActive>").append("\n").append(" ") .append(" <maxIdle>8</maxIdle>").append("\n").append(" ") .append(" <maxWait>-1</maxWait>").append("\n").append(" ") .append(" <minIdle>0</minIdle>").append("\n").append(" ") .append(" <testOnBorrow>true</testOnBorrow>").append("\n").append(" ") .append(" <testOnReturn>false</testOnReturn>").append("\n").append(" ") .append(" <testWhileIdle>false</testWhileIdle>").append("\n") .append(" ") .append(" <validationQuery>select 1 from dual</validationQuery>") .append("\n").append(" ").append(" </connectionProperties>").append("\n") .append(" ").append("</pooledDataSourceProvider>").toString()); // database end xmlWriter.write(document); } catch (Exception e) { log.error("fail to making {} - {}", file.getName(), e.getMessage()); error = true; } finally { try { writer.flush(); writer.close(); } catch (Exception e) { log.error("error", e); error = true; } lock.unlock(); } } else { try { log.debug(CommonLogLocalizer.format("003011", file.getPath())); this.setupProperties = new LocalApplicationProperties(file); } catch (IOException e) { log.error(CommonLogLocalizer.getMessage("003013"), e); } } } else { return LocalApplicationProperties.EMPTY_APPLICATION_PROPERTIES; } } return setupProperties; }
From source file:at.jabberwocky.impl.core.io.PacketReader.java
private Document parseDocument() throws DocumentException, IOException, XmlPullParserException { DocumentFactory df = docFactory;/*from w ww .j av a2s .com*/ Document document = df.createDocument(); Element parent = null; XmlPullParser pp = parser; int count = 0; while (true) { int type = -1; type = pp.nextToken(); switch (type) { case XmlPullParser.PROCESSING_INSTRUCTION: { String text = pp.getText(); int loc = text.indexOf(" "); if (loc >= 0) { document.addProcessingInstruction(text.substring(0, loc), text.substring(loc + 1)); } else { document.addProcessingInstruction(text, ""); } break; } case XmlPullParser.COMMENT: { if (parent != null) { parent.addComment(pp.getText()); } else { document.addComment(pp.getText()); } break; } case XmlPullParser.CDSECT: { String text = pp.getText(); if (parent != null) { parent.addCDATA(text); } else { if (text.trim().length() > 0) { throw new DocumentException("Cannot have text content outside of the root document"); } } break; } case XmlPullParser.ENTITY_REF: { String text = pp.getText(); if (parent != null) { parent.addText(text); } else { if (text.trim().length() > 0) { throw new DocumentException("Cannot have an entityref outside of the root document"); } } break; } case XmlPullParser.END_DOCUMENT: { return document; } case XmlPullParser.START_TAG: { QName qname = (pp.getPrefix() == null) ? df.createQName(pp.getName(), pp.getNamespace()) : df.createQName(pp.getName(), pp.getPrefix(), pp.getNamespace()); Element newElement = null; // Do not include the namespace if this is the start tag of a new packet // This avoids including "jabber:client", "jabber:server" or // "jabber:component:accept" if ("jabber:client".equals(qname.getNamespaceURI()) || "jabber:server".equals(qname.getNamespaceURI()) || "jabber:component:accept".equals(qname.getNamespaceURI()) || "http://jabber.org/protocol/httpbind".equals(qname.getNamespaceURI())) { newElement = df.createElement(pp.getName()); } else { newElement = df.createElement(qname); } int nsStart = pp.getNamespaceCount(pp.getDepth() - 1); int nsEnd = pp.getNamespaceCount(pp.getDepth()); for (int i = nsStart; i < nsEnd; i++) { if (pp.getNamespacePrefix(i) != null) { newElement.addNamespace(pp.getNamespacePrefix(i), pp.getNamespaceUri(i)); } } for (int i = 0; i < pp.getAttributeCount(); i++) { QName qa = (pp.getAttributePrefix(i) == null) ? df.createQName(pp.getAttributeName(i)) : df.createQName(pp.getAttributeName(i), pp.getAttributePrefix(i), pp.getAttributeNamespace(i)); newElement.addAttribute(qa, pp.getAttributeValue(i)); } if (parent != null) { parent.add(newElement); } else { document.add(newElement); } parent = newElement; count++; break; } case XmlPullParser.END_TAG: { if (parent != null) { parent = parent.getParent(); } count--; if (count < 1) { return document; } break; } case XmlPullParser.TEXT: { String text = pp.getText(); if (parent != null) { parent.addText(text); } else { if (text.trim().length() > 0) { throw new DocumentException("Cannot have text content outside of the root document"); } } break; } default: } } }
From source file:com.bullx.demo.xml.XMLParser.java
License:Open Source License
public static void bookListToXML(List<Book> books) { Document document = DocumentHelper.createDocument(); // XMLbooks/* w w w . j a v a 2 s . c om*/ Element booksElement = document.addElement("books"); // booksElement.addComment("This is a test for dom4j, liubida, 2012.8.11"); for (Book book : books) { // Element bookElement = booksElement.addElement("book"); // : show bookElement.addAttribute("show", book.getShow() ? "yes" : "no"); // title bookElement.addElement("title").setText(book.getTitle()); // express bookElement.addElement("express").setText(book.getExpress()); } OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); StringWriter out = new StringWriter(); XMLWriter xmlWriter = new XMLWriter(out, format); try { xmlWriter.write(document); xmlWriter.flush(); String s = out.toString(); System.out.println(s); Log.info("xml done!"); } catch (Exception e) { Log.error("xml error!"); } finally { try { if (null != xmlWriter) { xmlWriter.close(); } if (null != out) { out.close(); } } catch (IOException e) { e.printStackTrace(); } } }
From source file:com.hihframework.osplugins.dom4j.XmlParseUtil.java
License:Apache License
/** * ?//from ww w . j a va 2s .c om * * @param element * ? * @param comment * */ public void addComment(Element element, String comment) { element.addComment(comment); }
From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java
License:Apache License
/** * ???/*from ww w .j av a2 s . c o m*/ * @param document */ private void generateInsert(Element root) { root.addComment(""); Element insert = root.addElement("insert"); insert.addAttribute("id", SAVE_ID); insert.addAttribute("parameterType", this.domainSimpleName); StringBuilder sb = new StringBuilder(); //sb.append("\n"); //sb.append("\t\t"); sb.append("INSERT INTO {tableName} ("); int i = 0; int fileNameSize = fieldNames.size(); //? for (String fieldName : fieldNames) { i++; sb.append(fieldName.toUpperCase()); if (i != fileNameSize) { sb.append(", "); } } sb.append(") VALUES ("); i = 0; // for (String fieldName : fieldNames) { i++; sb.append("#{"); sb.append(fieldName); sb.append("}"); if (i != fileNameSize) { sb.append(", "); } } sb.append(")"); //sb.append("\n"); insert.setText(sb.toString()); }
From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java
License:Apache License
/** * ??/*from w ww .j av a 2 s . c o m*/ * @param root */ private void generateGet(Element root) { root.addComment("?ID?"); Element get = root.addElement("select"); get.addAttribute("id", GET_ID); get.addAttribute("parameterType", "int"); get.addAttribute("resultMap", this.domainSimpleName.toLowerCase() + "Map"); StringBuilder sb = new StringBuilder(); //sb.append("\n"); //sb.append("\t\t"); sb.append("SELECT "); int i = 0; int fileNameSize = fieldNames.size(); // for (String fieldName : fieldNames) { i++; sb.append(fieldName.toUpperCase()); if (i != fileNameSize) { sb.append(", "); } } sb.append(" FROM {tableName} WHERE ID = #{param2}"); //sb.append("\n"); get.setText(sb.toString()); }
From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java
License:Apache License
/** * ?/*www .j a v a 2 s. co m*/ * @param root */ private void generateUpdate(Element root) { root.addComment(""); Element update = root.addElement("update"); update.addAttribute("id", UPDATE_ID); update.addAttribute("parameterType", this.domainSimpleName); //sb.append("\n"); //sb.append("\t\t"); update.addText("\n\t\tUPDATE {tableName} "); Element set = update.addElement("set"); // int i = 0; int fileNameSize = fieldNames.size(); for (String fieldName : fieldNames) { i++; Element ifElement = set.addElement("if"); ifElement.addAttribute("test", fieldName + " != null and " + fieldName + " != ''"); String text = fieldName.toUpperCase() + " = #{" + fieldName + "}"; if (i != fileNameSize) { text += ","; } ifElement.setText(text); } update.addText("\n\t\t WHERE ID = #{id}"); //sb.append("\n"); }
From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java
License:Apache License
/** * ?// w w w .j av a2 s . c o m * @param root */ private void generateList(Element root) { root.addComment(""); Element list = root.addElement("select"); list.addAttribute("id", LIST_ID); list.addAttribute("resultMap", this.domainSimpleName.toLowerCase() + "Map"); StringBuilder sb = new StringBuilder(); //sb.append("\n"); //sb.append("\t\t"); sb.append("SELECT "); int i = 0; int fileNameSize = fieldNames.size(); // for (String fieldName : fieldNames) { i++; sb.append(fieldName.toUpperCase()); if (i != fileNameSize) { sb.append(", "); } } sb.append(" FROM {tableName} "); //sb.append("\n"); list.setText(sb.toString()); Element where = list.addElement("where"); for (String fieldName : fieldNames) { Element ifElement = where.addElement("if"); ifElement.addAttribute("test", fieldName + " != null and " + fieldName + " != ''"); ifElement.setText(fieldName.toUpperCase() + " = #{" + fieldName + "}"); } }
From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java
License:Apache License
/** * ?// w w w. ja va 2 s . c o m * @param root */ private void generateDelete(Element root) { root.addComment(""); Element delete = root.addElement("delete"); delete.addAttribute("id", DELETE_ID); delete.addAttribute("parameterType", "int"); delete.setText("DELETE FROM {tableName} WHERE ID = #{param2}"); }
From source file:com.jiangnan.es.orm.mybatis.util.MybatisMapperXmlGenerator.java
License:Apache License
/** * ?//www . j av a 2 s . com * @param root */ private void generateResultMap(Element root) { root.addComment(""); Element resultMap = root.addElement("resultMap"); resultMap.addAttribute("id", this.domainSimpleName.toLowerCase() + "Map"); resultMap.addAttribute("type", this.domainSimpleName); for (String fieldName : fieldNames) { Element result = null; if (fieldName.equalsIgnoreCase("id")) { result = resultMap.addElement("id"); } else { result = resultMap.addElement("result"); } result.addAttribute("column", fieldName.toUpperCase()); result.addAttribute("property", fieldName); } }