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(String message, Exception e) 

Source Link

Document

Create a new SAXException from an existing exception.

Usage

From source file:org.apache.cocoon.components.source.impl.XModuleSource.java

private void setOutputAttribute(String outputModuleName, String attributeName, Object value)
        throws SAXException {
    ServiceSelector selector = null;//from w  w w. ja va2 s . co m
    OutputModule outputModule = null;
    try {
        selector = (ServiceSelector) this.manager.lookup(OutputModule.ROLE + "Selector");
        outputModule = (OutputModule) selector.select(outputModuleName);
        outputModule.setAttribute(null, this.objectModel, attributeName, value);
        outputModule.commit(null, this.objectModel);

    } catch (ServiceException e) {
        throw new SAXException("Could not find an OutputModule of the type " + outputModuleName, e);
    } finally {
        if (outputModule != null)
            selector.release(outputModule);
        this.manager.release(selector);
    }
}

From source file:org.apache.cocoon.faces.taglib.UIComponentTag.java

public int doStartTag(String namespaceURI, String localName, String qName, Attributes attrs)
        throws SAXException {
    final UIComponentTag parentTag = findParent();

    this.component = findComponent(parentTag);

    try {//w ww .j a va 2s  . c o  m
        if (!isSuppressed()) {
            if (!this.component.getRendersChildren()) {
                encodeBegin();
                getFacesContext().getResponseWriter().flush();
            }
        }
    } catch (IOException e) {
        throw new SAXException("Exception in doStartTag", e);
    }

    return getDoStartValue();
}

From source file:org.apache.cocoon.faces.taglib.UIComponentTag.java

public int doEndTag(String namespaceURI, String localName, String qName) throws SAXException {
    removeOldChildren();//w w w  .  jav a2 s. co  m
    removeOldFacets();
    try {
        if (!isSuppressed()) {
            if (this.component.getRendersChildren()) {
                encodeBegin();
                encodeChildren();
            }
            encodeEnd();
            getFacesContext().getResponseWriter().flush();
        }
    } catch (IOException e) {
        throw new SAXException("Exception in doEndTag", e);
    }

    return getDoEndValue();
}

From source file:org.apache.cocoon.forms.datatype.EnumSelectionList.java

public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
    try {//  www  . ja  va2  s  .c  o m
        contentHandler.startElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL,
                FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES);
        // Create void element
        if (nullable) {
            AttributesImpl voidAttrs = new AttributesImpl();
            voidAttrs.addCDATAAttribute("value", "");
            contentHandler.startElement(FormsConstants.INSTANCE_NS, ITEM_EL,
                    FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL, voidAttrs);
            if (this.nullText != null) {
                contentHandler.startElement(FormsConstants.INSTANCE_NS, LABEL_EL,
                        FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES);
                contentHandler.startElement(FormsConstants.I18N_NS, TEXT_EL,
                        FormsConstants.I18N_PREFIX_COLON + TEXT_EL, XMLUtils.EMPTY_ATTRIBUTES);
                contentHandler.characters(nullText.toCharArray(), 0, nullText.length());
                contentHandler.endElement(FormsConstants.I18N_NS, TEXT_EL,
                        FormsConstants.I18N_PREFIX_COLON + TEXT_EL);
                contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL,
                        FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL);
            }
            contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL,
                    FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL);
        }
        // Test if we have an apache enum class
        boolean apacheEnumDone = false;
        if (Enum.class.isAssignableFrom(clazz)) {
            Iterator iter = EnumUtils.iterator(clazz);
            if (iter != null) {
                apacheEnumDone = true;
                while (iter.hasNext()) {
                    Enum element = (Enum) iter.next();
                    String stringValue = clazz.getName() + "." + element.getName();
                    generateItem(contentHandler, stringValue);
                }
            }
        }
        // If it's not an apache enum or we didn't manage to read the enum list, then proceed with common method.
        if (!apacheEnumDone) {
            Field fields[] = clazz.getDeclaredFields();
            for (int i = 0; i < fields.length; ++i) {
                int mods = fields[i].getModifiers();
                if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods)
                        && fields[i].get(null).getClass().equals(clazz)) {
                    String stringValue = clazz.getName() + "." + fields[i].getName();
                    generateItem(contentHandler, stringValue);
                }
            }
        }
        // End the selection-list
        contentHandler.endElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL,
                FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL);
    } catch (Exception e) {
        throw new SAXException("Got exception trying to get enum's values", e);
    }
}

From source file:org.apache.cocoon.serialization.SVGSerializer.java

/**
 * Receive notification of a successfully completed DOM tree generation.
 *//*from  www. j  a  v  a 2 s .c  o m*/
public void notify(Document doc) throws SAXException {

    try {
        TranscoderInput transInput = new TranscoderInput(doc);

        // Buffering is done by the pipeline (See shouldSetContentLength)
        TranscoderOutput transOutput = new TranscoderOutput(this.output);
        transcoder.transcode(transInput, transOutput);
    } catch (TranscoderException ex) {
        if (ex.getException() != null) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Got transcoder exception writing image, rethrowing nested exception", ex);
            }
            throw new SAXException("Exception writing image", ex.getException());
        }

        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Got transcoder exception writing image, rethrowing", ex);
        }
        throw new SAXException("Exception writing image", ex);
    } catch (Exception ex) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Got exception writing image, rethrowing", ex);
        }
        throw new SAXException("Exception writing image", ex);
    }
}

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

