本文整理汇总了Java中org.jdom.output.Format.setEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java Format.setEncoding方法的具体用法?Java Format.setEncoding怎么用?Java Format.setEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom.output.Format
的用法示例。
在下文中一共展示了Format.setEncoding方法的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: 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("defaults");
Namespace xsiNS = Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");
t_objRoot.addNamespaceDeclaration(xsiNS);
this.exportResidues(t_objRoot);
this.exportPersubstitutions(t_objRoot);
this.exportIons(t_objRoot);
this.exportDericatisation(t_objRoot);
this.exportMolecules(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 );
}
示例4: 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();
}
示例5: 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 );
}
示例6: 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();
}
示例7: writeToFile
import org.jdom.output.Format; //导入方法依赖的package包/类
/**
* Save a xml document in a file
* @param fname the name of the file to be created
* @param doc the xml document
*/
public static void writeToFile(String fname, Document doc){
try{
FileOutputStream out = new FileOutputStream(fname);
Format format = Format.getPrettyFormat();
format.setIndent(" ");
format.setEncoding("ISO-8859-1");
XMLOutputter op = new XMLOutputter(format);
op.output(doc,out);
out.flush();
out.close();
}
catch (IOException e){
System.err.println(e);
}
}
示例8: JPFClasspathFixProcessor
import org.jdom.output.Format; //导入方法依赖的package包/类
public JPFClasspathFixProcessor()
{
super();
sax = new SAXBuilder();
sax.setValidation(false);
sax.setReuseParser(true);
sax.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
Format format = Format.getRawFormat();
format.setOmitEncoding(true);
format.setOmitDeclaration(true);
format.setLineSeparator("\n");
format.setEncoding("UTF-8");
xmlOut = new XMLOutputter(format);
}
示例9: NewPluginWizard
import org.jdom.output.Format; //导入方法依赖的package包/类
public NewPluginWizard()
{
fFirstPage = new NewJPFPluginWizardPageOne();
fSecondPage = new NewJavaProjectWizardPageTwo(fFirstPage);
Format format = Format.getPrettyFormat();
format.setIndent("\t");
format.setOmitEncoding(true);
format.setOmitDeclaration(true);
format.setLineSeparator("\n");
format.setEncoding("UTF-8");
xmlOut = new XMLOutputter(format);
}
示例10: createPrettyFormat
import org.jdom.output.Format; //导入方法依赖的package包/类
private Format createPrettyFormat() {
final Format prettyFormat = Format.getPrettyFormat();
prettyFormat.setExpandEmptyElements(expandEmptyElements);
prettyFormat.setEncoding(encoding);
prettyFormat.setLineSeparator("\n");
prettyFormat.setIndent(indentCharacters);
return prettyFormat;
}
示例11: output
import org.jdom.output.Format; //导入方法依赖的package包/类
/**
* Writes to an Writer the XML representation for the given WireFeed.
* <p>
* If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
* of the developer to ensure the Writer instance is using the same charset encoding.
* <p>
* NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
* <p>
* @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
* the type given to the FeedOuptut constructor.
* @param writer Writer to write the XML representation for the given WireFeed.
* @param prettyPrint pretty-print XML (true) oder collapsed
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
* @throws IOException thrown if there was some problem writing to the Writer.
* @throws FeedException thrown if the XML representation for the feed could not be created.
*
*/
public void output(WireFeed feed,Writer writer,boolean prettyPrint) throws IllegalArgumentException,IOException, FeedException {
Document doc = outputJDom(feed);
String encoding = feed.getEncoding();
Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
if (encoding!=null) {
format.setEncoding(encoding);
}
XMLOutputter outputter = new XMLOutputter(format);
outputter.output(doc,writer);
}
示例12: writeXML
import org.jdom.output.Format; //导入方法依赖的package包/类
/**
* Serializes the database to the output stream.
*
* @param outputStream the output
* @param encoding the encoding to use
* @param indent the indent
* @param lineSeparator the lineSeparator
* @throws IOException in case the xml could not be written
*/
public void writeXML(OutputStream outputStream, String encoding, String indent, String lineSeparator)
throws IOException {
XMLOutputter outputter = new XMLOutputter();
Format format = Format.getPrettyFormat();
format.setEncoding(encoding);
format.setIndent(indent);
format.setLineSeparator(lineSeparator);
outputter.setFormat(format);
outputter.output(getDocument(), outputStream);
}
示例13: outputString
import org.jdom.output.Format; //导入方法依赖的package包/类
/**
* Creates a String with the XML representation for the given WireFeed.
* <p>
* If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
* of the developer to ensure that if the String is written to a character stream the stream charset is the same as
* the feed encoding property.
* <p>
* NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
* <p>
* @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
* the type given to the FeedOuptut constructor.
* @return a String with the XML representation for the given WireFeed.
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
* @throws FeedException thrown if the XML representation for the feed could not be created.
*
*/
public String outputString(WireFeed feed) throws IllegalArgumentException,FeedException {
Document doc = outputJDom(feed);
String encoding = feed.getEncoding();
Format format = Format.getPrettyFormat();
if (encoding!=null) {
format.setEncoding(encoding);
}
XMLOutputter outputter = new XMLOutputter(format);
return outputter.outputString(doc);
}
示例14: output
import org.jdom.output.Format; //导入方法依赖的package包/类
/**
* Writes to an Writer the XML representation for the given WireFeed.
* <p>
* If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
* of the developer to ensure the Writer instance is using the same charset encoding.
* <p>
* NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
* <p>
* @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
* the type given to the FeedOuptut constructor.
* @param writer Writer to write the XML representation for the given WireFeed.
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
* @throws IOException thrown if there was some problem writing to the Writer.
* @throws FeedException thrown if the XML representation for the feed could not be created.
*
*/
public void output(WireFeed feed,Writer writer) throws IllegalArgumentException,IOException, FeedException {
Document doc = outputJDom(feed);
String encoding = feed.getEncoding();
Format format = Format.getPrettyFormat();
if (encoding!=null) {
format.setEncoding(encoding);
}
XMLOutputter outputter = new XMLOutputter(format);
outputter.output(doc,writer);
}
示例15: outputString
import org.jdom.output.Format; //导入方法依赖的package包/类
/**
* Creates a String with the XML representation for the given WireFeed.
* <p>
* If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
* of the developer to ensure that if the String is written to a character stream the stream charset is the same as
* the feed encoding property.
* <p>
* NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
* <p>
* @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
* the type given to the FeedOuptut constructor.
* @param prettyPrint pretty-print XML (true) oder collapsed
* @return a String with the XML representation for the given WireFeed.
* @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
* @throws FeedException thrown if the XML representation for the feed could not be created.
*
*/
public String outputString(WireFeed feed, boolean prettyPrint) throws IllegalArgumentException,FeedException {
Document doc = outputJDom(feed);
String encoding = feed.getEncoding();
Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
if (encoding!=null) {
format.setEncoding(encoding);
}
XMLOutputter outputter = new XMLOutputter(format);
return outputter.outputString(doc);
}