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

The following examples show how to use org.dom4j.io.OutputFormat#createCompactFormat() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XmppStreamOpen.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public String toXml() {
    StringWriter out = new StringWriter();
    XMLWriter writer = new XMLWriter(out, OutputFormat.createCompactFormat());
    try {
        out.write("<");
        writer.write(element.getQualifiedName());
        for (Attribute attr : (List<Attribute>) element.attributes()) {
            writer.write(attr);
        }
        writer.write(Namespace.get(this.element.getNamespacePrefix(), this.element.getNamespaceURI()));
        writer.write(Namespace.get("jabber:client"));
        out.write(">");
    } catch (IOException ex) {
        log.info("Error writing XML", ex);
    }
    return out.toString();
}
 
Example 2
Source File: XMLWriter.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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
Source File: PropFindMethod.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 4
Source File: XmlClobType.java    From unitime with Apache License 2.0 5 votes vote down vote up
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
Source File: XmlBlobType.java    From unitime with Apache License 2.0 5 votes vote down vote up
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
Source File: StudentSectioningQueue.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void setMessage(Document document) {
	try {
		if (document == null) {
			setData(null);
		} else {
			StringWriter string = new StringWriter();
			XMLWriter writer = new XMLWriter(string, OutputFormat.createCompactFormat());
			writer.write(document);
			writer.flush(); writer.close();
			setData(string.toString());
		}
	} catch (IOException e) {
		throw new HibernateException(e.getMessage(),e);
	}
}
 
Example 7
Source File: CurriculumClassification.java    From unitime with Apache License 2.0 5 votes vote down vote up
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 8
Source File: SolverInfo.java    From unitime with Apache License 2.0 5 votes vote down vote up
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 9
Source File: DataDstXml.java    From xresloader with MIT License 5 votes vote down vote up
/**
 * 转储常量数据
 * 
 * @return 常量数据,不支持的时候返回空
 */
public final byte[] dumpConst(HashMap<String, Object> data) throws ConvException, IOException {
    // 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, "");

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

    return bos.toByteArray();
}
 
Example 10
Source File: WebDAVMethod.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 11
Source File: DataDstXml.java    From xresloader with MIT License 4 votes vote down vote up
@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");
    Element data_message_type = DocumentHelper.createElement("data_message_type");

    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());

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

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

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

        return bos.toByteArray();
    } catch (Exception e) {
        this.logErrorMessage("write xml failed, %s", e.getMessage());
        return null;
    }
}