List of usage examples for org.dom4j.io XMLWriter XMLWriter
public XMLWriter(OutputStream out, OutputFormat format) throws UnsupportedEncodingException
From source file:net.sf.jguard.core.util.XMLUtils.java
License:Open Source License
/** * write the updated configuration to the XML file in the UTF-8 format. * * @param url URL of the file to write * @param document dom4j Document//from w w w .ja v a2 s.com * @throws IOException */ public static void write(URL url, Document document) throws IOException { OutputFormat outFormat = OutputFormat.createPrettyPrint(); if (document.getXMLEncoding() != null) { outFormat.setEncoding(document.getXMLEncoding()); } else { outFormat.setEncoding(UTF_8); } XMLWriter out = new XMLWriter(new BufferedOutputStream(new FileOutputStream(url.getPath())), outFormat); out.write(document); out.flush(); out.close(); }
From source file:net.sf.jguard.ext.authentication.manager.XmlAuthenticationManager.java
License:Open Source License
public void writeAsXML(OutputStream outputStream, String encodingScheme) throws IOException { OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding(encodingScheme); XMLWriter writer = new XMLWriter(outputStream, outformat); writer.write(this.document); writer.flush();/* w ww . j a v a 2 s . co m*/ }
From source file:net.sf.jguard.ext.authentication.manager.XmlAuthenticationManager.java
License:Open Source License
public void exportAsXMLFile(String fileName) throws IOException { FileWriter fileWriter = null; try {//from w ww . ja v a2 s. co m fileWriter = new FileWriter(fileName); XMLWriter xmlWriter = new XMLWriter(fileWriter, OutputFormat.createPrettyPrint()); xmlWriter.write(document); xmlWriter.close(); } finally { if (fileWriter != null) { fileWriter.close(); } } }
From source file:net.sf.jguard.ext.authorization.manager.XmlAuthorizationManager.java
License:Open Source License
public void exportAsXMLFile(String fileName) throws IOException { XMLWriter xmlWriter = null;// w w w . java 2s . co m FileWriter fileWriter = null; try { fileWriter = new FileWriter(fileName); xmlWriter = new XMLWriter(fileWriter, OutputFormat.createPrettyPrint()); xmlWriter.write(document); } finally { if (fileWriter != null) { fileWriter.close(); } if (xmlWriter != null) { xmlWriter.close(); } } }
From source file:net.sf.jvifm.model.AppStatus.java
License:Open Source License
public static boolean writeAppStatus() { try {//from w w w . ja v a 2s . co m String[][] currentPath = Main.fileManager.getAllCurrentPath(); Document document = DocumentHelper.createDocument(); Element root = document.addElement("tabs"); for (int i = 0; i < currentPath.length; i++) { Element tabElement = root.addElement("tab"); tabElement.addAttribute("left", currentPath[i][0]); tabElement.addAttribute("right", currentPath[i][1]); } FileOutputStream fos = new FileOutputStream(appStatusPath); OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-8"); BufferedOutputStream out = new BufferedOutputStream(fos); XMLWriter writer = new XMLWriter(out, outformat); writer.write(document); writer.flush(); writer.close(); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:net.sf.jvifm.model.BookmarkManager.java
License:Open Source License
@SuppressWarnings("unchecked") public void store() { try {/* w ww . j av a 2 s . c om*/ Document document = DocumentHelper.createDocument(); Element root = document.addElement("bookmarks"); for (Iterator it = bookmarkList.iterator(); it.hasNext();) { Bookmark bm = (Bookmark) it.next(); Element bookmarkElement = root.addElement("bookmark"); bookmarkElement.addElement("name").addText(bm.getName()); bookmarkElement.addElement("path").addText(bm.getPath()); if (bm.getKey() != null) bookmarkElement.addElement("key").addText(bm.getKey()); } FileOutputStream fos = new FileOutputStream(storePath); OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-8"); BufferedOutputStream out = new BufferedOutputStream(fos); XMLWriter writer = new XMLWriter(out, outformat); writer.write(document); writer.flush(); writer.close(); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.sf.jvifm.model.MimeManager.java
License:Open Source License
@SuppressWarnings("unchecked") public void store() { try {//from www . j a v a2 s . com Document document = DocumentHelper.createDocument(); Element root = document.addElement("mimes"); for (Iterator it = mimeInfo.keySet().iterator(); it.hasNext();) { String postfix = (String) it.next(); Element filetypeEle = root.addElement("filetype"); filetypeEle.addAttribute("postfix", postfix); List<String> appPathList = mimeInfo.get(postfix); for (String appPath : appPathList) { filetypeEle.addElement("appPath").addText(appPath); } } FileOutputStream fos = new FileOutputStream(storePath); OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-8"); BufferedOutputStream out = new BufferedOutputStream(fos); XMLWriter writer = new XMLWriter(out, outformat); writer.write(document); writer.flush(); writer.close(); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.sf.jvifm.model.ShortcutsManager.java
License:Open Source License
public void store() { try {/*w ww . j a va2 s. co m*/ Document document = DocumentHelper.createDocument(); Element root = document.addElement("commands"); for (Shortcut shortcut : shortcutsList) { Element shortcutElement = root.addElement("command"); shortcutElement.addElement("name").addText(shortcut.getName()); shortcutElement.addElement("text").addText(shortcut.getText()); } FileOutputStream fos = new FileOutputStream(storePath); OutputFormat outformat = OutputFormat.createPrettyPrint(); outformat.setEncoding("UTF-8"); BufferedOutputStream out = new BufferedOutputStream(fos); XMLWriter writer = new XMLWriter(out, outformat); writer.write(document); writer.flush(); writer.close(); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.shopxx.action.admin.InstallAction.java
public String save() throws URISyntaxException, IOException, DocumentException { if (isInstalled()) { return ajaxJsonErrorMessage("SHOP++?????"); }//from ww w. j a v a 2s . 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() + SystemConfigUtil.CONFIG_FILE_NAME; File systemConfigFile = new File(systemConfigFilePath); 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:net.sourceforge.sqlexplorer.dbproduct.AliasManager.java
License:Open Source License
/** * Saves all the Aliases to the users preferences * //from w w w. j av a2 s .co m */ public void saveAliases() throws ExplorerException { DefaultElement root = new DefaultElement(Alias.ALIASES); for (Alias alias : aliases.values()) { root.add(alias.describeAsXml()); } try { FileWriter writer = new FileWriter(new File(ApplicationFiles.USER_ALIAS_FILE_NAME)); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter xmlWriter = new XMLWriter(writer, format); xmlWriter.write(root); writer.flush(); writer.close(); } catch (IOException e) { throw new ExplorerException(e); } }