You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by st...@locus.apache.org on 2000/08/17 19:03:17 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon Cocoon.java
stefano 00/08/17 10:03:16
Modified: src/org/apache/cocoon Tag: xml-cocoon2 Cocoon.java
Log:
added final static variables and cleaned-up syntax (you know, I'm picky for those things)
Revision Changes Path
No revision
No revision
1.4.2.18 +57 -43 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.4.2.17
retrieving revision 1.4.2.18
diff -u -r1.4.2.17 -r1.4.2.18
--- Cocoon.java 2000/08/04 21:11:03 1.4.2.17
+++ Cocoon.java 2000/08/17 17:03:15 1.4.2.18
@@ -5,6 +5,7 @@
* version 1.1, a copy of which has been included with this distribution in *
* the LICENSE file. *
*****************************************************************************/
+
package org.apache.cocoon;
import java.io.File;
@@ -32,34 +33,46 @@
import org.apache.cocoon.serialization.Serializer;
import org.apache.cocoon.sitemap.SitemapManager;
-//import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
+ * Cocoon Main Class
*
* @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
* (Apache Software Foundation, Exoffice Technologies)
- * @version CVS $Revision: 1.4.2.17 $ $Date: 2000/08/04 21:11:03 $
+ * @version CVS $Revision: 1.4.2.18 $ $Date: 2000/08/17 17:03:15 $
*/
public class Cocoon
-implements Component, Configurable, ComponentManager, Modifiable,
- Processor {
+ implements Component, Configurable, ComponentManager, Modifiable, Processor {
+
+ /*
+ * Cocoon Default Strings
+ */
+ public static final String NAME = "Cocoon";
+ public static final String VERSION = "@version@";
+ public static final String YEAR = "@year@";
+
+ public static final String RELOAD_PARAM = "cocoon-reload";
+ public static final String SHOWTIME_PARAM = "cocoon-showtime";
+ public static final String VIEW_PARAM = "cocoon-view";
+ public static final String TEMPDIR_PROPERTY = "org.apache.cocoon.properties.tempdir";
+
/** The table of role-class */
- private Hashtable components=new Hashtable();
+ private Hashtable components = new Hashtable();
/** The table of role-configuration */
- private Hashtable configurations=new Hashtable();
+ private Hashtable configurations = new Hashtable();
/** The configuration file */
- private File configurationFile=null;
+ private File configurationFile = null;
/** The sitemap file */
- private String sitemapFileName=null;
+ private String sitemapFileName = null;
/** The configuration tree */
- private Configuration configuration=null;
+ private Configuration configuration = null;
/** The sitemap manager */
- private SitemapManager sitemapManager=null;
+ private SitemapManager sitemapManager = null;
/** The root uri/path */
- private URL root=null;
+ private URL root = null;
/**
* Create a new <code>Cocoon</code> instance.
@@ -67,12 +80,12 @@
protected Cocoon()
throws ConfigurationException {
super();
+
// Setup the default parser, for parsing configuration.
// If one need to use a different parser, set the given system property
- String parser=null;
- parser=System.getProperty("org.apache.cocoon.components.parser.Parser",
+ String parser = System.getProperty("org.apache.cocoon.components.parser.Parser",
"org.apache.cocoon.components.parser.XercesParser");
- this.components.put("parser",this.getClass(parser,null));
+ this.components.put("parser", this.getClass(parser,null));
}
/**
@@ -82,18 +95,19 @@
public Cocoon(String configuration)
throws SAXException, IOException, ConfigurationException {
this();
- this.configurationFile=new File(configuration).getCanonicalFile();
+ this.configurationFile = new File(configuration).getCanonicalFile();
if (!this.configurationFile.isFile())
throw new FileNotFoundException(configuration);
- Parser p=(Parser)this.getComponent("parser");
- SAXConfigurationBuilder b=new SAXConfigurationBuilder();
+
+ Parser p = (Parser) this.getComponent("parser");
+ SAXConfigurationBuilder b = new SAXConfigurationBuilder();
p.setContentHandler(b);
String path = this.configurationFile.getPath();
InputSource is = new InputSource(new FileReader(path));
is.setSystemId(path);
p.parse(is);
this.setConfiguration(b.getConfiguration());
- this.root=this.configurationFile.getParentFile().toURL();
+ this.root = this.configurationFile.getParentFile().toURL();
}
/**
@@ -103,30 +117,30 @@
public void setRoot(URL root) {
this.root = root;
}
-
+
/**
* Get the <code>Component</code> associated with the given role.
*/
public Component getComponent(String role)
throws ComponentNotFoundException, ComponentNotAccessibleException {
- if (role==null) throw new ComponentNotFoundException("Null role");
+ if (role == null) throw new ComponentNotFoundException("Null role");
if (role.equals("cocoon")) return (this);
- Class c=(Class)this.components.get(role);
- if (c==null)
- throw new ComponentNotFoundException("Can't find component "+role);
+ Class c = (Class) this.components.get(role);
+ if (c == null)
+ throw new ComponentNotFoundException("Can't find component " + role);
try {
- Component comp=(Component)c.newInstance();
+ Component comp = (Component) c.newInstance();
if (comp instanceof Composer)
((Composer)comp).setComponentManager(this);
if (comp instanceof Configurable) {
- Configuration conf=(Configuration)this.configurations.get(role);
+ Configuration conf = (Configuration) this.configurations.get(role);
if (conf!=null) ((Configurable)comp).setConfiguration(conf);
}
return(comp);
} catch (Exception e) {
- throw new ComponentNotAccessibleException("Can't access class "+
- c.getName()+" with role "+role+" due to a "+
- e.getClass().getName()+"("+e.getMessage()+")",e);
+ throw new ComponentNotAccessibleException("Can't access class '" +
+ c.getName() + "' with role '" + role + "' due to a " +
+ e.getClass().getName() + "[" + e.getMessage() + "]", e);
}
}
@@ -135,25 +149,27 @@
*/
public void setConfiguration(Configuration conf)
throws ConfigurationException {
- this.configuration=conf;
+ this.configuration = conf;
if (!conf.getName().equals("cocoon"))
- throw new ConfigurationException("Invalid configuration file",conf);
+ throw new ConfigurationException("Invalid configuration file", conf);
if (!conf.getAttribute("version").equals("2.0"))
- throw new ConfigurationException("Invalid version",conf);
+ throw new ConfigurationException("Invalid version", conf);
+
// Set components
- Enumeration e=conf.getConfigurations("component");
+ Enumeration e = conf.getConfigurations("component");
while (e.hasMoreElements()) {
- Configuration co=(Configuration)e.nextElement();
- String ro=co.getAttribute("role");
- String cl=co.getAttribute("class");
- this.components.put(ro,this.getClass(cl,co));
+ Configuration co = (Configuration) e.nextElement();
+ String ro = co.getAttribute("role");
+ String cl = co.getAttribute("class");
+ this.components.put(ro, this.getClass(cl,co));
this.configurations.put(ro,co);
}
+
// Create the sitemap
- Configuration sconf=conf.getConfiguration("sitemap");
+ Configuration sconf = conf.getConfiguration("sitemap");
if (sconf==null)
throw new ConfigurationException("No sitemap configuration",conf);
- this.sitemapManager=new SitemapManager();
+ this.sitemapManager = new SitemapManager();
this.sitemapManager.setComponentManager(this);
this.sitemapManager.setConfiguration(conf);
this.sitemapFileName = sconf.getAttribute("file");
@@ -163,7 +179,7 @@
* Queries the class to estimate its ergodic period termination.
*/
public boolean modifiedSince(long date) {
- return(date<this.configurationFile.lastModified()
+ return(date < this.configurationFile.lastModified()
|| sitemapManager.hasChanged());
}
@@ -175,8 +191,7 @@
String s = environment.resolveEntity(null,this.sitemapFileName).getSystemId();
URL url = new URL (s);
s = url.getFile();
- return this.sitemapManager.invoke (environment, "",
- s, true);
+ return this.sitemapManager.invoke (environment, "", s, true);
}
/** Get a new class */
@@ -188,8 +203,7 @@
try {
return(this.getClass().getClassLoader().loadClass(className));
} catch (ClassNotFoundException e) {
- throw new ConfigurationException("Cannot load class "+className,
- conf);
+ throw new ConfigurationException("Cannot load class " + className, conf);
}
}
}