/**
 * Start recording of compiled xml.// www . j a va 2 s .c om
 * The incomming SAX events are recorded and a compiled representation
 * is created. These events are not forwarded to the next component in
 * the pipeline.
 */
protected void startCompiledXMLRecording() throws SAXException {
    if (this.getLogger().isDebugEnabled()) {
        this.getLogger().debug("BEGIN startCompiledXMLRecording");
    }

    try {
        this.recorder = (XMLSerializer) this.manager.lookup(XMLSerializer.ROLE);

        this.addRecorder(recorder);

    } catch (ServiceException ce) {
        throw new SAXException("Unable to lookup xml serializer for compiling xml.", ce);
    }
    if (this.getLogger().isDebugEnabled()) {
        this.getLogger().debug("END startCompiledXMLRecording");
    }
}

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

/**
 * @see org.xml.sax.ContentHandler#endDocument()
 *///from   w  ww.  j av a2  s .  c o m
public void endDocument() throws SAXException {
    if (this.compiling) {
        Object compiledXML = this.endCompiledXMLRecording();
        XMLDeserializer deserializer = null;
        try {
            deserializer = (XMLDeserializer) this.manager.lookup(XMLDeserializer.ROLE);
            deserializer.setConsumer(this.filter);
            deserializer.deserialize(compiledXML);
        } catch (ServiceException ce) {
            throw new SAXException("Unable to lookup xml deserializer.", ce);
        } finally {
            this.manager.release(deserializer);
        }
    }
    super.endDocument();
}

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

/**
 * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
 *//* w w w .  j  a  va2  s  .  com*/
public void startElement(String uri, String local, String qName, Attributes attr) throws SAXException {
    if (uri != null && uri.equals(CIncludeTransformer.CINCLUDE_NAMESPACE_URI)
            && local.equals(CIncludeTransformer.CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT)) {
        // this is a placeholder
        try {
            final String src = attr.getValue("", CIncludeTransformer.CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE);
            this.transformer.cacheManager.stream(src, this.transformer.cachingSession, this);
        } catch (IOException ioe) {
            throw new SAXException("IOException", ioe);
        }
    } else {
        super.startElement(uri, local, qName, attr);
    }
}

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

/**
 * Intercept the <dasl:query> end tag, convert buffered input to a String, build and execute the
 * DASL query./* ww  w . ja  v a 2  s.  c  o m*/
 *
 * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
 */
public void endElement(String uri, String name, String raw) throws SAXException {
    String query;
    if (name.equals(QUERY_TAG) && uri.equals(DASL_QUERY_NS)) {
        DocumentFragment frag = this.endRecording();
        try {
            Properties props = XMLUtils.createPropertiesForXML(false);
            props.put(OutputKeys.ENCODING, "ISO-8859-1");
            query = XMLUtils.serializeNode(frag, props);
            // Perform the DASL query
            this.performSearchMethod(query);
        } catch (ProcessingException e) {
            throw new SAXException("Unable to fetch the query data:", e);
        }
    } else if (name.equals(SUBSTITUTE_TAG) && uri.equals(DASL_QUERY_NS)) {
        //Do nothing!!!!
    } else {
        super.endElement(uri, name, raw);
    }
}

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

public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
    Object saxFragment = null;/*from  ww  w. j  a v  a 2  s  . co  m*/

    // Are we recording?
    if (recordingLevel > 0) {
        if (--recordingLevel > 0) {
            currentConsumer.endElement(namespaceURI, localName, qName);
            return;
        }
        // Recording finished
        saxFragment = endRecording();
    }

    if (skipLevel > 0) {
        if (--skipLevel > 0) {
            return;
        }
    }

    Tag tag = (Tag) tagStack.pop();
    if (tag != null) {
        ComponentSelector tagSelector = (ComponentSelector) tagSelectorStack.pop();
        try {
            if (saxFragment != null) {
                // Start Iteration
                IterationTag iterTag = (IterationTag) tag;
                XMLDeserializer xmlDeserializer = null;
                try {
                    xmlDeserializer = (XMLDeserializer) manager.lookup(XMLDeserializer.ROLE);
                    xmlDeserializer.setConsumer(this);

                    // BodyTag Support
                    XMLConsumer backup = this.currentConsumer;
                    if (tag instanceof BodyTag) {
                        SaxBuffer content = new SaxBuffer();
                        this.currentConsumer = content;
                        ((BodyTag) tag).setBodyContent(new BodyContent(content, backup));
                        ((BodyTag) tag).doInitBody();
                    }

                    do {
                        xmlDeserializer.deserialize(saxFragment);
                    } while (iterTag.doAfterBody() != Tag.SKIP_BODY);

                    // BodyTag Support
                    if (tag instanceof BodyTag) {
                        this.currentConsumer = backup;
                    }

                } catch (ServiceException e) {
                    throw new SAXException("Can't obtain XMLDeserializer", e);
                } finally {
                    if (xmlDeserializer != null) {
                        manager.release(xmlDeserializer);
                    }
                }
            }
            tag.doEndTag(namespaceURI, localName, qName);
            currentTag = tag.getParent();

            if (tag == this.currentConsumer) {
                popConsumer();
            }
        } finally {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("endElement: Release tag " + qName);
            }

            tagSelector.release(tag);
            tagNamespaceSelector.release(tagSelector);

            if (transformerSelector != null && tag instanceof XMLProducer) {
                getLogger().debug("endElement: Release transformer");
                Transformer transformer = (Transformer) tagTransformerStack.pop();
                transformerSelector.release(transformer);
            }
        }
    } else {
        this.currentConsumer.endElement(namespaceURI, localName, qName);
    }
}