incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r582246 - in /incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl: mapper/ resolver/ resolver/Mapping.java resolver/ResolvedURLImpl.java resolver/URLMapperFilter.java
Date Fri, 05 Oct 2007 13:14:14 GMT
Author: fmeschbe
Date: Fri Oct  5 06:14:11 2007
New Revision: 582246

URL: http://svn.apache.org/viewvc?rev=582246&view=rev
Log:
SLING-40 Define proper ContentResolver service
  (Intermediate checkin, project will not currently build)

Added:
    incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/
      - copied from r581202, incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/mapper/
    incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/Mapping.java
      - copied, changed from r582245, incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/mapper/Mapping.java
    incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/ResolvedURLImpl.java
    incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/URLMapperFilter.java
      - copied, changed from r582245, incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/mapper/URLMapperFilter.java
Removed:
    incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/mapper/

Copied: incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/Mapping.java
(from r582245, incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/mapper/Mapping.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/Mapping.java?p2=incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/Mapping.java&p1=incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/mapper/Mapping.java&r1=582245&r2=582246&rev=582246&view=diff
==============================================================================
--- incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/mapper/Mapping.java
(original)
+++ incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/Mapping.java
Fri Oct  5 06:14:11 2007
@@ -16,12 +16,14 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.core.impl.mapper;
+package org.apache.sling.core.impl.resolver;
 
 
 /**
+ * The <code>Mapping</code> class conveys the mapping configuration used by the
+ * {@link ContentResolverFilter}.
  */
-public class Mapping {
+class Mapping {
 
     /** defines the 'inbound' direction, that is mapping request path to item path */
     public static final int INBOUND = 1;
@@ -59,7 +61,7 @@
      * @throws NullPointerException if either <code>from</code> or
      * 		<code>to</code> is <code>null</code>.
      */
-    public Mapping(String from, String to, String dir) {
+    Mapping(String from, String to, String dir) {
         this(from, to, "in".equals(dir) ? Mapping.INBOUND :
                        ("out".equals(dir) ? Mapping.OUTBOUND:
                         Mapping.BOTH));

Added: incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/ResolvedURLImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/ResolvedURLImpl.java?rev=582246&view=auto
==============================================================================
--- incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/ResolvedURLImpl.java
(added)
+++ incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/ResolvedURLImpl.java
Fri Oct  5 06:14:11 2007
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.sling.core.impl.resolver;
+
+import org.apache.sling.component.Content;
+import org.apache.sling.core.ResolvedURL;
+
+/**
+ * The <code>ResolvedURLImpl</code> class represents the URL after resolution
+ * to the Content. It also contains the selectors and extension extracted from
+ * the request URL.
+ */
+public class ResolvedURLImpl implements ResolvedURL {
+
+    /**
+     * The original URL from which was decomposed into this instance. This field
+     * must be set by either the constructor or later calling the
+     * {@link #setOriginalURL(String)} method.
+     */
+    private String originalURL;
+
+    /**
+     * The content object addressed by the original URL. This field must be set
+     * by either the constructor or later calling the
+     * {@link #setContent(Content)} method.
+     */
+    private Content content;
+
+    /**
+     * The decomposed array of the request selectors. By default the selectors
+     * array is empty.
+     */
+    private String[] selectors = new String[0];
+
+    /**
+     * The complete selector string, elements separated by dots. By default the
+     * selector string is empty.
+     */
+    private String selectorString = "";
+
+    /**
+     * The extension of the request URL. By default the extension is empty.
+     */
+    private String extension = "";
+
+    /**
+     * The suffix of the request URL. By default the suffix is empty.
+     */
+    private String suffix = "";
+
+    /**
+     * Creates an instance of this class for the original URL and the mapped
+     * content.
+     *
+     * @param originalURL The original, unmodified URL. The content path need
+     *      not necessairily be the prefix of this URL.
+     * @param content The Content object resolved from the given original URL
+     */
+    public ResolvedURLImpl(String originalURL, Content content) {
+        setOriginalURL(originalURL);
+        setContent(content);
+    }
+
+    /**
+     * Creates a new instance of this class copying the contents of the given
+     * ResolvedURL into the new instance.
+     *
+     * @param resolvedURL The ResolvedURL to copy into the new instance
+     *
+     * @throws NullPointerException If resolvedURL is <code>null</code>.
+     */
+    public ResolvedURLImpl(ResolvedURL resolvedURL) {
+        setOriginalURL(resolvedURL.getOriginalURL());
+        setContent(resolvedURL.getContent());
+        setSelectorString(resolvedURL.getSelectorString());
+        setExtension(resolvedURL.getExtension());
+        setSuffix(resolvedURL.getSuffix());
+    }
+
+    //---------- ResolvedURL interface ----------------------------------------
+
+    public String getOriginalURL() {
+        return originalURL;
+    }
+
+    public Content getContent() {
+        return content;
+    }
+
+    public String[] getSelectors() {
+        return selectors;
+    }
+
+    public String getSelectorString() {
+        return selectorString;
+    }
+
+    public String getSelector(int i) {
+        return (i >= 0 && i < selectors.length) ? selectors[i] : null;
+    }
+
+    public String getExtension() {
+        return extension;
+    }
+
+    public String getSuffix() {
+        return suffix;
+    }
+
+    //---------- setters for the parts of the URL decomposition ---------------
+
+    public void setOriginalURL(String originalURL) {
+        this.originalURL = originalURL;
+    }
+
+    public void setContent(Content content) {
+        this.content = content;
+    }
+
+    /**
+     * The selectors to set here is the string of dot-separated words after the
+     * path but before any optional subsequent slashes. This string includes the
+     * request URL extension, which is extracted here, too.
+     *
+     * @param The string of selectors and the extension to be decomposed into
+     *      the selectors and the extension.
+     *
+     * @throws NullPointerException if selectors is <code>null</code>.
+     */
+    public void setSelectorsExtension(String selectors) {
+        int lastDot = selectors.lastIndexOf('.');
+        if (lastDot < 0) {
+            // no selectors, just the extension
+            setExtension(selectors);
+            setSelectorString("");
+            return;
+        }
+
+        // extension comes after last dot, rest are selectors
+        setExtension(selectors.substring(lastDot + 1));
+        setSelectorString(selectors.substring(0, lastDot));
+    }
+
+    public void setExtension(String extension) {
+        this.extension = extension;
+    }
+
+    /**
+     * Sets the selector string and the decomposed array of selectors.
+     *
+     * @throws NullPointerException If selectorString is <code>null</code>.
+     */
+    public void setSelectorString(String selectorString) {
+        // cut off extension to split selectors
+        this.selectorString = selectorString;
+        this.selectors = selectorString.split("\\.");
+    }
+
+    public void setSuffix(String suffix) {
+        this.suffix = suffix;
+    }
+}

Copied: incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/URLMapperFilter.java
(from r582245, incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/mapper/URLMapperFilter.java)
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/URLMapperFilter.java?p2=incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/URLMapperFilter.java&p1=incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/mapper/URLMapperFilter.java&r1=582245&r2=582246&rev=582246&view=diff
==============================================================================
--- incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/mapper/URLMapperFilter.java
(original)
+++ incubator/sling/trunk/core/src/main/java/org/apache/sling/core/impl/resolver/URLMapperFilter.java
Fri Oct  5 06:14:11 2007
@@ -16,20 +16,17 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.core.impl.mapper;
+package org.apache.sling.core.impl.resolver;
 
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.security.AccessControlException;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Dictionary;
 import java.util.List;
 import java.util.StringTokenizer;
 
-import javax.jcr.Node;
-import javax.jcr.Session;
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.commons.collections.BidiMap;
@@ -45,11 +42,11 @@
 import org.apache.sling.component.Content;
 import org.apache.sling.content.ContentManager;
 import org.apache.sling.content.jcr.JcrContentManagerFactory;
+import org.apache.sling.core.ContentResolver;
+import org.apache.sling.core.ResolvedURL;
 import org.apache.sling.core.content.SelectableContent;
 import org.apache.sling.core.content.Selector;
 import org.apache.sling.core.impl.RequestData;
-import org.apache.sling.core.mapper.URLMapper;
-import org.apache.sling.core.mapper.URLTranslationInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -62,9 +59,9 @@
  * @scr.property name="service.vendor" value="The Apache Software Foundation"
  * @scr.property name="filter.scope" value="request" private="true"
  * @scr.property name="filter.order" value="-500" type="Integer" private="true"
- * @scr.service interface="org.apache.sling.component.ComponentFilter"
+ * @scr.service
  */
-public class URLMapperFilter implements ComponentFilter, URLMapper {
+public class URLMapperFilter implements ComponentFilter, ContentResolver {
 
     /**
     * @scr.property value="true" type="Boolean"
@@ -89,10 +86,11 @@
     public static final String MAPPER_MAPPING = "mapper.mapping";
 
     /** default log */
-    private static final Logger log = LoggerFactory.getLogger(URLMapperFilter.class);
+    private final Logger log = LoggerFactory.getLogger(URLMapperFilter.class);
 
     /**
-     * @scr.reference
+     * Allow startup without the factory
+     * @scr.reference cardinality="0..1" policy="dynamic"
      */
     private JcrContentManagerFactory contentManagerFactory;
 
@@ -114,19 +112,28 @@
             ComponentFilterChain filterChain) throws IOException,
             ComponentException {
 
+        // fail early, if we have no ContentManagerFactory
+        JcrContentManagerFactory cmf = contentManagerFactory;
+        if (cmf == null) {
+            log.error("Missing ContentManageFactory, cannot access data");
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+
         RequestData requestData = RequestData.getRequestData(request);
 
-        ContentManager cm = this.contentManagerFactory.getContentManager(requestData.getSession());
+        ContentManager cm = cmf.getContentManager(requestData.getSession());
         requestData.setContentManager(cm);
 
         // 1.6 URL Mapping / Content Resolution --> URL Mapper
-        Content content = this.getMappedURL(requestData);
-        if (content == null) {
+        ResolvedURL resolvedURL = resolveURL(cm, requestData.getRequestURI());
+        if (resolvedURL == null) {
             response.sendError(HttpServletResponse.SC_NOT_FOUND);
             return;
         }
 
         // 1.7 Check content selection
+        Content content = resolvedURL.getContent();
         if (content instanceof SelectableContent) {
             Selector sel = ((SelectableContent) content).getSelector();
             if (sel != null) {
@@ -138,11 +145,16 @@
                         "No content selected");
                     return;
                 }
+
+                // replace content in the resolved URL with the selected content
+                ResolvedURLImpl ru = new ResolvedURLImpl(resolvedURL);
+                ru.setContent(content);
+                resolvedURL = ru;
             }
         }
 
         // 2. Handle the request
-        requestData.pushContent(content);
+        requestData.pushContent(resolvedURL);
         try {
             filterChain.doFilter(request, new MapperComponentResponse(response, request.getContextPath()));
         } finally {
@@ -158,47 +170,37 @@
 
     protected void activate(org.osgi.service.component.ComponentContext context) {
 
-        Dictionary properties = context.getProperties();
+        Dictionary<?, ?> properties = context.getProperties();
 
         BidiMap fakes = new TreeBidiMap();
         String[] fakeList = (String[]) properties.get(MAPPER_FAKE);
         for (int i=0; fakeList != null && i < fakeList.length; i++) {
-            String[] parts = this.split(fakeList[i]);
+            String[] parts = split(fakeList[i]);
             fakes.put(parts[0], parts[2]);
         }
-        this.fakeURLs = fakes;
+        fakeURLs = fakes;
 
-        List maps = new ArrayList();
+        List<Mapping> maps = new ArrayList<Mapping>();
         String[] mappingList = (String[]) properties.get(MAPPER_MAPPING);
         for (int i=0; mappingList != null && i < mappingList.length; i++) {
-            maps.add(new Mapping(this.split(mappingList[i])));
+            maps.add(new Mapping(split(mappingList[i])));
         }
-        Mapping[] tmp = (Mapping[]) maps.toArray(new Mapping[maps.size()]);
+        Mapping[] tmp = maps.toArray(new Mapping[maps.size()]);
 
         // check whether direct mappings are allowed
         Boolean directProp = (Boolean) properties.get(MAPPER_ALLOW_DIRECT);
-        this.allowDirect = (directProp != null) ? directProp.booleanValue() : true;
-        if (this.allowDirect) {
+        allowDirect = (directProp != null) ? directProp.booleanValue() : true;
+        if (allowDirect) {
             Mapping[] tmp2 = new Mapping[tmp.length + 1];
             tmp2[0] = new Mapping("", "", null);
             System.arraycopy(tmp, 0, tmp2, 1, tmp.length);
-            this.mappings = tmp2;
+            mappings = tmp2;
         } else {
-            this.mappings = tmp;
+            mappings = tmp;
         }
     }
 
-    protected void bindContentManagerFactory(
-            JcrContentManagerFactory contentManagerFactory) {
-        this.contentManagerFactory = contentManagerFactory;
-    }
-
-    protected void unbindContentManagerFactory(
-            JcrContentManagerFactory contentManagerFactory) {
-        this.contentManagerFactory = null;
-    }
-
-    // ---------- URLMapperService interface -----------------------------------
+    // ---------- ContentResolver interface -----------------------------------
 
     /**
      * Creates a MappedURL object from the url.
@@ -212,10 +214,9 @@
      * @throws UnauthorizedException if access to the repository node is not
      *      allowed for the request.
      */
-    public Content getMappedURL(RequestData requestData) {
+    public ResolvedURL resolveURL(ContentManager cm, String requestURI) {
 
         // decode the request URI (required as the servlet container does not
-        String requestURI = requestData.getRequestURI();
         try {
             requestURI = URLDecoder.decode(requestURI, "UTF-8");
         } catch (UnsupportedEncodingException uee) {
@@ -225,11 +226,11 @@
         }
 
         // convert fake urls
-        requestURI = this.checkFakeURL(requestURI);
+        requestURI = checkFakeURL(requestURI);
         try {
 
             // translate url to a mapped url structure
-            return this.transformURL(requestData, requestURI);
+            return transformURL(cm, requestURI);
 
         } catch (AccessControlException ace) {
             // rethrow AccessControlExceptions to be handled
@@ -249,19 +250,19 @@
     /**
      * @see URLMapperService#handleToURL(String)
      */
-    public String handleToURL(String handle) {
-        return this.handleToURL(null, handle, null);
+    public String pathToURL(String handle) {
+        return pathToURL(null, handle, null);
     }
 
     /**
      * @see URLMapperService#handleToURL(String, String, String)
      */
-    public String handleToURL(String prefix, String handle, String suffix) {
+    public String pathToURL(String prefix, String handle, String suffix) {
         String href = null;
 
         // get first map
-        for (int i = this.allowDirect ? 1 : 0; i < this.mappings.length; i++) {
-            href = this.mappings[i].mapHandle(handle);
+        for (int i = allowDirect ? 1 : 0; i < mappings.length; i++) {
+            href = mappings[i].mapHandle(handle);
             if (href != null) {
                 break;
             }
@@ -273,7 +274,7 @@
         }
 
         // check fake mappings
-        String fake = (String) this.fakeURLs.getKey(href);
+        String fake = (String) fakeURLs.getKey(href);
         if (fake != null) {
             href = fake;
         }
@@ -312,43 +313,42 @@
      * @return The <code>Content</code> object to which the URL maps or
      *      <code>null</code> if no such mapping can be found
      */
-    private Content transformURL(RequestData requestData, String url) {
+    private ResolvedURL transformURL(ContentManager cm, String url) {
 
-        ContentManager pm = requestData.getContentManager();
-        for (int i = 0; i < this.mappings.length; i++) {
+        for (int i = 0; i < mappings.length; i++) {
             // exchange the 'to'-portion with the 'from' portion and check
-            String href = this.mappings[i].mapUri(url);
+            String href = mappings[i].mapUri(url);
             if (href == null) {
-                log.debug("Mapping {} cannot map {}", this.mappings[i], url);
+                log.debug("Mapping {} cannot map {}", mappings[i], url);
                 continue;
             }
-            Content content = this.findItem(pm, href);
+            Content content = findItem(cm, href);
             if (content == null) {
                 log.debug("Cannot resolve {} to an item", href);
                 continue;
             }
 
             // the URL which lead to the content loaded
-            requestData.setOriginalURL(url);
+            ResolvedURLImpl ru = new ResolvedURLImpl(url, content);
 
             // selectors come after handle - where's the period ?
             int selectorStart = content.getPath().length() + 1;
             if (selectorStart > href.length()) {
                 // neither selectors nor extension
-                return content;
+                return ru;
             }
 
             // suffix is path elements (with slashes) after selectors
             int suffixPos = href.indexOf('/', selectorStart);
             if (suffixPos < 0) {
-                requestData.setSelectorsExtension(href.substring(selectorStart));
+                ru.setSelectorsExtension(href.substring(selectorStart));
             } else {
-                requestData.setSelectorsExtension(href.substring(selectorStart,
+                ru.setSelectorsExtension(href.substring(selectorStart,
                     suffixPos));
-                requestData.setSuffix(href.substring(suffixPos));
+                ru.setSuffix(href.substring(suffixPos));
             }
 
-            return content;
+            return ru;
         }
 
         log.error("Could not resolve URL {} to a Content object", url);
@@ -358,10 +358,10 @@
     // ---------- internal -----------------------------------------------------
 
     // TODO
-    private Content findItem(ContentManager pm, String href) {
+    private Content findItem(ContentManager cm, String href) {
 
         // common case, test as is
-        Content jcrObject = pm.load(href);
+        Content jcrObject = cm.load(href);
         if (jcrObject != null) {
             return jcrObject;
         }
@@ -370,7 +370,7 @@
         for (int i = href.lastIndexOf('.'); i > 0; i = href.lastIndexOf('.',
             i - 1)) {
             String sub = href.substring(0, i);
-            jcrObject = pm.load(sub);
+            jcrObject = cm.load(sub);
             if (jcrObject != null) {
                 return jcrObject;
             }
@@ -381,270 +381,16 @@
         return null;
     }
 
-    // private HandlePatternList getHandlePatterns(URLMapperConfig[]
-    // mapperConfig) {
-    // // extract the from strings to build the handle pattern list
-    // String[] fromStrings = new String[mapperConfig.length];
-    // for (int i=0; i < mapperConfig.length; i++) {
-    // fromStrings[i] = mapperConfig[i].from;
-    // }
-    //
-    // // create the pattern list and register to get notified
-    // return new HandlePatternList(fromStrings);
-    // }
-
-    // private Mapping[] buildMappingList(URLMapperConfig[] mapperConfig /*,
-    // HandleExpander handleExpander */) {
-    //
-    // // prepare the mappings in this list
-    // List mappings = new ArrayList(mapperConfig.length);
-    //
-    // // convert the mapper config to the list of mappers
-    // for (int i=0; i < mapperConfig.length; i++) {
-    // mapperConfig[i].addMappings(mappings, null /* handleExpander */);
-    // }
-    //
-    // // return converted to array
-    // return (Mapping[]) mappings.toArray(new Mapping[mappings.size()]);
-    // }
-
     /**
      * checks for a fakeurl
      *
      * @return the new url, if matches, otherwise the old one
      */
     private String checkFakeURL(String url) {
-        String fake = (String) this.fakeURLs.get(url);
+        String fake = (String) fakeURLs.get(url);
         return (fake != null) ? fake : url;
     }
 
-    /**
-     * @see URLMapperService#externalizeHref(Ticket, String, String, String,
-     *      String)
-     */
-    public URLTranslationInfo externalizeHref(Session session, String prefix,
-            String href, String base, String suffix) {
-
-        return null;
-
-        // if (href == null || href.length() == 0) {
-        // throw new IllegalArgumentException("href must not be empty");
-        // }
-        // if (prefix.equals("/")) {
-        // prefix = "";
-        // }
-        //
-        // String original = href;
-        //
-        // // cut off query from href
-        // int pos = href.indexOf('?');
-        // String query = "";
-        // if (pos > 0) {
-        // query = href.substring(pos);
-        // href = href.substring(0, pos);
-        // }
-        //
-        // // check for missing dot, assume ".html" (if not "/")
-        // if (!href.equals("/") && href.lastIndexOf('.') <=
-        // href.lastIndexOf('/')) {
-        // log.warn("Extension missing in link: {}. Extending it.", original);
-        // href = href += ".html";
-        // }
-        //
-        // // prepare the href
-        // UUID uuid = null;
-        // pos = 0;
-        //
-        // if (href.charAt(0) == '[') {
-        // // extract the UUID from the href
-        // pos = href.indexOf(']');
-        // if (pos < 0) {
-        // log.warn("HREF scrambled (not found): {}", href);
-        // pos = 0;
-        // } else {
-        // try {
-        // uuid = new UUID(href.substring(1, pos));
-        // } catch (Exception e) {
-        // log.warn("UUID in href not valid: {}", e.getMessage());
-        // }
-        // }
-        //
-        // } else if (href.charAt(0) != '/') {
-        // if (base == null) {
-        // log.warn(
-        // "Relative translation required but no base handle specified.
-        // href={}",
-        // href);
-        // return new URLTranslationInfoImpl(original, href + query, null);
-        // }
-        // href = Text.fullPath(base, href);
-        // }
-        //
-        // /*
-        // * Remove the prefix (Servlet Context Path) from the href before
-        // further
-        // * checking just in case someone already added it before. Here we have
-        // * to remove the "prefix" from the href, if the href starts with the
-        // * prefix and a slash immediately follows the prefix in href or if the
-        // * href equals the prefix. Before actually removing the prefix, we
-        // have
-        // * to make sure, it does not actually address a valid ContentBus
-        // * hierarchy node (directly or via URL mapping). This second check
-        // * ensures, that e.g. /author/author/something remains addressable.
-        // Note
-        // * that I assume that the secondary check may be somewhat expensive
-        // * because I consider it an exception that the href actually starts
-        // with
-        // * the prefix.
-        // */
-        // if (prefix.length() > 0 && href.startsWith(prefix)) {
-        // if (href.length() <= prefix.length()
-        // || href.charAt(prefix.length()) == '/') {
-        // if (!session.hasPage(prefix)
-        // && getMappedURL(session, href) == null) {
-        // // remove the prefix for the checking
-        // href = href.substring(prefix.length());
-        // }
-        // }
-        // }
-        //
-        // // now search the href
-        // int endPos = 0;
-        // try {
-        // // resolve the handle to a hierarchy node
-        // endPos = session.matchHandle(href, pos);
-        // String matchedHandle = href.substring(pos, endPos);
-        //
-        // log.debug("handle matched: {}-{} = {}.", String.valueOf(pos),
-        // String.valueOf(endPos), matchedHandle);
-        //
-        // HierarchyNode node = session.getNode(matchedHandle);
-        //
-        // if (node.hasContentNode()) {
-        // // if the CSD is invalid, we cannot map
-        // if (!session.getHierarchyMgr().hasCSDInfo(
-        // node.getContentNode().getCSD())) {
-        // return null;
-        // }
-        //
-        // // here we know, that the handle exists
-        // if (uuid != null) {
-        // // check contentid
-        // log.debug("Handle ''{}'' ok (no contentid validation).",
-        // href);
-        // if (uuid.equals(node.getContentNode().getUUID())) {
-        // return new URLTranslationInfoImpl(original,
-        // handleToURL(prefix, matchedHandle,
-        // href.substring(endPos))
-        // + query, node);
-        // }
-        //
-        // } else {
-        // // since we cannot check it. the handle should be ok
-        // if (original.charAt(0) == '/' || original.charAt(0) == '[') {
-        // return new URLTranslationInfoImpl(original,
-        // handleToURL(prefix, matchedHandle,
-        // href.substring(endPos))
-        // + query, node);
-        // } else {
-        // // we respect the original href, if it was a relative
-        // // link
-        // return new URLTranslationInfoImpl(original, original,
-        // node);
-        // }
-        // }
-        // }
-        // } catch (AccessControlException e) {
-        // // matchHandle()
-        // log.warn("trouble while externalizing href {}: {}", original,
-        // e.getMessage());
-        // return null;
-        // } catch (NoSuchNodeException e) {
-        // // getNode()
-        // // drop out
-        // } catch (ContentBusException e) {
-        // // all contentbus calls
-        // log.info("trouble while externalizing href {}: {}", original,
-        // e.getMessage());
-        // // drop out
-        // } catch (MalformedURLException e) {
-        // // matchHandle()
-        // log.info("trouble while externalizing href {}: {}", original,
-        // e.getMessage());
-        // // drop out
-        // }
-        //
-        // // what we know here :
-        // // -- either the handle does not denote a node with content, valid
-        // CSD
-        // // and - if the UUID is contained in href - the content's UUID
-        // // does not match the desired UUID
-        // // -- or the handle is invalid
-        //
-        // // here we know, that provided handle is incorrect
-        // if (uuid == null) {
-        // // ok, href is not really a handle but might be an URL of
-        // // some sort. try to get a MappedURL from it, if so take the
-        // // handle as is without a node.
-        // MappedURL url = getMappedURL(session, href);
-        // if (url == null) {
-        // log.info("Handle ''{}'' broken (no contentid).", href);
-        // return null;
-        // }
-        // log.info("Non-ContentBus Link Specified: {} (mapped to {})",
-        // original, url.getHandle());
-        // try {
-        // return new URLTranslationInfoImpl(original, prefix + href
-        // + query, session.getNode(url.getHandle()));
-        // } catch (NoSuchNodeException e) {
-        // log.info("Handle ''{}'' broken (content gone).", href);
-        // return null;
-        // } catch (ContentBusException e) {
-        // log.error("Error while accessing valid data?", e);
-        // return null;
-        // }
-        // }
-        //
-        // // ok, href handle is invalid, but a UUID exists, get on of those
-        // try {
-        // // so get the (first) node for the UUID with a content node
-        // HierarchyNodeIterator iter = session.getNodes(uuid);
-        // HierarchyNode node = null;
-        // while (iter.hasNext()) {
-        // node = iter.nextNode();
-        // // actually, we should respect current handle and respect best
-        // // matching
-        // if (node.hasContentNode()) break;
-        // node = null;
-        // }
-        //
-        // // not even the uuid gives content
-        // if (node == null) {
-        // // content if gone aswell
-        // log.info("Handle ''{}'' broken (content gone).", href);
-        // return null;
-        // }
-        //
-        // // this is not very cool, but we have to guess the invalid, old
-        // handle
-        // if (endPos == 0) endPos = href.indexOf('.', pos);
-        // if (endPos < pos) {
-        // // kind of default
-        // return new URLTranslationInfoImpl(original, handleToURL(prefix,
-        // node.getHandle(), ".html")
-        // + query, node);
-        // } else {
-        // return new URLTranslationInfoImpl(original, handleToURL(prefix,
-        // node.getHandle(), href.substring(endPos))
-        // + query, node);
-        // }
-        //
-        // } catch (ContentBusException e) {
-        // log.info("Handle ''{}'' broken (error: {}).", original, e);
-        // return null;
-        // }
-    }
-
     private class MapperComponentResponse extends ComponentResponseWrapper {
 
         private String contextPath;
@@ -655,126 +401,11 @@
         }
 
         public String encodeURL(String path) {
-            return super.encodeURL(URLMapperFilter.this.handleToURL(this.contextPath, path,
null));
-        }
-
-// No implemented yet, will be done when ComponentResponse extends HttpServletResponse
-//        public String encodeRedirectURL(String path) {
-//            return super.encodeRedirectURL(handleToURL(path));
-//        }
-    }
-
-    /**
-     * Implementation of <code>URLTranslationInfo</code>
-     */
-    private final static class URLTranslationInfoImpl implements
-            URLTranslationInfo {
-
-        /** the mapped href (or null if not valid) */
-        public final String href;
-
-        /** the original href */
-        public final String original;
-
-        /** the underlaying hierarchy node */
-        private final Node node;
-
-        public URLTranslationInfoImpl(String ori, String href, Node node) {
-            this.original = ori;
-            this.href = href;
-            this.node = node;
-        }
-
-        public Node getNode() {
-            return this.node;
+            return super.encodeURL(pathToURL(contextPath, path, null));
         }
 
-        public String getExternalHref() {
-            return this.href;
-        }
-
-        public String getInternalHref() {
-            return this.original;
-        }
-    }
-
-    /**
-     * The <code>URLMapperConfig</code> class is a simple data container to
-     * internally store the original configuration found in the mapping
-     * configuration element.
-     */
-    private static class URLMapperConfig {
-        final String from;
-
-        final String to;
-
-        final String dir;
-
-        boolean addSlash;
-
-        String stringValue;
-
-        URLMapperConfig(String from, String to, String dir) {
-            this.from = from;
-            this.to = to;
-            this.dir = dir;
-            this.addSlash = from != null && from.endsWith("/");
-        }
-
-        boolean isValid() {
-            return this.from != null && this.to != null;
-        }
-
-        void addMappings(Collection mappings,
-                Object /* HandleExpander */handleExpander) {
-
-            // check validity of this entry
-            if (!this.isValid()) {
-                log.debug("addMappings: mapperConfig={} invalid", this.toString());
-                return;
-            }
-
-            if (handleExpander == null || this.from.length() == 0) {
-
-                log.debug("addMappings: Add unexpanded mapping from {} to"
-                    + " {}, dir={}", new Object[] { this.from, this.to, this.dir });
-                mappings.add(new Mapping(this.from, this.to, this.dir));
-
-            } else {
-                // check for wildcard, otherwise don't expand (bug #9465)
-                String[] fromList;
-                // TODO: Have to decide how to handle patterns -> maybe XPath ??
-                // if (GlobPattern.containsWildcards(from)) {
-                // // handle expand the from property
-                // fromList = new String[0]; // FIXME:
-                // handleExpander.expand(from);
-                // } else {
-                fromList = new String[] { this.from };
-                this.addSlash = false;
-                // }
-                for (int i = 0; i < fromList.length; i++) {
-                    // add slash lost during expansion
-                    if (this.addSlash) {
-                        fromList[i] += "/";
-                    }
-                    log.debug(
-                        "addMappings: Add mapping from {} to {}, dir={}",
-                        new Object[] { fromList[i], this.to, this.dir });
-                    mappings.add(new Mapping(fromList[i], this.to, this.dir));
-                }
-
-            }
-        }
-
-        public String toString() {
-            if (this.stringValue != null) {
-                StringBuffer buf = new StringBuffer(super.toString());
-                buf.append(" [from=").append(this.from);
-                buf.append(", to=").append(this.to);
-                buf.append(", dir=").append(this.dir).append("]");
-                this.stringValue = buf.toString();
-            }
-            return this.stringValue;
+        public String encodeRedirectURL(String path) {
+            return super.encodeRedirectURL(pathToURL(contextPath, path, null));
         }
     }
 }



Mime
View raw message