Example usage for org.xml.sax SAXException SAXException

List of usage examples for org.xml.sax SAXException SAXException

Introduction

In this page you can find the example usage for org.xml.sax SAXException SAXException.

Prototype

public SAXException(Exception e) 

Source Link

Document

Create a new SAXException wrapping an existing exception.

Usage

From source file:org.apache.cocoon.forms.transformation.EffectWidgetReplacingPipe.java

/**
 * Get non-empty value of the required attribute
 *//*  ww w . j a  va 2 s .c  o m*/
protected String getRequiredAttributeValue(String loc, Attributes attrs, String name) throws SAXException {
    String value = attrs.getValue(name);
    if (value == null || value.length() == 0) {
        throw new SAXException(
                "Element '" + loc + "' missing required '" + name + "' attribute, " + "at " + getLocation());
    }
    return value;
}

From source file:org.apache.cocoon.forms.transformation.EffectWidgetReplacingPipe.java

/**
 * Set the widget by its path//from w  ww  .j a va 2s .c  o  m
 */
protected void setWidget(String loc, String path) throws SAXException {
    widget = contextWidget.lookupWidget(path);
    if (widget == null) {
        if (contextWidget.getRequestParameterName().length() == 0) {
            throw new SAXException("Element '" + loc + "' refers to unexistent widget path '" + path + "', "
                    + "relative to the form container, at " + getLocation());
        } else {
            throw new SAXException("Element '" + loc + "' refers to unexistent widget path '" + path + "', "
                    + "relative to the '" + contextWidget.getRequestParameterName() + "', " + "at "
                    + getLocation());
        }
    }
}

From source file:org.apache.cocoon.forms.transformation.EffectWidgetReplacingPipe.java

/**
 * Set typed widget by the id attribute//from   ww  w  . ja v  a 2s.co m
 */
protected void setTypedWidget(String loc, Attributes attrs, Class wclass, String wname) throws SAXException {
    setWidget(loc, attrs);
    if (!wclass.isInstance(widget)) {
        throw new SAXException(
                "Element '" + loc + "' can only be used with " + wname + " widgets, " + "at " + getLocation());
    }
}

From source file:org.apache.cocoon.forms.transformation.EffectWidgetReplacingPipe.java

/**
 * Process the SAX event./*from  w w  w . j ava 2 s .  c om*/
 * @see org.xml.sax.ContentHandler#endPrefixMapping
 */
public void endPrefixMapping(String prefix) throws SAXException {
    String uri = null;

    if (prefix != null) {
        // Find and remove the namespace prefix
        boolean found = false;
        for (int i = this.namespaces.size() - 1; i >= 0; i--) {
            final String[] prefixAndUri = (String[]) this.namespaces.get(i);
            if (prefixAndUri[0].equals(prefix)) {
                uri = prefixAndUri[1];
                this.namespaces.remove(i);
                found = true;
                break;
            }
        }
        if (!found) {
            throw new SAXException("Namespace for prefix '" + prefix + "' not found.");
        }
    }

    // Consume template namespace mapping
    if (!FormsConstants.TEMPLATE_NS.equals(uri)) {
        super.endPrefixMapping(prefix);
    }
}

From source file:org.apache.cocoon.forms.transformation.FormsPipelineConfig.java

/**
 * Finds the form from the current request-context based on the settings of
 * this configuration object.  The fall-back search-procedure is as follows:
 * <ol><li>Use the provided jxpathExpression (if not null)</li>
 * <li>Use the setting of the 'attribute-name' parameter on the request</li>
 * <li>Obtain the form from it's default location in the flow context</li>
 * </ol>//w  w  w  .  j  a  va  2s  .  co m
 *
 * @param jxpathExpression that should be pointing to the form
 * @return the found form if found
 * @throws SAXException in any of the following cases:
 * <ul><li>The provided jxpathExpression (if not null) not point to a
 * {@link Form} instance.</li>
 * <li>The request is not holding a {@link Form} instance under the key
 * specified by 'attribute-name' (if specified)</li>
 * <li>Both jxpathExpression and 'attribute-name' were not specified AND
 * also the default location was not holding a valid {@link Form} instance.</li>
 * </ol>
 */
