You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by di...@apache.org on 2001/02/24 16:58:05 UTC
cvs commit: xml-cocoon/src/org/apache/cocoon Cocoon.java Main.java
dims 01/02/24 07:58:05
Modified: src/org/apache/cocoon Tag: xml-cocoon2 Cocoon.java Main.java
Log:
Generate .java and .class files for sitemap and xsp's from the command-line.
Revision Changes Path
No revision
No revision
1.4.2.59 +58 -1 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.58
retrieving revision 1.4.2.59
diff -u -r1.4.2.58 -r1.4.2.59
--- Cocoon.java 2001/02/22 19:07:34 1.4.2.58
+++ Cocoon.java 2001/02/24 15:58:04 1.4.2.59
@@ -40,12 +40,16 @@
import org.xml.sax.SAXException;
import org.xml.sax.InputSource;
+import org.apache.cocoon.components.language.generator.ProgramGenerator;
+import org.apache.cocoon.components.language.generator.CompiledComponent;
+import org.apache.cocoon.components.url.URLFactory;
+
/**
* The Cocoon Object is the main Kernel for the entire Cocoon system.
*
* @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a> (Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.4.2.58 $ $Date: 2001/02/22 19:07:34 $
+ * @version CVS $Revision: 1.4.2.59 $ $Date: 2001/02/24 15:58:04 $
*/
public class Cocoon extends AbstractLoggable implements Component, Initializable, Modifiable, Processor, Contextualizable {
/** The application context */
@@ -206,5 +210,58 @@
public boolean process(Environment environment)
throws Exception {
return this.sitemapManager.invoke(environment, "", this.sitemapFileName, true);
+ }
+
+ /**
+ * Process the given <code>Environment</code> to generate the sitemap.
+ */
+ public void generateSitemap(Environment environment)
+ throws Exception {
+ URLFactory urlFactory = (URLFactory) this.componentManager.lookup(Roles.URL_FACTORY);
+ File sourceFile = new File(urlFactory.getURL(environment.resolveEntity(null, sitemapFileName).getSystemId()).getFile());
+ String markupLanguage = "sitemap";
+ String programmingLanguage = "java";
+
+ getLogger().debug("Sitemap regeneration begin:" + sitemapFileName);
+ try {
+ ProgramGenerator programGenerator = (ProgramGenerator) this.componentManager.lookup(Roles.PROGRAM_GENERATOR);
+ CompiledComponent smap = (CompiledComponent) programGenerator.load(sourceFile, markupLanguage, programmingLanguage, environment);
+ getLogger().debug("Sitemap regeneration complete");
+
+ if (smap != null) {
+ getLogger().debug("Main: The sitemap has been successfully compiled!");
+ } else {
+ getLogger().debug("Main: No errors, but the sitemap has not been set.");
+ }
+
+ this.componentManager.release((Component) programGenerator);
+ } catch (Exception e) {
+ getLogger().error("Main: Error compiling sitemap", e);
+ throw e;
+ }
+ }
+
+ /**
+ * Process the given <code>Environment</code> to generate Java code for specified XSP files.
+ */
+ public void generateXSP(String fileName, Environment environment)
+ throws Exception {
+ getLogger().debug("XSP generation begin:" + fileName);
+
+ URLFactory urlFactory = (URLFactory) this.componentManager.lookup(Roles.URL_FACTORY);
+ File sourceFile = new File(urlFactory.getURL(environment.resolveEntity(null, fileName).getSystemId()).getFile());
+ String markupLanguage = "xsp";
+ String programmingLanguage = "java";
+
+ try {
+ ProgramGenerator programGenerator = (ProgramGenerator) this.componentManager.lookup(Roles.PROGRAM_GENERATOR);
+ CompiledComponent xsp = (CompiledComponent) programGenerator.load(sourceFile, markupLanguage, programmingLanguage, environment);
+ getLogger().debug("XSP generation complete:" + xsp);
+
+ this.componentManager.release((Component) programGenerator);
+ } catch (Exception e) {
+ getLogger().error("Main: Error compiling XSP", e);
+ throw e;
+ }
}
}
1.1.4.24 +34 -30 xml-cocoon/src/org/apache/cocoon/Attic/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Main.java,v
retrieving revision 1.1.4.23
retrieving revision 1.1.4.24
diff -u -r1.1.4.23 -r1.1.4.24
--- Main.java 2001/02/24 13:57:49 1.1.4.23
+++ Main.java 2001/02/24 15:58:04 1.1.4.24
@@ -49,7 +49,7 @@
* Command line entry point.
*
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.1.4.23 $ $Date: 2001/02/24 13:57:49 $
+ * @version CVS $Revision: 1.1.4.24 $ $Date: 2001/02/24 15:58:04 $
*/
public class Main {
@@ -308,7 +308,8 @@
public void warmup() throws Exception {
log.info("Warming up...");
log.info(" [Cocoon might need to compile the sitemaps, this might take a while]");
- cocoon.process(new LinkSamplingEnvironment("/", context, attributes, null));
+ //cocoon.process(new LinkSamplingEnvironment("/", context, attributes, null));
+ cocoon.generateSitemap(new LinkSamplingEnvironment("/", context, attributes, null));
}
/**
@@ -318,10 +319,18 @@
log.info("...ready, let's go:");
Iterator i = uris.iterator();
while (i.hasNext()) {
- this.processURI(NetUtils.normalize((String) i.next()), 0, xspOnly);
+ if(xspOnly)
+ this.processXSP(NetUtils.normalize((String) i.next()));
+ else
+ this.processURI(NetUtils.normalize((String) i.next()), 0);
}
}
+ public void processXSP(String uri) throws Exception {
+ Environment env = new LinkSamplingEnvironment("/", context, attributes, null);
+ cocoon.generateXSP(uri, env);
+ }
+
/**
* Processes the given URI in a recursive way. The algorithm followed by
* this method is the following:
@@ -340,7 +349,7 @@
* <li>then the file name of the translated URI is returned</li>
* </ul>
*/
- public String processURI(String uri, int level, boolean xspOnly) throws Exception {
+ public String processURI(String uri, int level) throws Exception {
log.info("Processing URI: " + leaf(level) + uri);
Collection links = this.getLinks(uri);
@@ -351,38 +360,33 @@
String path = NetUtils.getPath(uri);
String relativeLink = (String) i.next();
String absoluteLink = NetUtils.normalize(NetUtils.absolutize(path, relativeLink));
- String translatedAbsoluteLink = this.processURI(absoluteLink, level + 1, xspOnly);
+ String translatedAbsoluteLink = this.processURI(absoluteLink, level + 1);
String translatedRelativeLink = NetUtils.relativize(path, translatedAbsoluteLink);
translatedLinks.put(relativeLink, translatedRelativeLink);
}
String filename = mangle(uri);
- if (!xspOnly) {
- File file = IOUtils.createFile(destDir, filename);
- FileOutputStream output = new FileOutputStream(file);
- String type = getPage(uri, translatedLinks, output);
- output.close();
-
- String ext = NetUtils.getExtension(filename);
- String defaultExt = MIMEUtils.getDefaultExtension(type);
-
- if ((ext == null) || (!ext.equals(defaultExt))) {
- filename += defaultExt;
- File newFile = IOUtils.createFile(destDir, filename);
- file.renameTo(newFile);
- file = newFile;
- }
- log.info(tree(level));
-
- if (type == null) {
- log.warn(leaf(level + 1) + "[broken link]--> " + filename);
- resourceUnavailable(file);
- } else {
- log.info(leaf(level + 1) + "[" + type + "]--> " + filename);
- }
+ File file = IOUtils.createFile(destDir, filename);
+ FileOutputStream output = new FileOutputStream(file);
+ String type = getPage(uri, translatedLinks, output);
+ output.close();
+
+ String ext = NetUtils.getExtension(filename);
+ String defaultExt = MIMEUtils.getDefaultExtension(type);
+
+ if ((ext == null) || (!ext.equals(defaultExt))) {
+ filename += defaultExt;
+ File newFile = IOUtils.createFile(destDir, filename);
+ file.renameTo(newFile);
+ file = newFile;
+ }
+ log.info(tree(level));
+
+ if (type == null) {
+ log.warn(leaf(level + 1) + "[broken link]--> " + filename);
+ resourceUnavailable(file);
} else {
- log.info(tree(level));
- log.info(leaf(level + 1) + "--> " + filename);
+ log.info(leaf(level + 1) + "[" + type + "]--> " + filename);
}
return filename;