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


Java CharacterEscapeHandler类代码示例

本文整理汇总了Java中com.sun.xml.bind.marshaller.CharacterEscapeHandler的典型用法代码示例。如果您正苦于以下问题:Java CharacterEscapeHandler类的具体用法?Java CharacterEscapeHandler怎么用?Java CharacterEscapeHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CharacterEscapeHandler类属于com.sun.xml.bind.marshaller包,在下文中一共展示了CharacterEscapeHandler类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertToXML

import com.sun.xml.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
/**
 * Object to XML
 * @param object object
 * @return xml
 */
public static String convertToXML(Object object){
	try {
		Map<Class<?>, Marshaller> mMap = mMapLocal.get();
		if(!mMap.containsKey(object.getClass())){
			JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
			Marshaller marshaller = jaxbContext.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
			//设置CDATA输出字符
			marshaller.setProperty(CharacterEscapeHandler.class.getName(), new CharacterEscapeHandler() {
				public void escape(char[] ac, int i, int j, boolean flag, Writer writer) throws IOException {
					writer.write(ac, i, j);
				}
			});
			mMap.put(object.getClass(), marshaller);
		}
		StringWriter stringWriter = new StringWriter();
		mMap.get(object.getClass()).marshal(object,stringWriter);
		return stringWriter.getBuffer().toString();
	} catch (JAXBException e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:29,代码来源:XMLConverUtil.java

示例2: convertToXML

import com.sun.xml.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
/**
 * Object to XML
 * @param object
 * @return
 */
public static String convertToXML(Object object){
	try {
		if(!mMap.containsKey(object.getClass())){
			JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
			Marshaller marshaller = jaxbContext.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            marshaller.setProperty(CharacterEscapeHandler.class.getName(), new CharacterEscapeHandler() {
                public void escape(char[] ac, int i, int j, boolean flag,Writer writer) throws IOException {
                writer.write( ac, i, j ); }
            });
			mMap.put(object.getClass(), marshaller);
		}
		StringWriter stringWriter = new StringWriter();
		mMap.get(object.getClass()).marshal(object,stringWriter);
		return stringWriter.getBuffer().toString();
	} catch (JAXBException e) {
		Exceptions.printException(e);;
	}
	return null;
}
 
开发者ID:simbest,项目名称:simbest-cores,代码行数:26,代码来源:XMLConverUtil.java

示例3: createEscapeHandler

import com.sun.xml.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
protected CharacterEscapeHandler createEscapeHandler( String encoding ) {
    if( escapeHandler!=null )
        // user-specified one takes precedence.
        return escapeHandler;
    
    if( encoding.startsWith("UTF") )
        // no need for character reference. Use the handler
        // optimized for that pattern.
        return MinimumEscapeHandler.theInstance;
    
    // otherwise try to find one from the encoding
    try {
        // try new JDK1.4 NIO
        return new NioEscapeHandler( getJavaEncoding(encoding) );
    } catch( Throwable e ) {
        // if that fails, fall back to the dumb mode
        return DumbEscapeHandler.theInstance;
    }
}
 
开发者ID:nhrdl,项目名称:javacash,代码行数:20,代码来源:MarshallerImpl.java

示例4: setProperty

import com.sun.xml.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
public void setProperty(String name, Object value) throws PropertyException {
    if( INDENT_STRING.equals(name) && value instanceof String ) {
        indent = (String)value;
        return;
    }
    if( ENCODING_HANDLER.equals(name) ) {
        escapeHandler = (CharacterEscapeHandler)value;
        return;
    }
    if( PREFIX_MAPPER.equals(name) ) {
        prefixMapper = (NamespacePrefixMapper)value;
        return;
    }
    if( XMLDECLARATION.equals(name) ) {
        printXmlDeclaration = ((Boolean)value).booleanValue();
        return;
    }
    if( XML_HEADERS.equals(name) ) {
        header = (String)value;
        return;
    }
        
    super.setProperty(name, value);
}
 
开发者ID:nhrdl,项目名称:javacash,代码行数:25,代码来源:MarshallerImpl.java

示例5: getMarshaller

import com.sun.xml.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
public static Marshaller getMarshaller() throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(Node.class, Property.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setProperty(INDENT_STRING, INDENTATION);
    marshaller.setProperty(CharacterEscapeHandler.class.getName(), (CharacterEscapeHandler) (chars, start, length, isAttVal, writer) -> {
        boolean cdata = new String(chars).trim().startsWith(CDATA_START);
        if (cdata) {
            writer.write(chars, start, length);
        } else {
            MinimumEscapeHandler.theInstance.escape(chars, start, length, isAttVal, writer);
        }
    });
    return marshaller;
}
 
开发者ID:openweb-nl,项目名称:hippo-groovy-updater,代码行数:16,代码来源:Marshal.java

示例6: main

import com.sun.xml.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
public static void main( String[] args ) throws Exception {
    
    // create JAXBContext for the primer.xsd
    JAXBContext context = JAXBContext.newInstance(ObjectFactory.class);
    ObjectFactory of = new ObjectFactory();
    
    // \u00F6 is o with diaeresis
    JAXBElement<String> e = of.createE("G\u00F6del & his friends");
    
    
    // set up a normal marshaller
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty( "jaxb.encoding", "US-ASCII" );
    marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
    
    // check out the console output
    marshaller.marshal( e, System.out );
    
    
    // set up a marshaller with a custom character encoding handler
    marshaller = context.createMarshaller();
    marshaller.setProperty( "jaxb.encoding", "US-ASCII" );
    marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
    marshaller.setProperty(
      CharacterEscapeHandler.class.getName(),
      new CustomCharacterEscapeHandler() );
    
    // check out the console output
    marshaller.marshal( e, System.out );
}
 
开发者ID:IntershopCommunicationsAG,项目名称:jaxb-gradle-plugin,代码行数:31,代码来源:Main.java

示例7: StreamingMarshalXml

import com.sun.xml.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
StreamingMarshalXml(final OutputStream outputStream, String root) {
    try {
        this.root = root;

        xmlOut = new NamespaceSuppressingOutputStream(outputStream);

        marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(CharacterEscapeHandler.class.getName(), NEWLINE_ESCAPE_HANDLER);

    } catch (JAXBException e) {
        throw new StreamingException(e);
    }
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:16,代码来源:StreamingMarshalXml.java


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