本文整理汇总了Java中org.jdom.output.Format.getPrettyFormat方法的典型用法代码示例。如果您正苦于以下问题:Java Format.getPrettyFormat方法的具体用法?Java Format.getPrettyFormat怎么用?Java Format.getPrettyFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom.output.Format
的用法示例。
在下文中一共展示了Format.getPrettyFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doOutput
import org.jdom.output.Format; //导入方法依赖的package包/类
public void doOutput(List<StudentEntity> students){
Element root = new Element("students");
Document document = new Document(root);
Iterator<StudentEntity> iter = students.iterator();
while(iter.hasNext()){
StudentEntity student = iter.next();
Element studentEl = new Element("student");
studentEl.addContent(new Element("studentnumber").setText(student.getStudentNumber()));
studentEl.addContent(new Element("studentname").setText(student.getStudentName()));
studentEl.addContent(new Element("major").setText(student.getMajor()));
studentEl.addContent(new Element("grade").setText(student.getGrade()));
studentEl.addContent(new Element("classname").setText(student.getClassName()));
studentEl.addContent(new Element("gender").setText(student.getGender()));
root.addContent(studentEl);
}
try {
XMLOutputter out = new XMLOutputter();
Format f = Format.getPrettyFormat();
f.setEncoding("UTF-8");
out.setFormat(f);
out.output(document, new FileOutputStream(outputFile));
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: writeToXml
import org.jdom.output.Format; //导入方法依赖的package包/类
/**
* Writes the JDOM document to the outputstream specified
* @param out the outputstream to which the JDOM document should be writed
* @param validate if true, validate the dom structure before writing. If there is a validation error,
* or the xsd is not in the classpath, an exception will be thrown.
* @throws ConverterException
*/
public void writeToXml(Pathway pwy, OutputStream out, boolean validate) throws ConverterException {
Document doc = createJdom(pwy);
//Validate the JDOM document
if (validate) validateDocument(doc);
// Get the XML code
XMLOutputter xmlcode = new XMLOutputter(Format.getPrettyFormat());
Format f = xmlcode.getFormat();
f.setEncoding("UTF-8");
f.setTextMode(Format.TextMode.PRESERVE);
xmlcode.setFormat(f);
try
{
//Send XML code to the outputstream
xmlcode.output(doc, out);
}
catch (IOException ie)
{
throw new ConverterException(ie);
}
}
示例3: printXML
import org.jdom.output.Format; //导入方法依赖的package包/类
public static void printXML(Document doc){
Format format = Format.getPrettyFormat();
format.setIndent("\t");
XMLOutputter op = new XMLOutputter(format);
if(doc == null){
System.err.println("Null document");
}
else{
try {
op.output(doc, System.out);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println();
}
}
示例4: write
import org.jdom.output.Format; //导入方法依赖的package包/类
static void write(File file) throws FileNotFoundException, IOException{
Document document = new Document();
Element root = new Element("document");
root.setAttribute("version", Main.VERSION_ID);
for(Blueprint bp : Main.blueprints){
Element blueprint = writeGraphEditor(bp);
for(VFunction f : bp.getFunctions()){
blueprint.addContent(writeGraphEditor(f.getEditor()));
}
root.addContent(blueprint);
}
document.setRootElement(root);
XMLOutputter output = new XMLOutputter();
Format format = Format.getPrettyFormat();//getRawFormat();
format.setOmitDeclaration(true);
format.setOmitEncoding(true);
format.setTextMode(TextMode.PRESERVE);
output.setFormat(format);
output.output(document, new FileOutputStream(file));
}
示例5: processFullCreoleXmlTree
import org.jdom.output.Format; //导入方法依赖的package包/类
private void processFullCreoleXmlTree(Plugin plugin,
Document jdomDoc, CreoleAnnotationHandler annotationHandler)
throws GateException, IOException, JDOMException {
// now we can process any annotations on the new classes
// and augment the XML definition
annotationHandler.processAnnotations(jdomDoc);
// debugging
if(DEBUG) {
XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
xmlOut.output(jdomDoc, System.out);
}
// finally, parse the augmented definition with the normal parser
DefaultHandler handler =
new CreoleXmlHandler(this, plugin);
SAXOutputter outputter =
new SAXOutputter(handler, handler, handler, handler);
outputter.output(jdomDoc);
if(DEBUG) {
Out.prln("done parsing " + plugin);
}
}
示例6: write
import org.jdom.output.Format; //导入方法依赖的package包/类
/**
* Method write
*
* @param project
* @param stream
* @param document
* @deprecated
*/
public void write( Model project, Document document, OutputStream stream )
throws java.io.IOException
{
updateModel( project, "project", new Counter( 0 ), document.getRootElement() );
XMLOutputter outputter = new XMLOutputter();
Format format = Format.getPrettyFormat();
format.setIndent( " " ).setLineSeparator( System.getProperty( "line.separator" ) );
outputter.setFormat( format );
outputter.output( document, stream );
}
示例7: writeSettingsToFile
import org.jdom.output.Format; //导入方法依赖的package包/类
public void writeSettingsToFile(File f)
{
Element component = new Element("component");
component.setAttribute("name", Rearranger.COMPONENT_NAME);
Element r = new Element(Rearranger.COMPONENT_NAME);
component.getChildren().add(r);
writeExternal(r);
Format format = Format.getPrettyFormat();
XMLOutputter outputter = new XMLOutputter(format);
try
{
final FileOutputStream fileOutputStream = new FileOutputStream(f);
outputter.output(component, fileOutputStream);
fileOutputStream.close();
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
示例8: saveXML
import org.jdom.output.Format; //导入方法依赖的package包/类
public void saveXML() throws IOException
{
if(!gexManager.isConnected()) return;
File finalFile = getFileForDb();
if (finalFile.exists()) finalFile.delete();
finalFile.createNewFile();
OutputStream out = new FileOutputStream(finalFile);
Document xmlDoc = new Document();
Element root = new Element(ROOT_XML_ELEMENT);
xmlDoc.setRootElement(root);
root.addContent(colorSetMgr.getXML());
Element vis = new Element(XML_ELEMENT);
for(Visualization v : getVisualizations()) {
vis.addContent(v.toXML());
}
root.addContent(vis);
XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
xmlOut.output(xmlDoc, out);
out.close();
Logger.log.info("Saved visualizations and color sets to xml: " + finalFile);
}
示例9: flush
import org.jdom.output.Format; //导入方法依赖的package包/类
public void flush() throws IOException
{
XMLOutputter xmlcode = new XMLOutputter(Format.getPrettyFormat());
Format f = xmlcode.getFormat();
f.setEncoding("ISO-8859-1");
f.setTextMode(Format.TextMode.PRESERVE);
f.setLineSeparator(System.getProperty("line.separator"));
xmlcode.setFormat(f);
//Open a filewriter
PrintWriter writer = new PrintWriter(out);
xmlcode.output(doc, writer);
out.flush();
}
示例10: export
import org.jdom.output.Format; //导入方法依赖的package包/类
public byte[] export(ExportDataSet dataSet) {
if (dataSet == null) {
throw new IllegalArgumentException("Xml Exporter cannot handle NULL data.");
}
Element rootElement = new Element(DATA_ELEMENT, WORKFLOW_NAMESPACE);
rootElement.addNamespaceDeclaration(SCHEMA_NAMESPACE);
rootElement.setAttribute(SCHEMA_LOCATION_ATTR, WORKFLOW_SCHEMA_LOCATION, SCHEMA_NAMESPACE);
Document document = new Document(rootElement);
boolean shouldPrettyPrint = true;
for (XmlExporter exporter : xmlImpexRegistry.getExporters()) {
Element exportedElement = exporter.export(dataSet);
if (exportedElement != null) {
if (!exporter.supportPrettyPrint()) {
shouldPrettyPrint = false;
}
appendIfNotEmpty(rootElement, exportedElement);
}
}
// TODO: KULRICE-4420 - this needs cleanup
Format f;
if (!shouldPrettyPrint) {
f = Format.getRawFormat();
f.setExpandEmptyElements(false);
f.setTextMode(Format.TextMode.PRESERVE);
} else {
f = Format.getPrettyFormat();
}
XMLOutputter outputer = new XMLOutputter(f);
StringWriter writer = new StringWriter();
try {
outputer.output(document, writer);
} catch (IOException e) {
throw new WorkflowRuntimeException("Could not write XML data export.", e);
}
return writer.toString().getBytes();
}
示例11: getXMLCode
import org.jdom.output.Format; //导入方法依赖的package包/类
public String getXMLCode() throws IOException
{
Format t_objFormat = Format.getPrettyFormat();
XMLOutputter t_objExportXML = new XMLOutputter(t_objFormat);
StringWriter t_objWriter = new StringWriter();
t_objExportXML.output(this.m_objDocument, t_objWriter );
return t_objWriter.toString();
}
示例12: export
import org.jdom.output.Format; //导入方法依赖的package包/类
/**
* @param t_objdb
* @param string
* @throws IOException
* @throws SQLException
*/
public void export(DBInterface a_objDB, String a_strFileName) throws IOException, SQLException
{
this.m_objDB = a_objDB;
// Erzeugung eines XML-Dokuments
Document t_objDocument = new Document();
// Erzeugung des Root-XML-Elements
Element t_objRoot = new Element("fragments");
Namespace xsiNS = Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
t_objRoot.addNamespaceDeclaration(xsiNS);
this.exportAX(t_objRoot);
this.exportOthers(t_objRoot);
// Und jetzt haengen wir noch das Root-Element an das Dokument
t_objDocument.setRootElement(t_objRoot);
// Damit das XML-Dokument schoen formattiert wird holen wir uns ein Format
Format t_objFormat = Format.getPrettyFormat();
t_objFormat.setEncoding("iso-8859-1");
// Erzeugung eines XMLOutputters dem wir gleich unser Format mitgeben
XMLOutputter t_objExportXML = new XMLOutputter(t_objFormat);
// Schreiben der XML-Datei in einen String
FileWriter t_objWriter = new FileWriter(a_strFileName);
t_objExportXML.output(t_objDocument, t_objWriter );
}
示例13: saveDOM
import org.jdom.output.Format; //导入方法依赖的package包/类
public void saveDOM(org.jdom.Document document, String filename) {
File file = new java.io.File(filename);
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter(file));
XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
xout.output(document, out);
} catch (IOException e) {
System.out.println("Error in producing file: " + e.getMessage());
}
}
示例14: exportParameter
import org.jdom.output.Format; //导入方法依赖的package包/类
/**
* Exports a parameter object to an XML string
*
* @param t_objSetting
* @return XML-string
* @throws IOException
*/
public String exportParameter(CalculationParameter t_objSetting) throws IOException
{
// Erzeugung eines XML-Dokuments
Document t_objDocument = new Document();
// Erzeugung des Root-XML-Elements
Element t_objRoot = new Element("glycopeakfinder_calculation");
Namespace xsiNS = Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
t_objRoot.addNamespaceDeclaration(xsiNS);
t_objRoot.setAttribute(new Attribute("noNamespaceSchemaLocation",this.m_strFile, xsiNS));
// write Settings to element
this.exportParameter(t_objRoot, t_objSetting);
// Und jetzt haengen wir noch das Root-Element an das Dokument
t_objDocument.setRootElement(t_objRoot);
// Damit das XML-Dokument schoen formattiert wird holen wir uns ein Format
Format t_objFormat = Format.getPrettyFormat();
t_objFormat.setEncoding("iso-8859-1");
// Erzeugung eines XMLOutputters dem wir gleich unser Format mitgeben
XMLOutputter t_objExportXML = new XMLOutputter(t_objFormat);
// Schreiben der XML-Datei in einen String
StringWriter t_objWriter = new StringWriter();
t_objExportXML.output(t_objDocument, t_objWriter );
return t_objWriter.toString();
}
示例15: serializeAddROSpec
import org.jdom.output.Format; //导入方法依赖的package包/类
/**
* ORANGE: This method serializes a ADD_ROSPEC to an xml and writes it into a file.
* @param addRoSpec containing the ADD_ROSPEC to be written into a file
* @param pathName the file where to store
* @throws IOException whenever an io problem occurs
*/
public static void serializeAddROSpec(ADD_ROSPEC addRoSpec, String pathName) throws IOException {
try {
Document document = addRoSpec.encodeXML();
XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
outputter.output(document, new FileOutputStream(pathName));
} catch (InvalidLLRPMessageException e) {
log.error("could not serialize AddROSpec:", e);
}
}