cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Butler, Mark H (Labs Bristol)" <mark-h.but...@hp.com>
Subject Question about the best way to locate the path to WEB-INF
Date Thu, 21 Oct 2004 12:57:50 GMT
Hi team,

I need your advice on the best way to fix a problem when using Cocoon on
Tomcat caused by DELI that I do not encounter when running Cocoon on
Jetty. Therefore I would like your advice as solving the problem seems
to require an understanding of the differences between servlet engines
that I'm afraid I do not possess. Patrick Melo has reported this
exception:

java.net.MalformedURLException: Path
\\server\share\webappname\webappname\WEB-INF/deli/config/deliConfig.xml
does not start with a "/" character
java.net.MalformedURLException: Path
\\server\share\webappname\webappname\WEB-INF/deli/config/deliConfig.xml
does not start with a "/" character
	at
org.apache.catalina.core.ApplicationContext.getResource(ApplicationConte
xt.java:469)
	at
org.apache.catalina.core.ApplicationContextFacade.getResource(Applicatio
nContextFacade.java:176)
	at
org.apache.cocoon.environment.http.HttpContext.getResource(HttpContext.j
ava:99)
	at
org.apache.cocoon.components.deli.DeliImpl$CocoonServletContext.getResou
rce(DeliImpl.java:254)
	at com.hp.hpl.deli.Workspace.getResource(Workspace.java:473)
	at com.hp.hpl.deli.Workspace.getInputSource(Workspace.java:439)
	at
com.hp.hpl.deli.Workspace$1$CreateWorkspace.<init>(Workspace.java:181)
	at com.hp.hpl.deli.Workspace.configure(Workspace.java:367)
	at
org.apache.cocoon.components.deli.DeliImpl.initialize(DeliImpl.java:147)
	at
org.apache.avalon.framework.container.ContainerUtil.initialize(Container


Now currently DELI is determining the path using the following code:

servletContext = sc;

if (servletContext != null) {
  if (path == null) {
    try {
      path = servletContext.getRealPath("/WEB-INF").toString();
      printDebug("Using getRealPath: " + path);
    } catch (Exception e) {
      printDebug("Unable to use getRealPath to locate /WEB-INF");     
    }
   }

   if (path == null) {
     try {
       URL resUrl = servletContext.getResource("/WEB-INF");

       if (resUrl != null) {
         path = resUrl.toString();
         printDebug("Using getResource: " + path);
       }
      } catch (java.net.MalformedURLException me) {
      printDebug("Unable to use getResource to locate /WEB-INF");
      }
   }
} else {
 path = "";
}

if (path.endsWith("WEB-INF")) {
  path = path.substring(0, path.length() - "WEB-INF".length()); }

printDebug("DELI is using path: " + path); 


then GetResource works as follows:


protected InputStream getResource(String name) throws Exception {
 try {
    printDebug("Getting resource: " + path + name);

    File file = new File(path + name);
    InputStream in;

    if (name.startsWith("http") || name.startsWith("file") ||
         name.startsWith("jndi")) {
        in = (new URL(name)).openStream();
    } else if (file.exists()) {
        in = new FileInputStream(path + name); 
    } else if (servletContext != null) {
       /*in = servletContext.getResourceAsStream(name);*/
       URL url = servletContext.getResource(name);
       in = url.openStream();
       } else {
         in = getClass().getClassLoader().getResourceAsStream(name);
       }

       return in;
    } catch (FileNotFoundException fnfe) {
      printDebug("Could not load file: " + name);
    } catch (Exception e) {
      printDebug("Cannot retrieve resource: " + name);
    }
  return null;
}

any suggestions on a better way to do this?

thanks in advance

Mark H. Butler
mark-h.butler@hp.com
HP Labs Bristol http://www.hpl.hp.com/people/marbut

Mime
View raw message