List of usage examples for org.dom4j.io OutputFormat createPrettyPrint
public static OutputFormat createPrettyPrint()
From source file:com.yahoo.validatar.report.junit.JUnitFormatter.java
License:Apache License
/** * {@inheritDoc}/* w w w. j a v a 2s . c o m*/ * Writes out the report for the given testSuites in the JUnit XML format. */ @Override public void writeReport(List<TestSuite> testSuites) throws IOException { Document document = DocumentHelper.createDocument(); Element testSuitesRoot = document.addElement("testsuites"); // Output for each test suite for (TestSuite testSuite : testSuites) { Element testSuiteRoot = testSuitesRoot.addElement("testsuite") .addAttribute("tests", Integer.toString(testSuite.queries.size() + testSuite.tests.size())) .addAttribute("name", testSuite.name); for (Query query : testSuite.queries) { Element queryNode = testSuiteRoot.addElement("testcase").addAttribute("name", query.name); if (query.failed()) { String failureMessage = StringUtils.join(query.getMessages(), ", "); queryNode.addElement("failed").addText(failureMessage); } } for (Test test : testSuite.tests) { Element testNode = testSuiteRoot.addElement("testcase").addAttribute("name", test.name); if (test.failed()) { String failedAsserts = StringUtils.join(test.getMessages(), ", "); String failureMessage = "Description: " + test.description + ";\n" + "Failed asserts: " + failedAsserts + "\n"; testNode.addElement("failed").addText(failureMessage); } } } OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(outputFile), format); writer.write(document); writer.close(); }
From source file:com.yeliu.Main.java
License:Open Source License
/** * ??manifest//from w w w . ja v a 2s .c o m * @param channel * @return */ private File saveChannelManifest(String channel) { OutputFormat format = OutputFormat.createPrettyPrint(); // format.setEncoding("GBK"); // ???XML File out = new File( processDirPath + File.separator + "manifesttemp" + File.separator + "AndroidManifest.xml"); File outDir = out.getParentFile(); if (!outDir.exists()) { outDir.mkdirs(); } XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(out), format); writer.write(xmlDoc); // return out; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } finally { try { if (writer != null) { writer.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.zg.action.admin.InstallAction.java
public String save() throws URISyntaxException, IOException, DocumentException { if (isInstalled()) { return ajaxJsonErrorMessage("SHOP++?????"); }// www . j av a2 s .c om if (StringUtils.isEmpty(databaseHost)) { return ajaxJsonErrorMessage("?!"); } if (StringUtils.isEmpty(databasePort)) { return ajaxJsonErrorMessage("??!"); } if (StringUtils.isEmpty(databaseUsername)) { return ajaxJsonErrorMessage("???!"); } if (StringUtils.isEmpty(databasePassword)) { return ajaxJsonErrorMessage("??!"); } if (StringUtils.isEmpty(databaseName)) { return ajaxJsonErrorMessage("???!"); } if (StringUtils.isEmpty(adminUsername)) { return ajaxJsonErrorMessage("???!"); } if (StringUtils.isEmpty(adminPassword)) { return ajaxJsonErrorMessage("??!"); } if (StringUtils.isEmpty(installStatus)) { Map<String, String> jsonMap = new HashMap<String, String>(); jsonMap.put(STATUS, "requiredCheckFinish"); return ajaxJson(jsonMap); } String jdbcUrl = "jdbc:mysql://" + databaseHost + ":" + databasePort + "/" + databaseName + "?useUnicode=true&characterEncoding=UTF-8"; Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; try { // ? connection = DriverManager.getConnection(jdbcUrl, databaseUsername, databasePassword); DatabaseMetaData databaseMetaData = connection.getMetaData(); String[] types = { "TABLE" }; resultSet = databaseMetaData.getTables(null, databaseName, "%", types); if (StringUtils.equalsIgnoreCase(installStatus, "databaseCheck")) { Map<String, String> jsonMap = new HashMap<String, String>(); jsonMap.put(STATUS, "databaseCheckFinish"); return ajaxJson(jsonMap); } // ? if (StringUtils.equalsIgnoreCase(installStatus, "databaseCreate")) { StringBuffer stringBuffer = new StringBuffer(); BufferedReader bufferedReader = null; String sqlFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI() .getPath() + SQL_INSTALL_FILE_NAME; bufferedReader = new BufferedReader( new InputStreamReader(new FileInputStream(sqlFilePath), "UTF-8")); String line = ""; while (null != line) { line = bufferedReader.readLine(); stringBuffer.append(line); if (null != line && line.endsWith(";")) { System.out.println("[SHOP++?]SQL: " + line); preparedStatement = connection.prepareStatement(stringBuffer.toString()); preparedStatement.executeUpdate(); stringBuffer = new StringBuffer(); } } String insertAdminSql = "INSERT INTO `admin` VALUES ('402881862bec2a21012bec2bd8de0003','2010-10-10 0:0:0','2010-10-10 0:0:0','','admin@shopxx.net',b'1',b'0',b'0',b'0',NULL,NULL,0,NULL,'?','" + DigestUtils.md5Hex(adminPassword) + "','" + adminUsername + "');"; String insertAdminRoleSql = "INSERT INTO `admin_role` VALUES ('402881862bec2a21012bec2bd8de0003','402881862bec2a21012bec2b70510002');"; preparedStatement = connection.prepareStatement(insertAdminSql); preparedStatement.executeUpdate(); preparedStatement = connection.prepareStatement(insertAdminRoleSql); preparedStatement.executeUpdate(); } } catch (SQLException e) { e.printStackTrace(); return ajaxJsonErrorMessage("???!"); } finally { try { if (resultSet != null) { resultSet.close(); resultSet = null; } if (preparedStatement != null) { preparedStatement.close(); preparedStatement = null; } if (connection != null) { connection.close(); connection = null; } } catch (SQLException e) { e.printStackTrace(); } } // ??? String configFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + JDBC_CONFIG_FILE_NAME; Properties properties = new Properties(); properties.put("jdbc.driver", "com.mysql.jdbc.Driver"); properties.put("jdbc.url", jdbcUrl); properties.put("jdbc.username", databaseUsername); properties.put("jdbc.password", databasePassword); properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); properties.put("hibernate.show_sql", "false"); properties.put("hibernate.format_sql", "false"); OutputStream outputStream = new FileOutputStream(configFilePath); properties.store(outputStream, JDBC_CONFIG_FILE_DESCRIPTION); outputStream.close(); // ?? String backupWebConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI() .getPath() + BACKUP_WEB_CONFIG_FILE_NAME; String backupApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader() .getResource("").toURI().getPath() + BACKUP_APPLICATION_CONTEXT_CONFIG_FILE_NAME; String backupCompassApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader() .getResource("").toURI().getPath() + BACKUP_COMPASS_APPLICATION_CONTEXT_CONFIG_FILE_NAME; String backupSecurityApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader() .getResource("").toURI().getPath() + BACKUP_SECURITY_APPLICATION_CONTEXT_CONFIG_FILE_NAME; String webConfigFilePath = new File( Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath()).getParent() + "/" + WEB_CONFIG_FILE_NAME; String applicationContextConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("") .toURI().getPath() + APPLICATION_CONTEXT_CONFIG_FILE_NAME; String compassApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader() .getResource("").toURI().getPath() + COMPASS_APPLICATION_CONTEXT_CONFIG_FILE_NAME; String securityApplicationContextConfigFilePath = Thread.currentThread().getContextClassLoader() .getResource("").toURI().getPath() + SECURITY_APPLICATION_CONTEXT_CONFIG_FILE_NAME; FileUtils.copyFile(new File(backupWebConfigFilePath), new File(webConfigFilePath)); FileUtils.copyFile(new File(backupApplicationContextConfigFilePath), new File(applicationContextConfigFilePath)); FileUtils.copyFile(new File(backupCompassApplicationContextConfigFilePath), new File(compassApplicationContextConfigFilePath)); FileUtils.copyFile(new File(backupSecurityApplicationContextConfigFilePath), new File(securityApplicationContextConfigFilePath)); // ?? //String systemConfigFilePath = Thread.currentThread().getContextClassLoader().getResource("").toURI().getPath() + SystemConfigUtils.CONFIG_FILE_NAME; File systemConfigFile = new File( ConfigurationManager.getConfigProperties(SystemConfigUtils.CONFIG_FILE_PATH_NAME)); SAXReader saxReader = new SAXReader(); Document document = saxReader.read(systemConfigFile); Element rootElement = document.getRootElement(); Element systemConfigElement = rootElement.element("systemConfig"); Node isInstalledNode = document.selectSingleNode("/shopxx/systemConfig/isInstalled"); if (isInstalledNode == null) { isInstalledNode = systemConfigElement.addElement("isInstalled"); } isInstalledNode.setText("true"); try { OutputFormat outputFormat = OutputFormat.createPrettyPrint();// XML? outputFormat.setEncoding("UTF-8");// XML? outputFormat.setIndent(true);// ? outputFormat.setIndent(" ");// TAB? outputFormat.setNewlines(true);// ?? XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(systemConfigFile), outputFormat); xmlWriter.write(document); xmlWriter.close(); } catch (Exception e) { e.printStackTrace(); } return ajaxJsonSuccessMessage("SHOP++?????"); }
From source file:com.zimbra.common.soap.DomUtil.java
License:Open Source License
/** Convert an Element to a String. */ public static String toString(Element env, boolean prettyPrint) { if (prettyPrint) { StringWriter buff = new StringWriter(); try {//from w w w .jav a2 s. c om OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(buff, format); writer.write(env); writer.close(); } catch (IOException e) { // ignore, since StringWriter doesn't throw IOExceptions } return buff.toString(); } else { return env.asXML(); } }
From source file:com.zimbra.cs.account.accesscontrol.RightManager.java
License:Open Source License
private void writeXML(String fileName, Document document) throws IOException { // Pretty print the document to output file OutputFormat format = OutputFormat.createPrettyPrint(); BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); XMLWriter xmlWriter = new XMLWriter(writer, format); xmlWriter.write(document);/*from w ww . j av a2 s .c om*/ writer.close(); }
From source file:com.zimbra.cs.dav.client.DavRequest.java
License:Open Source License
public String getRequestMessageString() throws IOException { if (mDoc != null) { OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false);/* w w w. j av a2s . c om*/ format.setOmitEncoding(false); ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(out, format); writer.write(mDoc); return new String(out.toByteArray(), "UTF-8"); } return ""; }
From source file:com.zimbra.cs.dav.DomUtil.java
License:Open Source License
public static void writeDocumentToStream(Document doc, OutputStream out) throws IOException { OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false);/*from w w w . j a va 2s . c om*/ format.setOmitEncoding(false); XMLWriter writer = new XMLWriter(out, format); writer.write(doc); }
From source file:com.zimbra.cs.dav.resource.DavResource.java
License:Open Source License
protected String getPropertiesAsText(DavContext ctxt) throws IOException { Element e = org.dom4j.DocumentHelper.createElement(DavElements.E_PROP); for (ResourceProperty rp : mProps.values()) rp.toElement(ctxt, e, false);//from w w w . ja v a 2 s .c o m OutputFormat format = OutputFormat.createPrettyPrint(); format.setTrimText(false); format.setOmitEncoding(false); ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(baos, format); writer.write(e); return new String(baos.toByteArray()); }
From source file:com.zimbra.soap.util.WsdlGenerator.java
License:Open Source License
public static void writeWsdl(OutputStream xmlOut, String targetNamespace, String serviceName, List<WsdlInfoForNamespace> nsInfos) throws IOException { Document wsdlDoc = makeWsdlDoc(nsInfos, serviceName, targetNamespace); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(xmlOut, format); writer.write(wsdlDoc);/*w w w.j ava2 s . co m*/ writer.close(); }
From source file:com.ztesoft.inf.extend.xstream.io.xml.Dom4JDriver.java
License:Open Source License
public Dom4JDriver() { this(new DocumentFactory(), OutputFormat.createPrettyPrint()); outputFormat.setTrimText(false); }