incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r585170 - in /incubator/sling/whiteboard/microsling/src: main/java/org/apache/sling/microsling/api/ main/java/org/apache/sling/microsling/contenttype/ main/java/org/apache/sling/microsling/request/ main/java/org/apache/sling/microsling/requ...
Date Tue, 16 Oct 2007 15:22:04 GMT
Author: bdelacretaz
Date: Tue Oct 16 08:21:50 2007
New Revision: 585170

URL: http://svn.apache.org/viewvc?rev=585170&view=rev
Log:
SLING-50 :  SlingRequestPathInfo and SlingRequestPathInfoParser added

Added:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java
  (with props)
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
  (with props)
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
  (with props)
Modified:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/SlingRequestContext.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/SlingPostServlet.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/VelocityTemplatesServlet.java

Added: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java?rev=585170&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java
(added)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java
Tue Oct 16 08:21:50 2007
@@ -0,0 +1,124 @@
+/*
+ * 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.microsling.api;
+
+/** Sling breaks the request URI into four parts: the path itself, 
+ *  optional dot-separated selectors and extension that follow it, and 
+ *  an optional path suffix.
+ *  
+ * <p id="decomp">
+ * <b>Decomposition of a Request URL</b>
+ * <li>{@link Content#getPath() content path} - The longest substring of the
+ * request URI resolving to a {@link Content} object such that the content path
+ * is either the complete request URI the next character in the request URI
+ * after the content path is either a dot (<code>.</code>) or a slash (<code>/</code>).
+ * <li>{@link #getSelectors() selectors} - If the first character in the
+ * request URI after the content path is a dot, the string after the dot upto
+ * but not including the last dot before the next slash character or the end of
+ * the request URI. If the content path spans the complete request URI or if a
+ * slash follows the content path in the request, the no seletors exist. If only
+ * one dot follows the content path before the end of the request URI or the
+ * next slash, no selectors exist. The selectors are available as
+ * {@link #getSelectorString() a single string}, an
+ * {@link #getSelectors() array of strings}, which is the selector string
+ * splitted on dots, or
+ * {@link #getSelector(int) selectively by zero-based index}.
+ * <li>{@link #getExtension() extension} - The string after the last dot after
+ * the content path in the request uri but before the end of the request uri or
+ * the next slash after the content path in the request uri. If a slash follows
+ * the content path in the request URI, the extension is empty.
+ * <li>{@link #getSuffix() suffix path} - If the request URI contains more a
+ * slash character after the content path and optional selectors and extension,
+ * the path starting with the slash upto the end of the request URI is the
+ * suffix path.
+ * </ol>
+ * TODO: copy examples from the Sling ComponentRequest, or better, generate them
+ * from test cases.
+ */
+
+public interface SlingRequestPathInfo {
+    /**
+     * Returns the extension from the URL or an empty string if the request URL
+     * does not contain an extension.
+     * <p>
+     * Decomposition of the request URL is defined in the <a
+     * href="#decomp">Decomposition of a Request URL</a> above.
+     *
+     * @return The extension from the request URL.
+     */
+    String getExtension();
+
+    /**
+     * Returns the i-th selector of the selector string split on dots or
+     * <code>null</code> if i&lt;0 or i&gt;getSelectors().length. Alyways
+     * returns <code>null</code> if the request has no selectors.
+     * <p>
+     * Decomposition of the request URL is defined in the <a
+     * href="#decomp">Decomposition of a Request URL</a> above.
+     *
+     * @param i The index of the selector to return.
+     * @return The value of the selector if 0 &lt;= i &lt;
+     *         <code>getSelectors().length</code> or <code>null</code>
+     *         otherwise.
+     * @see #getSelectorString()
+     * @see #getSelectors()
+     */
+    String getSelector(int i);
+
+    /**
+     * Returns the selectors decoded from the request URL as an array of
+     * strings. This array is derived from the
+     * {@link #getSelectorString() selector string} by splitting the string on
+     * dots. Returns an empty array if the request has no selectors.
+     * <p>
+     * Decomposition of the request URL is defined in the <a
+     * href="#decomp">Decomposition of a Request URL</a> above.
+     *
+     * @see #getSelectorString()
+     * @see #getSelector(int)
+     */
+    String[] getSelectors();
+
+    /**
+     * Returns the selectors decoded from the request URL as string. Returns an
+     * empty string if the request has no selectors.
+     * <p>
+     * Decomposition of the request URL is defined in the <a
+     * href="#decomp">Decomposition of a Request URL</a> above.
+     *
+     * @see #getSelectors()
+     * @see #getSelector(int)
+     */
+    String getSelectorString();
+
+    /**
+     * Returns the suffix part of the URL or an empty string if the request URL
+     * does not contain a suffix.
+     * <p>
+     * Decomposition of the request URL is defined in the <a
+     * href="#decomp">Decomposition of a Request URL</a> above.
+     *
+     * @return The suffix part of the request URL.
+     */
+    String getSuffix();
+    
+    /** 
+     * Return the "content path" part of the URL, what comes before selectors, extension

+     * and suffix
+     */
+    String getContentPath();
+}

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/SlingRequestPathInfo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java?rev=585170&r1=585169&r2=585170&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/contenttype/ResponseContentTypeResolverFilter.java
Tue Oct 16 08:21:50 2007
@@ -23,7 +23,7 @@
 
         final SlingRequestContext ctx = SlingRequestContext.getFromRequest(request);
 
