当前位置: 首页>>代码示例>>Java>>正文


Java OutputFormat.setNewlines方法代码示例

本文整理汇总了Java中org.dom4j.io.OutputFormat.setNewlines方法的典型用法代码示例。如果您正苦于以下问题:Java OutputFormat.setNewlines方法的具体用法?Java OutputFormat.setNewlines怎么用?Java OutputFormat.setNewlines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.dom4j.io.OutputFormat的用法示例。


在下文中一共展示了OutputFormat.setNewlines方法的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: 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

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

示例5: 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, "");
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:13,代码来源:XmlBuilderTest.java

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

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

示例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.setNewlines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。