本文整理汇总了Java中org.dom4j.io.OutputFormat.setEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java OutputFormat.setEncoding方法的具体用法?Java OutputFormat.setEncoding怎么用?Java OutputFormat.setEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dom4j.io.OutputFormat
的用法示例。
在下文中一共展示了OutputFormat.setEncoding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: removeHttpConfig
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
/**
* 删除配置
*
* @param name
* @throws Exception
*/
public static void removeHttpConfig(String name) throws Exception {
SAXReader reader = new SAXReader();
File xml = new File(HTTP_CONFIG_FILE);
Document doc;
Element root;
try (FileInputStream in = new FileInputStream(xml); Reader read = new InputStreamReader(in, "UTF-8")) {
doc = reader.read(read);
root = doc.getRootElement();
Element cfg = (Element) root.selectSingleNode("/root/configs");
Element e = (Element) root.selectSingleNode("/root/configs/config[@name='" + name + "']");
if (e != null) {
cfg.remove(e);
CONFIG_MAP.remove(name);
}
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
XMLWriter writer = new XMLWriter(new FileOutputStream(xml), format);
writer.write(doc);
writer.close();
}
}
示例5: toXML
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
public String toXML(boolean pretty) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
OutputFormat format = new OutputFormat();
format.setEncoding(Charsets.UTF_8.name());
if (pretty) {
format.setIndent(true);
format.setNewlines(true);
} else {
format.setIndent(false);
format.setNewlines(false);
}
new XMLWriter(baos, format).write(getWrapped());
return baos.toString(Charsets.UTF_8.name());
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
示例6: parseXMLToString
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
/**
* xml 2 string
*
* @param document xml document
* @return
*/
public static String parseXMLToString(Document document) {
Assert.notNull(document);
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
StringWriter writer = new StringWriter();
XMLWriter xmlWriter = new XMLWriter(writer, format);
try {
xmlWriter.write(document);
xmlWriter.close();
} catch (IOException e) {
throw new RuntimeException("XML解析发生错误");
}
return writer.toString();
}
示例7: documentToString
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
/**
* Devuelve la representaci�n de un Document XML en String bien formateado
* y con codificaci�n UTF-8.
* @param doc Documento.
* @return string representando el documento formateado y en UTF-8.
*/
private String documentToString(Document doc) {
String result = null;
StringWriter writer = new StringWriter();
OutputFormat of = OutputFormat.createPrettyPrint();
of.setEncoding("UTF-8");
XMLWriter xmlWriter = new XMLWriter(writer, of);
try {
xmlWriter.write(doc);
xmlWriter.close();
result = writer.toString();
} catch (IOException e) {
log.error("Error escribiendo xml", e);
}
return result;
}
示例8: doc2XmlFile
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
/**
* doc2XmlFile
* 将Document对象保存为一个xml文件到本地
* @return true:保存成功 flase:失败
* @param filename 保存的文件名
* @param document 需要保存的document对象
*/
public static boolean doc2XmlFile(Document document,String filename)
{
boolean flag = true;
try{
/* 将document中的内容写入文件中 */
//默认为UTF-8格式,指定为"GB2312"
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("GB2312");
XMLWriter writer = new XMLWriter(new FileWriter(new File(filename)),format);
writer.write(document);
writer.close();
}catch(Exception ex){
flag = false;
ex.printStackTrace();
}
return flag;
}
示例9: testExpandEmptyElements
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
@Test
public void testExpandEmptyElements() throws IOException {
Document document = DocumentHelper.createDocument();
Element root = document.addElement("root");
Element id = root.addElement("id");
id.addText("1");
root.addElement("empty");
OutputFormat xmlFormat = new OutputFormat();
// OutputFormat.createPrettyPrint();
xmlFormat.setSuppressDeclaration(true);
xmlFormat.setEncoding("UTF-8");
// If this is true, elements without any child nodes
// are output as <name></name> instead of <name/>.
xmlFormat.setExpandEmptyElements(true);
StringWriter out = new StringWriter();
XMLWriter xmlWriter = new XMLWriter(out, xmlFormat);
xmlWriter.write(document);
xmlWriter.close();
assertEquals("<root><id>1</id><empty></empty></root>", out.toString());
}
示例10: writeToXML
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
public static boolean writeToXML(Document document, String tempPath) {
try {
// 使用XMLWriter写入,可以控制格式,经过调试,发现这种方式会出现乱码,主要是因为Eclipse中xml文件和JFrame中文件编码不一致造成的
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding(EncodingUtil.CHARSET_UTF8);
// format.setSuppressDeclaration(true);//这句话会压制xml文件的声明,如果为true,就不打印出声明语句
format.setIndent(true);// 设置缩进
format.setIndent(" ");// 空行方式缩进
format.setNewlines(true);// 设置换行
XMLWriter writer = new XMLWriter(new FileWriterWithEncoding(new File(tempPath), EncodingUtil.CHARSET_UTF8), format);
writer.write(document);
writer.close();
} catch (IOException e) {
e.printStackTrace();
MyLogger.logger.error("写入xml文件出错!");
return false;
}
return true;
}
示例11: store
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
public static void store(OutputStream out, List snips, List users, String filter, List ignoreElements, File fileStore) {
try {
OutputFormat outputFormat = new OutputFormat();
outputFormat.setEncoding("UTF-8");
outputFormat.setNewlines(true);
XMLWriter xmlWriter = new XMLWriter(out, outputFormat);
Element root = DocumentHelper.createElement("snipspace");
xmlWriter.writeOpen(root);
storeUsers(xmlWriter, users);
storeSnips(xmlWriter, snips, filter, ignoreElements, fileStore);
xmlWriter.writeClose(root);
xmlWriter.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: store
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
/**
* Store snips and users from the SnipSpace to an xml document into a stream.
* @param out outputstream to write to
*/
public static void store(OutputStream out, String appOid, Connection connection) {
try {
OutputFormat outputFormat = new OutputFormat();
outputFormat.setEncoding("UTF-8");
outputFormat.setNewlines(true);
XMLWriter xmlWriter = new XMLWriter(out, outputFormat);
xmlWriter.startDocument();
Element root = DocumentHelper.createElement("snipspace");
xmlWriter.writeOpen(root);
// storeUsers(xmlWriter, connection);
storeSnips(xmlWriter, appOid, connection);
xmlWriter.writeClose(root);
xmlWriter.endDocument();
xmlWriter.flush();
xmlWriter.close();
} catch (Exception e) {
System.err.println("JDBCDatabaseExport: error while writing document: " + e.getMessage());
}
}
示例13: 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);
}
示例14: 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);
}
示例15: 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;
}