-        String file = "dummy." + ctx.getExtension();
+        String file = "dummy." + ctx.getRequestPathInfo().getExtension();
         final String contentType = getFilterConfig().getServletContext().getMimeType(file);
         if (contentType != null) {
             // Need this info in the SlingRequestContext,

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/SlingRequestContext.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/SlingRequestContext.java?rev=585170&r1=585169&r2=585170&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/SlingRequestContext.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/SlingRequestContext.java
Tue Oct 16 08:21:50 2007
@@ -26,19 +26,20 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.sling.microsling.api.Resource;
+import org.apache.sling.microsling.api.SlingRequestPathInfo;
 import org.apache.sling.microsling.api.exceptions.SlingException;
 import org.apache.sling.microsling.etc.MissingRequestAttributeException;
+import org.apache.sling.microsling.request.helpers.SlingRequestPathInfoParser;
 
 /** Additional Request-based info used by for SlingServlets */
 public class SlingRequestContext {
 
     private Session session;
-    private final String contentPath;
-    private final String extension;
     private String responseContentType;
     private final ServletContext servletContext;
     private final Repository repository;
     private Resource resource;
+    private final SlingRequestPathInfoParser requestPathInfo;
     
     public static final String REQ_ATTR_NAME = SlingRequestContext.class.getName();
     
@@ -63,23 +64,15 @@
         // Store this into the request attributes
         req.setAttribute(REQ_ATTR_NAME,this);
         
-        // Access our Repository and get a Session
+        // Access our Repository
         final String repoAttr = Repository.class.getName();
         repository = (Repository)sctx.getAttribute(repoAttr);
         if(repository==null) {
             throw new SlingException("Repository not available in ServletContext attribute
" + repoAttr);
         }
         
-        // TODO more precise parsing: selectors, suffix, etc.
-        final String path = req.getPathInfo();
-        final int lastDot = path.lastIndexOf('.');
-        if(lastDot < 0) {
-            contentPath = path;
-            extension = "";
-        } else {
-            contentPath = path.substring(0,lastDot);
-            extension = path.substring(lastDot + 1);
-        }
+        // Parse request URI
+        requestPathInfo = new SlingRequestPathInfoParser(req.getPathInfo());
     }
     
     /** Acquire a JCR Session if not done yet, and return it */  
@@ -90,14 +83,6 @@
         return session;
     }
 
-    public String getContentPath() {
-        return contentPath;
-    }
-
-    public String getExtension() {
-        return extension;
-    }
-
     public Resource getResource() {
         return resource;
     }
@@ -117,5 +102,9 @@
     /** Use the ServletContext to compute the mime-type for given filename */
     public String getMimeType(String filename) {
         return servletContext.getMimeType(filename);
+    }
+    
+    public SlingRequestPathInfo getRequestPathInfo() {
+        return requestPathInfo;
     }
 }

