Search in sources :

Example 1 with ErrorListener

use of javax.xml.transform.ErrorListener in project robovm by robovm.

the class StylesheetHandler method warning.

/**
   * Receive notification of a XSLT processing warning.
   *
   * @param e The warning information encoded as an exception.
   *
   * @throws org.xml.sax.SAXException that wraps a
   * {@link javax.xml.transform.TransformerException} if the current
   * {@link javax.xml.transform.ErrorListener#warning}
   * method chooses to flag this condition as an error.
   */
public void warning(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException {
    String formattedMsg = e.getMessage();
    SAXSourceLocator locator = getLocator();
    ErrorListener handler = m_stylesheetProcessor.getErrorListener();
    try {
        handler.warning(new TransformerException(formattedMsg, locator));
    } catch (TransformerException te) {
        throw new org.xml.sax.SAXException(te);
    }
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) SAXSourceLocator(org.apache.xml.utils.SAXSourceLocator) TransformerException(javax.xml.transform.TransformerException)

Example 2 with ErrorListener

use of javax.xml.transform.ErrorListener in project robovm by robovm.

the class StylesheetHandler method error.

/**
   * Tell the user of an error, and probably throw an
   * exception.
   *
   * @param msg An error message.
   * @param e An error which the SAXException should wrap.
   *
   * @throws org.xml.sax.SAXException that wraps a
   * {@link javax.xml.transform.TransformerException} if the current
   * {@link javax.xml.transform.ErrorListener#error}
   * method chooses to flag this condition as an error.
   * @xsl.usage internal
   */
protected void error(String msg, Exception e) throws org.xml.sax.SAXException {
    SAXSourceLocator locator = getLocator();
    ErrorListener handler = m_stylesheetProcessor.getErrorListener();
    TransformerException pe;
    if (!(e instanceof TransformerException)) {
        pe = (null == e) ? new TransformerException(msg, locator) : new TransformerException(msg, locator, e);
    } else
        pe = (TransformerException) e;
    if (null != handler) {
        try {
            handler.error(pe);
        } catch (TransformerException te) {
            throw new org.xml.sax.SAXException(te);
        }
    } else
        throw new org.xml.sax.SAXException(pe);
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) SAXSourceLocator(org.apache.xml.utils.SAXSourceLocator) TransformerException(javax.xml.transform.TransformerException)

Example 3 with ErrorListener

use of javax.xml.transform.ErrorListener in project robovm by robovm.

the class StylesheetHandler method createXPath.

/**
   * Process an expression string into an XPath.
   * Must be public for access by the AVT class.
   *
   * @param str A non-null reference to a valid or invalid XPath expression string.
   *
   * @return A non-null reference to an XPath object that represents the string argument.
   *
   * @throws javax.xml.transform.TransformerException if the expression can not be processed.
   * @see <a href="http://www.w3.org/TR/xslt#section-Expressions">Section 4 Expressions in XSLT Specification</a>
   */
public XPath createXPath(String str, ElemTemplateElement owningTemplate) throws javax.xml.transform.TransformerException {
    ErrorListener handler = m_stylesheetProcessor.getErrorListener();
    XPath xpath = new XPath(str, owningTemplate, this, XPath.SELECT, handler, m_funcTable);
    // Visit the expression, registering namespaces for any extension functions it includes.
    xpath.callVisitors(xpath, new ExpressionVisitor(getStylesheetRoot()));
    return xpath;
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) XPath(org.apache.xpath.XPath) ExpressionVisitor(org.apache.xalan.extensions.ExpressionVisitor)

Example 4 with ErrorListener

use of javax.xml.transform.ErrorListener in project robovm by robovm.

the class FuncDocument method error.

/**
   * Tell the user of an error, and probably throw an
   * exception.
   *
   * @param xctxt The XPath runtime state.
   * @param msg The error message key
   * @param args Arguments to be used in the error message
   * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
   * the error condition is severe enough to halt processing.
   *
   * @throws javax.xml.transform.TransformerException
   */
public void error(XPathContext xctxt, String msg, Object[] args) throws javax.xml.transform.TransformerException {
    String formattedMsg = XSLMessages.createMessage(msg, args);
    ErrorListener errHandler = xctxt.getErrorListener();
    TransformerException spe = new TransformerException(formattedMsg, (SourceLocator) xctxt.getSAXLocator());
    if (null != errHandler)
        errHandler.error(spe);
    else
        System.out.println(formattedMsg);
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) XMLString(org.apache.xml.utils.XMLString) TransformerException(javax.xml.transform.TransformerException)

Example 5 with ErrorListener

use of javax.xml.transform.ErrorListener in project robovm by robovm.

the class ToStream method setProp.

void setProp(String name, String val, boolean defaultVal) {
    if (val != null) {
        char first = getFirstCharLocName(name);
        switch(first) {
            case 'c':
                if (OutputKeys.CDATA_SECTION_ELEMENTS.equals(name)) {
                    String cdataSectionNames = val;
                    addCdataSectionElements(cdataSectionNames);
                }
                break;
            case 'd':
                if (OutputKeys.DOCTYPE_SYSTEM.equals(name)) {
                    this.m_doctypeSystem = val;
                } else if (OutputKeys.DOCTYPE_PUBLIC.equals(name)) {
                    this.m_doctypePublic = val;
                    if (val.startsWith("-//W3C//DTD XHTML"))
                        m_spaceBeforeClose = true;
                }
                break;
            case 'e':
                String newEncoding = val;
                if (OutputKeys.ENCODING.equals(name)) {
                    String possible_encoding = Encodings.getMimeEncoding(val);
                    if (possible_encoding != null) {
                        // if the encoding is being set, try to get the
                        // preferred
                        // mime-name and set it too.
                        super.setProp("mime-name", possible_encoding, defaultVal);
                    }
                    final String oldExplicitEncoding = getOutputPropertyNonDefault(OutputKeys.ENCODING);
                    final String oldDefaultEncoding = getOutputPropertyDefault(OutputKeys.ENCODING);
                    if ((defaultVal && (oldDefaultEncoding == null || !oldDefaultEncoding.equalsIgnoreCase(newEncoding))) || (!defaultVal && (oldExplicitEncoding == null || !oldExplicitEncoding.equalsIgnoreCase(newEncoding)))) {
                        // We are trying to change the default or the non-default setting of the encoding to a different value
                        // from what it was
                        EncodingInfo encodingInfo = Encodings.getEncodingInfo(newEncoding);
                        if (newEncoding != null && 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.
                            final String msg = Utils.messages.createMessage(MsgKey.ER_ENCODING_NOT_SUPPORTED, new Object[] { newEncoding });
                            final String msg2 = "Warning: encoding \"" + newEncoding + "\" not supported, using " + Encodings.DEFAULT_MIME_ENCODING;
                            try {
                                // Prepare to issue the warning message
                                final Transformer tran = super.getTransformer();
                                if (tran != null) {
                                    final ErrorListener errHandler = tran.getErrorListener();
                                    // Issue the warning message
                                    if (null != errHandler && m_sourceLocator != null) {
                                        errHandler.warning(new TransformerException(msg, m_sourceLocator));
                                        errHandler.warning(new TransformerException(msg2, m_sourceLocator));
                                    } else {
                                        System.out.println(msg);
                                        System.out.println(msg2);
                                    }
                                } else {
                                    System.out.println(msg);
                                    System.out.println(msg2);
                                }
                            } catch (Exception e) {
                            }
                            // We said we are using UTF-8, so use it
                            newEncoding = Encodings.DEFAULT_MIME_ENCODING;
                            // to store the modified value into the properties a little later
                            val = Encodings.DEFAULT_MIME_ENCODING;
                            encodingInfo = Encodings.getEncodingInfo(newEncoding);
                        }
                        // as the non-default value is already the one to use.
                        if (defaultVal == false || oldExplicitEncoding == null) {
                            m_encodingInfo = encodingInfo;
                            if (newEncoding != null)
                                m_isUTF8 = newEncoding.equals(Encodings.DEFAULT_MIME_ENCODING);
                            // if there was a previously set OutputStream
                            OutputStream os = getOutputStream();
                            if (os != null) {
                                Writer w = getWriter();
                                // If the writer was previously set, but
                                // set by the user, or if the new encoding is the same
                                // as the old encoding, skip this block
                                String oldEncoding = getOutputProperty(OutputKeys.ENCODING);
                                if ((w == null || !m_writer_set_by_user) && !newEncoding.equalsIgnoreCase(oldEncoding)) {
                                    // Make the change of encoding in our internal
                                    // table, then call setOutputStreamInternal
                                    // which will stomp on the old Writer (if any)
                                    // with a new Writer with the new encoding.
                                    super.setProp(name, val, defaultVal);
                                    setOutputStreamInternal(os, false);
                                }
                            }
                        }
                    }
                }
                break;
            case 'i':
                if (OutputPropertiesFactory.S_KEY_INDENT_AMOUNT.equals(name)) {
                    setIndentAmount(Integer.parseInt(val));
                } else if (OutputKeys.INDENT.equals(name)) {
                    boolean b = "yes".equals(val) ? true : false;
                    m_doIndent = b;
                }
                break;
            case 'l':
                if (OutputPropertiesFactory.S_KEY_LINE_SEPARATOR.equals(name)) {
                    m_lineSep = val.toCharArray();
                    m_lineSepLen = m_lineSep.length;
                }
                break;
            case 'm':
                if (OutputKeys.MEDIA_TYPE.equals(name)) {
                    m_mediatype = val;
                }
                break;
            case 'o':
                if (OutputKeys.OMIT_XML_DECLARATION.equals(name)) {
                    boolean b = "yes".equals(val) ? true : false;
                    this.m_shouldNotWriteXMLHeader = b;
                }
                break;
            case 's':
                // if standalone was explicitly specified
                if (OutputKeys.STANDALONE.equals(name)) {
                    if (defaultVal) {
                        setStandaloneInternal(val);
                    } else {
                        m_standaloneWasSpecified = true;
                        setStandaloneInternal(val);
                    }
                }
                break;
            case 'v':
                if (OutputKeys.VERSION.equals(name)) {
                    m_version = val;
                }
                break;
            default:
                break;
        }
        super.setProp(name, val, defaultVal);
    }
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) Transformer(javax.xml.transform.Transformer) OutputStream(java.io.OutputStream) TransformerException(javax.xml.transform.TransformerException) EmptyStackException(java.util.EmptyStackException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WrappedRuntimeException(org.apache.xml.serializer.utils.WrappedRuntimeException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

ErrorListener (javax.xml.transform.ErrorListener)53 TransformerException (javax.xml.transform.TransformerException)49 SAXSourceLocator (org.apache.xml.utils.SAXSourceLocator)18 XString (org.apache.xpath.objects.XString)8 Transformer (javax.xml.transform.Transformer)6 SAXException (org.xml.sax.SAXException)6 IOException (java.io.IOException)4 ExpressionVisitor (org.apache.xalan.extensions.ExpressionVisitor)4 XMLString (org.apache.xml.utils.XMLString)4 XPath (org.apache.xpath.XPath)4 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Writer (java.io.Writer)2 EmptyStackException (java.util.EmptyStackException)2 SourceLocator (javax.xml.transform.SourceLocator)2 WrappedRuntimeException (org.apache.xml.serializer.utils.WrappedRuntimeException)2 XPathStylesheetDOM3Exception (org.apache.xpath.domapi.XPathStylesheetDOM3Exception)2 XObject (org.apache.xpath.objects.XObject)2