cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r368174 - in /cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon: blocks/BlockContext.java components/modules/input/BlockPathModule.java components/source/impl/BlockSource.java
Date Thu, 12 Jan 2006 00:05:24 GMT
Author: danielf
Date: Wed Jan 11 16:05:14 2006
New Revision: 368174

URL: http://svn.apache.org/viewcvs?rev=368174&view=rev
Log:
Moved the sitemap specific knowledge about prefix and path from the BlockContext to BlockSource
and BlockPathModule.

Modified:
    cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockContext.java
    cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/components/modules/input/BlockPathModule.java
    cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/components/source/impl/BlockSource.java

Modified: cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockContext.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockContext.java?rev=368174&r1=368173&r2=368174&view=diff
==============================================================================
--- cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockContext.java
(original)
+++ cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/blocks/BlockContext.java
Wed Jan 11 16:05:14 2006
@@ -35,66 +35,81 @@
 import org.apache.cocoon.blocks.util.ServletContextWrapper;
 
 /**
-* @version $Id$
-*/
+ * @version $Id$
+ */
 public class BlockContext extends ServletContextWrapper {
 
     private Hashtable attributes;
+
     private BlockWiring wiring;
+
     private Blocks blocks;
-    
-    public BlockContext(ServletContext parentContext, BlockWiring wiring, Blocks blocks)
-    throws ServletException, MalformedURLException {
-    	super(parentContext);
+
+    public BlockContext(ServletContext parentContext, BlockWiring wiring,
+            Blocks blocks) throws ServletException, MalformedURLException {
+        super(parentContext);
         this.wiring = wiring;
         this.blocks = blocks;
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see javax.servlet.ServletContext#getAttribute(java.lang.String)
      */
     public Object getAttribute(String name) {
         return this.attributes.get(name);
     }
 
-    /* (non-Javadoc)
-     * @see javax.servlet.ServletContext#setAttribute(java.lang.String, java.lang.Object)
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#setAttribute(java.lang.String,
+     *      java.lang.Object)
      */
     public void setAttribute(String name, Object value) {
         this.attributes.put(name, value);
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see javax.servlet.ServletContext#removeAttribute(java.lang.String)
      */
     public void removeAttribute(String name) {
         this.attributes.remove(name);
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see javax.servlet.ServletContext#getAttributeNames()
      */
     public Enumeration getAttributeNames() {
         return this.attributes.keys();
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see javax.servlet.ServletContext#getResource(java.lang.String)
      */
     public URL getResource(String path) throws MalformedURLException {
-        // A path starting with '/' should be resolved relative to the context and
-        // the '/' need to be removed to work with the URI resolver.
+        // A path starting with '/' should be resolved relative to the context
+        // and the '/' need to be removed to work with the URI resolver.
         while (path.length() >= 1 && path.charAt(0) == '/') {
             path = path.substring(1);
         }
         String location = this.wiring.getLocation();
         if (location.length() > 0 && location.charAt(0) != '/') {
-        	location = "/" + location;
+            location = "/" + location;
         }
-        return super.servletContext.getResource(location +  path);
+        return super.servletContext.getResource(location + path);
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see javax.servlet.ServletContext#getRealPath(java.lang.String)
      */
     public String getRealPath(String path) {
@@ -102,38 +117,47 @@
         return null;
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see javax.servlet.ServletContext#getInitParameter(java.lang.String)
      */
     // FIXME, this should be defined in the config instead
     public String getInitParameter(String name) {
-		String value = this.wiring.getProperty(name);
-	    // Ask the super block for the property
-		if (value == null) {
-		    String superId = this.wiring.getBlockId(Block.SUPER);
-		    // this.getLogger().debug("Try super property=" + name + " block=" + superId);
-		    Block block = this.blocks.getBlock(superId);
-		    if (block != null) {
-                // FIXME Should be taken from the ServletConfig rather than the ServletContext
-		        value =  block.getBlockServlet().getServletConfig().getServletContext().getInitParameter(name);
-		    }
-		}
-		// Ask the parent context
-		if (value == null) {
-			super.getInitParameter(name);
-		}
-		return value;
+        String value = this.wiring.getProperty(name);
+        // Ask the super block for the property
+        if (value == null) {
+            String superId = this.wiring.getBlockId(Block.SUPER);
+            // this.getLogger().debug("Try super property=" + name + " block=" +
+            // superId);
+            Block block = this.blocks.getBlock(superId);
+            if (block != null) {
+                // FIXME Should be taken from the ServletConfig rather than the
+                // ServletContext
+                value = block.getBlockServlet().getServletConfig()
+                        .getServletContext().getInitParameter(name);
+            }
+        }
+        // Ask the parent context
+        if (value == null) {
+            super.getInitParameter(name);
+        }
+        return value;
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see javax.servlet.ServletContext#getInitParameterNames()
      */
     public Enumeration getInitParameterNames() {
-		// TODO Auto-generated method stub
-		return null;
-	}
+        // TODO Auto-generated method stub
+        return null;
+    }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String)
      */
     public InputStream getResourceAsStream(String path) {
@@ -146,75 +170,90 @@
         }
     }
 
-	/* (non-Javadoc)
-	 * @see javax.servlet.ServletContext#getContext(java.lang.String)
-	 */
-	public ServletContext getContext(String uripath) {
-		return null;
-	}
-
-	/* (non-Javadoc)
-	 * @see javax.servlet.ServletContext#getMajorVersion()
-	 */
-	public int getMajorVersion() {
-		return 2;
-	}
-
-	/* (non-Javadoc)
-	 * @see javax.servlet.ServletContext#getMinorVersion()
-	 */
-	public int getMinorVersion() {
-		return 3;
-	}
-
-	/* (non-Javadoc)
-	 * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
-	 */
-	public Set getResourcePaths(String arg0) {
-		return null;
-	}
-
-	/* (non-Javadoc)
-	 * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String)
-	 */
-	public RequestDispatcher getRequestDispatcher(String arg0) {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	/* (non-Javadoc)
-	 * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
-	 */
-	public RequestDispatcher getNamedDispatcher(String name) {
-        NamedDispatcher dispatcher = new NamedDispatcher(name); 
-		return dispatcher.exists() ? dispatcher : null;
-	}
-
-	/* (non-Javadoc)
-	 * @see javax.servlet.ServletContext#getServerInfo()
-	 */
-	public String getServerInfo() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-
-	/* (non-Javadoc)
-	 * @see javax.servlet.ServletContext#getServletContextName()
-	 */
-	public String getServletContextName() {
-		// TODO Auto-generated method stub
-		return null;
-	}
-    
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getContext(java.lang.String)
+     */
+    public ServletContext getContext(String uripath) {
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getMajorVersion()
+     */
+    public int getMajorVersion() {
+        return 2;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getMinorVersion()
+     */
+    public int getMinorVersion() {
+        return 3;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
+     */
+    public Set getResourcePaths(String arg0) {
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getRequestDispatcher(java.lang.String)
+     */
+    public RequestDispatcher getRequestDispatcher(String arg0) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
+     */
+    public RequestDispatcher getNamedDispatcher(String name) {
+        NamedDispatcher dispatcher = new NamedDispatcher(name);
+        return dispatcher.exists() ? dispatcher : null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getServerInfo()
+     */
+    public String getServerInfo() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.servlet.ServletContext#getServletContextName()
+     */
+    public String getServletContextName() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
     // Block specific methods
-    
+
     /**
-     * Takes the scheme specific part of a block URI (the scheme is
-     * the responsibilty of the BlockSource) and resolve it with
-     * respect to the blocks mount point.
+     * Takes the scheme specific part of a block URI (the scheme is the
+     * responsibilty of the BlockSource) and resolve it with respect to the
+     * blocks mount point.
      */
-    public URI absolutizeURI(URI uriToResolve, URI base) throws URISyntaxException {
-        URI uri = resolveURI(uriToResolve, base);
+    public URI absolutizeURI(URI uri) throws URISyntaxException {
         String blockName = uri.getScheme();
         String blockId = null;
         if (blockName == null) {
@@ -226,11 +265,12 @@
         }
         Block block = this.blocks.getBlock(blockId);
         if (block == null)
-            throw new URISyntaxException(uriToResolve.toString(), "Unknown block name");
+            throw new URISyntaxException(uri.toString(), "Unknown block name");
 
         String mountPath = block.getMountPath();
         if (mountPath == null)
-            throw new URISyntaxException(uri.toString(), "No mount point for this URI");
+            throw new URISyntaxException(uri.toString(),
+                    "No mount point for this URI");
         if (mountPath.endsWith("/"))
             mountPath = mountPath.substring(0, mountPath.length() - 1);
         String absoluteURI = mountPath + uri.getSchemeSpecificPart();
@@ -238,45 +278,22 @@
         return new URI(absoluteURI);
     }
 
-    /**
-     * Parses and resolves the scheme specific part of a block URI
-     * with respect to the base URI of the current sitemap. The scheme
-     * specific part of the block URI has the form
-     * <code>foo:/bar</code> when refering to another block, in this
-     * case only an absolute path is allowed. For reference to the own
-     * block, both absolute <code>/bar</code> and relative
-     * <code>./foo</code> paths are allowed.
-     */
-    public URI resolveURI(URI uri, URI base) throws URISyntaxException {
-        log("BlockManager: resolving " + uri.toString() + " with scheme " +
-                          uri.getScheme() + " and ssp " + uri.getSchemeSpecificPart());
-        if (uri.getPath() != null && uri.getPath().length() >= 2 &&
-            uri.getPath().startsWith("./")) {
-            // self reference relative to the current sitemap, e.g. ./foo
-            if (uri.isAbsolute())
-                throw new URISyntaxException(uri.toString(), "When the protocol refers to
other blocks the path must be absolute");
-            URI resolvedURI = base.resolve(uri);
-            log("BlockManager: resolving " + uri.toString() +
-                              " to " + resolvedURI.toString() + " with base URI " + base.toString());
-            uri = resolvedURI;
-        }
-        return uri;
-    }
-    
-
     private class NamedDispatcher implements RequestDispatcher {
-        
+
         private String blockName;
+
         private String blockId;
+
         private boolean superCall = false;
+
         private Servlet servlet;
+
         private RequestDispatcher dispatcher;
- 
-        
+
         private NamedDispatcher(String blockName) {
             this.blockName = blockName;
             this.blockId = BlockContext.this.wiring.getBlockId(this.blockName);
-            
+
             this.superCall = Block.SUPER.equals(this.blockName);
 
             if (blockId != null) {
@@ -289,28 +306,35 @@
                 // be defined there instead.
                 blockId = BlockContext.this.wiring.getBlockId(Block.SUPER);
                 if (blockId != null) {
-                    Block superBlock = BlockContext.this.blocks.getBlock(blockId);
+                    Block superBlock = BlockContext.this.blocks
+                            .getBlock(blockId);
                     if (superBlock != null) {
                         Servlet superServlet = superBlock.getBlockServlet();
-                        this.dispatcher =
-                            superServlet.getServletConfig().getServletContext().getNamedDispatcher(blockName);
-                        this.superCall = true;                        
+                        this.dispatcher = superServlet.getServletConfig()
+                                .getServletContext().getNamedDispatcher(
+                                        blockName);
+                        this.superCall = true;
                     }
                 }
             }
         }
-        
+
         private boolean exists() {
             return this.servlet != null || this.dispatcher != null;
         }
 
-        /* (non-Javadoc)
-         * @see javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
+        /*
+         * (non-Javadoc)
+         * 
+         * @see javax.servlet.RequestDispatcher#forward(javax.servlet.ServletRequest,
+         *      javax.servlet.ServletResponse)
          */
-        public void forward(ServletRequest request, ServletResponse response) throws ServletException,
IOException {
+        public void forward(ServletRequest request, ServletResponse response)
+                throws ServletException, IOException {
             // Call to named block
 
-            BlockContext.this.log("Enter processing in block " + this.blockName);
+            BlockContext.this
+                    .log("Enter processing in block " + this.blockName);
             if (this.servlet != null) {
                 if (!this.superCall) {
                     try {
@@ -322,13 +346,13 @@
                         this.servlet.service(request, response);
                     } finally {
                         BlockCallStack.leaveBlock();
-                    }               
+                    }
                 } else {
                     // A super block should be called in the context of
                     // the called block to get polymorphic calls resolved
                     // in the right way. Therefore no new current block is
                     // set.
-                    this.servlet.service(request, response);                    
+                    this.servlet.service(request, response);
                 }
             } else if (this.dispatcher != null) {
                 this.dispatcher.forward(request, response);
@@ -336,15 +360,20 @@
                 // Cannot happen
                 throw new IllegalStateException();
             }
-            BlockContext.this.log("Leaving processing in block " + this.blockName);
-         }
+            BlockContext.this.log("Leaving processing in block "
+                    + this.blockName);
+        }
 
-        /* (non-Javadoc)
-         * @see javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
+        /*
+         * (non-Javadoc)
+         * 
+         * @see javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest,
+         *      javax.servlet.ServletResponse)
          */
-        public void include(ServletRequest request, ServletResponse response) throws ServletException,
IOException {
+        public void include(ServletRequest request, ServletResponse response)
+                throws ServletException, IOException {
             throw new UnsupportedOperationException();
         }
-        
+
     }
 }

Modified: cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/components/modules/input/BlockPathModule.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/components/modules/input/BlockPathModule.java?rev=368174&r1=368173&r2=368174&view=diff
==============================================================================
--- cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/components/modules/input/BlockPathModule.java
(original)
+++ cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/components/modules/input/BlockPathModule.java
Wed Jan 11 16:05:14 2006
@@ -29,6 +29,7 @@
 import org.apache.cocoon.blocks.BlockContext;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.blocks.BlockCallStack;
+import org.apache.cocoon.components.source.impl.BlockSource;
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
 
 /**
@@ -49,8 +50,8 @@
         try {
             BlockContext blockContext =
                 (BlockContext) block.getServletConfig().getServletContext();
-            URI uri = blockContext.absolutizeURI(new URI(name), new URI(null, null, baseURI,
null));
-            absoluteURI = uri.toString();
+            URI uri = BlockSource.resolveURI(new URI(name), new URI(null, null, baseURI,
null));
+            absoluteURI= blockContext.absolutizeURI(uri).toString();
         } catch (URISyntaxException e) {
             throw new ConfigurationException("Couldn't absolutize " + name);
         }

Modified: cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/components/source/impl/BlockSource.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/components/source/impl/BlockSource.java?rev=368174&r1=368173&r2=368174&view=diff
==============================================================================
--- cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/components/source/impl/BlockSource.java
(original)
+++ cocoon/trunk/cocoon-blocks-fw/src/main/java/org/apache/cocoon/components/source/impl/BlockSource.java
Wed Jan 11 16:05:14 2006
@@ -32,7 +32,6 @@
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.cocoon.blocks.BlockCallStack;
-import org.apache.cocoon.blocks.BlockContext;
 import org.apache.cocoon.blocks.util.BlockHttpServletRequestWrapper;
 import org.apache.cocoon.blocks.util.BlockHttpServletResponseWrapper;
 import org.apache.cocoon.environment.Environment;
@@ -64,6 +63,8 @@
     private final Servlet block;
     
     private String systemId;
+    
+    private Logger logger;
 
     /**
      * Construct a new object
@@ -74,6 +75,8 @@
                        Logger         logger)
         throws MalformedURLException {
 
+        this.logger = logger;
+        
         Environment env = EnvironmentHelper.getCurrentEnvironment();
         if (env == null) {
             throw new MalformedURLException("The block protocol can not be used outside an
environment.");
@@ -144,6 +147,10 @@
     public boolean exists() {
         return true;
     }
+    
+    protected final Logger getLogger() {
+        return this.logger;
+    }
 
     /**
      * Recyclable
@@ -151,6 +158,27 @@
     public void recycle() {
     }
 
+    /**
+     * Parses and resolves the scheme specific part of a block URI
+     * with respect to the base URI of the current sitemap. The scheme
+     * specific part of the block URI has the form
+     * <code>foo:/bar</code> when refering to another block, in this
+     * case only an absolute path is allowed. For reference to the own
+     * block, both absolute <code>/bar</code> and relative
+     * <code>./foo</code> paths are allowed.
+     */
+    public static URI resolveURI(URI uri, URI base) throws URISyntaxException {
+        if (uri.getPath() != null && uri.getPath().length() >= 2 &&
+            uri.getPath().startsWith("./")) {
+            // self reference relative to the current sitemap, e.g. ./foo
+            if (uri.isAbsolute())
+                throw new URISyntaxException(uri.toString(), "When the protocol refers to
other blocks the path must be absolute");
+            URI resolvedURI = base.resolve(uri);
+            uri = resolvedURI;
+        }
+        return uri;
+    }
+    
     // Parse the block protocol.
     private URI parseBlockURI(Environment env, String blockURI) 
         throws URISyntaxException {
@@ -168,11 +196,12 @@
         if (baseURI.length() == 0 || !baseURI.startsWith("/"))
             baseURI = "/" + baseURI;
         
-        BlockContext blockContext =
-            (BlockContext) this.block.getServletConfig().getServletContext();
-
-        uri = blockContext.resolveURI(new URI(uri.getSchemeSpecificPart()),
-                new URI(null, null, baseURI, null));
+        this.getLogger().debug("BlockSource: resolving " + uri.toString() + " with scheme
" +
+                        uri.getScheme() + " and ssp " + uri.getSchemeSpecificPart());
+        uri = BlockSource.resolveURI(new URI(uri.getSchemeSpecificPart()),
+                        new URI(null, null, baseURI, null));
+        this.getLogger().debug("BlockSource: resolved to " + uri.toString() +
+                        " with base URI " + baseURI.toString());
         
         this.blockName = uri.getScheme();
         String path = uri.getPath();
@@ -186,4 +215,3 @@
         return new URI(scheme, null, path, queryString, null);
     }
 }
-



Mime
View raw message