Added: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java?rev=585170&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
(added)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
Tue Oct 16 08:21:50 2007
@@ -0,0 +1,124 @@
+/*
+ * 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.microsling.request.helpers;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+import org.apache.sling.microsling.api.SlingRequestPathInfo;
+
+/** microsling request URI parser that provides SlingRequestPathInfo 
+ *  for the current request.
+ */
+public class SlingRequestPathInfoParser implements SlingRequestPathInfo {
+    
+    private final String contentPath;
+    private final String selectorString;
+    private final String [] selectors;
+    private final String extension;
+    private final String suffix;
+    
+    private final static String EMPTY = "";
+    
+    private static Pattern splitInThreePattern;
+    private static Pattern selectorExtPattern; 
+    private static PatternSyntaxException parsingPatternException;
+    
+    static {
+        try {
+            // we love regular expressions (along with their unit tests ;-)
+            // first pattern splits (path) (selectors + extension) (suffix) 
+            splitInThreePattern = Pattern.compile("([^\\.]*)?((\\.[^/]*)?(/.*)?)?");
+            
+            // second pattern separates (selectors) and (extension)
+            selectorExtPattern = Pattern.compile("(\\.(.*))?(\\.([^\\.]*))");
+            
+            parsingPatternException = null;
+        } catch(PatternSyntaxException pse) {
+            parsingPatternException = pse;
+        }
+    }
+    
+    /** break requestPath as required by SlingRequestPathInfo */
+    public SlingRequestPathInfoParser(String requestPath) throws PatternSyntaxException {
+        if(parsingPatternException != null) {
+            throw parsingPatternException;
+        }
+        
+        if(requestPath == null) {
+            requestPath = "";
+        }
+        
+        Matcher m = splitInThreePattern.matcher(requestPath);
+        contentPath = groupOrEmpty(m,1);
+        suffix = groupOrEmpty(m,4);
+        
+        final String selAndExt = groupOrEmpty(m,3);
+        m = selectorExtPattern.matcher(selAndExt);
+        selectorString = groupOrEmpty(m,2);
+        selectors = selectorString.split("\\.");
+        extension = groupOrEmpty(m,4);
+    }
+    
+    /** Return the contents of m.group(index), empty string if that's null */
+    private static String groupOrEmpty(Matcher m, int index) {
+        String result = null;
+        if(m.matches()) {
+            result = m.group(index);
+        }
+        return result == null ? EMPTY : result;
+    }
+    
+    @Override
+    public String toString() {
+        return 
+          "SlingRequestPathInfoParser:"
+          + ", path='" + contentPath + "'"
+          + ", selectorString='" + selectorString + "'"
+          + ", extension='" + extension + "'"
+          + ", suffix='" + suffix + "'"
+        ;
+    }
+    
+    public String getExtension() {
+        return extension;
+    }
+
+    public String getSelector(int i) {
+        if(i >= 0 && i < selectors.length) {
+            return selectors[i];
+        }
+        return null;
+    }
+
+    public String[] getSelectors() {
+        return selectors;
+    }
+
+    public String getSelectorString() {
+        return selectorString;
+    }
+
+    public String getSuffix() {
+        return suffix;
+    }
+    
+    public String getContentPath() {
+        return contentPath;
+    }
+}

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java?rev=585170&r1=585169&r2=585170&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/ResourceResolverFilter.java
Tue Oct 16 08:21:50 2007
@@ -45,9 +45,10 @@
 
         // TODO support OCM-mapped objects as well
         try {
-            if (ctx.getSession().itemExists(ctx.getContentPath())) {
+            final String contentPath = ctx.getRequestPathInfo().getContentPath();
+            if (ctx.getSession().itemExists(contentPath)) {
                 Resource r = new JcrNodeResource(ctx.getSession(),
-                    ctx.getContentPath());
+                    contentPath);
                 ctx.setResource(r);
             }
         } catch (RepositoryException re) {

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java?rev=585170&r1=585169&r2=585170&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/RhinoJavascriptServlet.java
Tue Oct 16 08:21:50 2007
@@ -105,9 +105,7 @@
             ScriptableObject.putProperty(scope, "resource", wrappedResource);
 
             // set the output content type
-            final String fakeFilename = "fake." + ctx.getExtension();
-            resp.setContentType(ctx.getMimeType(fakeFilename)
-                + "; charset=utf-8");
+            resp.setContentType(ctx.getResponseContentType() + "; charset=utf-8");
 
             // evaluate the script, assuming it writes something to the output
             final PrintWriter pw = new PrintWriter(new OutputStreamWriter(

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/SlingPostServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/SlingPostServlet.java?rev=585170&r1=585169&r2=585170&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/SlingPostServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/SlingPostServlet.java
Tue Oct 16 08:21:50 2007
@@ -39,7 +39,7 @@
         final SlingRequestContext ctx = SlingRequestContext.getFromRequest(req);
         
         // Create or update node under current path
-        final String nodePath = ctx.getContentPath();
+        final String nodePath = ctx.getRequestPathInfo().getContentPath();
         
         final Session s = ctx.getSession();
         Node current  = null;

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/VelocityTemplatesServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/VelocityTemplatesServlet.java?rev=585170&r1=585169&r2=585170&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/VelocityTemplatesServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/VelocityTemplatesServlet.java
Tue Oct 16 08:21:50 2007
@@ -81,8 +81,7 @@
         }
         
         // set the output content type
-        final String fakeFilename = "fake." + ctx.getExtension();
-        resp.setContentType(ctx.getMimeType(fakeFilename) + "; charset=utf-8");
+        resp.setContentType(ctx.getResponseContentType() + "; charset=utf-8");
         
         // let Velocity evaluate the script, and send the output to the browser
         final Writer w = new OutputStreamWriter(resp.getOutputStream());

Added: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java?rev=585170&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
(added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
Tue Oct 16 08:21:50 2007
@@ -0,0 +1,98 @@
+/*
+ * 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.microsling.request.helpers;
+
+import junit.framework.TestCase;
+
+/** Test the SlingRequestPathInfoParser */
+public class SlingRequestPathInfoParserTest extends TestCase {
+
+    public void testSimplePath() {
+        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
+        assertEquals("/some/path",p.getContentPath());
+    }
+    
+    public void testSimpleSuffix() {
+        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
+        assertEquals("/some/suffix",p.getSuffix());
+    }
+    
+    public void testSimpleSelectorString() {
+        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
+        assertEquals("print.a4",p.getSelectorString());
+    }
+    
+    public void testSimpleExtension() {
+        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
+        assertEquals("html",p.getExtension());
+    }
+    
+    public void testAllOptions() {
+        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
+        assertEquals("/some/path",p.getContentPath());
+        assertEquals("print.a4",p.getSelectorString());
+        assertEquals("html",p.getExtension());
+        assertEquals("/some/suffix",p.getSuffix());
+    }
+    
+    public void testAllEmpty() {
+        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser(null);
+        assertEquals("",p.getContentPath());
+        assertEquals("",p.getSelectorString());
+        assertEquals("",p.getExtension());
+        assertEquals("",p.getSuffix());
+    }
+    
+    public void testPathOnly() {
+        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path/here");
+        assertEquals("/some/path/here",p.getContentPath());
+        assertEquals("",p.getSelectorString());
+        assertEquals("",p.getExtension());
+        assertEquals("",p.getSuffix());
+    }
+    
+    public void testPathAndExtensionOnly() {
+        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path/here.html");
+        assertEquals("/some/path/here",p.getContentPath());
+        assertEquals("",p.getSelectorString());
+        assertEquals("html",p.getExtension());
+        assertEquals("",p.getSuffix());
+    }
+    
+    public void testPathAndOneSelectorOnly() {
+        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path/here.print.html");
+        assertEquals("/some/path/here",p.getContentPath());
+        assertEquals("print",p.getSelectorString());
+        assertEquals("html",p.getExtension());
+        assertEquals("",p.getSuffix());
+    }
+    
+    public void testPathExtAndSuffix() {
+        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path/here.html/something");
+        assertEquals("/some/path/here",p.getContentPath());
+        assertEquals("",p.getSelectorString());
+        assertEquals("html",p.getExtension());
+        assertEquals("/something",p.getSuffix());
+    }
+    
+    public void testSelectorsSplit() {
+        SlingRequestPathInfoParser p = new SlingRequestPathInfoParser("/some/path.print.a4.html/some/suffix");
+        assertEquals(2,p.getSelectors().length);
+        assertEquals("print",p.getSelector(0));
+        assertEquals("a4",p.getSelector(1));
+    }
+}

Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message