Search in sources :

Example 16 with ErrorListener

use of javax.xml.transform.ErrorListener in project j2objc by google.

the class ToXMLStream method getXMLVersion.

/**
     * 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;
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) Transformer(javax.xml.transform.Transformer) TransformerException(javax.xml.transform.TransformerException) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException)

Example 17 with ErrorListener

use of javax.xml.transform.ErrorListener in project j2objc by google.

the class ToXMLStream method addAttribute.

/**
     * Add an attribute to the current element.
     * @param uri the URI associated with the element name
     * @param localName local part of the attribute name
     * @param rawName   prefix:localName
     * @param type
     * @param value the value of the attribute
     * @param xslAttribute true if this attribute is from an xsl:attribute,
     * false if declared within the elements opening tag.
     * @throws SAXException
     */
public void addAttribute(String uri, String localName, String rawName, String type, String value, boolean xslAttribute) throws SAXException {
    if (m_elemContext.m_startTagOpen) {
        boolean was_added = addAttributeAlways(uri, localName, rawName, type, value, xslAttribute);
        /*
             * We don't run this block of code if:
             * 1. The attribute value was only replaced (was_added is false).
             * 2. The attribute is from an xsl:attribute element (that is handled
             *    in the addAttributeAlways() call just above.
             * 3. The name starts with "xmlns", i.e. it is a namespace declaration.
             */
        if (was_added && !xslAttribute && !rawName.startsWith("xmlns")) {
            String prefixUsed = ensureAttributesNamespaceIsDeclared(uri, localName, rawName);
            if (prefixUsed != null && rawName != null && !rawName.startsWith(prefixUsed)) {
                // use a different raw name, with the prefix used in the
                // generated namespace declaration
                rawName = prefixUsed + ":" + localName;
            }
        }
        addAttributeAlways(uri, localName, rawName, type, value, xslAttribute);
    } else {
        /*
             * The startTag is closed, yet we are adding an attribute?
             *
             * Section: 7.1.3 Creating Attributes Adding an attribute to an
             * element after a PI (for example) has been added to it is an
             * error. The attributes can be ignored. The spec doesn't explicitly
             * say this is disallowed, as it does for child elements, but it
             * makes sense to have the same treatment.
             *
             * We choose to ignore the attribute which is added too late.
             */
        // Generate a warning of the ignored attributes
        // Create the warning message
        String msg = Utils.messages.createMessage(MsgKey.ER_ILLEGAL_ATTRIBUTE_POSITION, new Object[] { localName });
        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 (TransformerException e) {
            // A user defined error handler, errHandler, may throw
            // a TransformerException if it chooses to, and if it does
            // we will wrap it with a SAXException and re-throw.
            // Of course if the handler throws another type of
            // exception, like a RuntimeException, then that is OK too.
            SAXException se = new SAXException(e);
            throw se;
        }
    }
}
Also used : ErrorListener(javax.xml.transform.ErrorListener) Transformer(javax.xml.transform.Transformer) TransformerException(javax.xml.transform.TransformerException) SAXException(org.xml.sax.SAXException)

Example 18 with ErrorListener

use of javax.xml.transform.ErrorListener in project j2objc by google.

the class StylesheetHandler method fatalError.

/**
   * Report a fatal XSLT processing error.
   *
   * @param e The error 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#fatalError}
   * method chooses to flag this condition as an error.
   */
public void fatalError(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException {
    String formattedMsg = e.getMessage();
    SAXSourceLocator locator = getLocator();
    ErrorListener handler = m_stylesheetProcessor.getErrorListener();
    try {
        handler.fatalError(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 19 with ErrorListener

use of javax.xml.transform.ErrorListener in project j2objc by google.

the class StylesheetHandler method createMatchPatternXPath.

/**
   * Process an expression string into an XPath.
   *
   * @param str A non-null reference to a valid or invalid match pattern string.
   *
   * @return A non-null reference to an XPath object that represents the string argument.
   *
   * @throws javax.xml.transform.TransformerException if the pattern can not be processed.
   * @see <a href="http://www.w3.org/TR/xslt#patterns">Section 5.2 Patterns in XSLT Specification</a>
   */
XPath createMatchPatternXPath(String str, ElemTemplateElement owningTemplate) throws javax.xml.transform.TransformerException {
    ErrorListener handler = m_stylesheetProcessor.getErrorListener();
    XPath xpath = new XPath(str, owningTemplate, this, XPath.MATCH, 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 20 with ErrorListener

use of javax.xml.transform.ErrorListener in project j2objc by google.

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)

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