List of usage examples for org.dom4j.io OutputFormat setIndent
public void setIndent(boolean doIndent)
From source file:org.apache.taglibs.xtags.xpath.OutputTag.java
License:Apache License
public int doStartTag() throws JspException { OutputFormat format = null; if (indent != null) { format = OutputFormat.createPrettyPrint(); format.setIndent(indent); } else {//from w ww . j a va2 s . co m format = new OutputFormat(); } format.setOmitEncoding(asBoolean(omitXmlDeclaration)); Writer out = pageContext.getOut(); if (method != null && method.equalsIgnoreCase("html")) { xmlWriter = new HTMLWriter(out, format); } else { xmlWriter = new XMLWriter(out, format); } return EVAL_BODY_INCLUDE; }
From source file:org.beangle.emsapp.security.action.MenuAction.java
License:Open Source License
public void exportXML() { Document doc = DocumentHelper.createDocument(); Element root = doc.addElement("root"); List<Menu> menus = (List<Menu>) entityDao.search(getQueryBuilder().limit(null)); for (Menu m : menus) { Element em = root.addElement("menu"); em.addAttribute("id", m.getId().toString()); em.addAttribute("code", m.getCode()); em.addAttribute("name", m.getName()); em.addAttribute("title", m.getTitle()); em.addAttribute("entry", m.getEntry()); em.addAttribute("remark", m.getRemark()); em.addAttribute("profileId", m.getProfile().getId().toString()); if (m.getParent() != null) { em.addAttribute("parentId", m.getParent().getId().toString()); }//w ww . j a va2s. c om for (Resource res : m.getResources()) { Element eres = em.addElement("resource"); eres.addAttribute("id", res.getId().toString()); eres.addAttribute("name", res.getName()); eres.addAttribute("title", res.getTitle()); eres.addAttribute("remark", res.getRemark()); eres.addAttribute("scope", res.getScope() + ""); for (Category c : res.getCategories()) { Element ec = eres.addElement("category"); ec.addAttribute("id", c.getId().toString()); } } } try { HttpServletResponse response = ServletActionContext.getResponse(); response.setHeader("Content-Disposition", "attachment;filename=menu.xml"); response.setContentType("application/x-msdownload"); OutputFormat of = new OutputFormat(); of.setIndent(true); of.setNewlines(true); XMLWriter writer = new XMLWriter(getResponse().getOutputStream(), of); writer.write(doc); writer.close(); } catch (UnsupportedEncodingException e) { logger.error("exportXML error", e); } catch (IOException e) { logger.error("exportXML error", e); } }
From source file:org.eclipse.ecr.core.io.impl.AbstractDocumentWriter.java
License:Open Source License
public static OutputFormat createCompactFormat() { OutputFormat format = new OutputFormat(); format.setIndent(false); format.setNewlines(false);/* w ww . j a va 2s . c om*/ return format; }
From source file:org.mule.devkit.model.schema.SchemaModel.java
License:Open Source License
private void buildSchema(SchemaLocation schemaLocation) throws JAXBException, IOException { OutputStream schemaStream = null; try {//from w w w. ja v a 2 s .c om JAXBContext jaxbContext = JAXBContext.newInstance(Schema.class); Marshaller marshaller = jaxbContext.createMarshaller(); NamespaceFilter outFilter = new NamespaceFilter("mule", "http://www.mulesoft.org/schema/mule/core", true); OutputFormat format = new OutputFormat(); format.setIndent(true); format.setNewlines(true); schemaStream = codeWriter.openBinary(null, schemaLocation.getFileName()); XMLWriter writer = new XMLWriter(schemaStream, format); outFilter.setContentHandler(writer); marshaller.marshal(schemaLocation.getSchema(), outFilter); } finally { IOUtils.closeQuietly(schemaStream); } }
From source file:org.mule.devkit.model.studio.StudioModel.java
License:Open Source License
private void serializeXml() throws JAXBException, IOException { JAXBContext jaxbContext = JAXBContext.newInstance(NamespaceType.class); Marshaller marshaller = jaxbContext.createMarshaller(); NamespaceFilter outFilter = new NamespaceFilter("mule", "http://www.mulesoft.org/schema/mule/core", true); OutputFormat format = new OutputFormat(); format.setIndent(true); format.setNewlines(true);/*from www.j a va2s . c o m*/ OutputStream schemaStream = codeWriter.openBinary(null, outputFileName); XMLWriter writer = new XMLWriter(schemaStream, format); outFilter.setContentHandler(writer); marshaller.marshal(namespaceType, outFilter); }
From source file:org.mule.module.extension.internal.capability.xml.schema.SchemaGenerator.java
License:Open Source License
private String renderSchema(Schema schema) { try {/* w w w .ja v a 2s . com*/ JAXBContext jaxbContext = JAXBContext.newInstance(Schema.class); Marshaller marshaller = jaxbContext.createMarshaller(); NamespaceFilter outFilter = new NamespaceFilter("mule", SchemaConstants.MULE_NAMESPACE, true); OutputFormat format = new OutputFormat(); format.setIndent(true); format.setNewlines(true); StringWriter sw = new StringWriter(); XMLWriter writer = new XMLWriter(sw, format); outFilter.setContentHandler(writer); marshaller.marshal(schema, outFilter); return sw.toString(); } catch (JAXBException e) { throw new RuntimeException(e); } }
From source file:org.napile.asm.io.xml.out.AsmXmlFileWriter.java
License:Apache License
@NotNull @Override//from w w w . ja va 2s.co m protected File getResult() { File file = null; List<FqName> paths = fqName.path(); for (int i = 0; i < paths.size(); i++) { FqName path = paths.get(i); file = new File(outputDir, path.getFqName().replace(".", File.separator)); // last segment is original FqName if (i != paths.size() - 1) file.mkdirs(); } assert file != null; file = new File(file.getAbsolutePath() + DOT_EXTENSION); OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndent("\t"); try { XMLWriter writer = new XMLWriter(new FileOutputStream(file), format); writer.write(document); writer.close(); } catch (IOException e) { e.printStackTrace(); } return file; }
From source file:org.napile.asm.io.xml.out.AsmXmlTextWriter.java
License:Apache License
@NotNull @Override/* w w w. ja v a2 s . c o m*/ protected String getResult() { StringWriter stringWriter = new StringWriter(); OutputFormat format = OutputFormat.createPrettyPrint(); format.setIndent("\t"); try { XMLWriter writer = new XMLWriter(stringWriter, format); writer.write(document); writer.close(); } catch (IOException e) { e.printStackTrace(); } return stringWriter.toString(); }
From source file:org.openadaptor.util.XmlUtils.java
License:Open Source License
/** * Uses a Dom4j SAXReader to apply formatting to the supplied XML fragment. In this case we use a prettyprinter to * indent the tags.//from ww w .j av a2 s.c o m * * @param xml * The XML to be formatted (can be just a fragment) * @param isFragment * If you supplied a XML fragment then this must be set to true so that the writer doesn't output an XML * declaration * * @return the formatted XML * * @throws IOException * if there was a problem applying the formatting * @throws DocumentException * if there was a problem with the XML */ public static String format(String xml, boolean isFragment) throws IOException, DocumentException { OutputFormat format = OutputFormat.createPrettyPrint(); format.setSuppressDeclaration(isFragment); format.setIndent("\t"); SAXReader reader = new SAXReader(); Reader r = new StringReader(xml); org.dom4j.Document document = reader.read(r); Writer w = new StringWriter(); XMLWriter out = new XMLWriter(w, format); out.write(document); out.close(); return w.toString(); }
From source file:org.orbeon.oxf.xml.dom4j.Dom4jUtils.java
License:Open Source License
/** * Convert a dom4j document to a compact string, with all text being trimmed. * * @param document document to convert/*from www .j a v a 2 s . c o m*/ * @return resulting string */ public static String domToCompactString(final Document document) { final OutputFormat format = new OutputFormat(); format.setIndent(false); format.setNewlines(false); format.setTrimText(true); return domToString(document.getRootElement(), format); }