stefano 00/05/01 16:53:17 Modified: src/org/apache/cocoon Cocoon.java cocoon.properties Defaults.java Log: now cocoon is able to understand if run by tomcat and get it's properties from getResource()... This should ease installation on tomcat since you can use the deployment descriptor shipped with the distribution without even touching it (Paul, I improved your patch a little, hope you don't mind) Revision Changes Path 1.14 +53 -6 xml-cocoon/src/org/apache/cocoon/Cocoon.java Index: Cocoon.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Cocoon.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- Cocoon.java 2000/04/04 11:10:10 1.13 +++ Cocoon.java 2000/05/01 23:53:16 1.14 @@ -1,4 +1,4 @@ -/*-- $Id: Cocoon.java,v 1.13 2000/04/04 11:10:10 stefano Exp $ -- +/*-- $Id: Cocoon.java,v 1.14 2000/05/01 23:53:16 stefano Exp $ -- ============================================================================ The Apache Software License, Version 1.1 @@ -64,7 +64,7 @@ * separate different knowledge contexts in different processing layers. * * @author Stefano Mazzocchi - * @version $Revision: 1.13 $ $Date: 2000/04/04 11:10:10 $ + * @version $Revision: 1.14 $ $Date: 2000/05/01 23:53:16 $ */ public class Cocoon extends HttpServlet implements Defaults { @@ -78,6 +78,8 @@ String statusURL = null; boolean errorsInternally = false; boolean showStatus = false; + int containerMajorVersion; + int containerMinorVersion; /** * Returns the version signature of Cocoon @@ -97,18 +99,37 @@ // Get the initialization argument confsName = config.getInitParameter(INIT_ARG); + containerMajorVersion = this.getContainerMajorVersion(); + containerMinorVersion = this.getContainerMinorVersion(); if (confsName == null) { exception = null; - message = "
The servlet initialization argument \"" + INIT_ARG + "\" was not found. " + - "Please, make sure Cocoon is able to find its configurations or it won't be able to execute correctly.
" + - "A template for such configurations may be found in the file \"/conf/cocoon.properties\" in the distribution.
"; + message = "The servlet initialization argument \"" + + INIT_ARG + + "\" was not found. Please, make sure Cocoon is able to " + + "find its configurations or it won't be able to execute correctly.
" + + "A template for such configurations may be found in the " + + "file \"/conf/cocoon.properties\" in the distribution.
"; return; } try { // Create the configuration object - confs = new Configurations(confsName); + // if we are using a servlet container that is 2.1 or higher then we + // can use container based resources instead of files + if ((containerMajorVersion >= 2) && (containerMinorVersion > 0)) { + try { + URL resource = config.getServletContext().getResource(confsName); + InputStream confsStream = resource.openConnection().getInputStream(); + confs = new Configurations(confsStream); + confsStream.close(); + } catch (Exception ex) { + exception = ex; + message = "Unable to open resource: " + confsName; + } + } else { + confs = new Configurations(confsName); + } // Save servlet configurations showStatus = ((String) confs.get(SHOW_STATUS, "false")).toLowerCase().equals("true"); @@ -179,7 +200,33 @@ public String getServletInfo() { return version(); } + + /** + * This method tries to guess the container major version. + */ + private int getContainerMajorVersion() { + int v; + try { + v = getServletConfig().getServletContext().getMajorVersion(); + } catch (NoSuchMethodError e) { + v = 2; // using pre 2.1 servlet container + } + return v; + } + /** + * This method tries to guess the container minor version. + */ + private int getContainerMinorVersion() { + int v; + try { + v = getServletConfig().getServletContext().getMinorVersion(); + } catch (NoSuchMethodError e) { + v = 0; // using pre 2.1 servlet container + } + return v; + } + /** * The entry point for standalone usage of Cocoon. * 1.29 +2 -2 xml-cocoon/src/org/apache/cocoon/cocoon.properties Index: cocoon.properties =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/cocoon.properties,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- cocoon.properties 2000/04/27 22:38:27 1.28 +++ cocoon.properties 2000/05/01 23:53:16 1.29 @@ -163,7 +163,7 @@ # This is used when no PI is present to indicate # which MIME type to associate to the document. -# NOTE: this type must present in the above map. +# NOTE: this type must present in the map below. formatter.default = text/html # These are used when the PI is present @@ -216,7 +216,7 @@ # PDF formatter.text/xslfo.MIME-type = application/pdf -# HTML 4.0 (trasitional) +# HTML 4.0 (transitional) formatter.text/html/loose.doctype-public = -//W3C//DTD HTML 4.0 Transitional//EN formatter.text/html/loose.doctype-system = http://www.w3.org/TR/REC-html40/loose.dtd formatter.text/html/loose.preserve-space = true 1.12 +3 -2 xml-cocoon/src/org/apache/cocoon/Defaults.java Index: Defaults.java =================================================================== RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Defaults.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- Defaults.java 2000/03/17 16:46:58 1.11 +++ Defaults.java 2000/05/01 23:53:16 1.12 @@ -1,4 +1,4 @@ -/*-- $Id: Defaults.java,v 1.11 2000/03/17 16:46:58 stefano Exp $ -- +/*-- $Id: Defaults.java,v 1.12 2000/05/01 23:53:16 stefano Exp $ -- ============================================================================ The Apache Software License, Version 1.1 @@ -54,7 +54,7 @@ * The Cocoon strings. * * @author Stefano Mazzocchi - * @version $Revision: 1.11 $ $Date: 2000/03/17 16:46:58 $ + * @version $Revision: 1.12 $ $Date: 2000/05/01 23:53:16 $ */ public interface Defaults { @@ -64,6 +64,7 @@ public static final String YEAR = "@year@"; public static final String INIT_ARG = "properties"; + public static final String PROPERTIES = "cocoon.properties"; public static final String INTERNAL_PROPERTIES = "org/apache/cocoon/" + PROPERTIES;