本文整理汇总了Java中org.apache.xml.serialize.OutputFormat.setLineWidth方法的典型用法代码示例。如果您正苦于以下问题:Java OutputFormat.setLineWidth方法的具体用法?Java OutputFormat.setLineWidth怎么用?Java OutputFormat.setLineWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xml.serialize.OutputFormat
的用法示例。
在下文中一共展示了OutputFormat.setLineWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: save
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
public void save() throws AtsConfigurationException {
// save the XML file
try {
OutputFormat format = new OutputFormat(doc);
format.setIndenting(true);
format.setIndent(4);
format.setLineWidth(1000);
XMLSerializer serializer = new XMLSerializer(new FileOutputStream(new File(atsConfigurationFile)),
format);
serializer.serialize(doc);
} catch (Exception e) {
throw new AtsConfigurationException("Error saving ATS configuration in '" + atsConfigurationFile
+ "'", e);
}
}
示例2: formatDocumentForTesting
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
* Cette méthode permet de reformater le contenu d'une chaîne XML
* et donc de s'affranchir des problèmes liés au formatage (tabulations, espaces, retours chariot, ...).
*
* @param document
* @return une chaîne de caractères "normalisée" créé à partir d'un document Document Object Model
*/
public String formatDocumentForTesting(Document document) {
try {
OutputFormat format = new OutputFormat(document);
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(document);
return out.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例3: store
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
* store loaded data to xml file
* @throws SearchException
*/
protected final synchronized void store() throws SearchException {
//Collection.Key[] keys=collections.keys();
Iterator<Key> it = collections.keyIterator();
Key k;
while(it.hasNext()) {
k=it.next();
Element collEl = getCollectionElement(k.getString());
SearchCollection sc = getCollectionByName(k.getString());
setAttributes(collEl,sc);
}
OutputFormat format = new OutputFormat(doc, null, true);
format.setLineSeparator("\r\n");
format.setLineWidth(72);
OutputStream os=null;
try {
XMLSerializer serializer = new XMLSerializer(os=IOUtil.toBufferedOutputStream(searchFile.getOutputStream()), format);
serializer.serialize(doc.getDocumentElement());
} catch (IOException e) {
throw new SearchException(e);
}
finally {
IOUtil.closeEL(os);
}
}
示例4: save
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
public static void save(Writer writer, Document document)
throws IOException
{
OutputFormat outputFormat = new OutputFormat(document);
outputFormat.setIndenting(true);
outputFormat.setLineWidth(Integer.MAX_VALUE);
outputFormat.setLineSeparator(Util.nl);
try {
XMLSerializer serializer = new XMLSerializer(writer, outputFormat);
serializer.serialize(document);
} finally {
if (writer != null) {
writer.close();
}
}
}
示例5: formatXml
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
* This function will format the XML profile with intends and new lines.
*
* @param xmlToFormat the xml String you want to format
* @return the formated version of teh given XML string
*/
private String formatXml(String xmlToFormat) {
try {
final Document document = generateXmlDocument(xmlToFormat);
OutputFormat format = new OutputFormat(document);
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
format.setOmitXMLDeclaration(true);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(document);
return out.toString();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例6: getResponseFromFile
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
private String getResponseFromFile(String file) throws Exception {
String filePath = this.getClass().getResource(file).getPath();
Document xmlDocument;
InputStream inputXML;
inputXML = new FileInputStream(new File(filePath));
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
xmlDocument = builder.parse(inputXML);
OutputFormat format = new OutputFormat(xmlDocument);
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(xmlDocument);
return out.toString();
}
示例7: getXml
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
@Override
public String getXml() throws IOException {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputFormat format = new OutputFormat();
format.setLineWidth(200);
format.setIndenting(true);
format.setIndent(2);
XMLSerializer serializer = new XMLSerializer(bos, format);
serializer.serialize(((Document)this.node).getDocumentElement());
return new String(bos.toByteArray(), "UTF-8");
} catch(Exception e) {
e.printStackTrace();
}
return null;
}
示例8: prettyDocumentToString
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
* Serialize a Document to a String using JAXP with identation (4 spaces)
* @param doc to serialize
* @return xml string
*/
public static String prettyDocumentToString(Document doc) {
StringWriter writer = new StringWriter();
OutputFormat out = new OutputFormat();
out.setOmitXMLDeclaration(true);
out.setIndenting(true);
out.setIndent(4);
out.setLineSeparator(System.getProperty("line.separator"));
out.setLineWidth(Integer.MAX_VALUE);
XMLSerializer serializer = new XMLSerializer(writer, out);
try {
Element rootElement = doc.getDocumentElement();
serializer.serialize(rootElement);
} catch (IOException e) {
log.error(e);
}
return writer.toString();
}
示例9: formatXML
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
public static String formatXML(String xml) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
Document document = db.parse(is);
OutputFormat format = new OutputFormat(document);
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
Writer out = new StringWriter();
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(document);
return out.toString();
} catch (Exception e) {
return xml;
}
}
示例10: writedoc
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
* Writes the given element's subtree to the specified file.
*
* @param fname The output file name
* @param ele The xml Element subtree to write to file
* @param doc The Document
* @return True if content previously existed in the given file and the content is the same
* as the new content provided
* @exception Hexception If exception
*/
private boolean writedoc(
String fname,
Element ele,
Document doc)
throws Hexception {
try {
boolean contentEquals = false;
String s1 = null;
File f = new File(fname);
if (f.exists())
s1 = Files.readFileToEncoding(f, "UTF-8").toString();
FileOutputStream fos = new FileOutputStream(f);
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
Writer wtr = new BufferedWriter(osw);
OutputFormat format = new OutputFormat(doc, "UTF-8", true);
// Indenting true
format.setMethod("xml");
// May not ne necessary to call this
format.setLineWidth(0);
// No line wrapping
XMLSerializer ser = new XMLSerializer(wtr, format);
ser.serialize(ele);
fos.close();
osw.close();
wtr.close();
if (s1 != null)
contentEquals = s1.contentEquals(Files.readFileToEncoding(f, "UTF-8"));
return contentEquals;
} catch (IOException ioe) {
throw new Hexception("cannot write file \"" + fname
+ "\" reason: " + ioe);
}
}
示例11: formatXML
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
* Formats a given unformatted XML string
*
* @param xml
* @return A CDATA wrapped, formatted XML String
*/
public String formatXML(String xml) {
try {
DocumentBuilder docBuilder;
Document xmlDoc;
// create the factory
DocumentBuilderFactory docFactory = IdentityUtil.getSecuredDocumentBuilderFactory();
docFactory.setIgnoringComments(true);
// now use the factory to create the document builder
docBuilder = docFactory.newDocumentBuilder();
xmlDoc = docBuilder.parse(new ByteArrayInputStream(xml.getBytes(Charsets.UTF_8)));
OutputFormat format = new OutputFormat(xmlDoc);
format.setLineWidth(0);
format.setIndenting(true);
format.setIndent(2);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLSerializer serializer = new XMLSerializer(baos, format);
serializer.serialize(xmlDoc);
xml = baos.toString("UTF-8");
} catch (ParserConfigurationException pce) {
throw new IllegalArgumentException("Failed to parse the unformatted XML String. ", pce);
} catch (Exception e) {
log.error("Error occured while formtting the unformatted XML String. ", e);
}
return "<![CDATA[" + xml + "]]>";
}
示例12: writedoc
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
* Writes the given element's subtree to the specified file.
*
* @param fname The output file.
* @param ele The xml element subtree.
* @param doc DESCRIPTION
* @exception Hexception DESCRIPTION
*/
private void writedoc(
String fname,
Element ele,
Document doc)
throws Hexception {
try {
FileOutputStream fos = new FileOutputStream(fname);
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
Writer wtr = new BufferedWriter(osw);
OutputFormat format = new OutputFormat(doc, "UTF-8", true);
// Indenting true
format.setMethod("xml");
// May not ne necessary to call this
format.setLineWidth(0);
// No line wrapping
XMLSerializer ser = new XMLSerializer(wtr, format);
ser.serialize(ele);
fos.close();
osw.close();
wtr.close();
} catch (IOException ioe) {
throw new Hexception("cannot write file \"" + fname
+ "\" reason: " + ioe);
}
}
示例13: store
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
* store loaded data to xml file
* @param doc
* @param res
* @throws IOException
*/
public synchronized void store(Document doc,Resource res) throws IOException {
OutputFormat format = new OutputFormat(doc, null, true);
format.setLineSeparator("\r\n");
format.setLineWidth(72);
OutputStream os=null;
try {
XMLSerializer serializer = new XMLSerializer(os=res.getOutputStream(), format);
serializer.serialize(doc.getDocumentElement());
}
finally {
IOUtil.closeEL(os);
}
}
示例14: store
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
* store loaded data to xml file
* @param doc
* @param res
* @throws IOException
*/
public void store(Document doc,Resource res) throws IOException {
OutputFormat format = new OutputFormat(doc, null, true);
format.setLineSeparator("\r\n");
format.setLineWidth(72);
OutputStream os=null;
try {
XMLSerializer serializer = new XMLSerializer(os=res.getOutputStream(), format);
serializer.serialize(doc.getDocumentElement());
}
finally {
IOUtil.closeEL(os);
}
}
示例15: documentToString
import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
* Returns a String representation for the XML Document.
*
* @param xmlDocument the XML Document
* @return String representation for the XML Document
* @throws IOException
*/
public static String documentToString(Document xmlDocument) throws IOException {
String encoding = (xmlDocument.getXmlEncoding() == null) ? "UTF-8" : xmlDocument.getXmlEncoding();
OutputFormat format = new OutputFormat(xmlDocument);
format.setLineWidth(65);
format.setIndenting(true);
format.setIndent(2);
format.setEncoding(encoding);
try (Writer out = new StringWriter()) {
XMLSerializer serializer = new XMLSerializer(out, format);
serializer.serialize(xmlDocument);
return out.toString();
}
}