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

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

本文整理了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

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

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

/**
 * Creates a new Format instance with default (raw) behavior.
 */
private Format() {
  setEncoding(STANDARD_ENCODING);
}

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

public static void outputDocument( final Document document, final OutputStream outputStream )
    throws IOException
{
  final Format format = Format.getPrettyFormat();
  format.setEncoding( STORAGE_CHARSET.toString() );
  final XMLOutputter outputter = new XMLOutputter();
  outputter.setFormat( format );
  try ( Writer writer = new OutputStreamWriter( outputStream, STORAGE_CHARSET ) )
  {
    outputter.output( document, writer );
  }
}

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

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

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

/**
 * Method write
 *
 * @param project
 * @param writer
 * @param document
 */
public void write( Model project, Document document, OutputStreamWriter writer )
  throws java.io.IOException
{
  Format format = Format.getRawFormat();
  format.setEncoding( writer.getEncoding() ).setLineSeparator( System.getProperty( "line.separator" ) );
  write( project, document, writer, format );
} // -- void write(Model, Document, OutputStreamWriter)

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

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

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

/**
   * This method just saves a JDOM document to a file automatically closes {@link OutputStream}.
   *
   * @param mcrUser
   *            the JDOM XML document to be printed
   * @param outFile
   *            a FileOutputStream object for the output
   * @throws IOException
   *             if output file can not be closed
   */
  private static void saveToXMLFile(MCRUser mcrUser, FileOutputStream outFile) throws MCRException, IOException {
    // Create the output
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setEncoding(MCRConstants.DEFAULT_ENCODING));

    try {
      outputter.output(MCRUserTransformer.buildExportableXML(mcrUser), outFile);
    } catch (Exception e) {
      throw new MCRException("Error while save XML to file: " + e.getMessage());
    } finally {
      outFile.close();
    }
  }
}

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

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

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

private static void writeXML( ModsInfo modsInfo, OutputStreamWriter dst, String indent, int depth ) throws IOException {
  Format xmlFormat = Format.getPrettyFormat();
  xmlFormat.setEncoding( dst.getEncoding() );
  XMLOutputter xmlOut = new XMLOutputter( xmlFormat );
  writeIndent( dst, indent, depth++ ).append( "<modsinfo>\n" );
  writeIndent( dst, indent, depth ); dst.append("<title>").append( xmlOut.escapeElementEntities( modsInfo.getTitle() ) ).append( "</title>\n" );
  writeIndent( dst, indent, depth ); dst.append("<author>").append( xmlOut.escapeElementEntities( modsInfo.getAuthor() ) ).append( "</author>\n" );
  writeIndent( dst, indent, depth ); dst.append("<threadUrl><![CDATA[ ").append( modsInfo.getThreadURL() ).append( " ]]></threadUrl>\n" );
  writeIndent( dst, indent, depth++ ).append( "<versions>\n" );
  for ( Map.Entry<String,String> entry : modsInfo.getVersionsMap().entrySet() ) {
    String versionFileHash = entry.getKey();
    String versionString = entry.getValue();
    writeIndent( dst, indent, depth );
    dst.append( "<version hash=\"" ).append( xmlOut.escapeAttributeEntities( versionFileHash ) ).append( "\">" );
    dst.append( xmlOut.escapeElementEntities( versionString ) );
    dst.append( "</version>" ).append( "\n" );
  }
  writeIndent( dst, indent, --depth ).append( "</versions>\n" );
  writeIndent( dst, indent, depth ); dst.append("<threadHash>").append( modsInfo.getThreadHash() ).append( "</threadHash>\n" );
  dst.append( "\n" );
  writeIndent( dst, indent, depth ); dst.append( "<description>" ).append( "<![CDATA[" );
  dst.append( modsInfo.getDescription() );
  dst.append( "]]>\n" );
  writeIndent( dst, indent, depth ); dst.append( "</description>\n" );
  writeIndent( dst, indent, --depth ).append( "</modsinfo>\n" );
}

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

public void move(String from, String to) {
  try {
    // get from
    URL fromURL = MCRWebPagesSynchronizer.getURL(from);
    Document document;
    if (fromURL == null) {
      // if the from resource couldn't be found we assume its not created yet.
      MyCoReWebPageProvider wpp = new MyCoReWebPageProvider();
      wpp.addSection("neuer Eintrag", new Element("p").setText("TODO"), "de");
      document = wpp.getXML();
    } else {
      SAXBuilder builder = new SAXBuilder();
      document = builder.build(fromURL);
    }
    // save
    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setEncoding("UTF-8"));
    try (OutputStream fout = MCRWebPagesSynchronizer.getOutputStream(to)) {
      out.output(document, fout);
    }
    // delete old
    if (fromURL != null) {
      Files.delete(Paths.get(fromURL.toURI()));
    }
  } catch (Exception exc) {
    LOGGER.error("Error moving {} to {}", from, to, exc);
    throwError(ErrorType.couldNotMove, to);
  }
}

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

/**
 * 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);
}

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

format.setEncoding(encoding);

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

/**
 * 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);
}

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

format.setEncoding(encoding);

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

/**
 * 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);
}

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

/**
 * 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);
}

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

format.setEncoding(encoding);

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

format.setEncoding(encoding);

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

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

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

format.setEncoding( encoding );

相关文章