cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Goers" <Ralph.Go...@dslextreme.com>
Subject Re: InputStream as source or generator
Date Tue, 18 May 2004 23:44:41 GMT
I used Betwixt's SAXBeanWriter to convert my bean to a generator. I
believe this is more efficient since no "real" xml is ever created.


public class BetwixtGenerator extends AbstractGenerator
{
    protected ServiceManager manager;
    private Object           bean;

    /**
     * Sets up the BetwixtGenerator.
     *
     * @param resolver the source resolver
     * @param objectModel the Cocoon object model
     * @param src ignored by the BetwixtGenerator
     * @param par ignored by the BetwixtGenerator
     * @throws ProcessingException
     * @throws SAXException
     * @throws IOException
     */
    public final void setup(SourceResolver resolver, Map objectModel,
String src,
                      Parameters par)
        throws ProcessingException, SAXException, IOException
    {
        super.setup(resolver, objectModel, src, par);

        Request request =
(Request)objectModel.get(ObjectModelHelper.REQUEST_OBJECT);
        this.bean =
request.getAttribute(BusinessDelegate.DATA_TRANSFER_OBJECT);
        if (this.bean == null)
        {
            throw new ProcessingException("No object was provided to
serialize");
        }
    }

    /**
     * Generate XML data.
     * @throws SAXException
     */
    public final void generate()
        throws SAXException
    {
        try
        {
            SAXBeanWriter beanWriter = new
SAXBeanWriter(this.contentHandler);
            beanWriter.setWriteEmptyElements(false);
            beanWriter.setWriteIDs(false);
            beanWriter.getXMLIntrospector().setElementNameMapper(new
CapitalizeNameMapper());
            beanWriter.getXMLIntrospector().setAttributesForPrimitives(true);
            beanWriter.write(this.bean);
        }
        catch (Exception e)
        {
            getLogger().error("Cannot generate XML for " + bean, e);
            SAXException saxException = new SAXException(e.getMessage());
            throw saxException;
        }
    }


Craig Christophersen said:
> Can anyone point me in a direction of how to use an InputStream as either
> a Source or Generator in the pipeline? The StreamGenerator is just for
> request input from a post. I would like to use an inputstream from a DTO,
> bean, or ejb.
> I have created an action to instantiate a bean and can use the parameters
> retrieved as strings. I would like to get the inputstream(of xml data)
> into the pipeline.
>
> Craig Christophersen
> (406)496-6421
> craigch@synesis7.com


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message