Java Code Examples for org.dom4j.io.OutputFormat.createCompactFormat()

The following are Jave code examples for showing how to use createCompactFormat() of the org.dom4j.io.OutputFormat class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: nest-old   File: HibernatePersistentConfigurationInitializer.java   Source Code and License Vote up 7 votes
/**
 * convert definition to hibernate xml
 * 
 * @param descriptor
 * @return
 * @throws IOException
 */
protected String convertToXML(IStandalonePersistentBeanDescriptor descriptor) {
	Document doc = createDocument(descriptor);

	StringWriter sw = new StringWriter();
	XMLWriter writer = new XMLWriter(sw, OutputFormat.createCompactFormat());
	try {
		writer.write(doc);
	} catch (IOException e) {
		if (getLogger().isErrorEnabled()) {
			getLogger().error("Failed to cast xml document to string.", e);
		}
		throw new ResourceException("Failed to cast xml document to string.", e);
	}
	if (getLogger().isDebugEnabled()) {
		getLogger()
				.debug("Class [" + descriptor.getResourceClass().getName()
						+ "] has been configured into hibernate. XML as [" + sw.toString().replace("\n", "") + "].");
	}
	return sw.toString();
}
 
Example 2
Project: alfresco-repository   File: XMLWriter.java   Source Code and License Vote up 5 votes
public XMLWriter(OutputStream outputStream, boolean prettyPrint, String encoding)
        throws UnsupportedEncodingException
{
    OutputFormat format = prettyPrint ? OutputFormat.createPrettyPrint() : OutputFormat.createCompactFormat();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);
    format.setEncoding(encoding);
    output = outputStream;
    this.dom4jWriter = new org.dom4j.io.XMLWriter(outputStream, format);
}
 
Example 3
Project: xpath-to-xml   File: XmlBuilderTest.java   Source Code and License Vote up 5 votes
private String xmlToString(Document xml) throws IOException {
    String lineSeparator = System.getProperty("line.separator");
    OutputFormat format = OutputFormat.createCompactFormat();
    format.setIndentSize(4);
    format.setNewlines(true);
    format.setLineSeparator(lineSeparator);
    format.setSuppressDeclaration(true);
    StringWriter result = new StringWriter();
    XMLWriter writer = new XMLWriter(result, format);
    writer.write(xml);
    return result.toString().replaceFirst(lineSeparator, "");
}
 
Example 4
Project: unitimes   File: XmlClobType.java   Source Code and License Vote up 5 votes
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException {
    if (value == null) {
        ps.setNull(index, sqlTypes()[0]);
    } else {
        try {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            XMLWriter writer = new XMLWriter(bytes,OutputFormat.createCompactFormat());
            writer.write((Document)value);
            writer.flush(); writer.close();
            ps.setCharacterStream(index, new CharArrayReader(bytes.toString().toCharArray(),0,bytes.size()), bytes.size());
        } catch (IOException e) {
            throw new HibernateException(e.getMessage(),e);
        }
    }
}
 
Example 5
Project: unitimes   File: XmlBlobType.java   Source Code and License Vote up 5 votes
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException {
    if (value == null) {
        ps.setNull(index, sqlTypes()[0]);
    } else {
        try {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            XMLWriter writer = new XMLWriter(new GZIPOutputStream(bytes),OutputFormat.createCompactFormat());
            writer.write((Document)value);
            writer.flush(); writer.close();
            ps.setBinaryStream(index, new ByteArrayInputStream(bytes.toByteArray(),0,bytes.size()), bytes.size());
        } catch (IOException e) {
            throw new HibernateException(e.getMessage(),e);
        }
    }
}
 
Example 6
Project: unitimes   File: CurriculumClassification.java   Source Code and License Vote up 5 votes
public void setStudentsDocument(Document document) {
	try {
		if (document == null) {
			setStudents(null);
		} else {
			StringWriter string = new StringWriter();
			XMLWriter writer = new XMLWriter(string, OutputFormat.createCompactFormat());
			writer.write(document);
			writer.flush(); writer.close();
			setStudents(string.toString());
		}
	} catch (Exception e) {
		sLog.warn("Failed to store cached students for " + getCurriculum().getAbbv() + " " + getName() + ": " + e.getMessage(), e);
	}
}
 
Example 7
Project: unitimes   File: SolverInfo.java   Source Code and License Vote up 5 votes
public void setValue(Document document) {
	try {
		if (document == null) {
			setData(null);
		} else {
			 ByteArrayOutputStream bytes = new ByteArrayOutputStream();
             XMLWriter writer = new XMLWriter(new GZIPOutputStream(bytes),OutputFormat.createCompactFormat());
             writer.write(document);
             writer.flush(); writer.close();
             setData(bytes.toByteArray());
		}
	} catch (IOException e) {
		throw new HibernateException(e.getMessage(),e);
	}
}
 