public Form findForm(String jxpathExpression) throws SAXException {
    Object form = null;
    if (jxpathExpression != null) {
        form = this.jxpathContext.getValue(jxpathExpression);
        if (form == null) {
            throw new SAXException("No Cocoon Form found at location \"" + jxpathExpression + "\".");
        } else if (!(form instanceof Form)) {
            throw new SAXException(
                    "Object returned by expression \"" + jxpathExpression + "\" is not a Cocoon Form.");
        }
    } else if (this.attributeName != null) { // then see if an attribute-name was specified
        form = this.request.getAttribute(this.attributeName);
        if (form == null) {
            throw new SAXException(
                    "No Cocoon Form found in request attribute with name \"" + this.attributeName + "\"");
        } else if (!(form instanceof Form)) {
            throw new SAXException(
                    "Object found in request (attribute = '" + this.attributeName + "') is not a Cocoon Form.");
        }
    } else { // and then see if we got a form from the flow
        jxpathExpression = "/" + FormsPipelineConfig.CFORMSKEY;
        try {
            form = this.jxpathContext.getValue(jxpathExpression);
        } catch (JXPathException e) {
            /* do nothing */ }
        if (form == null) {
            throw new SAXException("No Cocoon Form found.");
        }
    }
    return (Form) form;
}

From source file:org.apache.cocoon.portal.wsrp.adapter.WSRPAdapter.java

/**
  * Checks the values of the <tt>portlet-key</tt> and the <tt>user</tt> for current portlet-instance<br/>
  * After that all passed the <tt>getMarkup()</tt>-call will be initiated<br />
  * /*w ww .  j av  a  2  s .co m*/
 * @see org.apache.cocoon.portal.coplet.adapter.impl.AbstractCopletAdapter#streamContent(org.apache.cocoon.portal.coplet.CopletInstanceData, org.xml.sax.ContentHandler)
 */
public void streamContent(CopletInstanceData coplet, ContentHandler contentHandler) throws SAXException {
    try {
        // set the coplet in the thread local variable to give other components access to
        // the instance
        this.setCurrentCopletInstanceData(coplet);

        // get the portlet key and the user
        final PortletKey portletKey = (PortletKey) coplet.getTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_KEY);
        if (portletKey == null) {
            throw new SAXException("WSRP configuration is missing: portlet key.");
        }
        final User user = (User) coplet.getTemporaryAttribute(ATTRIBUTE_NAME_USER);
        if (user == null) {
            throw new SAXException("WSRP configuration is missing: user.");
        }

        final String portletInstanceKey = (String) coplet
                .getTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_INSTANCE_KEY);

        // getMarkup()
        final WSRPPortlet wsrpportlet = consumerEnvironment.getPortletRegistry().getPortlet(portletKey);

        SimplePortletWindowSession windowSession = getSimplePortletWindowSession(wsrpportlet,
                portletInstanceKey, user);
        final MarkupContext markupContext = this.getMarkupContext(wsrpportlet, windowSession, user);
        if (markupContext == null || markupContext.getMarkupString() == null) {
            throw new SAXException("No markup received from wsrp coplet " + coplet.getId());
        }
        final String content = markupContext.getMarkupString();

        final Boolean usePipeline;
        final boolean usesGet;
        // If the portlet uses the method get we always have to rewrite form elements
        final Producer producer = this.consumerEnvironment.getProducerRegistry()
                .getProducer(portletKey.getProducerId());
        final PortletDescription desc = producer.getPortletDescription(portletKey.getPortletHandle());
        if (desc.getUsesMethodGet() != null && desc.getUsesMethodGet().booleanValue()) {
            usePipeline = Boolean.TRUE;
            usesGet = true;
        } else {
            usePipeline = (Boolean) this.getConfiguration(coplet, "use-pipeline", Boolean.FALSE);
            usesGet = false;
        }
        if (usePipeline.booleanValue()) {
            if (usesGet) {
                contentHandler = new FormRewritingHandler(contentHandler);
            }
            HtmlSaxParser.parseString(content, HtmlSaxParser.getContentFilter(contentHandler));
        } else {
            // stream out the include for the serializer
            IncludingHTMLSerializer.addPortlet(portletInstanceKey, content);
            contentHandler.startPrefixMapping("portal", IncludingHTMLSerializer.NAMESPACE);
            final AttributesImpl attr = new AttributesImpl();
            attr.addCDATAAttribute("portlet", portletInstanceKey);
            contentHandler.startElement(IncludingHTMLSerializer.NAMESPACE, "include", "portal:include", attr);
            contentHandler.endElement(IncludingHTMLSerializer.NAMESPACE, "include", "portal:include");
            contentHandler.endPrefixMapping("portal");
        }
    } catch (WSRPException e) {
        throw new SAXException("Exception during getMarkup of wsrp coplet: " + coplet.getId(), e);
    } catch (SAXException se) {
        throw se;
    } finally {
        this.setCurrentCopletInstanceData(null);
    }
}

From source file:org.apache.cocoon.taglib.core.ForEachSupport.java

protected void prepare() throws SAXException {
    // produce the right sort of ForEachIterator
    if (rawItems != null) {
        // extract an iterator over the 'items' we've got
        items = supportedTypeForEachIterator(rawItems);
    } else {/*from   w  w  w .  j  a  v  a2s .  c  o m*/
        // no 'items', so use 'begin' and 'end'
        items = beginEndForEachIterator();
    }

    // step must be 1 when ResultSet is passed in
    if (rawItems instanceof ResultSet && step != 1)
        throw new SAXException("FOREACH_STEP_NO_RESULTSET");
}

