當前位置: 首頁>>代碼示例>>Java>>正文


Java Format.setLineSeparator方法代碼示例

本文整理匯總了Java中org.jdom2.output.Format.setLineSeparator方法的典型用法代碼示例。如果您正苦於以下問題:Java Format.setLineSeparator方法的具體用法?Java Format.setLineSeparator怎麽用?Java Format.setLineSeparator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jdom2.output.Format的用法示例。


在下文中一共展示了Format.setLineSeparator方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sloppyPrint

import org.jdom2.output.Format; //導入方法依賴的package包/類
/**
 * 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 );
}
 
開發者ID:Vhati,項目名稱:Slipstream-Mod-Manager,代碼行數:43,代碼來源:SloppyXMLOutputProcessor.java

示例2: patch

import org.jdom2.output.Format; //導入方法依賴的package包/類
public static void patch(InputStream target, InputStream diff,
                         OutputStream result) throws IOException {

    try {
        Document targetDoc = XmlHelper.parse(target);
        Document diffDoc = XmlHelper.parse(diff);

        Element diffRoot = diffDoc.getRootElement();
        for (Object o : diffRoot.getChildren()) {
            patch(targetDoc, (Element) o);
        }

        XMLOutputter outputter = new XMLOutputter();

        // Use the separator that is appropriate for the platform.
        Format format = Format.getRawFormat();
        format.setLineSeparator(System.getProperty("line.separator"));
        outputter.setFormat(format);

        outputter.output(targetDoc, result);
    } catch (JDOMException e) {
        throw new PatchException(ErrorCondition.INVALID_DIFF_FORMAT, e);
    }
}
 
開發者ID:dnault,項目名稱:xml-patch,代碼行數:25,代碼來源:Patcher.java

示例3: getRawContents

import org.jdom2.output.Format; //導入方法依賴的package包/類
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();
}
 
開發者ID:ayakovlevgh,項目名稱:jodtemplate,代碼行數:9,代碼來源:JDOMHelper.java

示例4: convertElementToText

import org.jdom2.output.Format; //導入方法依賴的package包/類
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();
}
 
開發者ID:ayakovlevgh,項目名稱:jodtemplate,代碼行數:9,代碼來源:TestUtils.java

示例5: convertDocumentToText

import org.jdom2.output.Format; //導入方法依賴的package包/類
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();
}
 
開發者ID:ayakovlevgh,項目名稱:jodtemplate,代碼行數:9,代碼來源:TestUtils.java

示例6: sloppyPrint

import org.jdom2.output.Format; //導入方法依賴的package包/類
/**
 * 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 );
}
 
開發者ID:kartoFlane,項目名稱:superluminal2,代碼行數:24,代碼來源:SloppyXMLOutputProcessor.java

示例7: csToNmasXML

import org.jdom2.output.Format; //導入方法依賴的package包/類
static String csToNmasXML( final ChallengeSet cs, final String guidValue )
{
    final Element rootElement = new Element( NMAS_XML_ROOTNODE );
    rootElement.setAttribute( NMAS_XML_ATTR_RANDOM_COUNT, String.valueOf( cs.getMinRandomRequired() ) );
    if ( guidValue != null )
    {
        rootElement.setAttribute( "GUID", guidValue );
    }
    else
    {
        rootElement.setAttribute( "GUID", "0" );
    }

    for ( final Challenge challenge : cs.getChallenges() )
    {
        final Element loopElement = new Element( NMAS_XML_NODE_CHALLENGE );
        if ( challenge.getChallengeText() != null )
        {
            loopElement.setText( challenge.getChallengeText() );
        }

        if ( challenge.isAdminDefined() )
        {
            loopElement.setAttribute( NMAS_XML_ATTR_DEFINE, "Admin" );
        }
        else
        {
            loopElement.setAttribute( NMAS_XML_ATTR_DEFINE, "User" );
        }

        if ( challenge.isRequired() )
        {
            loopElement.setAttribute( NMAS_XML_ATTR_TYPE, "Required" );
        }
        else
        {
            loopElement.setAttribute( NMAS_XML_ATTR_TYPE, "Random" );
        }

        loopElement.setAttribute( NMAS_XML_ATTR_MIN_LENGTH, String.valueOf( challenge.getMinLength() ) );
        loopElement.setAttribute( NMAS_XML_ATTR_MAX_LENGTH, String.valueOf( challenge.getMaxLength() ) );

        rootElement.addContent( loopElement );
    }

    final XMLOutputter outputter = new XMLOutputter();
    final Format format = Format.getRawFormat();
    format.setTextMode( Format.TextMode.PRESERVE );
    format.setLineSeparator( "" );
    outputter.setFormat( format );
    return outputter.outputString( rootElement );
}
 
開發者ID:ldapchai,項目名稱:ldapchai,代碼行數:53,代碼來源:NmasResponseSet.java

示例8: write

import org.jdom2.output.Format; //導入方法依賴的package包/類
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);
}
 
開發者ID:ayakovlevgh,項目名稱:jodtemplate,代碼行數:7,代碼來源:JDOMHelper.java


注:本文中的org.jdom2.output.Format.setLineSeparator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。