本文整理匯總了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;
}