List of usage examples for org.dom4j.io XMLWriter startDocument
public void startDocument() throws SAXException
From source file:com.bstek.dorado.idesupport.output.RuleSetOutputter.java
License:Open Source License
public void output(Writer writer, RuleTemplateManager ruleTemplateManager) throws Exception { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(Constants.DEFAULT_CHARSET); XMLWriter xmlWriter = new XMLWriter(writer, format); xmlWriter.startDocument(); Element rootElement = DocumentHelper.createElement("RuleSet"); rootElement.addAttribute("version", ruleTemplateManager.getVersion()); xmlWriter.writeOpen(rootElement);// w ww . j av a2s . c om OutputContext context = new OutputContext(); outputPackageInfos(xmlWriter, ruleTemplateManager, context); for (RuleTemplate ruleTemplate : ruleTemplateManager.getRuleTemplates()) { // PropertyDataType? // if (ruleTemplate.isAbstract() // && ruleTemplate.getSubRuleTemplates().length == 0) { // continue; // } outputRuleTemplate(xmlWriter, ruleTemplate, context); } xmlWriter.writeClose(rootElement); xmlWriter.endDocument(); xmlWriter.close(); }
From source file:com.rowtheboat.gui.OptionsSingleton.java
License:Open Source License
/** * This method saves the options to the options.xml file *//* w ww. j a v a2 s . c o m*/ public void saveOptions() throws SAXException, IOException { /* Start the document */ OutputFormat format = OutputFormat.createPrettyPrint(); XMLWriter writer = new XMLWriter(new FileWriter(optionsFile), format); writer.startDocument(); /* Add the main options section */ Document document = DocumentHelper.createDocument(); Element root = document.addElement("Options"); /* Standard options */ DefaultElement standardElement = new DefaultElement("Standard"); standardElement.addElement("FullStrokeData").addText(getFullStrokeData() + ""); standardElement.addElement("BoatSmoothing").addText(getBoatSmoothing() + ""); root.add(standardElement); /* Input options */ DefaultElement inputElement = new DefaultElement("Input"); inputElement.addElement("SerialPort").addText(getSerialPort()); root.add(inputElement); /* Race options */ DefaultElement raceElement = new DefaultElement("Race"); raceElement.addElement("Countdown").addText(getDelay() + ""); root.add(raceElement); /* End the document */ writer.write(root); writer.endDocument(); writer.close(); }
From source file:com.thoughtworks.xstream.io.xml.Dom4JXmlWriter.java
License:Open Source License
/** * @since 1.4/*from w w w. j a va 2 s . c om*/ */ public Dom4JXmlWriter(XMLWriter writer, NameCoder nameCoder) { super(nameCoder); this.writer = writer; this.elementStack = new FastStack(16); this.attributes = new AttributesImpl(); try { writer.startDocument(); } catch (SAXException e) { throw new StreamException(e); } }
From source file:com.ztesoft.inf.extend.xstream.io.xml.Dom4JXmlWriter.java
License:Open Source License
/** * @since 1.2// w w w . j a v a 2 s . c o m */ public Dom4JXmlWriter(XMLWriter writer, XmlFriendlyReplacer replacer) { super(replacer); this.writer = writer; this.elementStack = new FastStack(16); this.attributes = new AttributesImpl(); try { writer.startDocument(); } catch (SAXException e) { throw new StreamException(e); } }
From source file:jp.aegif.alfresco.online_webdav.LockMethod.java
License:Open Source License
/** * Generates the XML lock discovery response body *///www . j a v a 2s. com protected void generateResponse(FileInfo lockNodeInfo, String userName) throws Exception { String scope; String lt; String owner; Date expiry; if (lockToken != null) { // In case of lock creation take the scope from request header scope = this.createExclusive ? WebDAV.XML_EXCLUSIVE : WebDAV.XML_SHARED; // Output created lock lt = lockToken; } else { // In case of lock refreshing take the scope from previously stored lock scope = this.lockInfo.getScope(); // Output refreshed lock lt = this.lockInfo.getExclusiveLockToken(); } owner = lockInfo.getOwner(); expiry = lockInfo.getExpires(); XMLWriter xml = createXMLWriter(); xml.startDocument(); String nsdec = generateNamespaceDeclarations(null); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_PROP + nsdec, WebDAV.XML_NS_PROP + nsdec, getDAVHelper().getNullAttributes()); // Output the lock details generateLockDiscoveryXML(xml, lockNodeInfo, false, scope, WebDAV.getDepthName(m_depth), lt, owner, expiry); // Close off the XML xml.endElement(WebDAV.DAV_NS, WebDAV.XML_PROP, WebDAV.XML_NS_PROP); // Send remaining data flushXML(xml); }
From source file:jp.aegif.alfresco.online_webdav.PropFindMethod.java
License:Open Source License
/** * Execute the main WebDAV request processing * //from w ww .ja v a 2 s .com * @exception WebDAVServerException */ protected void executeImpl() throws WebDAVServerException, Exception { m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS); FileInfo pathNodeInfo = null; try { // Check that the path exists pathNodeInfo = getDAVHelper().getFileInfoFromRequestPath(m_request); } catch (FileNotFoundException e) { // The path is not valid - send a 404 error back to the client // throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND); pathNodeInfo = null; } // Set the response content type m_response.setContentType(WebDAV.XML_CONTENT_TYPE); // Create multistatus response XMLWriter xml = createXMLWriter(); xml.startDocument(); String nsdec = generateNamespaceDeclarations(m_namespaces); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS + nsdec, WebDAV.XML_NS_MULTI_STATUS + nsdec, getDAVHelper().getNullAttributes()); // Create the path for the current location in the tree StringBuilder baseBuild = new StringBuilder(256); baseBuild.append(getPath()); if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar) { baseBuild.append(WebDAVHelper.PathSeperatorChar); } String basePath = baseBuild.toString(); // Output the response for the root node, depth zero generateResponseForNode(xml, pathNodeInfo, basePath); // If additional levels are required and the root node is a folder then recurse to the required // level and output node details a level at a time // if (getDepth() != WebDAV.DEPTH_0 && pathNodeInfo.isFolder()) // { // // Create the initial list of nodes to report // List<FileInfo> nodeInfos = new ArrayList<FileInfo>(10); // nodeInfos.add(pathNodeInfo); // // int curDepth = WebDAV.DEPTH_1; // // // Save the base path length // int baseLen = baseBuild.length(); // // // List of next level of nodes to report // List<FileInfo> nextNodeInfos = null; // if (getDepth() > WebDAV.DEPTH_1) // { // nextNodeInfos = new ArrayList<FileInfo>(10); // } // // // Loop reporting each level of nodes to the requested depth // while (curDepth <= getDepth() && nodeInfos != null) // { // // Clear out the next level of nodes, if required // if (nextNodeInfos != null) // { // nextNodeInfos.clear(); // } // // // Output the current level of node(s), the node list should // // only contain folder nodes // // for (FileInfo curNodeInfo : nodeInfos) // { // // Get the list of child nodes for the current node // List<FileInfo> childNodeInfos = fileFolderService.list(curNodeInfo.getNodeRef()); // // // can skip the current node if it doesn't have children // if (childNodeInfos.size() == 0) // { // continue; // } // // // Output the child node details // // Generate the base path for the current parent node // // baseBuild.setLength(baseLen); // try // { // String pathSnippet = getDAVHelper().getPathFromNode(pathNodeInfo.getNodeRef(), curNodeInfo.getNodeRef()); // baseBuild.append(pathSnippet); // } // catch (FileNotFoundException e) // { // // move to the next node // continue; // } // // int curBaseLen = baseBuild.length(); // // // Output the child node details // for (FileInfo curChildInfo : childNodeInfos) // { // // Build the path for the current child node // baseBuild.setLength(curBaseLen); // // baseBuild.append(curChildInfo.getName()); // // // Output the current child node details // generateResponseForNode(xml, curChildInfo, baseBuild.toString()); // // // If the child is a folder add it to the list of next level nodes // if (nextNodeInfos != null && curChildInfo.isFolder()) // { // nextNodeInfos.add(curChildInfo); // } // } // } // // // Update the current tree depth // curDepth++; // // // Move the next level of nodes to the current node list // nodeInfos = nextNodeInfos; // } // } // Close the outer XML element xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS); // Send remaining data // xml.flush(); flushXML(xml); }
From source file:jp.aegif.alfresco.online_webdav.PropPatchMethod.java
License:Open Source License
@Override protected void executeImpl() throws WebDAVServerException, Exception { m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS); FileInfo pathNodeInfo = null;//from ww w.ja va 2 s . c om try { pathNodeInfo = this.getDAVHelper().getFileInfoFromRequestPath(m_request); } catch (FileNotFoundException e) { // The path is not valid - send a 404 error back to the client throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND); } checkNode(pathNodeInfo); // Set the response content type m_response.setContentType(WebDAV.XML_CONTENT_TYPE); // Create multistatus response XMLWriter xml = createXMLWriter(); xml.startDocument(); String nsdec = generateNamespaceDeclarations(m_namespaces); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS + nsdec, WebDAV.XML_NS_MULTI_STATUS + nsdec, getDAVHelper().getNullAttributes()); // Create the path for the current location in the tree StringBuilder baseBuild = new StringBuilder(256); baseBuild.append(getPath()); if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar) { baseBuild.append(WebDAVHelper.PathSeperatorChar); } String basePath = baseBuild.toString(); // Output the response for the root node, depth zero generateResponse(xml, pathNodeInfo, basePath); // Close the outer XML element xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS); // Send remaining data flushXML(xml); }
From source file:net.bpfurtado.ljcolligo.util.Util.java
License:Open Source License
public static void save(Element root, File file) { OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndentSize(4);/*from w w w. ja v a2 s . c o m*/ format.setEncoding("UTF-8"); format.setNewlines(true); format.setLineSeparator(System.getProperty("line.separator")); XMLWriter writer; try { writer = new XMLWriter(new FileWriter(file), format); writer.startDocument(); writer.write(root); writer.close(); logger.debug("All entries saved to file [" + file.getAbsolutePath() + "]"); } catch (Exception e) { throw new LJColligoException("File [" + file.getAbsolutePath() + "]", e); } }
From source file:net.sourceforge.sqlexplorer.XMLUtils.java
License:Open Source License
public static void save(Element pRoot, File pFile) { try {/*from www . j a v a 2 s.c om*/ XMLWriter xmlWriter = new XMLWriter(new FileOutputStream(pFile), OutputFormat.createPrettyPrint()); xmlWriter.startDocument(); xmlWriter.write(pRoot); xmlWriter.endDocument(); xmlWriter.flush(); xmlWriter.close(); } catch (Exception e) { SQLExplorerPlugin.error("Couldn't save: " + pFile.getAbsolutePath(), e); } }
From source file:org.alfresco.module.vti.web.fp.DeleteMethod.java
License:Open Source License
@Override protected void executeImpl() throws WebDAVServerException, Exception { try {/* w w w. j a v a 2 s . com*/ super.executeImpl(); m_response.setStatus(HttpServletResponse.SC_NO_CONTENT); } catch (WebDAVServerException e) { if (e.getHttpStatusCode() == WebDAV.WEBDAV_SC_LOCKED) { // SharePoint requires a special response for the case of // trying to delete a locked document m_response.setStatus(WebDAV.WEBDAV_SC_MULTI_STATUS); m_response.setContentType(WebDAV.XML_CONTENT_TYPE); m_response.addHeader(HEADER_X_MSDAVEXT_ERROR, "589838"); // TODO Don't hard code this constant XMLWriter xml = createXMLWriter(); xml.startDocument(); String nsdec = generateNamespaceDeclarations(namespaceMap); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS + nsdec, WebDAV.XML_NS_MULTI_STATUS + nsdec, getDAVHelper().getNullAttributes()); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE, getDAVHelper().getNullAttributes()); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF, getDAVHelper().getNullAttributes()); xml.write(m_request.getRequestURL().toString()); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS, getDAVHelper().getNullAttributes()); xml.write(WebDAV.HTTP1_1 + " " + WebDAV.WEBDAV_SC_LOCKED + " " + SC_LOCKED_DESC); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_STATUS, WebDAV.XML_NS_STATUS); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE); // Close the outer XML element xml.endElement(WebDAV.DAV_NS, WebDAV.XML_MULTI_STATUS, WebDAV.XML_NS_MULTI_STATUS); // Send remaining data flushXML(xml); } else { throw e; } } }