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


Java OutputFormat.setIndent方法代碼示例

本文整理匯總了Java中org.dom4j.io.OutputFormat.setIndent方法的典型用法代碼示例。如果您正苦於以下問題:Java OutputFormat.setIndent方法的具體用法?Java OutputFormat.setIndent怎麽用?Java OutputFormat.setIndent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.dom4j.io.OutputFormat的用法示例。


在下文中一共展示了OutputFormat.setIndent方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例3: main

import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
public static void main(String args[]){

		Namespace rootNs = new Namespace("", "uri:oozie:workflow:0.4"); // root namespace uri
		QName rootQName = QName.get("workflow-app", rootNs); // your root element's name
		Element workflow = DocumentHelper.createElement(rootQName);
		Document doc = DocumentHelper.createDocument(workflow);
		
		workflow.addAttribute("name", "test");
		Element test = workflow.addElement("test");
		test.addText("hello");
				OutputFormat outputFormat = OutputFormat.createPrettyPrint();
				outputFormat.setEncoding("UTF-8");
				outputFormat.setIndent(true); 
				outputFormat.setIndent("    "); 
				outputFormat.setNewlines(true); 
		try {
			StringWriter stringWriter = new StringWriter();
			XMLWriter xmlWriter = new XMLWriter(stringWriter);
			xmlWriter.write(doc);
			xmlWriter.close();
			System.out.println( doc.asXML() );
			System.out.println( stringWriter.toString().trim());

		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
 
開發者ID:ICT-BDA,項目名稱:EasyML,代碼行數:28,代碼來源:WFGraph.java

示例4: 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();
}
 
開發者ID:mobileboxlab,項目名稱:appium-java-repl,代碼行數:19,代碼來源:Utils.java

示例5: save

import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
@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();
}
 
開發者ID:color-coding,項目名稱:btulz.transforms,代碼行數:36,代碼來源:XmlTransformerDom4j.java

示例6: 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();
}
 
開發者ID:apache,項目名稱:openmeetings,代碼行數:12,代碼來源:XmlExport.java

示例7: createOutputFormat

import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
/**
 * 建構格式化
 * 
 * @param encoding
 *            String
 * @return OutputFormat
 */
public static OutputFormat createOutputFormat(String encoding) {
	OutputFormat format = OutputFormat.createPrettyPrint();
	format.setEncoding(encoding);
	// format.setIndent(StringUtil.TAB);
	format.setIndent("  ");
	format.setLineSeparator(System.getProperty("line.separator"));
	format.setTrimText(true);
	return format;
}
 
開發者ID:mixaceh,項目名稱:openyu-commons,代碼行數:17,代碼來源:Dom4jHelper.java

示例8: getXMLOutputFormat

import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
/**
 * @see org.alfresco.repo.webdav.WebDAVMethod#createXMLWriter()
 */
@Override
protected OutputFormat getXMLOutputFormat()
{
    OutputFormat outputFormat = new OutputFormat();
    outputFormat.setNewLineAfterDeclaration(false);
    outputFormat.setNewlines(false);
    outputFormat.setIndent(false);
    return outputFormat;
}
 
開發者ID:Alfresco,項目名稱:community-edition-old,代碼行數:13,代碼來源:LockMethod.java

示例9: getXMLOutputFormat

import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
@Override
protected OutputFormat getXMLOutputFormat()
{
    OutputFormat outputFormat = new OutputFormat();
    outputFormat.setNewLineAfterDeclaration(false);
    outputFormat.setNewlines(false);
    outputFormat.setIndent(false);
    return outputFormat;
}
 
開發者ID:Alfresco,項目名稱:community-edition-old,代碼行數:10,代碼來源:DeleteMethod.java

示例10: toWorkflow

import org.dom4j.io.OutputFormat; //導入方法依賴的package包/類
/**
 * Transform the Graph into an workflow xml definition
 * @param jobname the job name of Oozie job, can't be null
 * @return workflow xml
 */
public String toWorkflow(String jobname) {
	Namespace xmlns = new Namespace("", "uri:oozie:workflow:0.4"); // root namespace uri
	QName qName = QName.get("workflow-app", xmlns); // your root element's name
	Element workflow = DocumentHelper.createElement(qName);
	Document xmldoc = DocumentHelper.createDocument(workflow);
	// Create workflow root
	workflow.addAttribute("xmlns", "uri:oozie:workflow:0.4");
	// <workflow-app name='xxx'></workflow-app>
	if (jobname == null || "".equals(jobname))
		workflow.addAttribute("name", "Not specified");
	else
		workflow.addAttribute("name", jobname);

	Queue<NodeDef> que = new LinkedList<NodeDef>();
	que.add(start);

	while (!que.isEmpty()) {
		NodeDef cur = que.remove();

		cur.append2XML(workflow);

		for (NodeDef toNode : cur.getOutNodes()) {
			toNode.delInNode(cur);
			if (toNode.getInDegree() == 0)
				que.add(toNode);
		}
	}

	// Set XML document format
	OutputFormat outputFormat = OutputFormat.createPrettyPrint();
	// Set XML encoding, use the specified encoding to save the XML document to the string, it can be specified GBK or ISO8859-1
	outputFormat.setEncoding("UTF-8");
	outputFormat.setSuppressDeclaration(true); // Whether generate xml header
	outputFormat.setIndent(true); // Whether set indentation
	outputFormat.setIndent("    "); // Implement indentation with four spaces
	outputFormat.setNewlines(true); // Set whether to wrap

	try {
		// stringWriter is used to save xml document
		StringWriter stringWriter = new StringWriter();
		// xmlWriter is used to write XML document to string(tool)
		XMLWriter xmlWriter = new XMLWriter(stringWriter, outputFormat);
		
		// Write the created XML document into the string
		xmlWriter.write(xmldoc);

		xmlWriter.close();

		System.out.println( stringWriter.toString().trim());
		// Print the string, that is, the XML document
		return stringWriter.toString().trim();

	} catch (Exception ex) {
		ex.printStackTrace();
	}
	return null;
}
 
開發者ID:ICT-BDA,項目名稱:EasyML,代碼行數:63,代碼來源:WFGraph.java


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