本文整理汇总了Java中com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler类的典型用法代码示例。如果您正苦于以下问题:Java CharacterEscapeHandler类的具体用法?Java CharacterEscapeHandler怎么用?Java CharacterEscapeHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CharacterEscapeHandler类属于com.sun.xml.internal.bind.marshaller包,在下文中一共展示了CharacterEscapeHandler类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IndentingUTF8XmlOutput
import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
/**
*
* @param indentStr
* set to null for no indentation and optimal performance.
* otherwise the string is used for indentation.
*/
public IndentingUTF8XmlOutput(OutputStream out, String indentStr, Encoded[] localNames, CharacterEscapeHandler escapeHandler) {
super(out, localNames, escapeHandler);
if(indentStr!=null) {
Encoded e = new Encoded(indentStr);
indent8 = new Encoded();
indent8.ensureSize(e.len*8);
unitLen = e.len;
for( int i=0; i<8; i++ )
System.arraycopy(e.buf, 0, indent8.buf, unitLen*i, unitLen);
} else {
this.indent8 = null;
this.unitLen = 0;
}
}
示例2: createEscapeHandler
import com.sun.xml.internal.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;
}
}
示例3: marshal
import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
public static String marshal(Object bean, Class... types) {
StringWriter sw = new StringWriter();
try {
JAXBContext carContext = JAXBContext.newInstance(types);
Marshaller marshaller = carContext.createMarshaller();
// marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
// marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); // without xml declaration
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(CharacterEscapeHandler.class.getName(), OnDemandCDataEscapeHandler.instance);
marshaller.marshal(bean, sw);
return sw.toString();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
示例4: convertToXML
import com.sun.xml.internal.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) {
e.printStackTrace();
}
return null;
}
示例5: C14nXmlOutput
import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
public C14nXmlOutput(OutputStream out, Encoded[] localNames, boolean namedAttributesAreOrdered, CharacterEscapeHandler escapeHandler) {
super(out, localNames, escapeHandler);
this.namedAttributesAreOrdered = namedAttributesAreOrdered;
for( int i=0; i<staticAttributes.length; i++ )
staticAttributes[i] = new StaticAttribute();
}
示例6: UTF8XmlOutput
import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
/**
*
* @param localNames
* local names encoded in UTF-8.
*/
public UTF8XmlOutput(OutputStream out, Encoded[] localNames, CharacterEscapeHandler escapeHandler) {
this.out = out;
this.localNames = localNames;
for( int i=0; i<prefixes.length; i++ )
prefixes[i] = new Encoded();
this.escapeHandler = escapeHandler;
}
示例7: setProperty
import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
@Override
public void setProperty(String name, Object value) throws PropertyException {
if( INDENT_STRING.equals(name) ) {
checkString(name, value);
indent = (String)value;
return;
}
if( ENCODING_HANDLER.equals(name) || ENCODING_HANDLER2.equals(name)) {
if(!(value instanceof CharacterEscapeHandler))
throw new PropertyException(
Messages.MUST_BE_X.format(
name,
CharacterEscapeHandler.class.getName(),
value.getClass().getName() ) );
escapeHandler = (CharacterEscapeHandler)value;
return;
}
if( PREFIX_MAPPER.equals(name) ) {
if(!(value instanceof NamespacePrefixMapper))
throw new PropertyException(
Messages.MUST_BE_X.format(
name,
NamespacePrefixMapper.class.getName(),
value.getClass().getName() ) );
prefixMapper = (NamespacePrefixMapper)value;
return;
}
if( XMLDECLARATION.equals(name) ) {
checkBoolean(name, value);
// com.sun.xml.internal.bind.xmlDeclaration is an alias for JAXB_FRAGMENT
// setting it to false is treated the same as setting fragment to true.
super.setProperty(JAXB_FRAGMENT, !(Boolean)value);
return;
}
if( XML_HEADERS.equals(name) ) {
checkString(name, value);
header = (String)value;
return;
}
if( C14N.equals(name) ) {
checkBoolean(name,value);
c14nSupport = (Boolean)value;
return;
}
if (OBJECT_IDENTITY_CYCLE_DETECTION.equals(name)) {
checkBoolean(name,value);
serializer.setObjectIdentityCycleDetection((Boolean)value);
return;
}
super.setProperty(name, value);
}
示例8: XMLStreamWriterOutput
import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
protected XMLStreamWriterOutput(XMLStreamWriter out, CharacterEscapeHandler escapeHandler) {
this.out = out;
this.escapeHandler = escapeHandler;
this.writerWrapper = new XmlStreamOutWriterAdapter(out);
}
示例9: getEscapeHandler
import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler; //导入依赖的package包/类
/**
* Returns escape handler provided with JAXB context parameters.
*
* @return escape handler
*/
CharacterEscapeHandler getEscapeHandler() {
return escapeHandler;
}