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

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

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

Format.setIndent介绍

[英]This will set the indent String to use; this is usually a String of empty spaces. If you pass the empty string (""), then no indentation will happen but newlines will still be generated. Passing null will result in no indentation and no newlines generated. Default: none (null)
[中]这将设置要使用的缩进String;这通常是String个空格。如果传递空字符串(“”),则不会发生缩进,但仍会生成换行。传递null将不会产生缩进和换行。默认值:无(空)

代码示例

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

/**
 * Returns a new Format object that performs whitespace beautification with
 * 2-space indents, uses the UTF-8 encoding, doesn't expand empty elements,
 * includes the declaration and encoding, and uses the default entity
 * escape strategy.
 * Tweaks can be made to the returned Format instance without affecting
 * other instances.
 *
 * @return                     a Format with whitespace beautification
 */
public static Format getPrettyFormat() {
  Format f = new Format();
  f.setIndent(STANDARD_INDENT);
  f.setTextMode(TextMode.TRIM);
  return f;
}

代码示例来源: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.mycore/mycore-xeditor

/**
   * There are dummy attributes in the root element of the XSL, which are removed here.
   * Those attributes were generated during transformation to force passing through namespace nodes.
   */
  private MCRContent removeDummyAttributes(MCRContent xsl) throws JDOMException, IOException, SAXException {
    Document doc = xsl.asXML();
    List<Attribute> attributes = doc.getRootElement().getAttributes();

    for (Iterator<Attribute> iter = attributes.iterator(); iter.hasNext();) {
      if ("dummy".equals(iter.next().getName())) {
        iter.remove();
      }
    }
    MCRJDOMContent out = new MCRJDOMContent(doc);
    out.setFormat(Format.getPrettyFormat().setIndent("  "));
    return out;
  }
}

代码示例来源:origin: ssaring/sportstracker

/**
   * Writes the specified JDOM element to the XML file specified by filename.
   * The file will use UTF-8 encoding and has 4-space indentation.
   *
   * @param eRoot root element of the XML document
   * @param filename filename of the XML file to create
   * @throws IOException
   */
  public static void writeXMLFile(Element eRoot, String filename) throws IOException {

    Document document = new Document(eRoot);
    XMLOutputter outputter = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    format.setLineSeparator(System.getProperty("line.separator"));
    format.setIndent("    ");
    outputter.setFormat(format);

    // FileWriter can't be used here, because default encoding on Win32 isn't UTF-8
    try (OutputStreamWriter osWriter = new OutputStreamWriter(new FileOutputStream(filename), "UTF-8")) {
      outputter.output(document, osWriter);
      osWriter.flush();
    }
  }
}

代码示例来源:origin: org.opencadc/caom2

fmt.setIndent("  "); // 2 spaces

代码示例来源:origin: io.wcm.tooling.commons/io.wcm.tooling.commons.crx-packmgr-helper

private void writeXmlWithExcludes(InputStream inputStream, OutputStream outputStream, Set<String> namespacePrefixes)
  throws IOException, JDOMException {
 SAXBuilder saxBuilder = new SAXBuilder();
 Document doc = saxBuilder.build(inputStream);
 Set<String> namespacePrefixesActuallyUsed = new HashSet<>();
 applyXmlExcludes(doc.getRootElement(), "", namespacePrefixesActuallyUsed);
 XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()
   .setIndent("    ")
   .setLineSeparator(LineSeparator.UNIX));
 outputter.setXMLOutputProcessor(new OneAttributePerLineXmlProcessor(namespacePrefixes, namespacePrefixesActuallyUsed));
 outputter.output(doc, outputStream);
 outputStream.flush();
}

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

/**
 * Writes the internal xml after validation to file.
 * 
 * @param localDoc
 *            the local doc
 * @param outFilename
 *            the output file name
 */
public static void writeInternalXmlToFile(Document localDoc, String outFilename) {
  final PrintWriter writer = FileUtils.getWriter(outFilename);
  final XMLOutputter outputter = new XMLOutputter();
  Format format = Format.getPrettyFormat();
  format.setIndent("    ");
  format.setLineSeparator("\n");
  outputter.setFormat(format);
  outputter.setFormat(format);
  try {
    LOG.info("  write internal xml after validation to file \"" + outFilename + "\"");
    outputter.output(localDoc, writer);
  } catch (final Exception e) {
    e.printStackTrace();
  }
}

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

/**
 * 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 );
} // -- void write(Model, Document, OutputStream)

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

format.setExpandEmptyElements( false );
format.setOmitDeclaration( false );
format.setIndent( "\t" );
format.setLineSeparator( LineSeparator.CRNL );

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

format.setIndent( "\t" );
format.setLineSeparator( LineSeparator.CRNL );

相关文章