本文整理汇总了Java中org.apache.xml.serializer.Serializer.getOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java Serializer.getOutputStream方法的具体用法?Java Serializer.getOutputStream怎么用?Java Serializer.getOutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xml.serializer.Serializer
的用法示例。
在下文中一共展示了Serializer.getOutputStream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: switchSerializerIfHTML
import org.apache.xml.serializer.Serializer; //导入方法依赖的package包/类
/**
* Switch to HTML serializer if element is HTML
*
*
* @param transformer Non-null transformer instance
* @param ns Namespace URI of the element
* @param localName Local part of name of element
*
* @throws TransformerException
*/
public static void switchSerializerIfHTML(
TransformerImpl transformer, String ns, String localName)
throws TransformerException
{
if (null == transformer)
return;
if (((null == ns) || (ns.length() == 0))
&& localName.equalsIgnoreCase("html"))
{
// System.out.println("transformer.getOutputPropertyNoDefault(OutputKeys.METHOD): "+
// transformer.getOutputPropertyNoDefault(OutputKeys.METHOD));
// Access at level of hashtable to see if the method has been set.
if (null != transformer.getOutputPropertyNoDefault(OutputKeys.METHOD))
return;
// Getting the output properties this way won't cause a clone of
// the properties.
Properties prevProperties = transformer.getOutputFormat().getProperties();
// We have to make sure we get an output properties with the proper
// defaults for the HTML method. The easiest way to do this is to
// have the OutputProperties class do it.
OutputProperties htmlOutputProperties = new OutputProperties(Method.HTML);
htmlOutputProperties.copyFrom(prevProperties, true);
Properties htmlProperties = htmlOutputProperties.getProperties();
try
{
// Serializer oldSerializer = transformer.getSerializer();
Serializer oldSerializer = null;
if (null != oldSerializer)
{
Serializer serializer =
SerializerFactory.getSerializer(htmlProperties);
Writer writer = oldSerializer.getWriter();
if (null != writer)
serializer.setWriter(writer);
else
{
OutputStream os = oldSerializer.getOutputStream();
if (null != os)
serializer.setOutputStream(os);
}
// transformer.setSerializer(serializer);
ContentHandler ch = serializer.asContentHandler();
transformer.setContentHandler(ch);
}
}
catch (java.io.IOException e)
{
throw new TransformerException(e);
}
}
}