Example 8
Project: alfresco-remote-api   File: PropFindMethod.java   Source Code and License Vote up 5 votes
@Override
protected OutputFormat getXMLOutputFormat()
{
    String userAgent = m_request.getHeader("User-Agent");
    return ((null != userAgent) && userAgent.toLowerCase().startsWith("microsoft-webdav-miniredir/5.1.")) ? OutputFormat.createCompactFormat() : super.getXMLOutputFormat();

}
 
Example 9
Project: btulz.transforms   File: XmlTransformerDom4j.java   Source Code and License Vote up 5 votes
@Override
protected void save(File outFolder, IDomain domain) throws Exception {
	String fileName = this.getSaveFilePath(outFolder.getPath(), domain);
	Document document = DocumentHelper.createDocument();
	// 领域模型
	Element domainElement = document.addElement("Domain");
	this.writeElement(domain, domainElement);
	// 模型
	for (IModel model : domain.getModels()) {
		Element modelElement = domainElement.addElement("Model");
		this.writeElement(model, modelElement);
		// 模型属性
		for (IProperty property : model.getProperties()) {
			Element propertyElement = modelElement.addElement("Property");
			this.writeElement(property, propertyElement);
		}
	}
	// 业务对象
	for (IBusinessObject businessObject : domain.getBusinessObjects()) {
		Element boElement = domainElement.addElement("BusinessObject");
		this.writeElement(businessObject, boElement);
		for (IBusinessObjectItem boItem : businessObject.getRelatedBOs()) {
			Element biElement = boElement.addElement("RelatedBO");
			this.writeElement(boItem, biElement);
		}
	}
	OutputFormat xmlFormat = OutputFormat.createCompactFormat();
	xmlFormat.setEncoding(XML_FILE_ENCODING);
	xmlFormat.setNewlines(true);
	xmlFormat.setIndent(true);
	xmlFormat.setIndent("  ");
	XMLWriter writer = new XMLWriter(new FileWriter(fileName), xmlFormat);
	writer.write(document);
	writer.close();
}
 
Example 10
Project: xstream   File: Dom4JXmlWriterTest.java   Source Code and License Vote up 5 votes
protected void setUp() throws Exception {
    super.setUp();

    Dom4JDriver driver = new Dom4JDriver();

    OutputFormat format = OutputFormat.createCompactFormat();
    format.setTrimText(false);
    format.setSuppressDeclaration(true);
    driver.setOutputFormat(format);

    out = new StringWriter();
    writer = driver.createWriter(out);
}
 
Example 11
Project: unitime   File: XmlClobType.java   Source Code and License Vote up 5 votes
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException {
    if (value == null) {
        ps.setNull(index, sqlTypes()[0]);
    } else {
        try {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            XMLWriter writer = new XMLWriter(bytes,OutputFormat.createCompactFormat());
            writer.write((Document)value);
            writer.flush(); writer.close();
            ps.setCharacterStream(index, new CharArrayReader(bytes.toString().toCharArray(),0,bytes.size()), bytes.size());
        } catch (IOException e) {
            throw new HibernateException(e.getMessage(),e);
        }
    }
}
 
Example 12
Project: unitime   File: XmlBlobType.java   Source Code and License Vote up 5 votes
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException {
    if (value == null) {
        ps.setNull(index, sqlTypes()[0]);
    } else {
        try {
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            XMLWriter writer = new XMLWriter(new GZIPOutputStream(bytes),OutputFormat.createCompactFormat());
            writer.write((Document)value);
            writer.flush(); writer.close();
            ps.setBinaryStream(index, new ByteArrayInputStream(bytes.toByteArray(),0,bytes.size()), bytes.size());
        } catch (IOException e) {
            throw new HibernateException(e.getMessage(),e);
        }
    }
}
 
Example 13
Project: unitime   File: CurriculumClassification.java   Source Code and License Vote up 5 votes
public void setStudentsDocument(Document document) {
	try {
		if (document == null) {
			setStudents(null);
		} else {
			StringWriter string = new StringWriter();
			XMLWriter writer = new XMLWriter(string, OutputFormat.createCompactFormat());
			writer.write(document);
			writer.flush(); writer.close();
			setStudents(string.toString());
		}
	} catch (Exception e) {
		sLog.warn("Failed to store cached students for " + getCurriculum().getAbbv() + " " + getName() + ": " + e.getMessage(), e);
	}
}
 
