當前位置: 首頁>>代碼示例>>Java>>正文


Java OutputFormat.setEncoding方法代碼示例

本文整理匯總了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);
       }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:24,代碼來源:ImportFileUpdater.java

示例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();
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:28,代碼來源:XMLTransferDestinationReportWriter.java

示例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);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:19,代碼來源:XMLTransferReportWriter.java

示例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();
    }
}
 
開發者ID:ajtdnyy,項目名稱:PackagePlugin,代碼行數:28,代碼來源:FileUtil.java

示例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);
	}
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:19,代碼來源:VersionedDocument.java

示例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();
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:22,代碼來源:XmlUtils.java

示例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;
}
 
開發者ID:GovernIB,項目名稱:sistra,代碼行數:22,代碼來源:InstanciaTelematicaProcessorEJB.java

示例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;      
}
 
開發者ID:codeWatching,項目名稱:codePay,代碼行數:25,代碼來源:XmlUtil.java

示例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());
}
 
開發者ID:bingoohuang,項目名稱:javacode-demo,代碼行數:26,代碼來源:Dom4jTest.java

示例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;
}
 
開發者ID:shijiebei2009,項目名稱:CEC-Automatic-Annotation,代碼行數:20,代碼來源:WriteToXMLUtil.java

示例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();
  }
}
 
開發者ID:thinkberg,項目名稱:snipsnap,代碼行數:17,代碼來源:XMLSnipExport.java

示例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());
    }
  }
 
開發者ID:thinkberg,項目名稱:snipsnap,代碼行數:27,代碼來源:JDBCDatabaseExport.java

示例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);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:10,代碼來源:XMLTransferRequsiteWriter.java

示例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);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:11,代碼來源:XMLWriter.java

示例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;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:14,代碼來源:ExportSourceImporter.java


注:本文中的org.dom4j.io.OutputFormat.setEncoding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。