本文整理匯總了Java中org.dom4j.io.OutputFormat.setIndentSize方法的典型用法代碼示例。如果您正苦於以下問題:Java OutputFormat.setIndentSize方法的具體用法?Java OutputFormat.setIndentSize怎麽用?Java OutputFormat.setIndentSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.dom4j.io.OutputFormat
的用法示例。
在下文中一共展示了OutputFormat.setIndentSize方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getWriter
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
/**
* Get the writer for the import file
*
* @param destination the destination XML import file
* @return the XML writer
*/
private XMLWriter getWriter(String destination)
{
try
{
// Define output format
OutputFormat format = OutputFormat.createPrettyPrint();
format.setNewLineAfterDeclaration(false);
format.setIndentSize(INDENT_SIZE);
format.setEncoding(this.fileEncoding);
return new XMLWriter(new FileOutputStream(destination), format);
}
catch (Exception exception)
{
throw new AlfrescoRuntimeException("Unable to create XML writer.", exception);
}
}
示例2: startTransferReport
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
/**
* Start the transfer report
*/
public void startTransferReport(String encoding, Writer writer)
{
OutputFormat format = OutputFormat.createPrettyPrint();
format.setNewLineAfterDeclaration(false);
format.setIndentSize(3);
format.setEncoding(encoding);
try
{
this.writer = new XMLWriter(writer, format);
this.writer.startDocument();
this.writer.startPrefixMapping(PREFIX, TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI);
// Start Transfer Manifest // uri, name, prefix
this.writer.startElement(TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI, TransferDestinationReportModel.LOCALNAME_TRANSFER_DEST_REPORT, PREFIX + ":" + TransferDestinationReportModel.LOCALNAME_TRANSFER_DEST_REPORT, EMPTY_ATTRIBUTES);
}
catch (SAXException se)
{
se.printStackTrace();
}
}
示例3: startTransferReport
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
/**
* Start the transfer report
*/
public void startTransferReport(String encoding, Writer writer) throws SAXException
{
OutputFormat format = OutputFormat.createPrettyPrint();
format.setNewLineAfterDeclaration(false);
format.setIndentSize(3);
format.setEncoding(encoding);
this.writer = new XMLWriter(writer, format);
this.writer.startDocument();
this.writer.startPrefixMapping(PREFIX, TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI);
// Start Transfer Manifest // uri, name, prefix
this.writer.startElement(TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI, TransferReportModel.LOCALNAME_TRANSFER_REPORT, PREFIX + ":" + TransferReportModel.LOCALNAME_TRANSFER_REPORT, EMPTY_ATTRIBUTES);
}
示例4: formatXml
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
/**
* Returns the given xml document as nicely formated string.
*
* @param node
* The xml document.
* @return the formated xml as string.
*/
private static String formatXml(Node node) {
OutputFormat format = OutputFormat.createPrettyPrint();
format.setIndentSize(4);
format.setTrimText(true);
format.setExpandEmptyElements(true);
StringWriter stringWriter = new StringWriter();
XMLWriter xmlWriter = new XMLWriter(stringWriter, format);
try {
xmlWriter.write(node);
xmlWriter.flush();
} catch (IOException e) {
// this should never happen
throw new RuntimeException(e);
}
return stringWriter.getBuffer().toString();
}
示例5: write
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
protected void write(String resource, Document document) throws IOException, DocumentException {
File file = null;
if (iSource == null) {
file = new File(getClass().getClassLoader().getResource(resource).getFile());
} else {
file = new File(iSource + File.separator + resource);
}
info(" -- writing " + file + " ...");
FileOutputStream fos = new FileOutputStream(file);
try {
OutputFormat format = OutputFormat.createPrettyPrint();
format.setIndentSize(4);
format.setPadText(false);
new MyXMLWriter(fos, format).write(document);
} finally {
fos.flush(); fos.close();
}
}
示例6: XMLTransferRequsiteWriter
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
public XMLTransferRequsiteWriter(Writer out)
{
OutputFormat format = OutputFormat.createPrettyPrint();
format.setNewLineAfterDeclaration(false);
format.setIndentSize(3);
format.setEncoding("UTF-8");
this.writer = new XMLWriter(out, format);
}
示例7: XMLWriter
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
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);
}
示例8: createXMLExporter
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
private XMLWriter createXMLExporter(Writer writer)
{
// Define output format
OutputFormat format = OutputFormat.createPrettyPrint();
format.setNewLineAfterDeclaration(false);
format.setIndentSize(3);
format.setEncoding("UTF-8");
// Construct an XML Exporter
XMLWriter xmlWriter = new XMLWriter(writer, format);
return xmlWriter;
}
示例9: xmlToString
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
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, "");
}
示例10: prettyXML
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
/**
* Pretty-Print XML.
*
* @param xml The XML
* @return A beautiful XML
* @throws IOException
* @throws DocumentException
*/
public static String prettyXML(final String xml) throws IOException, DocumentException {
Document doc = DocumentHelper.parseText(xml);
StringWriter sw = new StringWriter();
OutputFormat format = OutputFormat.createPrettyPrint();
format.setIndent(true);
format.setIndentSize(3);
XMLWriter xw = new XMLWriter(sw, format);
xw.write(doc);
return sw.toString();
}
示例11: toXml
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
public static void toXml(Writer out, Document doc) throws Exception {
OutputFormat outformat = OutputFormat.createPrettyPrint();
outformat.setIndentSize(1);
outformat.setIndent("\t");
outformat.setEncoding(UTF_8.name());
XMLWriter writer = new XMLWriter(out, outformat);
writer.write(doc);
writer.flush();
out.flush();
out.close();
}
示例12: dumpConst
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
/**
* 轉儲常量數據
* @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;
}
}
示例13: build
import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
@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;
}
}