cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From =?us-ascii?Q?Nicol=E1s?= Lichtmaier <n...@debian.org>
Subject [C1] [patch] Using Cocoon just to generate Java files.
Date Thu, 22 Feb 2001 04:20:09 GMT
 I'm the leader of a project here using Cocoon for a new site. The site is
for a big bank and they'll sell insurance policies. This is a very huge
client (one of the biggest banks in the world). This project is very
sensitive to us and I'd like to do it in the best possible way. We must reuse
code, and I don't like using "includes" to achieve that,

Sometimes I've needed some Cocoon modifications (which I have sent, allowing
XSP to be used in several JServ zones). Now I have another modification: We
need to share presentational XML. We need a way to create methods that
output DOM trees, and which can be shared among pages.

 With the patch I'm sending, this is done in the following way:

<xsp:page name="UtilClass" package="ar.com.technisys.somebank.xsp">

<xsp:logic>

	void sendInsurancePolicyHeader(HttpServletRequest request,
		HttpServletResponse response, Document document,
		Node xspCurrentNode, Policy pol)
	{
		Node xspParentNode;
		Stack xspNodeStack = new Stack();

		<xsp:content>
		This is content.
		[...]
		</xsp:content>
	}



</xsp:logic>

<myRootElement>This is not a page.</myRootElement>

</xsp:page>

The declaration of the method will be done later with a taglib, so nobody
will need to remember the Cocoon specific parameter or initializations (and
another taglib for calling the method).

 To insert this in the build.xml (running Cocoon from the command line), I
needed a way to tell the XSPProcessor to avoid compiling the page, and to
return just the generated source code. That's why that 'compile="no"'
attribute is there. I'm using the "name", and "package" attribute to set the
proper class name and package (so I needed to modify the preprocessor to not
clobber my values).

 This is the patch (fairly small):

Index: XSPProcessor.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon/src/org/apache/cocoon/processor/xsp/XSPProcessor.java,v
retrieving revision 1.40
diff -u -r1.40 XSPProcessor.java
--- XSPProcessor.java	2001/02/05 20:01:55	1.40
+++ XSPProcessor.java	2001/02/22 04:00:04
@@ -336,6 +337,11 @@
       throw new Exception("Unsupported language: " + languageName);
     }
 
+    boolean justTheCode = false;
+    String compile = root.getAttribute("compile");;
+    justTheCode=(compile != null && (compile.equals("no")
+    	|| compile.equals("false")));
+
     // Retrieve servletContext and request objects from parameters
     HttpServletRequest request =
       (HttpServletRequest) parameters.get("request");
@@ -444,6 +450,13 @@
            ((Hashtable) this.byNamespace.get("xsp")).get(languageName)
           ).apply(document, logicsheetParameters);
   
+
+        if(justTheCode) {
+            // We need to add a PI to send this to a text/plain formatter.
+            document.insertBefore(document.createProcessingInstruction("cocoon-format"
+                ,"type=\"text/plain\""),document.getDocumentElement());
+            return document;
+        }
   
         // Retrieve and format generated source code
         Element sourceElement = document.getDocumentElement();
@@ -669,7 +682,7 @@
     // Get page from Cocoon store
     PageEntry pageEntry = getPageEntry (request);
 
-    if (pageEntry == null) return false;
+    if (pageEntry == null || pageEntry.getPage() == null) return false;
 
     // NOT pageEntry.isCacheable ()! We are calling the isCacheable method
     // of the XSP page itself.
Index: language/java/XSPJavaPreprocessor.java
===================================================================
RCS file: /home/cvspublic/xml-cocoon/src/org/apache/cocoon/processor/xsp/language/java/XSPJavaPreprocessor.java,v
retrieving revision 1.6
diff -u -r1.6 XSPJavaPreprocessor.java
--- language/java/XSPJavaPreprocessor.java	2001/01/19 02:46:06	1.6
+++ language/java/XSPJavaPreprocessor.java	2001/02/22 04:00:04
@@ -75,8 +75,10 @@
     String packageName = this.javaProcessor.packageName(filename);
     String className = this.javaProcessor.className(filename);
     
-    root.setAttribute("name", className);
-    root.setAttribute("package", packageName);
+    if(root.getAttribute("name")==null || root.getAttribute("name").equals(""))
+        root.setAttribute("name", className);
+    if(root.getAttribute("package")==null || root.getAttribute("package").equals(""))
+        root.setAttribute("package", packageName);
 
     this.process(document);
 


Mime
View raw message