KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > OzoneProducer


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by softwarebuero m&b (SMB).
3
//
4
// Copyright (C) The Ozone Database Project. All rights reserved.
5
//
6
// $Id: OzoneProducer.java,v 1.1 2001/12/17 17:45:07 per_nyfelt Exp $
7

8 import java.io.*;
9 import org.w3c.dom.*;
10 import javax.servlet.http.*;
11
12 import org.apache.cocoon.framework.*;
13 import org.apache.cocoon.parser.Parser;
14 import org.apache.cocoon.producer.Producer;
15
16 import org.ozoneDB.*;
17 import org.ozoneDB.xml.*;
18 import org.ozoneDB.xml.dom.*;
19 import org.ozoneDB.xml.util.*;
20
21
22 /**
23  * Simple sample that shows how to use ozone together with Cocoon. You need to
24  * install Cocoon</a> in order to run this example. Please check
25  * http://xml.apache.org/cocoon.<p>
26  *
27  * The Infozone project (http://infozone-group.org) has been started to provide
28  * a complete content management framework based on ozone and Cocoon.
29  *
30  *
31  * @author <a HREF="mailto:zvia@netmanage.co.il">Zvi Avraham</a>
32  * @version $Revision: 1.1 $Date: 2001/12/17 17:45:07 $
33  */

34 public class OzoneProducer extends AbstractActor implements Producer, Status {
35     // TODO: make all this Configurable
36
private final static String JavaDoc hostname = "localhost";
37     private final static int port = 3333;
38     private final static String JavaDoc username = "zvi";
39     private final static String JavaDoc password = "111";
40     
41     private RemoteDatabase database = null;
42     
43     
44     /**
45      * get persistent DOM document form Ozone DB
46      * @return persistent DOM document form Ozone DB
47      */

48     public Document getDocument( HttpServletRequest request ) throws Exception JavaDoc {
49         if (database == null) {
50             database = new RemoteDatabase();
51             database.open( hostname, port, username, password );
52             database.reloadClasses();
53         }
54         ;
55         
56         final String JavaDoc documentName = request.getParameter( "document" );
57         final String JavaDoc query = request.getParameter( "query" );
58         final String JavaDoc stylesheet = request.getParameter( "stylesheet" );
59         
60         if (documentName == null) {
61             throw new Exception JavaDoc( "document parameter is not defined" );
62         }
63         ;
64         
65         Document document = (Document)database.objectForName( documentName );
66         
67         if (query != null) {
68             // TODO: return XPath.executeQuery(document, query);
69
throw new Exception JavaDoc( "XPath query engine still not implemented" );
70         }
71         ;
72         
73         if (stylesheet != null) {
74             // TODO: insert:
75
// <?xsl:stylesheet HREF=\""+stylesheet+"\"?>
76
// <?cocoon-process type="xslt"?>
77
throw new Exception JavaDoc( "XSLT processing still not implemented" );
78         }
79         ;
80         
81         return document;
82     }
83     
84     
85     /**
86      * This method is responsible to provide an input stream to read
87      * the data generated or contained by the resource mapped by
88      * this document producer. This stream is not guaranteed to be
89      * buffered.
90      */

91     public Reader getStream( HttpServletRequest request ) throws Exception JavaDoc {
92         return null;
93     }
94     
95     
96     /**
97      * Returns the path where the resource is found, or an empty string if
98      * no path can be applied to the resource.
99      * Warning, null values are not valid.
100      */

101     public String JavaDoc getPath( HttpServletRequest request ) {
102         return "";
103     }
104     
105     
106     /**
107      * This method always returns true to reduce the evaluation overhead to
108      * a minimum. Producer are highly encouradged to overwrite this method
109      * if they can provide a fast way to evaluate the response change.
110      */

111     public boolean hasChanged( Object JavaDoc request ) {
112         return true;
113     }
114     
115     
116     /**
117      * toString() like method ...
118      */

119     public String JavaDoc getStatus() {
120         return "Ozone PDOM Producer";
121     }
122 }
123
Popular Tags