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 2002/02/08 00:28:34 UTC

cvs commit: xml-cocoon2/src/java/org/apache/cocoon Cocoon.java Main.java

dims        02/02/07 15:28:34

  Modified:    .        build.xml
               src/java/org/apache/cocoon Cocoon.java Main.java
  Log:
  Trying to precompile both XSP and XMAP files. This can be used in Production WAR deployments where users do not need to tweak the XSP and XMAP.
  
  To try this out Just add "-Dbuild.precompile=true" when you call ant.
  
  Revision  Changes    Path
  1.159     +5 -2      xml-cocoon2/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/build.xml,v
  retrieving revision 1.158
  retrieving revision 1.159
  diff -u -r1.158 -r1.159
  --- build.xml	5 Feb 2002 14:47:35 -0000	1.158
  +++ build.xml	7 Feb 2002 23:28:34 -0000	1.159
  @@ -1016,11 +1016,14 @@
     <!-- =================================================================== -->
     <!-- Prepares the libraries for the war package                          -->
     <!-- =================================================================== -->
  -  <target name="prepare-xsp" depends="package" if="compile.xsp">
  +  <target name="prepare-xsp" depends="package" if="build.precompile">
       <java classname="org.apache.cocoon.Main" fork="yes" failonerror="true">
  -      <arg line="-x -w ${build.war}/WEB-INF/classes -c webapp" />
  +      <arg line="-P -C ${build.war}/cocoon.xconf -w ${build.war}/WEB-INF/classes -c ${build.war}" />
         <classpath>
           <fileset dir="lib/core">
  +          <include name="**/*.jar"/>
  +        </fileset>
  +        <fileset dir="lib/optional">
             <include name="**/*.jar"/>
           </fileset>
           <pathelement location="${build.dir}/${name}.jar"/>
  
  
  
  1.14      +2 -4      xml-cocoon2/src/java/org/apache/cocoon/Cocoon.java
  
  Index: Cocoon.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/Cocoon.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- Cocoon.java	6 Feb 2002 17:10:16 -0000	1.13
  +++ Cocoon.java	7 Feb 2002 23:28:34 -0000	1.14
  @@ -105,7 +105,7 @@
    * @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>
    * @author <a href="mailto:leo.sutic@inspireinfrastructure.com">Leo Sutic</a>
  - * @version CVS $Id: Cocoon.java,v 1.13 2002/02/06 17:10:16 cziegeler Exp $
  + * @version CVS $Id: Cocoon.java,v 1.14 2002/02/07 23:28:34 dims Exp $
    */
   public class Cocoon
           extends AbstractLoggable
  @@ -656,7 +656,7 @@
        * @param environment an <code>Environment</code> value
        * @exception Exception if an error occurs
        */
  -    public void generateXSP(String fileName, Environment environment)
  +    public void precompile(String fileName, Environment environment, String markupLanguage, String programmingLanguage)
       throws Exception {
           ProgramGenerator programGenerator = null;
           SourceHandler oldSourceHandler = environment.getSourceHandler();
  @@ -669,8 +669,6 @@
               programGenerator = (ProgramGenerator) this.componentManager.lookup(ProgramGenerator.ROLE);
               sourceHandler = (SourceHandler) this.componentManager.lookup(SourceHandler.ROLE);
               environment.setSourceHandler(sourceHandler);
  -            String markupLanguage = "xsp";
  -            String programmingLanguage = "java";
   
               CompiledComponent xsp = programGenerator.load(this.componentManager, fileName, markupLanguage, programmingLanguage, environment);
               if (getLogger().isDebugEnabled()) {
  
  
  
  1.16      +43 -19    xml-cocoon2/src/java/org/apache/cocoon/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/Main.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Main.java	4 Feb 2002 12:08:39 -0000	1.15
  +++ Main.java	7 Feb 2002 23:28:34 -0000	1.16
  @@ -99,7 +99,7 @@
    * Command line entry point.
    *
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Id: Main.java,v 1.15 2002/02/04 12:08:39 cziegeler Exp $
  + * @version CVS $Id: Main.java,v 1.16 2002/02/07 23:28:34 dims Exp $
    */
   public class Main {
   
  @@ -114,13 +114,13 @@
       protected static final int CONTEXT_DIR_OPT =  'c';
       protected static final int DEST_DIR_OPT =     'd';
       protected static final int WORK_DIR_OPT =     'w';
  -    protected static final int XSP_OPT =          'x';
       protected static final int AGENT_OPT =        'a';
       protected static final int ACCEPT_OPT =       'p';
       protected static final int URI_FILE =         'f';
       protected static final int FOLLOW_LINKS_OPT = 'r';
       protected static final int CONFIG_FILE =      'C';
       protected static final int BROKEN_LINK_FILE = 'b';
  +    protected static final int PRECOMPILE_OPT =   'P';
   
       protected static final String DEFAULT_USER_AGENT = Constants.COMPLETE_NAME;
       protected static final String DEFAULT_ACCEPT = "text/html, */*";
  @@ -166,10 +166,10 @@
                                  CLOptionDescriptor.ARGUMENT_REQUIRED,
                                  WORK_DIR_OPT,
                                  "use given dir as working directory"),
  -        new CLOptionDescriptor("xspOnly",
  +        new CLOptionDescriptor("precompileOnly",
                                  CLOptionDescriptor.ARGUMENT_DISALLOWED,
  -                               XSP_OPT,
  -                               "generate java code for xsp files"),
  +                               PRECOMPILE_OPT,
  +                               "generate java code for xsp and xmap files"),
           new CLOptionDescriptor("userAgent",
                                  CLOptionDescriptor.ARGUMENT_REQUIRED,
                                  AGENT_OPT,
  @@ -236,7 +236,7 @@
           String logKit = null;
           String logger = null;
           String logLevel = "DEBUG";
  -        boolean xspOnly = false;
  +        boolean precompileOnly = false;
           String userAgent = DEFAULT_USER_AGENT;
           String accept = DEFAULT_ACCEPT;
           boolean followLinks = true;
  @@ -288,8 +288,8 @@
                       logLevel = option.getArgument();
                       break;
   
  -                case Main.XSP_OPT:
  -                    xspOnly = true;
  +                case Main.PRECOMPILE_OPT:
  +                    precompileOnly = true;
                       break;
   
                   case Main.AGENT_OPT:
  @@ -340,7 +340,7 @@
               System.exit(1);
           }
   
  -        if (targets.size() == 0 && !xspOnly) {
  +        if (targets.size() == 0 && !precompileOnly) {
               String error = "Please, specify at least one starting URI.";
               log.error(error);
               System.out.println(error);
  @@ -349,7 +349,7 @@
   
           try {
               File dest = null;
  -            if (!xspOnly) {
  +            if (!precompileOnly) {
                   dest = getDir(destDir, "destination");
               }
               File work = getDir(workDir, "working");
  @@ -359,7 +359,9 @@
               if ( null == configFile ) {
                   conf = getConfigurationFile(context);
               } else {
  -                conf = new File(context, configFile);
  +                 conf = new File(configFile);
  +                 if(!conf.exists())
  +                     conf = new File(context, configFile);
               }
   
               DefaultContext appContext = new DefaultContext();
  @@ -401,8 +403,8 @@
               main.accept = accept;
               main.followLinks = followLinks;
               main.warmup();
  -            if (main.process(targets, xspOnly) == 0) {
  -                main.recursivelyProcessXSP(context, context);
  +            if (main.process(targets, precompileOnly) == 0) {
  +                main.recursivelyPrecompile(context, context);
               }
               c.dispose();
               log.info("Done");
  @@ -558,11 +560,11 @@
       /**
        * Process the URI list and process them all independently.
        * @param uris a <code>Collection</code> of URIs
  -     * @param xspOnly a <code>boolean</code> denoting to process XSP only
  +     * @param precompileOnly a <code>boolean</code> denoting to process XSP only
        * @return an <code>int</code> value with the number of links processed
        * @exception Exception if an error occurs
        */
  -    public int process(Collection uris, boolean xspOnly) throws Exception {
  +    public int process(Collection uris, boolean precompileOnly) throws Exception {
           int nCount = 0;
           log.info("...ready, let's go:");
   
  @@ -580,7 +582,7 @@
   
               try {
                   if (allProcessedLinks.get(url) == null) {
  -                    if (xspOnly) {
  +                    if (precompileOnly) {
                           this.processXSP(url);
                       } else if (this.followLinks) {
                           i = this.processURI(url).iterator();
  @@ -616,11 +618,17 @@
        * @param contextDir a <code>File</code> value for the context directory
        * @param file a <code>File</code> value for a single XSP file or a directory to scan recursively
        */
  -    public void recursivelyProcessXSP(File contextDir, File file) {
  +    public void recursivelyPrecompile(File contextDir, File file) {
           if (file.isDirectory()) {
               String entries[] = file.list();
               for (int i = 0; i < entries.length; i++) {
  -                recursivelyProcessXSP(contextDir, new File(file, entries[i]));
  +                recursivelyPrecompile(contextDir, new File(file, entries[i]));
  +            }
  +        } else if (file.getName().toLowerCase().endsWith(".xmap")) {
  +            try {
  +                this.processXMAP(IOUtils.getContextFilePath(contextDir.getCanonicalPath(),file.getCanonicalPath()));
  +            } catch (Exception e){
  +                //Ignore for now.
               }
           } else if (file.getName().toLowerCase().endsWith(".xsp")) {
               try {
  @@ -638,9 +646,25 @@
        * @exception Exception if an error occurs
        */
       public void processXSP(String uri) throws Exception {
  +        String markupLanguage = "xsp";
  +        String programmingLanguage = "java";
  +        Environment env = new LinkSamplingEnvironment("/", context, attributes, null, this.log);
  +        cocoon.precompile(uri, env, markupLanguage, programmingLanguage);
  +    }
  +
  +    /**
  +     * Process a single XMAP file
  +     *
  +     * @param uri a <code>String</code> pointing to an xmap URI
  +     * @exception Exception if an error occurs
  +     */
  +    public void processXMAP(String uri) throws Exception {
  +        String markupLanguage = "sitemap";
  +        String programmingLanguage = "java";
           Environment env = new LinkSamplingEnvironment("/", context, attributes, null, this.log);
  -        cocoon.generateXSP(uri, env);
  +        cocoon.precompile(uri, env, markupLanguage, programmingLanguage);
       }
  +
   
       /**
        * Processes the given URI and return all links. The algorithm is the following:
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org