From source file:org.apache.cocoon.taglib.core.ForEachSupport.java

protected ForEachIterator toForEachIterator(Object o) throws SAXException {
    throw new SAXException("FOREACH_BAD_ITEMS");
}

From source file:org.apache.cocoon.taglib.core.ForEachSupport.java

protected ForEachIterator toForEachIterator(ResultSet rs) throws SAXException {

    // local adapter
    class ResultSetAdapter implements ForEachIterator {
        private ResultSet rs;

        public ResultSetAdapter(ResultSet rs) {
            this.rs = rs;
        }/*from w ww  .j a v a  2 s . c om*/

        public boolean hasNext() throws SAXException {
            try {
                return !(rs.isLast()); // dependent on JDBC 2.0
            } catch (java.sql.SQLException ex) {
                throw new SAXException(ex.getMessage());
            }
        }

        public Object next() throws SAXException {
            try {
                rs.next();
                return rs;
            } catch (java.sql.SQLException ex) {
                throw new SAXException(ex.getMessage());
            }
        }
    }

    return new ResultSetAdapter(rs);
}

From source file:org.apache.cocoon.transformation.CIncludeTransformer.java

protected String processCIncludeElement(String src, String element, String select, String ns, String prefix,
        boolean stripRoot, boolean cache) throws SAXException, IOException {

    if (src == null) {
        throw new SAXException("Missing 'src' attribute on cinclude:include element");
    }//w w w .j a  v  a  2  s  .c om

    if (element == null)
        element = "";
    if (select == null)
        select = "";
    if (ns == null)
        ns = "";
    if (prefix == null)
        prefix = "";

    if (getLogger().isDebugEnabled()) {
        getLogger().debug("Processing include element: src=" + src + ", element=" + element + ", select="
                + select + ", ns=" + ns + ", prefix=" + prefix + ", stripRoot=" + stripRoot + ", caching="
                + cache);
    }

    if (cache) {
        src = this.cacheManager.load(src, this.cachingSession);

        if (this.cachingSession.isParallel() && !this.cachingSession.isPreemptive()) {
            if (!this.compiling) {
                this.compiling = true;
                this.startCompiledXMLRecording();
            }
        } else {
            this.cacheManager.stream(src, this.cachingSession, this.filter);
        }

        return src;
    }

    // usual no caching stuff
    if (!"".equals(element)) {
        if (!ns.equals("")) {
            super.startPrefixMapping(prefix, ns);
        }
        super.startElement(ns, element,
                (!ns.equals("") && !prefix.equals("") ? prefix + ":" + element : element),
                XMLUtils.EMPTY_ATTRIBUTES);
    }

    Source source = null;
    try {
        source = this.resolver.resolveURI(src);

        if (!"".equals(select)) {

            DOMParser parser = null;
            XPathProcessor processor = null;

            try {
                parser = (DOMParser) this.manager.lookup(DOMParser.ROLE);
                processor = (XPathProcessor) this.manager.lookup(XPathProcessor.ROLE);

                InputSource input = SourceUtil.getInputSource(source);

                Document document = parser.parseDocument(input);
                NodeList list = processor.selectNodeList(document, select);
                int length = list.getLength();
                for (int i = 0; i < length; i++) {
                    IncludeXMLConsumer.includeNode(list.item(i), this.filter, this.filter);
                }
            } finally {
                this.manager.release(parser);
                this.manager.release(processor);
            }
        } else {
            String mimeType = null;
            if (null != this.configurationParameters) {
                mimeType = this.configurationParameters.getParameter("mime-type", mimeType);
            }
            if (this.compiling) {
                SourceUtil.toSAX(source, mimeType,
                        new IncludeXMLConsumer(this.contentHandler, this.lexicalHandler));
            } else {
                this.filter.setIgnoreRootElement(stripRoot);
                SourceUtil.toSAX(source, mimeType, this.filter);
            }
        }

    } catch (SourceException se) {
        throw new SAXException("Exception in CIncludeTransformer", se);
    } catch (IOException e) {
        throw new SAXException("CIncludeTransformer could not read resource", e);
    } catch (ProcessingException e) {
        throw new SAXException("Exception in CIncludeTransformer", e);
    } catch (ServiceException e) {
        throw new SAXException(e);
    } finally {
        this.resolver.release(source);
    }

    if (!"".equals(element)) {
        super.endElement(ns, element,
                (!ns.equals("") && !prefix.equals("") ? prefix + ":" + element : element));
        if (!ns.equals("")) {
            super.endPrefixMapping(prefix);
        }
    }
    return src;
}