當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。