org.jdom2.output.Format.setEncoding()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(158)

本文整理了Java中org.jdom2.output.Format.setEncoding()方法的一些代码示例,展示了Format.setEncoding()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Format.setEncoding()方法的具体详情如下:
包路径:org.jdom2.output.Format
类名称:Format
方法名:setEncoding

Format.setEncoding介绍

[英]Sets the output encoding. The name should be an accepted XML encoding.
[中]设置输出编码。该名称应为可接受的XML编码。

代码示例

代码示例来源:origin: gocd/gocd

  1. private static XMLOutputter xmlOutputer() {
  2. Format format = Format.getPrettyFormat().setEncoding("utf-8").setLineSeparator("\n");
  3. return new XMLOutputter(format);
  4. }

代码示例来源:origin: org.jdom/jdom

  1. /**
  2. * Creates a new Format instance with default (raw) behavior.
  3. */
  4. private Format() {
  5. setEncoding(STANDARD_ENCODING);
  6. }

代码示例来源:origin: pwm-project/pwm

  1. public static void outputDocument( final Document document, final OutputStream outputStream )
  2. throws IOException
  3. {
  4. final Format format = Format.getPrettyFormat();
  5. format.setEncoding( STORAGE_CHARSET.toString() );
  6. final XMLOutputter outputter = new XMLOutputter();
  7. outputter.setFormat( format );
  8. try ( Writer writer = new OutputStreamWriter( outputStream, STORAGE_CHARSET ) )
  9. {
  10. outputter.output( document, writer );
  11. }
  12. }

代码示例来源:origin: dqeasycloud/easy-cloud

  1. private void doXmlOutputter(Document doc, File xmlFile) throws IOException {
  2. Format format = Format.getPrettyFormat();
  3. format.setIndent(" ");
  4. format.setEncoding("UTF-8");
  5. XMLOutputter out = new XMLOutputter(format);
  6. out.output(doc, new FileWriter(xmlFile)); // 写文件
  7. }

代码示例来源:origin: org.apache.maven.plugins/maven-shade-plugin

  1. /**
  2. * Method write
  3. *
  4. * @param project
  5. * @param writer
  6. * @param document
  7. */
  8. public void write( Model project, Document document, OutputStreamWriter writer )
  9. throws java.io.IOException
  10. {
  11. Format format = Format.getRawFormat();
  12. format.setEncoding( writer.getEncoding() ).setLineSeparator( System.getProperty( "line.separator" ) );
  13. write( project, document, writer, format );
  14. } // -- void write(Model, Document, OutputStreamWriter)

代码示例来源:origin: org.mycore/mycore-user2

  1. /**
  2. * Exports a single role to the specified directory.
  3. * @throws FileNotFoundException if target directory does not exist
  4. */
  5. @MCRCommand(
  6. syntax = "export role {0} to directory {1}",
  7. help = "Export the role {0} to the directory {1}. The filename will be {0}.xml")
  8. public static void exportRole(String roleID, String directory) throws IOException {
  9. MCRRole mcrRole = MCRRoleManager.getRole(roleID);
  10. File targetFile = new File(directory, roleID + ".xml");
  11. try (FileOutputStream fout = new FileOutputStream(targetFile)) {
  12. XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat().setEncoding(MCRConstants.DEFAULT_ENCODING));
  13. xout.output(MCRRoleTransformer.buildExportableXML(mcrRole), fout);
  14. }
  15. }

代码示例来源:origin: org.mycore/mycore-user2

  1. /**
  2. * This method just saves a JDOM document to a file automatically closes {@link OutputStream}.
  3. *
  4. * @param mcrUser
  5. * the JDOM XML document to be printed
  6. * @param outFile
  7. * a FileOutputStream object for the output
  8. * @throws IOException
  9. * if output file can not be closed
  10. */
  11. private static void saveToXMLFile(MCRUser mcrUser, FileOutputStream outFile) throws MCRException, IOException {
  12. // Create the output
  13. XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setEncoding(MCRConstants.DEFAULT_ENCODING));
  14. try {
  15. outputter.output(MCRUserTransformer.buildExportableXML(mcrUser), outFile);
  16. } catch (Exception e) {
  17. throw new MCRException("Error while save XML to file: " + e.getMessage());
  18. } finally {
  19. outFile.close();
  20. }
  21. }
  22. }

