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


Java Serializer.asContentHandler方法代码示例

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


在下文中一共展示了Serializer.asContentHandler方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createContentHandler

import org.apache.xml.serializer.Serializer; //导入方法依赖的package包/类
/**
 * @param outputStream The output
 * @return A content handler
 * @throws IOException When there's an XML error
 */
private ContentHandler createContentHandler(OutputStream outputStream) throws IOException {
  Properties outputProperties = OutputPropertiesFactory.getDefaultMethodProperties(Method.XML);
  outputProperties.setProperty("indent", "yes");
  outputProperties.setProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT, "2");
  outputProperties.setProperty(OutputPropertiesFactory.S_KEY_LINE_SEPARATOR, "\n");
  Serializer serializer = SerializerFactory.getSerializer(outputProperties);
  serializer.setOutputStream(outputStream);
  return serializer.asContentHandler();
}
 
开发者ID:alfasoftware,项目名称:morf,代码行数:15,代码来源:XmlDataSetConsumer.java

示例2: startElement

import org.apache.xml.serializer.Serializer; //导入方法依赖的package包/类
/**
 * Receive notification of the start of an element.
 *
 * <p>By default, do nothing.  Application writers may override this
 * method in a subclass to take specific actions at the start of
 * each element (such as allocating a new tree node or writing
 * output to a file).</p>
 *
 * @param uri The Namespace URI, or the empty string if the
 *        element has no Namespace URI or if Namespace
 *        processing is not being performed.
 * @param localName The local name (without prefix), or the
 *        empty string if Namespace processing is not being
 *        performed.
 * @param qName The qualified name (with prefix), or the
 *        empty string if qualified names are not available.
 * @param attributes The specified or defaulted attributes.
 * @throws org.xml.sax.SAXException Any SAX exception, possibly
 *            wrapping another exception.
 * @see org.xml.sax.ContentHandler#startElement
 *
 * @throws SAXException
 */
public void startElement(
        String uri, String localName, String qName, Attributes attributes)
          throws SAXException
{

  if (!m_foundFirstElement && null != m_serializer)
  {
    m_foundFirstElement = true;

    Serializer newSerializer;

    try
    {
      newSerializer = SerializerSwitcher.switchSerializerIfHTML(uri,
              localName, m_outputFormat.getProperties(), m_serializer);
    }
    catch (TransformerException te)
    {
      throw new SAXException(te);
    }

    if (newSerializer != m_serializer)
    {
      try
      {
        m_resultContentHandler = newSerializer.asContentHandler();
      }
      catch (IOException ioe)  // why?
      {
        throw new SAXException(ioe);
      }

      if (m_resultContentHandler instanceof DTDHandler)
        m_resultDTDHandler = (DTDHandler) m_resultContentHandler;

      if (m_resultContentHandler instanceof LexicalHandler)
        m_resultLexicalHandler = (LexicalHandler) m_resultContentHandler;

      m_serializer = newSerializer;
    }
  }
  flushStartDoc();
  m_resultContentHandler.startElement(uri, localName, qName, attributes);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:68,代码来源:TransformerIdentityImpl.java

示例3: 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);
      }
    }
  }
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:75,代码来源:SerializerSwitcher.java


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