You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2001/08/05 20:20:45 UTC

cvs commit: xml-cocoon2/src/org/apache/cocoon/components/language/generator ProgramGeneratorImpl.java

vgritsenko    01/08/05 11:20:45

  Modified:    src/org/apache/cocoon/components/language/generator
                        ProgramGeneratorImpl.java
  Log:
  Exclude servlet context from generated package names
  
  Revision  Changes    Path
  1.15      +24 -6     xml-cocoon2/src/org/apache/cocoon/components/language/generator/ProgramGeneratorImpl.java
  
  Index: ProgramGeneratorImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/generator/ProgramGeneratorImpl.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ProgramGeneratorImpl.java	2001/07/29 04:17:47	1.14
  +++ ProgramGeneratorImpl.java	2001/08/05 18:20:44	1.15
  @@ -12,6 +12,7 @@
   import java.io.FileNotFoundException;
   import java.io.FileReader;
   import java.io.IOException;
  +import java.net.MalformedURLException;
   import org.apache.avalon.framework.activity.Disposable;
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
  @@ -49,7 +50,7 @@
   /**
    * The default implementation of <code>ProgramGenerator</code>
    * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
  - * @version CVS $Revision: 1.14 $ $Date: 2001/07/29 04:17:47 $
  + * @version CVS $Revision: 1.15 $ $Date: 2001/08/05 18:20:44 $
    */
   public class ProgramGeneratorImpl extends AbstractLoggable
       implements ProgramGenerator, Contextualizable, Composable, Configurable, ThreadSafe, Disposable {
  @@ -84,11 +85,25 @@
       /** The root package */
       protected String rootPackage;
   
  +    /** Servlet Context Directory */
  +    protected String contextDir;
  +
       /** Contextualize this class */
       public void contextualize(Context context) throws ContextException {
           if (this.workDir == null) {
               this.workDir = (File) context.get(Constants.CONTEXT_WORK_DIR);
           }
  +
  +        if (this.contextDir == null) {
  +            org.apache.cocoon.environment.Context ctx =
  +                (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
  +            try {
  +                this.contextDir = ctx.getResource("").toExternalForm();
  +            } catch (MalformedURLException e) {
  +                getLogger().warn("Could not get context directory", e);
  +                this.contextDir = "";
  +            }
  +        }
       }
   
       /**
  @@ -143,11 +158,14 @@
           // Set filenames
           StringBuffer contextFilename = new StringBuffer(this.rootPackage.replace('.', File.separatorChar));
           contextFilename.append(File.separator);
  -        /*
  -         * VG: Filename here is relative to (sub)sitemap - cannot be used
  -         * to generate classname.
  -         */
  -        contextFilename.append(source.getSystemId());
  +        String id = source.getSystemId();
  +        if(id.startsWith(this.contextDir)) {
  +            // VG: File is located under contextDir, using relative file name
  +            contextFilename.append(id.substring(this.contextDir.length()));
  +        } else {
  +            // VG: File is located outside of contextDir, using systemId
  +            contextFilename.append(id);
  +        }
           String normalizedName = IOUtils.normalizedFilename(contextFilename.toString());
   
           // Ensure no 2 requests for the same file overlap
  
  
  

----------------------------------------------------------------------
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