Example 14
Project: unitime   File: SolverInfo.java   Source Code and License Vote up 5 votes
public void setValue(Document document) {
	try {
		if (document == null) {
			setData(null);
		} else {
			 ByteArrayOutputStream bytes = new ByteArrayOutputStream();
             XMLWriter writer = new XMLWriter(new GZIPOutputStream(bytes),OutputFormat.createCompactFormat());
             writer.write(document);
             writer.flush(); writer.close();
             setData(bytes.toByteArray());
		}
	} catch (IOException e) {
		throw new HibernateException(e.getMessage(),e);
	}
}
 
Example 15
Project: nest-old   File: TestDom4j.java   Source Code and License Vote up 5 votes
@Test
public void test() throws IOException {
	Document doc = DocumentHelper.createDocument();
	doc.addDocType("hibernate-mapping", "-//Hibernate/Hibernate Mapping DTD 3.0//EN",
			"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd");

	StringWriter sw = new StringWriter();
	XMLWriter writer = new XMLWriter(sw, OutputFormat.createCompactFormat());
	writer.write(doc);
	System.out.println(sw.toString());
}
 
Example 16
Project: community-edition-old   File: PropFindMethod.java   Source Code and License Vote up 5 votes
@Override
protected OutputFormat getXMLOutputFormat()
{
    String userAgent = m_request.getHeader("User-Agent");
    return ((null != userAgent) && userAgent.toLowerCase().startsWith("microsoft-webdav-miniredir/5.1.")) ? OutputFormat.createCompactFormat() : super.getXMLOutputFormat();

}
 
Example 17
Project: community-edition-old   File: XMLWriter.java   Source Code and License Vote up 5 votes
public XMLWriter(OutputStream outputStream, boolean prettyPrint, String encoding)
        throws UnsupportedEncodingException
{
    OutputFormat format = prettyPrint ? OutputFormat.createPrettyPrint() : OutputFormat.createCompactFormat();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);
    format.setEncoding(encoding);
    output = outputStream;
    this.dom4jWriter = new org.dom4j.io.XMLWriter(outputStream, format);
}
 
Example 18
Project: xresloader   File: DataDstXml.java   Source Code and License Vote up 5 votes
/**
 * 转储常量数据
 * @return 常量数据,不支持的时候返回空
 */
public final byte[] dumpConst(HashMap<String, Object> data) {
    // pretty print
    OutputFormat of = null;
    if (ProgramOptions.getInstance().prettyIndent <= 0) {
        of= OutputFormat.createCompactFormat();
    } else {
        of = OutputFormat.createPrettyPrint();
        of.setIndentSize(ProgramOptions.getInstance().prettyIndent);
    }

    // build xml tree
    Document doc = DocumentHelper.createDocument();
    String encoding = SchemeConf.getInstance().getKey().getEncoding();
    if (null != encoding && false == encoding.isEmpty()) {
        doc.setXMLEncoding(encoding);
        of.setEncoding(encoding);
    }

    doc.setRootElement(DocumentHelper.createElement(ProgramOptions.getInstance().xmlRootName));
    doc.getRootElement().addComment("this file is generated by xresloader, please don't edit it.");

    writeData(doc.getRootElement(), data, "");

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        XMLWriter writer = new XMLWriter(bos, of);
        writer.write(doc);

        return bos.toByteArray();
    } catch(Exception e) {
        ProgramOptions.getLoger().error("write xml failed, %s", e.getMessage());
        return null;
    }
}
 
Example 19
Project: snipsnap   File: SnipSnapHandler.java   Source Code and License Vote up 5 votes
public String getSnipAsXml(String name) {
  Snip snip = space.load(name);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  OutputFormat outputFormat = OutputFormat.createCompactFormat();
  outputFormat.setEncoding("UTF-8");
  try {
    XMLWriter writer = new XMLWriter(out, outputFormat);
    writer.write(SnipSerializer.getInstance().serialize(snip));
    writer.flush();
  } catch (IOException e) {
    e.printStackTrace();
  }
  return out.toString();
}
 
Example 20
Project: alfresco-remote-api   File: WebDAVMethod.java   Source Code and License Vote up 4 votes
/**
 * Returns the format required for an XML response. This may vary per method.
 */
protected OutputFormat getXMLOutputFormat()
{
    // Check if debug output or XML pretty printing is enabled
    return (XMLPrettyPrint || logger.isDebugEnabled()) ? OutputFormat.createPrettyPrint() : OutputFormat.createCompactFormat();
}
 
