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


Java ErrorListener类代码示例

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


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

示例1: createTransformerHandler

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
public static TransformerHandler createTransformerHandler(final ErrorListener errorListener,
                                                          final boolean indentOutput) throws TransformerConfigurationException {
    final SAXTransformerFactory stf = (SAXTransformerFactory) TransformerFactoryFactory.newInstance();
    if (errorListener != null) {
        stf.setErrorListener(errorListener);
    }

    final TransformerHandler th = stf.newTransformerHandler();
    final Transformer transformer = th.getTransformer();
    setCommonOutputProperties(transformer, indentOutput);

    if (errorListener != null) {
        transformer.setErrorListener(errorListener);
    }

    return th;
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:18,代码来源:XMLUtil.java

示例2: newXMLFilter

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
public XMLFilter newXMLFilter(Templates templates)
    throws TransformerConfigurationException {
    try {
        return new com.sun.org.apache.xalan.internal.xsltc.trax.TrAXFilter(templates);
    }
    catch(TransformerConfigurationException e1) {
        if (_xsltcFactory == null) {
            createXSLTCTransformerFactory();
        }
        ErrorListener errorListener = _xsltcFactory.getErrorListener();
        if(errorListener != null) {
            try {
                errorListener.fatalError(e1);
                return null;
            }
            catch( TransformerException e2) {
                new TransformerConfigurationException(e2);
            }
        }
        throw e1;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:SmartTransformerFactoryImpl.java

示例3: warn

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * Warn the user of an problem.
 *
 * @param xctxt The XPath runtime context.
 * @param sourceNode Not used.
 * @param msg An error msgkey that corresponds to one of the constants found
 *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
 *            a key for a format string.
 * @param args An array of arguments represented in the format string, which
 *             may be null.
 *
 * @throws TransformerException if the current ErrorListoner determines to
 *                              throw an exception.
 */
public void warn(
        XPathContext xctxt, int sourceNode, String msg, Object[] args)
          throws javax.xml.transform.TransformerException
{

  String fmsg = XSLMessages.createXPATHWarning(msg, args);
  ErrorListener ehandler = xctxt.getErrorListener();

  if (null != ehandler)
  {

    // TO DO: Need to get stylesheet Locator from here.
    ehandler.warning(new TransformerException(fmsg, (SAXSourceLocator)xctxt.getSAXLocator()));
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:XPath.java

示例4: error

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * Tell the user of an error, and probably throw an
 * exception.
 *
 * @param xctxt The XPath runtime context.
 * @param sourceNode Not used.
 * @param msg An error msgkey that corresponds to one of the constants found
 *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
 *            a key for a format string.
 * @param args An array of arguments represented in the format string, which
 *             may be null.
 *
 * @throws TransformerException if the current ErrorListoner determines to
 *                              throw an exception.
 */
public void error(
        XPathContext xctxt, int sourceNode, String msg, Object[] args)
          throws javax.xml.transform.TransformerException
{

  String fmsg = XSLMessages.createXPATHMessage(msg, args);
  ErrorListener ehandler = xctxt.getErrorListener();

  if (null != ehandler)
  {
    ehandler.fatalError(new TransformerException(fmsg,
                            (SAXSourceLocator)xctxt.getSAXLocator()));
  }
  else
  {
    SourceLocator slocator = xctxt.getSAXLocator();
    System.out.println(fmsg + "; file " + slocator.getSystemId()
                       + "; line " + slocator.getLineNumber() + "; column "
                       + slocator.getColumnNumber());
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:XPath.java

示例5: warn

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * Warn the user of a problem.
 *
 * @param msg An error msgkey that corresponds to one of the constants found
 *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
 *            a key for a format string.
 * @param args An array of arguments represented in the format string, which
 *             may be null.
 *
 * @throws TransformerException if the current ErrorListoner determines to
 *                              throw an exception.
 */
void warn(String msg, Object[] args) throws TransformerException
{

  String fmsg = XSLMessages.createXPATHWarning(msg, args);
  ErrorListener ehandler = this.getErrorListener();

  if (null != ehandler)
  {
    // TO DO: Need to get stylesheet Locator from here.
    ehandler.warning(new TransformerException(fmsg, m_sourceLocator));
  }
  else
  {
    // Should never happen.
    System.err.println(fmsg);
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:XPathParser.java

示例6: error

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * Notify the user of an error, and probably throw an
 * exception.
 *
 * @param msg An error msgkey that corresponds to one of the constants found
 *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
 *            a key for a format string.
 * @param args An array of arguments represented in the format string, which
 *             may be null.
 *
 * @throws TransformerException if the current ErrorListoner determines to
 *                              throw an exception.
 */
void error(String msg, Object[] args) throws TransformerException
{

  String fmsg = XSLMessages.createXPATHMessage(msg, args);
  ErrorListener ehandler = this.getErrorListener();

  TransformerException te = new TransformerException(fmsg, m_sourceLocator);
  if (null != ehandler)
  {
    // TO DO: Need to get stylesheet Locator from here.
    ehandler.fatalError(te);
  }
  else
  {
    // System.err.println(fmsg);
    throw te;
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:XPathParser.java

示例7: setErrorListener

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * Setter for {@link #m_aErrorListener}
 *
 * @param errorListener
 *        The <code>ErrorListener</code> object.
 * @throws IllegalArgumentException
 */
@Override
public void setErrorListener (final ErrorListener errorListener) throws IllegalArgumentException
{

  synchronized (m_aReentryGuard)
  {
    if (CSTX.DEBUG)
      log.debug ("setting ErrorListener");
    if (errorListener == null)
    {
      throw new IllegalArgumentException ("ErrorListener is null");
    }
    this.m_aErrorListener = errorListener;
    m_aDefaultErrorListener.setUserErrorListener (errorListener);
  }
}
 
开发者ID:phax,项目名称:ph-stx,代码行数:24,代码来源:TransformerFactoryImpl.java

示例8: exampleIdentity

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * Show the Identity-transformation
 */
public static boolean exampleIdentity (final String sourceID) throws TransformerException,
                                                              TransformerConfigurationException
{

  // Create a transform factory instance.
  final TransformerFactory tfactory = TransformerFactory.newInstance ();
  // register own ErrorListener for the TransformerFactory
  final ErrorListener fListener = new ErrorListenerImpl ("TransformerFactory");
  tfactory.setErrorListener (fListener);

  // register own ErrorListener for the TransformerFactory
  final ErrorListener tListener = new ErrorListenerImpl ("Transformer");
  // Create a transformer for the stylesheet.
  final Transformer transformer = tfactory.newTransformer ();
  transformer.setErrorListener (tListener);

  // Transform the source XML to System.out.
  transformer.transform (_getSource (sourceID), new StreamResult (System.out));

  return true;
}
 
开发者ID:phax,项目名称:ph-stx,代码行数:25,代码来源:TestCases.java

示例9: exampleSimple1

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * Show the simplest possible transformation from system id to output stream.
 */
public static boolean exampleSimple1 (final String sourceID, final String stxID) throws TransformerException,
                                                                                 TransformerConfigurationException
{

  // Create a transform factory instance.
  final TransformerFactory tfactory = TransformerFactory.newInstance ();

  // register own ErrorListener for the TransformerFactory
  final ErrorListener fListener = new ErrorListenerImpl ("TransformerFactory");
  tfactory.setErrorListener (fListener);

  final ErrorListener tListener = new ErrorListenerImpl ("Transformer");
  // Create a transformer for the stylesheet.
  final Transformer transformer = tfactory.newTransformer (_getSource (stxID));
  transformer.setErrorListener (tListener);

  // Transform the source XML to System.out.
  transformer.transform (_getSource (sourceID), new StreamResult (System.out));

  return true;
}
 
开发者ID:phax,项目名称:ph-stx,代码行数:25,代码来源:TestCases.java

示例10: resolve

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
public TransformerHandler resolve (final String method,
                                   final String href,
                                   final String base,
                                   final URIResolver uriResolver,
                                   final ErrorListener errorListener,
                                   final Hashtable <String, Object> params) throws SAXException
{
  if (METHOD.equals (method))
  {
    if (href != null)
      throw new SAXException ("Specification of an external source '" + href + "' not allowed for " + method);
    skipUri = String.valueOf (params.get ("uri"));
    return this;
  }
  return null;
}
 
开发者ID:phax,项目名称:ph-stx,代码行数:17,代码来源:NSFilter.java

示例11: setErrorListener

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * javax.xml.transform.sax.TransformerFactory implementation.
 * Set the error event listener for the TransformerFactory, which is used
 * for the processing of transformation instructions, and not for the
 * transformation itself.
 *
 * @param listener The error listener to use with the TransformerFactory
 * @throws IllegalArgumentException
 */
@Override
public void setErrorListener(ErrorListener listener)
    throws IllegalArgumentException
{
    if (listener == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
                                    "TransformerFactory");
        throw new IllegalArgumentException(err.toString());
    }
    _errorListener = listener;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:TransformerFactoryImpl.java

示例12: setErrorListener

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * Implements JAXP's Transformer.setErrorListener()
 * Set the error event listener in effect for the transformation.
 * Register a message handler in the translet in order to forward
 * xsl:messages to error listener.
 *
 * @param listener The error event listener to use
 * @throws IllegalArgumentException
 */
@Override
public void setErrorListener(ErrorListener listener)
    throws IllegalArgumentException {
    if (listener == null) {
        ErrorMsg err = new ErrorMsg(ErrorMsg.ERROR_LISTENER_NULL_ERR,
                                    "Transformer");
        throw new IllegalArgumentException(err.toString());
    }
    _errorListener = listener;

    // Register a message handler to report xsl:messages
if (_translet != null)
    _translet.setMessageHandler(new MessageHandler(_errorListener));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:TransformerImpl.java

示例13: setEncoding

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
 * @param encoding the character encoding
 */
public void setEncoding(String encoding)
{
    String old = getEncoding();
    super.setEncoding(encoding);
    if (old == null || !old.equals(encoding)) {
       // If we have changed the setting of the
       m_encodingInfo = Encodings.getEncodingInfo(encoding);

       if (encoding != null && m_encodingInfo.name == null) {
           // We tried to get an EncodingInfo for Object for the given
           // encoding, but it came back with an internall null name
           // so the encoding is not supported by the JDK, issue a message.
           String msg = Utils.messages.createMessage(
                           MsgKey.ER_ENCODING_NOT_SUPPORTED,new Object[]{ encoding });
           try
           {
                   // Prepare to issue the warning message
                   Transformer tran = super.getTransformer();
                   if (tran != null) {
                           ErrorListener errHandler = tran.getErrorListener();
                           // Issue the warning message
                           if (null != errHandler && m_sourceLocator != null)
                                   errHandler.warning(new TransformerException(msg, m_sourceLocator));
                           else
                                   System.out.println(msg);
               }
                   else
                           System.out.println(msg);
           }
           catch (Exception e){}
       }
    }
    return;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:ToStream.java

示例14: getXMLVersion

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * This method checks for the XML version of output document.
 * If XML version of output document is not specified, then output
 * document is of version XML 1.0.
 * If XML version of output doucment is specified, but it is not either
 * XML 1.0 or XML 1.1, a warning message is generated, the XML Version of
 * output document is set to XML 1.0 and processing continues.
 * @return string (XML version)
 */
private String getXMLVersion()
{
    String xmlVersion = getVersion();
    if(xmlVersion == null || xmlVersion.equals(XMLVERSION10))
    {
        xmlVersion = XMLVERSION10;
    }
    else if(xmlVersion.equals(XMLVERSION11))
    {
        xmlVersion = XMLVERSION11;
    }
    else
    {
        String msg = Utils.messages.createMessage(
                           MsgKey.ER_XML_VERSION_NOT_SUPPORTED,new Object[]{ xmlVersion });
        try
        {
            // Prepare to issue the warning message
            Transformer tran = super.getTransformer();
            ErrorListener errHandler = tran.getErrorListener();
            // Issue the warning message
            if (null != errHandler && m_sourceLocator != null)
                errHandler.warning(new TransformerException(msg, m_sourceLocator));
            else
                System.out.println(msg);
        }
        catch (Exception e){}
        xmlVersion = XMLVERSION10;
    }
    return xmlVersion;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:ToXMLStream.java

示例15: setErrorListener

import javax.xml.transform.ErrorListener; //导入依赖的package包/类
/**
 * Set the ErrorListener where errors and warnings are to be reported.
 *
 * @param listener A non-null ErrorListener reference.
 */
public void setErrorListener(ErrorListener listener) throws IllegalArgumentException
{
  if (listener == null)
    throw new IllegalArgumentException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_NULL_ERROR_HANDLER, null)); //"Null error handler");
  m_errorListener = listener;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:XPathContext.java


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