cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dani...@apache.org
Subject svn commit: r179996 - in /cocoon/trunk/src/java/org/apache/cocoon/components: blocks/Block.java blocks/BlockManager.java blocks/BlocksManager.java modules/input/BlockPathModule.java source/impl/BlockSource.java source/impl/BlocksSource.java
Date Sat, 04 Jun 2005 15:05:06 GMT
Author: danielf
Date: Sat Jun  4 08:05:05 2005
New Revision: 179996

URL: http://svn.apache.org/viewcvs?rev=179996&view=rev
Log:
Functionallity to get the mount path of a block URI. The BlockPathModule is used for getting
the path and it use a method from Block.

Added:
    cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/BlockPathModule.java
  (with props)
Modified:
    cocoon/trunk/src/java/org/apache/cocoon/components/blocks/Block.java
    cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java
    cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlocksManager.java
    cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/BlockSource.java
    cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/BlocksSource.java

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/blocks/Block.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/blocks/Block.java?rev=179996&r1=179995&r2=179996&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/blocks/Block.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/blocks/Block.java Sat Jun  4 08:05:05
2005
@@ -15,6 +15,9 @@
  */
 package org.apache.cocoon.components.blocks;
 
+import java.net.URI;
+import java.net.URISyntaxException;
+
 import org.apache.cocoon.Processor;
 
 /**
@@ -25,7 +28,28 @@
     public static String NAME = Block.class.getName() + "-name";
     public static String SUPER = "super";
 
+    /**
+     * Get a block property
+     */
     public String getProperty(String name);
 
     // TODO: We should have a reflection friendly Map getProperties() also
