本文整理汇总了Java中org.dom4j.io.OutputFormat.createCompactFormat方法的典型用法代码示例。如果您正苦于以下问题:Java OutputFormat.createCompactFormat方法的具体用法?Java OutputFormat.createCompactFormat怎么用?Java OutputFormat.createCompactFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.dom4j.io.OutputFormat
的用法示例。
在下文中一共展示了OutputFormat.createCompactFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertToXML
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
/**
* convert definition to hibernate xml
*
* @param descriptor
* @return
* @throws IOException
*/
protected String convertToXML(IStandalonePersistentBeanDescriptor descriptor) {
Document doc = createDocument(descriptor);
StringWriter sw = new StringWriter();
XMLWriter writer = new XMLWriter(sw, OutputFormat.createCompactFormat());
try {
writer.write(doc);
} catch (IOException e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("Failed to cast xml document to string.", e);
}
throw new ResourceException("Failed to cast xml document to string.", e);
}
if (getLogger().isDebugEnabled()) {
getLogger()
.debug("Class [" + descriptor.getResourceClass().getName()
+ "] has been configured into hibernate. XML as [" + sw.toString().replace("\n", "") + "].");
}
return sw.toString();
}
示例2: 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);
}
示例3: 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, "");
}
示例4: nullSafeSet
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException {
if (value == null) {
ps.setNull(index, sqlTypes()[0]);
} else {
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(bytes,OutputFormat.createCompactFormat());
writer.write((Document)value);
writer.flush(); writer.close();
ps.setCharacterStream(index, new CharArrayReader(bytes.toString().toCharArray(),0,bytes.size()), bytes.size());
} catch (IOException e) {
throw new HibernateException(e.getMessage(),e);
}
}
}
示例5: nullSafeSet
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
public void nullSafeSet(PreparedStatement ps, Object value, int index, SessionImplementor session) throws SQLException, HibernateException {
if (value == null) {
ps.setNull(index, sqlTypes()[0]);
} else {
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(new GZIPOutputStream(bytes),OutputFormat.createCompactFormat());
writer.write((Document)value);
writer.flush(); writer.close();
ps.setBinaryStream(index, new ByteArrayInputStream(bytes.toByteArray(),0,bytes.size()), bytes.size());
} catch (IOException e) {
throw new HibernateException(e.getMessage(),e);
}
}
}
示例6: setStudentsDocument
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
public void setStudentsDocument(Document document) {
try {
if (document == null) {
setStudents(null);
} else {
StringWriter string = new StringWriter();
XMLWriter writer = new XMLWriter(string, OutputFormat.createCompactFormat());
writer.write(document);
writer.flush(); writer.close();
setStudents(string.toString());
}
} catch (Exception e) {
sLog.warn("Failed to store cached students for " + getCurriculum().getAbbv() + " " + getName() + ": " + e.getMessage(), e);
}
}
示例7: setValue
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
public void setValue(Document document) {
try {
if (document == null) {
setData(null);
} else {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(new GZIPOutputStream(bytes),OutputFormat.createCompactFormat());
writer.write(document);
writer.flush(); writer.close();
setData(bytes.toByteArray());
}
} catch (IOException e) {
throw new HibernateException(e.getMessage(),e);
}
}
示例8: getXMLOutputFormat
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
@Override
protected OutputFormat getXMLOutputFormat()
{
String userAgent = m_request.getHeader("User-Agent");
return ((null != userAgent) && userAgent.toLowerCase().startsWith("microsoft-webdav-miniredir/5.1.")) ? OutputFormat.createCompactFormat() : super.getXMLOutputFormat();
}
示例9: 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();
}
示例10: setUp
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
protected void setUp() throws Exception {
super.setUp();
Dom4JDriver driver = new Dom4JDriver();
OutputFormat format = OutputFormat.createCompactFormat();
format.setTrimText(false);
format.setSuppressDeclaration(true);
driver.setOutputFormat(format);
out = new StringWriter();
writer = driver.createWriter(out);
}
示例11: test
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
Document doc = DocumentHelper.createDocument();
doc.addDocType("hibernate-mapping", "-//Hibernate/Hibernate Mapping DTD 3.0//EN",
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd");
StringWriter sw = new StringWriter();
XMLWriter writer = new XMLWriter(sw, OutputFormat.createCompactFormat());
writer.write(doc);
System.out.println(sw.toString());
}
示例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: getSnipAsXml
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
public String getSnipAsXml(String name) {
Snip snip = space.load(name);
ByteArrayOutputStream out = new ByteArrayOutputStream();
OutputFormat outputFormat = OutputFormat.createCompactFormat();
outputFormat.setEncoding("UTF-8");
try {
XMLWriter writer = new XMLWriter(out, outputFormat);
writer.write(SnipSerializer.getInstance().serialize(snip));
writer.flush();
} catch (IOException e) {
e.printStackTrace();
}
return out.toString();
}
示例14: getXMLOutputFormat
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
/**
* Returns the format required for an XML response. This may vary per method.
*/
protected OutputFormat getXMLOutputFormat()
{
// Check if debug output or XML pretty printing is enabled
return (XMLPrettyPrint || logger.isDebugEnabled()) ? OutputFormat.createPrettyPrint() : OutputFormat.createCompactFormat();
}
示例15: createTrimedOutputFormat
import org.dom4j.io.OutputFormat; //导入方法依赖的package包/类
private static OutputFormat createTrimedOutputFormat(final String encoding) {
final OutputFormat format = OutputFormat.createCompactFormat();
format.setEncoding(encoding);
return format;
}