[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OzoneProducer



On Don, 13 Apr 2000, you wrote:
> hi, 
> 
> 
> Can you tell me what the type of documents i should be when using for
> the OzoneProducer from the examples. i stored the document using the Store
> (from /sample/XML/Store.java)
> 
> is have tryied 2 "types" of xml files 
> xml files with no PI's
> and 
> xml  with no PI's using:
> 	<?cocoon-process type="xsp"?>
> 	<?cocoon-process type="xslt"?>
> 	<?xml-stylesheet href="/xsl/main.xsl" type="text/xsl"?>
> Both wil give a different error.
> 
> 
> thanks 
> Kees Jongenburger
> 
> doc with no PI's
> -------------------------------------------------------
> Error found handling the request.
> 
> java.lang.ClassCastException: org.ozoneDB.xml.dom.DocumentImpl_Proxy
>         at org.ozoneDB.xml.dom.DocumentImpl_Proxy.getImplementation(DocumentImpl_Proxy.java:454)
>         at org.apache.xml.serialize.BaseMarkupSerializer.serializeNode(BaseMarkupSerializer.java:841)
>         at org.apache.xml.serialize.BaseMarkupSerializer.serialize(BaseMarkupSerializer.java:421)
>         at org.apache.cocoon.formatter.HTMLFormatter.format(HTMLFormatter.java:80)
>         at org.apache.cocoon.Engine.handle(Engine.java:309)
>         at org.apache.cocoon.Cocoon.service(Cocoon.java:145)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:309)
>         at org.apache.jserv.JServConnection.processRequest(JServConnection.java:314)
>         at org.apache.jserv.JServConnection.run(JServConnection.java, Compiled Code)
>         at java.lang.Thread.run(Thread.java, Compiled Code)
> 
> 
> doc with PI's
> -------------------------------------------------------
>                                             Error found handling the request.
> 
> java.lang.NullPointerException
>         at org.apache.cocoon.Utils.getFirstPI(Utils.java, Compiled Code)
>         at org.apache.cocoon.processor.ProcessorFactory.getType(ProcessorFactory.java, Compiled Code)
>         at org.apache.cocoon.processor.ProcessorFactory.getProcessor(ProcessorFactory.java, Compiled Code)
>         at org.apache.cocoon.Engine.handle(Engine.java, Compiled Code)
>         at org.apache.cocoon.Cocoon.service(Cocoon.java, Compiled Code)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled Code)
>         at org.apache.jserv.JServConnection.processRequest(JServConnection.java, Compiled Code)
>         at org.apache.jserv.JServConnection.run(JServConnection.java, Compiled Code)
>         at java.lang.Thread.run(Thread.java, Compiled Code)

There was a major problem using the OzoneProducer: The Cocoon processors
perform transformations on the DOM tree. If this DOM tree is an ozone object,
these transformation are stored persitently in the ozone database changing the
original XML DOM tree.
To work around  this problem you have to make an in-memory copy of the hole DOM
tree. You can do this 'by hand' or  - if you use DOM Level 2 - with the
Document.import() method. But this solution is very slow, because every method
call is a transaction between the producer and ozone.
You can speed it up, if you use the DOMConverterUtil class for conversion. I
attached the modified OzoneProducer class to this mail. Unfortunatly, for any
reason the XSLT processor doesn't find the stylesheet anymore though the
appropriate PIs are present. I couldn't find out, why. 

Suggestions are welcome!

Conny
// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by softwarebuero m&b (SMB).
//
// Copyright (C) The Ozone Database Project. All rights reserved.
//
// $Id: OzoneProducer.java,v 1.1 1999/11/20 15:58:47 daniela Exp $

import java.io.*;
import org.w3c.dom.*;
import javax.servlet.http.*;

import org.apache.cocoon.framework.*;
import org.apache.cocoon.parser.Parser;
import org.apache.cocoon.producer.*;

import org.ozoneDB.*;
import org.ozoneDB.xml.*;
import org.ozoneDB.xml.dom.*;
import org.ozoneDB.xml.util.*;


/**
@author <a href="/ozone-users/04-2000/mailto:zvia@netmanage.co.il">Zvi Avraham</a>
@version $Revision: 1.1 $Date: 1999/11/20 15:58:47 $
*/
public
    class       OzoneProducer
    extends     AbstractProducer
    implements  Producer,
                Status
{
    // TODO: make all this Configurable
    private final static String hostname    = "localhost";
    private final static int    port        = 3333;
    private final static String username    = "conny";
    private final static String password    = "";

    private RemoteDatabase database=null;
    
    /**
     * get persistent DOM document form Ozone DB
     * @return persistent DOM document form Ozone DB
     */
    public Document getDocument(HttpServletRequest request)
        throws Exception
    {
        if (database==null)
        {
            database=new RemoteDatabase();
            database.open(hostname, port, username, password);
            database.reloadClasses();
        };

        final String documentName = request.getParameter("document");
        final String query        = request.getParameter("query");
        final String stylesheet   = request.getParameter("stylesheet");
        
        if (documentName==null)
        {
            throw new Exception("document parameter is not defined");
        };
        
        Document ozoneDoc = (Document)database.objectForName(documentName);
        
        if (ozoneDoc == null) {
          throw new Exception("document " + documentName + " does not exist in database");
        }
        
        DOMConverterUtil converter = new DOMConverterUtil(database);

        Document inMemDoc = (Document) converter.convertDOM(ozoneDoc);
        
        if(query!=null)
        {
            // TODO: return XPath.executeQuery(document, query);
            throw new Exception("XPath query engine still not implemented");
        };

        if(stylesheet!=null)
        {
            // TODO: insert:
            // <?xsl:stylesheet href=\""+stylesheet+"\"?>
            // <?cocoon-process type="xslt"?>
            throw new Exception("XSLT processing still not implemented");
        };
         
        return inMemDoc;
    };

    /**
     * This method is responsible to provide an input stream to read
     * the data generated or contained by the resource mapped by
     * this document producer. This stream is not guaranteed to be 
     * buffered.
     */
    public Reader getStream(HttpServletRequest request)
        throws Exception
    {
        return null;
    };
    
    /**
     * Returns the path where the resource is found, or an empty string if
     * no path can be applied to the resource.
     * Warning, null values are not valid.
     */
    public String getPath(HttpServletRequest request)
    {
        return "";
    };

    /**
     * This method always returns true to reduce the evaluation overhead to
     * a minimum. Producer are highly encouradged to overwrite this method
     * if they can provide a fast way to evaluate the response change.
     */
    public boolean hasChanged(Object request)
    {
        return true;
    };

    /**
     * toString() like method ...
     */
    public String getStatus()
    {
        return "Ozone PDOM Producer";
    };
};