+
+    /**
+     * 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;
+
+    /**
+     * 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 uriToResolve, URI base) throws URISyntaxException;
 }

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java?rev=179996&r1=179995&r2=179996&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlockManager.java Sat Jun  4
08:05:05 2005
@@ -16,6 +16,8 @@
 package org.apache.cocoon.components.blocks;
 
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
@@ -253,6 +255,9 @@
         this.blocksManager = blocksManager;
     }
 
+    /**
+     * Get a block property
+     */
     public String getProperty(String name) {
         String value = (String)this.properties.get(name);
         getLogger().debug("Accessing property=" + name + " value=" + value + " block=" +
this.id);
@@ -266,6 +271,52 @@
 
     // TODO: We should have a reflection friendly Map getProperties() also
 
+    /**
+     * 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);
+        String blockName = uri.getScheme();
+        String blockId = null;
+        if (blockName == null)
+            // this block
+            blockId = this.id;
+        else
+            // another block
+            blockId = (String)this.connections.get(blockName);
+        if (blockId == null)
+            throw new URISyntaxException(uriToResolve.toString(), "Unknown block name");
+        // The block id for identificaition
+        uri = new URI(blockId, uri.getSchemeSpecificPart(), null);
+        return this.blocksManager.absolutizeURI(uri);
+    }
+
+    /**
+     * 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 {
+        getLogger().debug("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);
+            getLogger().debug("BlockManager: resolving " + uri.toString() +
+                              " to " + resolvedURI.toString() + " with base URI " + base.toString());
+            uri = resolvedURI;
+        }
+        return uri;
+    }
 
     // The Processor methods
 

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlocksManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlocksManager.java?rev=179996&r1=179995&r2=179996&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlocksManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/blocks/BlocksManager.java Sat Jun 
4 08:05:05 2005
@@ -16,6 +16,8 @@
 package org.apache.cocoon.components.blocks;
 
 import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -236,6 +238,18 @@
         } else {
             return null;
         }
+    }
+
+    public URI absolutizeURI(URI uri) throws URISyntaxException {
+        String mountPath =
+            ((Configuration)this.blockConfs.get(uri.getScheme())).getChild("mount").getAttribute("path",
null);
+        if (mountPath == null)
+            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();
+        getLogger().debug("Resolving " + uri.toString() + " to " + absoluteURI);
+        return new URI(absoluteURI);
     }
 
     public boolean process(String blockId, Environment environment) throws Exception {

Added: cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/BlockPathModule.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/BlockPathModule.java?rev=179996&view=auto
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/BlockPathModule.java
(added)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/BlockPathModule.java
Sat Jun  4 08:05:05 2005
@@ -0,0 +1,64 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.components.modules.input;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.cocoon.components.blocks.Block;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.internal.BlockEnvironmentHelper;
+import org.apache.cocoon.environment.internal.EnvironmentHelper;
+
+/**
+ * BlockPathModule returns the absolute path of a block protocol path.
+ *
+ * @version $Id:$
+ */
+public class BlockPathModule implements InputModule {
+
+    public Object getAttribute( String name, Configuration modeConf, Map objectModel )
+    throws ConfigurationException {
+        Environment env = EnvironmentHelper.getCurrentEnvironment();
+        Block block = BlockEnvironmentHelper.getCurrentBlock();
+        String absoluteURI = null;
+        String baseURI = env.getURIPrefix();
+        if (baseURI.length() == 0 || !baseURI.startsWith("/"))
+            baseURI = "/" + baseURI;
+        try {
+            URI uri = block.absolutizeURI(new URI(name), new URI(null, null, baseURI, null));
+            absoluteURI = uri.toString();
+        } catch (URISyntaxException e) {
+            throw new ConfigurationException("Couldn't absolutize " + name);
+        }
+        return absoluteURI;
+    }
+
+    public Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
+        throws ConfigurationException {
+        throw new UnsupportedOperationException();
+    }
+
+    public Iterator getAttributeNames(Configuration modeConf, Map objectModel)
+        throws ConfigurationException {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: cocoon/trunk/src/java/org/apache/cocoon/components/modules/input/BlockPathModule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/BlockSource.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/BlockSource.java?rev=179996&r1=179995&r2=179996&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/BlockSource.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/BlockSource.java Sat Jun
 4 08:05:05 2005
@@ -26,7 +26,6 @@
 
 import org.apache.avalon.framework.logger.Logger;
 import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.cocoon.ResourceNotFoundException;
 import org.apache.cocoon.components.blocks.Block;
 import org.apache.cocoon.environment.Environment;
 import org.apache.cocoon.environment.ObjectModelHelper;
@@ -34,7 +33,6 @@
 import org.apache.cocoon.environment.internal.EnvironmentHelper;
 import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
 import org.apache.excalibur.source.SourceException;
-import org.apache.excalibur.source.SourceNotFoundException;
 import org.apache.excalibur.source.impl.AbstractSource;
 
 /**
@@ -54,6 +52,9 @@
     /** The name of the called block */
     private String blockName;
 
+    /** The current block */
+    private final Block block;
+
     /**
      * Construct a new object
      */
@@ -69,6 +70,10 @@
         }
         this.manager = manager;
 
+        this.block = BlockEnvironmentHelper.getCurrentBlock();
+        if (this.block == null)
+            throw new MalformedURLException("Must be used in a block context " + this.getURI());
+
         SitemapSourceInfo info = null;
         try {
             info = parseBlockURI(env, uri);
@@ -102,12 +107,8 @@
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         this.environment.setOutputStream(os);
 
-        Block block = BlockEnvironmentHelper.getCurrentBlock();
-        if (block == null)
-            throw new SourceNotFoundException("Must be used in a block context " + this.getURI());
-
         try {
-            block.process(this.environment);
+            this.block.process(this.environment);
             
             return new ByteArrayInputStream(os.toByteArray());
 
@@ -149,30 +150,19 @@
                                          "Only absolute URIs are allowed for the block protocol.");
         }
         info.protocol = uri.getScheme();
-        
-        if (uri.isOpaque()) {
-            // Sub protocol or relative self reference
-            uri = new URI(uri.getSchemeSpecificPart());
-            if (uri.isAbsolute()) {
-                // Sub protocol refering to other block, e.g. block:foo:/bar
-                if (uri.isOpaque()) {
-                    throw new URISyntaxException(blockURI,
-                                                 "The protocol must have the form block:foo:/bar");
-                }
-                this.blockName = uri.getScheme();
-                info.uri = uri.getPath();
-            } else {
-                // self reference relative to the current sitemap, e.g. block:./foo
-                this.blockName = null;
-                URI base = new URI(null, null, env.getURIPrefix(), null);
-                info.uri = base.resolve(uri).toString();
-            }
-        } else {
-            // reference to the base sitemap of the own block, block:/foo
-            this.blockName = null;
-            info.uri = uri.getPath();
-        }
 
+        String baseURI = env.getURIPrefix();
+        if (baseURI.length() == 0 || !baseURI.startsWith("/"))
+            baseURI = "/" + baseURI;
+
+        uri = this.block.resolveURI(new URI(uri.getSchemeSpecificPart()),
+                                    new URI(null, null, baseURI, null));
+        
+        this.blockName = uri.getScheme();
+        info.uri = uri.getPath();
+        // Sub sitemap URI parsing doesn't like URIs starting with "/"
+        if (info.uri.length() != 0 && info.uri.startsWith("/"))
+            info.uri = info.uri.substring(1);
         // All URIs, also relative are resolved and processed from the block manager
         info.processFromRoot = true;
         info.prefix = "";
@@ -181,9 +171,10 @@
         info.view = SitemapSourceInfo.getView(info.queryString, env);
         
         // FIXME: This will not be a system global id, as the blockName is block local.
-        String ssp = (new URI(this.blockName, null, info.requestURI, info.queryString, null)).toString();
+        String ssp = (new URI(this.blockName, null, uri.getPath(), info.queryString, null)).toString();
         info.systemId = (new URI(info.protocol, ssp, null)).toString();
         
         return info;
     }
 }
+

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/BlocksSource.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/BlocksSource.java?rev=179996&r1=179995&r2=179996&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/BlocksSource.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/BlocksSource.java Sat Jun
 4 08:05:05 2005
@@ -74,7 +74,7 @@
             info = parseBlocksURI(env, uri);
         } catch (URISyntaxException e) {
             throw new MalformedURLException("Malformed URI in blocks source " +
-					    e.getMessage());
+                                            e.getMessage());
         }
         setScheme(info.protocol);
         setSystemId(info.systemId);
@@ -140,7 +140,7 @@
 
         if (!uri.isAbsolute() && uri.isOpaque() && uri.getAuthority() ==
null) {
             throw new URISyntaxException(sitemapURI,
-					 "The blocks protocol must be an absolute, hierachial URI whithout authority part");
+                                         "The blocks protocol must be an absolute, hierachial
URI whithout authority part");
         }
 
         SitemapSourceInfo info = new SitemapSourceInfo();



Mime
View raw message