Java 类org.jdom2.output.LineSeparator 实例源码

项目:Slipstream-Mod-Manager    文件:SloppyXMLOutputProcessor.java   
/**
 * Creates an outputter and writes an XML tree.
 *
 * The encoding argument here only sets an attribute in the
 * XML declaration. It's up to the caller to ensure the writer
 * is encoding bytes to match. If encoding is null, the default
 * is "UTF-8".
 *
 * If XML character entity escaping is allowed, otherwise unmappable
 * characters may be written without errors. If disabled, an
 * UnmappableCharacterException will make their presence obvious and fatal.
 *
 * LineEndings will be CR-LF. Except for comments!?
 *
 * @param doc
 * @param writer
 * @param disableEscaping
 */
public static void sloppyPrint( Document doc, Writer writer, String encoding, boolean allowEscaping ) throws IOException {
    Format format = Format.getPrettyFormat();
    format.setTextMode( Format.TextMode.PRESERVE );  // Permit leading/trailing space.
    format.setExpandEmptyElements( false );
    format.setOmitDeclaration( false );
    format.setIndent( "\t" );
    format.setLineSeparator( LineSeparator.CRNL );

    if ( encoding != null ) {
        format.setEncoding( encoding );
    }

    if ( !allowEscaping ) {
        format.setEscapeStrategy(new EscapeStrategy() {
            @Override
            public boolean shouldEscape( char ch ) {
                return false;
            }
        });
    }

    XMLOutputter outputter = new XMLOutputter( format, new SloppyXMLOutputProcessor() );
    outputter.output( doc, writer );
}
项目:jodtemplate    文件:JDOMHelper.java   
public String getRawContents(final Document dom) throws IOException {
    final Format format = Format.getRawFormat();
    format.setLineSeparator(LineSeparator.UNIX);
    final XMLOutputter outputter = new XMLOutputter(format, new StandaloneOutputProcessor());
    final Writer writer = new StringWriter();
    outputter.output(dom, writer);
    return writer.toString();
}
项目:jodtemplate    文件:TestUtils.java   
public static String convertElementToText(final Element element) throws IOException {
    final Format format = Format.getRawFormat();
    format.setLineSeparator(LineSeparator.UNIX);
    final XMLOutputter outputter = new XMLOutputter(format, new StandaloneOutputProcessor());
    final Writer writer = new StringWriter();
    outputter.output(element, writer);
    return writer.toString();
}
项目:jodtemplate    文件:TestUtils.java   
public static String convertDocumentToText(final Document document) throws IOException {
    final Format format = Format.getRawFormat();
    format.setLineSeparator(LineSeparator.UNIX);
    final XMLOutputter outputter = new XMLOutputter(format, new StandaloneOutputProcessor());
    final Writer writer = new StringWriter();
    outputter.output(document, writer);
    return writer.toString();
}
项目:pikes    文件:ReadWriteManager.java   
/**
     * Returns a string containing the XML content of a KAFDocument object.
     */
    static String kafToStr(KAFDocument kaf) {
        XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setLineSeparator(LineSeparator.UNIX));
//      out.getFormat().setTextMode(Format.TextMode.PRESERVE);
        Document jdom = KAFToDOM(kaf);
        return out.outputString(jdom);
    }
项目:superluminal2    文件:SloppyXMLOutputProcessor.java   
/**
 * Creates an outputter and writes an XML tree.
 *
 * The encoding argument here only sets an attribute in the
 * XML declaration. It's up to the caller to ensure the writer
 * is encoding bytes to match. If encoding is null, the default
 * is "UTF-8".
 *
 * LineEndings will be CR-LF. Except for comments!?
 */
public static void sloppyPrint( Document doc, Writer writer, String encoding ) throws IOException
{
    Format format = Format.getPrettyFormat();
    format.setExpandEmptyElements( false );
    format.setOmitDeclaration( false );
    format.setIndent( "\t" );
    format.setLineSeparator( LineSeparator.CRNL );

    if ( encoding != null ) format.setEncoding( encoding );

    XMLOutputter outputter = new XMLOutputter( format, new SloppyXMLOutputProcessor() );
    outputter.output( doc, writer );
}
项目:pom-manipulation-ext    文件:PomIO.java   
private static LineSeparator determineEOL( File pom )
    throws ManipulationException
{
    try (  BufferedInputStream bufferIn = new BufferedInputStream( new FileInputStream( pom ) ) )
    {
        int prev = -1;
        int ch;
        while ( ( ch = bufferIn.read() ) != -1 )
        {
            if ( ch == '\n' )
            {
                if ( prev == '\r' )
                {
                    return LineSeparator.CRNL;
                }
                else
                {
                    return LineSeparator.NL;
                }
            }
            else if ( prev == '\r' )
            {
                return LineSeparator.CR;
            }
            prev = ch;
        }
        throw new ManipulationException( "Could not determine end-of-line marker mode" );
    }
    catch ( IOException ioe )
    {
        throw new ManipulationException( "Could not determine end-of-line marker mode", ioe );
    }
}
项目:Elixa    文件:ReadWriteManager.java   
/** Returns a string containing the XML content of a KAFDocument object. */
   static String kafToStr(KAFDocument kaf) {
XMLOutputter out = new XMLOutputter(Format.getPrettyFormat().setLineSeparator(LineSeparator.UNIX).setTextMode(Format.TextMode.TRIM_FULL_WHITE));
Document jdom = KAFToDOM(kaf);
return out.outputString(jdom);
   }
项目:jodtemplate    文件:JDOMHelper.java   
public void write(final Document dom, final OutputStream stream) throws IOException {
    final Format format = Format.getRawFormat();
    format.setLineSeparator(LineSeparator.UNIX);
    final XMLOutputter outputter = new XMLOutputter(format, new StandaloneOutputProcessor());
    outputter.output(dom, stream);
}