当前位置: 首页>>代码示例>>Java>>正文


Java Format.setTextMode方法代码示例

本文整理汇总了Java中org.jdom2.output.Format.setTextMode方法的典型用法代码示例。如果您正苦于以下问题:Java Format.setTextMode方法的具体用法?Java Format.setTextMode怎么用?Java Format.setTextMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jdom2.output.Format的用法示例。


在下文中一共展示了Format.setTextMode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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


注:本文中的org.jdom2.output.Format.setTextMode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。