List of usage examples for org.dom4j.io OutputFormat createPrettyPrint
public static OutputFormat createPrettyPrint()
From source file:com.chingo247.structureapi.plan.PlanGenerator.java
License:Open Source License
private static void generatePlanFromSchematic(File file, File rootDirectory) throws IOException { String name = FilenameUtils.getBaseName(file.getName()); File directory = file.getParentFile(); Document d = DocumentHelper.createDocument(); Element root = new BaseElement(StructurePlanXMLConstants.STRUCTURE_PLAN_ROOT_ELEMENT); d.add(root);//from ww w . java2 s . co m Element nameElement = new BaseElement(StructurePlanXMLConstants.STRUCTURE_PLAN_NAME_ELEMENT); nameElement.setText(name); root.add(nameElement); Element priceElement = new BaseElement(StructurePlanXMLConstants.STRUCTURE_PLAN_PRICE_ELEMENT); priceElement.setText("0"); root.add(priceElement); Element description = new BaseElement(StructurePlanXMLConstants.STRUCTURE_PLAN_DESCRIPTION_ELEMENT); description.setText("None"); root.add(description); Element categoryElement = new BaseElement(StructurePlanXMLConstants.STRUCTURE_PLAN_CATEGORY_ELEMENT); String category = rootDirectory.getName().equals(directory.getName()) ? "Default" : directory.getName(); categoryElement.setText(category); root.add(categoryElement); Element placementElment = new BaseElement(StructurePlanXMLConstants.STRUCTURE_PLAN_PLACEMENT); Element typeElement = new BaseElement(PlacementXMLConstants.TYPE_ELEMENT); typeElement.setText(PlacementTypes.SCHEMATIC); Element schematicElement = new BaseElement(PlacementXMLConstants.SCHEMATIC_ELEMENT); schematicElement.setText(file.getName()); placementElment.add(typeElement); placementElment.add(schematicElement); root.add(placementElment); File planFile = new File(directory, name + ".xml"); OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(planFile), format); writer.write(d); writer.close(); }
From source file:com.controlj.addon.weather.util.Logging.java
License:Open Source License
private static String toXMLString(String reason, Document document) throws IOException { StringWriter stringWriter = new StringWriter(); PrintWriter pw = new PrintWriter(stringWriter); pw.println(reason);// w w w. ja v a 2 s. c om pw.flush(); XMLWriter writer = new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()); writer.write(document); return stringWriter.toString(); }
From source file:com.davis.bluefolder.BlueUtils.java
public String formatXML(String input) { try {/*from w ww . j a v a 2 s. c o m*/ org.dom4j.Document doc = DocumentHelper.parseText(input); StringWriter sw = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndent(true); format.setIndentSize(3); XMLWriter xw = new XMLWriter(sw, format); xw.write(doc); return sw.toString(); } catch (Exception e) { e.printStackTrace(); return input; } }
From source file:com.doculibre.constellio.izpack.PersistenceXMLUtils.java
License:Open Source License
@SuppressWarnings("unchecked") public static void run(AbstractUIProcessHandler handler, String[] args) { if (args.length != 5) { System.out.println("persistence_mysqlPath defaultPersistencePath server login password"); return;//from w ww .j a v a2s.c om } String persistence_mysqlPath = args[0]; String defaultPersistencePath = args[1]; String server = args[2]; String login = args[3]; String password = args[4]; Document xmlDocument; try { xmlDocument = new SAXReader().read(persistence_mysqlPath); Element root = xmlDocument.getRootElement(); Iterator<Element> it = root.elementIterator("persistence-unit"); if (!it.hasNext()) { System.out.println("Corrupt persistence file :" + persistence_mysqlPath); return; } it = it.next().elementIterator("properties"); if (!it.hasNext()) { System.out.println("Corrupt persistence file :" + persistence_mysqlPath); return; } Element properties = it.next(); for (it = properties.elementIterator("property"); it.hasNext();) { Element property = it.next(); String id = property.attributeValue("name"); if (id.equals(SERVER_ELEMENT_ID)) { Attribute att = property.attribute("value"); att.setText(BEFORE_SERVER_NAME + server + AFTER_SERVER_NAME); } else { if (id.equals(LOGIN_ELEMENT_ID)) { Attribute att = property.attribute("value"); att.setText(login); } else { if (id.equals(PASSWORD_ELEMENT_ID)) { Attribute att = property.attribute("value"); att.setText(password); } } } } OutputFormat format = OutputFormat.createPrettyPrint(); File xmlFile = new File(persistence_mysqlPath); XMLWriter writer2 = new XMLWriter(new FileOutputStream(xmlFile), format); writer2.write(xmlDocument); writer2.close(); // copier au fichier de persistence par dfaut: xmlFile = new File(defaultPersistencePath); writer2 = new XMLWriter(new FileOutputStream(xmlFile), format); writer2.write(xmlDocument); writer2.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.doculibre.constellio.izpack.TomcatUtil.java
License:Open Source License
@SuppressWarnings("unchecked") public static void run(AbstractUIProcessHandler handler, String[] args) { if (args.length != 2) { System.out.println("serverPath port"); return;//from w w w .j ava 2s . c om } String serverPath = args[0]; String port = args[1]; if (port.equals("8080")) { // C'est celui par defaut => ne rien faire return; } Document xmlDocument; try { xmlDocument = new SAXReader().read(serverPath); Element root = xmlDocument.getRootElement(); Iterator<Element> it = root.elementIterator("Service"); if (!it.hasNext()) { System.out.println("Corrupt persistence file :" + serverPath); return; } Element connectors = it.next(); for (it = connectors.elementIterator("Connector"); it.hasNext();) { Element connector = it.next(); String id = connector.attributeValue("protocol"); if (id.startsWith("HTTP")) { Attribute att = connector.attribute("port"); att.setText(port); break; } } OutputFormat format = OutputFormat.createPrettyPrint(); File xmlFile = new File(serverPath); XMLWriter writer2 = new XMLWriter(new FileOutputStream(xmlFile), format); writer2.write(xmlDocument); writer2.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.doculibre.constellio.izpack.UsersToXmlFile.java
License:Open Source License
public static void run(AbstractUIProcessHandler handler, String[] args) { if (args.length != 3) { System.out.println("file login password"); return;/*from www .j a v a 2 s . com*/ } String target = args[0]; File xmlFile = new File(target); BufferedWriter writer; try { writer = new BufferedWriter(new FileWriter(xmlFile)); } catch (IOException e) { e.printStackTrace(); return; } try { for (String line : Arrays.asList(emptyFileLines)) { writer.write(line + System.getProperty("line.separator")); } writer.close(); } catch (Exception e) { e.printStackTrace(); } String login = args[1]; String passwd = args[2]; UsersToXmlFile elem = new UsersToXmlFile(); ConstellioUser dataUser = elem.new ConstellioUser(login, passwd, null); dataUser.setFirstName("System"); dataUser.setLastName("Administrator"); dataUser.getRoles().add(Roles.ADMIN); Document xmlDocument; try { xmlDocument = new SAXReader().read(target); Element root = xmlDocument.getRootElement(); BaseElement user = new BaseElement(USER); user.addAttribute(FIRST_NAME, dataUser.getFirstName()); user.addAttribute(LAST_NAME, dataUser.getLastName()); user.addAttribute(LOGIN, dataUser.getUsername()); user.addAttribute(PASSWORD_HASH, dataUser.getPasswordHash()); if (dataUser.getLocale() != null) { user.addAttribute(LOCALE, dataUser.getLocaleCode()); } Set<String> constellioRoles = dataUser.getRoles(); if (!constellioRoles.isEmpty()) { Element roles = user.addElement(ROLES); for (String constellioRole : constellioRoles) { Element role = roles.addElement(ROLE); role.addAttribute(VALUE, constellioRole); } } root.add(user); OutputFormat format = OutputFormat.createPrettyPrint(); xmlFile = new File(target); // FIXME recrire la DTD // xmlDocument.addDocType(arg0, arg1, arg2) XMLWriter writer2 = new XMLWriter(new FileOutputStream(xmlFile), format); writer2.write(xmlDocument); writer2.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.doculibre.constellio.services.SolrServicesImpl.java
License:Open Source License
public static void writeXMLConfigInCloud(String collectionName, String fileName, Document schemaDocument) { String realCollectionName;/* w w w . j a va2 s .c om*/ if (SolrServicesImpl.isAliasInCloud(collectionName)) { realCollectionName = SolrServicesImpl.getRealCollectionInCloud(collectionName); } else { realCollectionName = collectionName; } try { OutputFormat format = OutputFormat.createPrettyPrint(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(outputStream, format); writer.write(schemaDocument); writer.close(); SolrZkClient zkClient = SolrCoreContext.getSolrZkClient(); zkClient.setData(ZkController.CONFIGS_ZKNODE + "/" + realCollectionName + "/" + fileName, outputStream.toByteArray(), true); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.doculibre.constellio.services.SolrServicesImpl.java
License:Open Source License
private static void writeConstellioDefaultSchema(Document schemaDocument) { File schemaFile = new File( ClasspathUtils.getCollectionsRootDir() + File.separator + SolrCoreContext.DEFAULT_COLLECTION_NAME + File.separator + "conf" + File.separator + "schema.xml"); FileOutputStream fos = null;// w w w . ja v a2 s .co m try { OutputFormat format = OutputFormat.createPrettyPrint(); fos = new FileOutputStream(schemaFile); XMLWriter writer = new XMLWriter(fos, format); writer.write(schemaDocument); writer.close(); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(fos); } }
From source file:com.doculibre.constellio.utils.izpack.UsersXmlFileUtils.java
License:Open Source License
public static void addUserTo(ConstellioUser constellioUser, String fileName) { Document xmlDocument;// w w w . j av a 2 s . c om try { xmlDocument = new SAXReader().read(fileName); Element root = xmlDocument.getRootElement(); Element user = toXmlElement(constellioUser); root.add(user); OutputFormat format = OutputFormat.createPrettyPrint(); File xmlFile = new File(fileName); //FIXME recrire la DTD //xmlDocument.addDocType(arg0, arg1, arg2) XMLWriter writer = new XMLWriter(new FileOutputStream(xmlFile), format); writer.write(xmlDocument); writer.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.dp2345.util.SettingUtils.java
License:Open Source License
/** * /*from w w w . jav a 2 s .co m*/ * * @param setting * */ public static void set(Setting setting) { try { File dp2345XmlFile = new ClassPathResource(CommonAttributes.DP2345_XML_PATH).getFile(); Document document = new SAXReader().read(dp2345XmlFile); List<Element> elements = document.selectNodes("/dp2345/setting"); for (Element element : elements) { try { String name = element.attributeValue("name"); String value = beanUtils.getProperty(setting, name); Attribute attribute = element.attribute("value"); attribute.setValue(value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } } FileOutputStream fileOutputStream = null; XMLWriter xmlWriter = null; try { OutputFormat outputFormat = OutputFormat.createPrettyPrint(); outputFormat.setEncoding("UTF-8"); outputFormat.setIndent(true); outputFormat.setIndent(" "); outputFormat.setNewlines(true); fileOutputStream = new FileOutputStream(dp2345XmlFile); xmlWriter = new XMLWriter(fileOutputStream, outputFormat); xmlWriter.write(document); } catch (Exception e) { e.printStackTrace(); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { } } IOUtils.closeQuietly(fileOutputStream); } Ehcache cache = cacheManager.getEhcache(Setting.CACHE_NAME); cache.put(new net.sf.ehcache.Element(Setting.CACHE_KEY, setting)); } catch (Exception e) { e.printStackTrace(); } }