Example 21
Project: libraries   File: DocumentUtilities.java   Source Code and License Vote up 4 votes
private static OutputFormat createTrimedOutputFormat(final String encoding) {
  final OutputFormat format = OutputFormat.createCompactFormat();
  format.setEncoding(encoding);
  return format;
}
 
Example 22
Project: community-edition-old   File: WebDAVMethod.java   Source Code and License Vote up 4 votes
/**
 * Returns the format required for an XML response. This may vary per method.
 */
protected OutputFormat getXMLOutputFormat()
{
    // Check if debug output or XML pretty printing is enabled
    return (XMLPrettyPrint || logger.isDebugEnabled()) ? OutputFormat.createPrettyPrint() : OutputFormat.createCompactFormat();
}
 
Example 23
Project: moxo   File: PropFindHandler.java   Source Code and License Vote up 4 votes
/**
 * Handle a PROPFIND request.
 *
 * @param request  the servlet request
 * @param response the servlet response
 * @throws IOException if there is an error that cannot be handled normally
 */
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
  SAXReader saxReader = new SAXReader();
  try {
    Document propDoc = saxReader.read(request.getInputStream());
    logXml(propDoc);

    Element propFindEl = propDoc.getRootElement();
    for (Object propElObject : propFindEl.elements()) {
      Element propEl = (Element) propElObject;
      if (VALID_PROPFIND_TAGS.contains(propEl.getName())) {
        FileObject object = VFSBackend.resolveFile(request.getPathInfo());
        if (object.exists()) {
          // respond as XML encoded multi status
          response.setContentType("text/xml");
          response.setCharacterEncoding("UTF-8");
          response.setStatus(SC_MULTI_STATUS);

          Document multiStatusResponse =
                  getMultiStatusResponse(object,
                                         propEl,
                                         getBaseUrl(request),
                                         getDepth(request));
          logXml(multiStatusResponse);

          // write the actual response
          XMLWriter writer = new XMLWriter(response.getWriter(), OutputFormat.createCompactFormat());
          writer.write(multiStatusResponse);
          writer.flush();
          writer.close();

        } else {
          response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
        break;
      }
    }
  } catch (DocumentException e) {
    LOG.error("invalid request: " + e.getMessage());
    response.sendError(HttpServletResponse.SC_BAD_REQUEST);
  }
}
 
Example 24
Project: xresloader   File: DataDstXml.java   Source Code and License Vote up 4 votes
@Override
public final byte[] build(DataDstImpl compiler) throws ConvException {
    // pretty print
    OutputFormat of = null;
    if (ProgramOptions.getInstance().prettyIndent <= 0) {
        of = OutputFormat.createCompactFormat();
    } else {
        of = OutputFormat.createPrettyPrint();
        of.setIndentSize(ProgramOptions.getInstance().prettyIndent);
    }

    // build data
    DataDstObject data_obj = build_data(compiler);

    // build xml tree
    Document doc = DocumentHelper.createDocument();
    String encoding = SchemeConf.getInstance().getKey().getEncoding();
    if (null != encoding && false == encoding.isEmpty()) {
        doc.setXMLEncoding(encoding);
        of.setEncoding(encoding);
    }

    doc.setRootElement(DocumentHelper.createElement(ProgramOptions.getInstance().xmlRootName));
    doc.getRootElement().addComment("this file is generated by xresloader, please don't edit it.");

    Element header = DocumentHelper.createElement("header");
    Element body = DocumentHelper.createElement("body");

    writeData(header, data_obj.header, header.getName());

    // body
    for(Map.Entry<String, List<Object> > item: data_obj.body.entrySet()) {
        for(Object obj: item.getValue()) {
            Element xml_item = DocumentHelper.createElement(item.getKey());

            writeData(xml_item, obj, item.getKey());

            body.add(xml_item);
        }
    }

    writeData(body, data_obj.body, body.getName());

    doc.getRootElement().add(header);
    doc.getRootElement().add(body);

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        XMLWriter writer = new XMLWriter(bos, of);
        writer.write(doc);

        return bos.toByteArray();
    } catch(Exception e) {
        ProgramOptions.getLoger().error("write xml failed, %s", e.getMessage());
        return null;
    }
}
 
Example 25
Project: xsd2xml   File: XmlGenOptions.java   Source Code and License Vote up 4 votes
public OutputFormat getOutputFormat() {
    if (outputFormat == null) {
        outputFormat = OutputFormat.createCompactFormat();   //default to compact format
    }
    return outputFormat;
}