代码示例来源:origin: org.mycore/mycore-wcms2

  1. XMLOutputter out = new XMLOutputter(Format.getRawFormat().setEncoding("UTF-8"));
  2. for (JsonElement e : items) {
  3. validateContent(e).ifPresent(item -> {

代码示例来源:origin: Vhati/Slipstream-Mod-Manager

  1. private static void writeXML( ModsInfo modsInfo, OutputStreamWriter dst, String indent, int depth ) throws IOException {
  2. Format xmlFormat = Format.getPrettyFormat();
  3. xmlFormat.setEncoding( dst.getEncoding() );
  4. XMLOutputter xmlOut = new XMLOutputter( xmlFormat );
  5. writeIndent( dst, indent, depth++ ).append( "<modsinfo>\n" );
  6. writeIndent( dst, indent, depth ); dst.append("<title>").append( xmlOut.escapeElementEntities( modsInfo.getTitle() ) ).append( "</title>\n" );
  7. writeIndent( dst, indent, depth ); dst.append("<author>").append( xmlOut.escapeElementEntities( modsInfo.getAuthor() ) ).append( "</author>\n" );
  8. writeIndent( dst, indent, depth ); dst.append("<threadUrl><![CDATA[ ").append( modsInfo.getThreadURL() ).append( " ]]></threadUrl>\n" );
  9. writeIndent( dst, indent, depth++ ).append( "<versions>\n" );
  10. for ( Map.Entry<String,String> entry : modsInfo.getVersionsMap().entrySet() ) {
  11. String versionFileHash = entry.getKey();
  12. String versionString = entry.getValue();
  13. writeIndent( dst, indent, depth );
  14. dst.append( "<version hash=\"" ).append( xmlOut.escapeAttributeEntities( versionFileHash ) ).append( "\">" );
  15. dst.append( xmlOut.escapeElementEntities( versionString ) );
  16. dst.append( "</version>" ).append( "\n" );
  17. }
  18. writeIndent( dst, indent, --depth ).append( "</versions>\n" );
  19. writeIndent( dst, indent, depth ); dst.append("<threadHash>").append( modsInfo.getThreadHash() ).append( "</threadHash>\n" );
  20. dst.append( "\n" );
  21. writeIndent( dst, indent, depth ); dst.append( "<description>" ).append( "<![CDATA[" );
  22. dst.append( modsInfo.getDescription() );
  23. dst.append( "]]>\n" );
  24. writeIndent( dst, indent, depth ); dst.append( "</description>\n" );
  25. writeIndent( dst, indent, --depth ).append( "</modsinfo>\n" );
  26. }

代码示例来源:origin: org.mycore/mycore-wcms2

  1. public void move(String from, String to) {
  2. try {
  3. // get from
  4. URL fromURL = MCRWebPagesSynchronizer.getURL(from);
  5. Document document;
  6. if (fromURL == null) {
  7. // if the from resource couldn't be found we assume its not created yet.
  8. MyCoReWebPageProvider wpp = new MyCoReWebPageProvider();
  9. wpp.addSection("neuer Eintrag", new Element("p").setText("TODO"), "de");
  10. document = wpp.getXML();
  11. } else {
  12. SAXBuilder builder = new SAXBuilder();
  13. document = builder.build(fromURL);
  14. }
  15. // save
  16. XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setEncoding("UTF-8"));
  17. try (OutputStream fout = MCRWebPagesSynchronizer.getOutputStream(to)) {
  18. out.output(document, fout);
  19. }
  20. // delete old
  21. if (fromURL != null) {
  22. Files.delete(Paths.get(fromURL.toURI()));
  23. }
  24. } catch (Exception exc) {
  25. LOGGER.error("Error moving {} to {}", from, to, exc);
  26. throwError(ErrorType.couldNotMove, to);
  27. }
  28. }

代码示例来源:origin: org.apache.marmotta/sesame-tools-rio-rss

  1. /**
  2. * Writes to an Writer the XML representation for the given WireFeed.
  3. * <p>
  4. * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
  5. * of the developer to ensure the Writer instance is using the same charset encoding.
  6. * <p>
  7. * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
  8. * <p>
  9. * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
  10. * the type given to the FeedOuptut constructor.
  11. * @param writer Writer to write the XML representation for the given WireFeed.
  12. * @param prettyPrint pretty-print XML (true) oder collapsed
  13. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
  14. * @throws IOException thrown if there was some problem writing to the Writer.
  15. * @throws FeedException thrown if the XML representation for the feed could not be created.
  16. *
  17. */
  18. public void output(WireFeed feed,Writer writer,boolean prettyPrint) throws IllegalArgumentException,IOException, FeedException {
  19. Document doc = outputJDom(feed);
  20. String encoding = feed.getEncoding();
  21. Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  22. if (encoding!=null) {
  23. format.setEncoding(encoding);
  24. }
  25. XMLOutputter outputter = new XMLOutputter(format);
  26. outputter.output(doc,writer);
  27. }

代码示例来源:origin: rometools/rome

  1. format.setEncoding(encoding);

代码示例来源:origin: apache/marmotta

  1. /**
  2. * Writes to an Writer the XML representation for the given WireFeed.
  3. * <p>
  4. * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
  5. * of the developer to ensure the Writer instance is using the same charset encoding.
  6. * <p>
  7. * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
  8. * <p>
  9. * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
  10. * the type given to the FeedOuptut constructor.
  11. * @param writer Writer to write the XML representation for the given WireFeed.
  12. * @param prettyPrint pretty-print XML (true) oder collapsed
  13. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
  14. * @throws IOException thrown if there was some problem writing to the Writer.
  15. * @throws FeedException thrown if the XML representation for the feed could not be created.
  16. *
  17. */
  18. public void output(WireFeed feed,Writer writer,boolean prettyPrint) throws IllegalArgumentException,IOException, FeedException {
  19. Document doc = outputJDom(feed);
  20. String encoding = feed.getEncoding();
  21. Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  22. if (encoding!=null) {
  23. format.setEncoding(encoding);
  24. }
  25. XMLOutputter outputter = new XMLOutputter(format);
  26. outputter.output(doc,writer);
  27. }

代码示例来源:origin: rometools/rome

  1. format.setEncoding(encoding);

代码示例来源:origin: apache/marmotta

  1. /**
  2. * Creates a String with the XML representation for the given WireFeed.
  3. * <p>
  4. * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
  5. * of the developer to ensure that if the String is written to a character stream the stream charset is the same as
  6. * the feed encoding property.
  7. * <p>
  8. * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
  9. * <p>
  10. * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
  11. * the type given to the FeedOuptut constructor.
  12. * @param prettyPrint pretty-print XML (true) oder collapsed
  13. * @return a String with the XML representation for the given WireFeed.
  14. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
  15. * @throws FeedException thrown if the XML representation for the feed could not be created.
  16. *
  17. */
  18. public String outputString(WireFeed feed, boolean prettyPrint) throws IllegalArgumentException,FeedException {
  19. Document doc = outputJDom(feed);
  20. String encoding = feed.getEncoding();
  21. Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  22. if (encoding!=null) {
  23. format.setEncoding(encoding);
  24. }
  25. XMLOutputter outputter = new XMLOutputter(format);
  26. return outputter.outputString(doc);
  27. }

代码示例来源:origin: org.apache.marmotta/sesame-tools-rio-rss

  1. /**
  2. * Creates a String with the XML representation for the given WireFeed.
  3. * <p>
  4. * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
  5. * of the developer to ensure that if the String is written to a character stream the stream charset is the same as
  6. * the feed encoding property.
  7. * <p>
  8. * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
  9. * <p>
  10. * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
  11. * the type given to the FeedOuptut constructor.
  12. * @param prettyPrint pretty-print XML (true) oder collapsed
  13. * @return a String with the XML representation for the given WireFeed.
  14. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
  15. * @throws FeedException thrown if the XML representation for the feed could not be created.
  16. *
  17. */
  18. public String outputString(WireFeed feed, boolean prettyPrint) throws IllegalArgumentException,FeedException {
  19. Document doc = outputJDom(feed);
  20. String encoding = feed.getEncoding();
  21. Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  22. if (encoding!=null) {
  23. format.setEncoding(encoding);
  24. }
  25. XMLOutputter outputter = new XMLOutputter(format);
  26. return outputter.outputString(doc);
  27. }

代码示例来源:origin: com.rometools/rome

  1. format.setEncoding(encoding);

代码示例来源:origin: com.rometools/rome

  1. format.setEncoding(encoding);

代码示例来源:origin: org.apache.maven.plugins/maven-shade-plugin

  1. Format format = Format.getPrettyFormat().setEncoding( encoding );

代码示例来源:origin: Vhati/Slipstream-Mod-Manager

  1. format.setEncoding( encoding );

相关文章