List of usage examples for org.dom4j.io XMLWriter XMLWriter
public XMLWriter(OutputFormat format) throws UnsupportedEncodingException
From source file:com.thinkberg.webdav.LockHandler.java
License:Apache License
private void sendLockAcquiredResponse(HttpServletResponse response, Lock lock) throws IOException { if (!lock.getObject().exists()) { response.setStatus(SC_CREATED);/*from w ww .ja va2 s. com*/ } response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.setHeader(HEADER_LOCK_TOKEN, "<" + lock.getToken() + ">"); Document propDoc = DocumentHelper.createDocument(); Element propEl = propDoc.addElement(TAG_PROP, "DAV:"); Element lockdiscoveryEl = propEl.addElement(TAG_LOCKDISCOVERY); lock.serializeToXml(lockdiscoveryEl); XMLWriter xmlWriter = new XMLWriter(response.getWriter()); xmlWriter.write(propDoc); logXml(propDoc); }
From source file:com.topsec.tsm.sim.util.TalVersionUtil.java
/** * @method: writeVersionFile /*from w w w . j av a2 s . c om*/ * ??. * @author: ?(yang_xuanjia@topsec.com.cn) * @param: newBuildVersion: ? * @return: null */ public synchronized void writeVersionFile(String newBuildVersion, String key) { Validate.notEmpty(newBuildVersion); Element readVersionFile = readVersionFile(); Element buildVersion = readVersionFile.element(key); buildVersion.setText(newBuildVersion); System.out.println(""); XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(new File(path + "buildVersion.xml"))); writer.write(readVersionFile); writer.flush(); } catch (Exception e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (Exception e2) { e2.printStackTrace(); } } } }
From source file:com.wabacus.config.xml.XmlAssistant.java
License:Open Source License
public void saveDocumentToXmlFile(String configfilepath, Document doc) throws IOException { XMLWriter xwriter = null;// w w w . ja v a 2 s . c o m try { File f = null; if (Tools.isDefineKey("classpath", Config.configpath)) { f = WabacusAssistant.getInstance().getFileObjByPathInClasspath( Tools.getRealKeyByDefine("classpath", Config.configpath), configfilepath); } else { f = new File(WabacusAssistant.getInstance().getRealFilePath(Config.configpath, configfilepath)); } OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding("UTF-8"); xwriter = new XMLWriter(new OutputStreamWriter(new FileOutputStream(f, false), "UTF-8")); xwriter.write(doc); } finally { if (xwriter != null) xwriter.close(); } }
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
public boolean save(OutputStream os, Document document) { boolean flag = true; XMLWriter writer = null;/* w w w . j a v a 2 s .c o m*/ OutputStreamWriter outputStream = null; try { outputStream = new OutputStreamWriter(os, DAFAULT_CHARSET); writer = new XMLWriter(outputStream); writer.write(document); writer.flush(); } catch (Exception ex) { log.error("?xml", ex); flag = false; throw new RuntimeException(ex); } finally { try { if (null != writer) { writer.close(); } if (outputStream != null) { outputStream.close(); } } catch (IOException e) { log.error("?xml:", e); } } return flag; }
From source file:com.webarch.common.io.xml.XMLEditor.java
License:Apache License
private void writeDocument(final OutputStream out, Document document) { XMLWriter xmlWriter = null;//from www . java 2 s.co m try { xmlWriter = new XMLWriter(out); xmlWriter.write(document); xmlWriter.flush(); } catch (IOException e) { throw new RuntimeException(e); } finally { if (xmlWriter != null) { try { xmlWriter.close(); } catch (IOException e) { throw new RuntimeException(e); } } } }
From source file:com.zimbra.cs.dav.service.DavMethod.java
License:Open Source License
public HttpMethod toHttpMethod(DavContext ctxt, String targetUrl) throws IOException, DavException { if (ctxt.getUpload() != null && ctxt.getUpload().getSize() > 0) { PostMethod method = new PostMethod(targetUrl) { @Override/*from www . j a v a 2s . c o m*/ public String getName() { return getMethodName(); } }; RequestEntity reqEntry; if (ctxt.hasRequestMessage()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLWriter writer = new XMLWriter(baos); writer.write(ctxt.getRequestMessage()); reqEntry = new ByteArrayRequestEntity(baos.toByteArray()); } else { // this could be a huge upload reqEntry = new InputStreamRequestEntity(ctxt.getUpload().getInputStream(), ctxt.getUpload().getSize()); } method.setRequestEntity(reqEntry); return method; } return new GetMethod(targetUrl) { @Override public String getName() { return getMethodName(); } }; }
From source file:condorclient.utilities.XMLHandler.java
public void removeJob(String clusterId) { SAXReader saxReader = new SAXReader(); Document document = null;// w w w . j a v a 2 s. c o m try { document = saxReader.read(new File("niInfo.xml")); } catch (DocumentException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } List list = document.selectNodes("/root/info/job");//?job Iterator iter = list.iterator(); Element root = document.getRootElement(); Element info = root.element("info"); while (iter.hasNext()) { Element job = (Element) iter.next(); String id = job.attributeValue("id"); if (id.equals(clusterId)) { info.remove(job); } } XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(new File("niInfo.xml"))); writer.write(document); writer.close(); } catch (IOException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:condorclient.utilities.XMLHandler.java
public void modifyJob(String name, String clusterId) { SAXReader saxReader = new SAXReader(); Document document = null;/*from w w w . jav a 2 s .com*/ try { document = saxReader.read(new File("niInfo.xml")); } catch (DocumentException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } List list = document.selectNodes("/root/info/job"); Iterator iter = list.iterator(); while (iter.hasNext()) { Element job = (Element) iter.next(); String id = job.attributeValue("id"); if (id.equals(clusterId)) { job.attribute("name").setValue(name); } } XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(new File("niInfo.xml"))); writer.write(document); writer.close(); } catch (IOException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:condorclient.utilities.XMLHandler.java
public void addJob(String name, String clusterId, String resultpath, String expFile, String infoFile) { SAXReader saxReader = new SAXReader(); Document document = null;/*from w w w.j av a 2 s . c o m*/ try { document = saxReader.read(new File("niInfo.xml")); } catch (DocumentException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } Element root = document.getRootElement(); Element info = root.element("info"); Element job = info.addElement("job"); job.addAttribute("name", name); job.addAttribute("id", clusterId); job.addAttribute("dir", resultpath); job.addAttribute("transfer", "0"); job.addAttribute("expFile", expFile); job.addAttribute("infoFile", infoFile); // System.out.println("id:" + job.attribute("id").getValue()); /** * document */ XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(new File("niInfo.xml"))); writer.write(document); writer.close(); } catch (IOException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:condorclient.utilities.XMLHandler.java
public void removeJobs(int[] delClusterIds, int delsum) { SAXReader saxReader = new SAXReader(); Document document = null;/*from w ww .j a va2 s . c om*/ try { document = saxReader.read(new File("niInfo.xml")); } catch (DocumentException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } List list = document.selectNodes("/root/info/job");//?job Iterator iter = list.iterator(); Element root = document.getRootElement(); Element info = root.element("info"); try { while (iter.hasNext()) { Element job = (Element) iter.next(); String id = job.attributeValue("id"); for (int i = 0; i < delsum; i++) { if (id.equals("" + delClusterIds[i])) { info.remove(job); } } } } catch (Exception e) { System.out.println("???"); } XMLWriter writer = null; try { writer = new XMLWriter(new FileWriter(new File("niInfo.xml"))); writer.write(document); writer.close(); } catch (IOException ex) { Logger.getLogger(XMLHandler.class.getName()).log(Level.SEVERE, null, ex); } }