abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r616540 - in /incubator/abdera/java/trunk: ./ dependencies/i18n/ dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/ jcr/src/main/java/org/apache/abdera/jcr/ jcr/src/test/java/org/apache/abdera/jcr/ server/src/main/java/org/ap...
Date Tue, 29 Jan 2008 22:22:15 GMT
Author: dandiep
Date: Tue Jan 29 14:22:13 2008
New Revision: 616540

URL: http://svn.apache.org/viewvc?rev=616540&view=rev
Log:
Flesh out the RouteManager so we can use it as the default way
to resolve and build uris.

Have defaultProvider use RouteManager by default. For those
who were using the servicesPattern functionality, you should
be able to accomplish the same thing by doing something like:

new DefaultProvider("/:base"). Then a route will be created 
like this:

.addRoute("service", "/:base", TargetType.TYPE_SERVICE)
.addRoute("feed", "/:base/:collection", TargetType.TYPE_COLLECTION)



Added:
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/route/
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/route/RouteTest.java   (with props)
Modified:
    incubator/abdera/java/trunk/dependencies/i18n/pom.xml
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Evaluator.java
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Route.java
    incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionAdapter.java
    incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionAdapterTest.java
    incubator/abdera/java/trunk/pom.xml
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProviderTest.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/SimpleAdapter.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapter.java
    incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
    incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/DefaultProviderDefinitionParser.java
    incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/ProviderFactoryBean.java
    incubator/abdera/java/trunk/spring/src/main/resources/META-INF/schemas/abdera-spring.xsd

Modified: incubator/abdera/java/trunk/dependencies/i18n/pom.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/pom.xml?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/pom.xml (original)
+++ incubator/abdera/java/trunk/dependencies/i18n/pom.xml Tue Jan 29 14:22:13 2008
@@ -1,85 +1,88 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  Licensed to the Apache Software Foundation (ASF) under one or more
-  contributor license agreements.  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.  For additional information regarding
-  copyright in this work, please see the NOTICE file in the top level
-  directory of this distribution. -->
-<project 
-  xmlns="http://maven.apache.org/POM/4.0.0" 
-  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>org.apache.abdera</groupId>
-  <artifactId>abdera-i18n</artifactId>
-  <packaging>jar</packaging>
-  <name>I18N Libraries</name>
-  <version>0.4.0-incubating-SNAPSHOT</version>
-  <description>RFC 3987 (Internationlaized Resource Identifier) libraries.</description>
-  <inceptionYear>2007</inceptionYear>
-  <url>http://incubator.apache.org/abdera</url>
-  <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/abdera/java/trunk/dependencies/i18n/</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/abdera/java/trunk/dependencies/i18n/</developerConnection>
-    <url>http://svn.apache.org/repos/asf/incubator/abdera/java/trunk/dependencies/i18n/</url>
-  </scm>
-  <dependencies>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>3.8.2</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.geronimo.specs</groupId>
-      <artifactId>geronimo-activation_1.0.2_spec</artifactId>
-      <version>1.1</version>
-      <scope>compile</scope>
-    </dependency>
-  </dependencies>
-  <build>
-    <plugins>
-      <plugin>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <configuration>
-          <source>1.5</source>
-          <target>1.5</target>
-        </configuration>
-      </plugin>
-      
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <excludes>
-            <exclude>**/*TestSuite*</exclude>
-            <exclude>**/*$*</exclude>
-          </excludes>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-  <distributionManagement>
-    <snapshotRepository>
-      <id>apache.snapshots</id>
-      <name>Apache SNAPSHOT Repository</name>
-      <url>scpexe://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
-    </snapshotRepository>
-    <repository>
-      <id>apache.incubating</id>
-      <name>Apache Incubating Repository</name>
-      <url>scpexe://people.apache.org/www/people.apache.org/repo/m2-incubating-repository</url>
-    </repository>
-  </distributionManagement>
-</project>
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  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.  For additional information regarding
+  copyright in this work, please see the NOTICE file in the top level
+  directory of this distribution. -->
+<project 
+  xmlns="http://maven.apache.org/POM/4.0.0" 
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>abdera-i18n</artifactId>
+  <packaging>jar</packaging>
+  <name>I18N Libraries</name>
+  <version>0.4.0-incubating-SNAPSHOT</version>
+  <description>RFC 3987 (Internationlaized Resource Identifier) libraries.</description>
+  <inceptionYear>2007</inceptionYear>
+  <url>http://incubator.apache.org/abdera</url>
+  <parent>
+    <groupId>org.apache.abdera</groupId>
+    <artifactId>abdera</artifactId>
+    <version>0.4.0-incubating-SNAPSHOT</version>
+  </parent>  
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/abdera/java/trunk/dependencies/i18n/</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/abdera/java/trunk/dependencies/i18n/</developerConnection>
+    <url>http://svn.apache.org/repos/asf/incubator/abdera/java/trunk/dependencies/i18n/</url>
+  </scm>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-activation_1.0.2_spec</artifactId>
+      <version>1.1</version>
+      <scope>compile</scope>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <excludes>
+            <exclude>**/*TestSuite*</exclude>
+            <exclude>**/*$*</exclude>
+          </excludes>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <distributionManagement>
+    <snapshotRepository>
+      <id>apache.snapshots</id>
+      <name>Apache SNAPSHOT Repository</name>
+      <url>scpexe://people.apache.org/www/people.apache.org/repo/m2-snapshot-repository</url>
+    </snapshotRepository>
+    <repository>
+      <id>apache.incubating</id>
+      <name>Apache Incubating Repository</name>
+      <url>scpexe://people.apache.org/www/people.apache.org/repo/m2-incubating-repository</url>
+    </repository>
+  </distributionManagement>
+</project>

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Evaluator.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Evaluator.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Evaluator.java (original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Evaluator.java Tue Jan 29 14:22:13 2008
@@ -66,6 +66,7 @@
    */
   String evaluate(
     String token, 
+    String defaultValue,
     Context context) {
       String value = null;
       Matcher matcher = PATTERN.matcher(token);
@@ -75,7 +76,18 @@
         String var = matcher.group(3);
         value = Operation.get(op).evaluate(var, arg, context);        
       }
+      if (value == null) {
+        value = defaultValue;
+      }
       return value != null ? value : "";
   }
-
+  
+  /**
+   * Evaluates the template token and returns the resolved value
+   */
+  String evaluate(
+    String token, 
+    Context context) {
+      return evaluate(token, "", context);
+  }
 }

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Route.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Route.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Route.java (original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/Route.java Tue Jan 29 14:22:13 2008
@@ -28,24 +28,28 @@
   private static final long serialVersionUID = -8979172281494208841L;
   
   private static final Evaluator EVALUATOR = new Evaluator();
-  private static final Pattern VARIABLE = Pattern.compile("[\\*\\:](?:\\()?[^\\/,;\\.#\\)]+(?:\\))?");
+  private static final Pattern VARIABLE = Pattern.compile("[\\*\\:](?:\\()?[0-9a-zA-Z]+(?:\\))?");
   
   private final String name;
   private final String pattern;
   private final String[] tokens;
   private final String[] variables;
-  private final Pattern parser;
-  private final String[] index;
-  
-  public Route(
-    String name,
-    String pattern) {
-      this.name = name;
-      this.pattern = CharUtils.stripBidiInternal(pattern);
-      this.tokens = initTokens();
-      this.variables = initVariables();
-      this.parser = compile();
-      this.index = index();
+
+  private Map<String, String> requirements;
+
+  private Map<String, String> defaultValues;
+
+  public Route(String name, String pattern) {
+    this(name, pattern, null, null);
+  }
+
+  public Route(String name, String pattern, Map<String, String> defaultValues, Map<String, String> requirements) {
+    this.name = name;
+    this.pattern = CharUtils.stripBidiInternal(pattern);
+    this.tokens = initTokens();
+    this.variables = initVariables();
+    this.defaultValues = defaultValues;
+    this.requirements = requirements;
   }
   
   private String[] initTokens() {
@@ -70,64 +74,100 @@
     return vars;
   }
   
-  private Pattern compile() {
-    Matcher m = VARIABLE.matcher(pattern);
-    StringBuilder buf = new StringBuilder();
-    int e = -1, s = 0;
-    while(m.find(s)) {
-      e = m.start();
-      if (s != 0) {
-        String q = "(?:" + Pattern.quote(pattern.substring(s,e)) + ")";
-        buf.append(q);
-        buf.append("]+))?");
-        buf.append(q);
-      }
-      buf.append("(?:([^\\/,;\\.#\\)\\?");
-      s = m.end();
-    }
-    if (s > 0) {
-      if (s < pattern.length()) {
-        String q = "(?:" + Pattern.quote(pattern.substring(s)) + ")";
-        buf.append(q);
-      }
-      buf.append("]+))?");
-    }
-    return Pattern.compile(buf.toString());
-  }
-  
-  private String[] index() {
-    List<String> index = new ArrayList<String>();
-    Matcher m = VARIABLE.matcher(pattern);
-    int s = 0;
-    while(m.find(s)) {
-      String var = var(m.group(0));
-      if (!index.contains(var)) index.add(var);
-      s = m.end();
-    }
-    return index.toArray(new String[index.size()]);
-  }
-  
   /**
    * Returns true if the given uri matches the route pattern
    */
-  public boolean match(String pattern) {
-    Matcher m = parser.matcher(pattern);
-    return m.find();
+  public boolean match(String uri) {
+    Matcher matcher = VARIABLE.matcher(pattern);
+    int uriStart = 0;
+    int prevPatternEnd = 0;
+    while (matcher.find()) {
+      int patternStart = matcher.start();
+      
+      String nonVariablePattern = pattern.substring(prevPatternEnd, patternStart);
+      if (prevPatternEnd == 0 && nonVariablePattern.length() == 0) {
+        prevPatternEnd = matcher.end();
+        continue;
+      }
+      
+      int idx = uri.indexOf(nonVariablePattern, uriStart);
+      if ((idx == -1 || idx+1 == uri.length()) && (defaultValues == null || !defaultValues.containsKey(var(matcher.group())))) {
+        return false;
+      } else {
+        uriStart = idx + 1 + nonVariablePattern.length();
+      }
+      
+      // TODO: ensure requirements are met
+      
+      prevPatternEnd = matcher.end();
+    }
+    
+    // Check if the non variable, end segment matches
+    if (prevPatternEnd != pattern.length()) {
+      if (!uri.endsWith(pattern.substring(prevPatternEnd))) {
+        return false;
+      } else {
+        return true;
+      }
+    } else if (uriStart > uri.length()) {
+      return false;
+    }
+    
+    return uri.indexOf('/', uriStart) == -1;
   }
   
   /**
    * Parses the given uri using the route pattern
    */
-  public Map<String,String> parse(String pattern) {
-    Matcher m = parser.matcher(pattern);
-    Map<String,String> results = new HashMap<String,String>();
-    if (m.find()) {
-      for (int n = 1; n <= m.groupCount(); n++) {
-        String label = index[n-1];
-        results.put(label, m.group(n));
+  public Map<String,String> parse(String uri) {
+    HashMap<String, String> vars = new HashMap<String, String>();
+    Matcher matcher = VARIABLE.matcher(pattern);
+    int uriStart = 0;
+    int prevPatternEnd = 0;
+    int valueStart = -1;
+    int nonVarIdx = -1; 
+    String prevVar = null;
+    while (matcher.find()) {
+      int patternStart = matcher.start();
+      String varName = var(matcher.group());
+      
+      String nonVariableSection = pattern.substring(prevPatternEnd, patternStart);
+      if (prevPatternEnd == 0 && nonVariableSection.length() == 0) {
+        prevPatternEnd = matcher.end();
+        valueStart = 0;
+        continue;
+      }
+
+      nonVarIdx = uri.indexOf(nonVariableSection, uriStart);
+      
+      if (valueStart != -1) {
+        vars.put(prevVar, uri.substring(valueStart, nonVarIdx));
       }
+      
+      if ((nonVarIdx == -1 || nonVarIdx+1 == uri.length()) && (defaultValues == null || !defaultValues.containsKey(varName))) {
+        valueStart = -1;
+        break;
+      }
+
+      // TODO: ensure requirements are met
+      
+      valueStart = nonVarIdx + nonVariableSection.length();
+      
+      uriStart = valueStart + 1;
+      prevVar = varName;
+      prevPatternEnd = matcher.end();
+    }
+    
+    int tailEnd = uri.length();
+    if (prevPatternEnd != pattern.length() && uri.endsWith(pattern.substring(prevPatternEnd))) {
+      tailEnd = tailEnd - (pattern.length() - prevPatternEnd);
+    }
+    
+    if (valueStart != uri.length() && valueStart != -1) {
+      vars.put(prevVar, uri.substring(valueStart, tailEnd));
     }
-    return results;
+    
+    return vars;
   }
 
   /**
@@ -137,12 +177,11 @@
     Context context) {
       String pattern = this.pattern;
       for(String token : this) {
+        String var = var(token);
         pattern = replace(
           pattern, 
           token, 
-          EVALUATOR.evaluate(
-            var(token), 
-            context));
+          EVALUATOR.evaluate(var, getDefaultValue(var), context));
       }
       StringBuffer buf = new StringBuffer(pattern);
       boolean qs = false;
@@ -162,6 +201,12 @@
       
       return buf.toString();
   }
+
+  private String getDefaultValue(String var) {
+    if (defaultValues == null) return null;
+    
+    return defaultValues.get(var);
+  }
   
   private String var(String token) {
     token = token.substring(1);
@@ -195,8 +240,8 @@
     String pattern, 
     String token, 
     String value) {
-      return pattern.replaceAll(
-        Pattern.quote(token),
+      return pattern.replace(
+        token,
         value);
   }
 

Modified: incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionAdapter.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionAdapter.java (original)
+++ incubator/abdera/java/trunk/jcr/src/main/java/org/apache/abdera/jcr/JcrCollectionAdapter.java Tue Jan 29 14:22:13 2008
@@ -190,7 +190,7 @@
   }
 
   @Override
-  public Node postMediaEntry(MimeType mimeType, String slug, 
+  public Node postMedia(MimeType mimeType, String slug, 
                                InputStream inputStream, RequestContext request)
     throws ResponseContextException {
     if (slug == null) {

Modified: incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionAdapterTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionAdapterTest.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionAdapterTest.java (original)
+++ incubator/abdera/java/trunk/jcr/src/test/java/org/apache/abdera/jcr/JcrCollectionAdapterTest.java Tue Jan 29 14:22:13 2008
@@ -53,7 +53,7 @@
     cp.setCollectionNodePath("entries");         
     cp.setRepository(repository);
     cp.setCredentials(new SimpleCredentials("username", "pass".toCharArray()));
-    cp.setHref("acme/feed");
+    cp.setHref("feed");
     cp.initialize();
     
     SimpleWorkspaceInfo wkspc = new SimpleWorkspaceInfo();
@@ -73,7 +73,7 @@
     String base = "http://localhost:9002/";
 
     // Testing of entry creation
-    IRI colUri = new IRI(base).resolve("acme/feed");
+    IRI colUri = new IRI(base).resolve("feed");
     Entry entry = factory.newEntry();
     entry.setTitle("Some Entry");
     entry.setUpdated(new Date());

Modified: incubator/abdera/java/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/pom.xml?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/pom.xml (original)
+++ incubator/abdera/java/trunk/pom.xml Tue Jan 29 14:22:13 2008
@@ -143,7 +143,7 @@
             <excludes>
               <exclude>**/*TestSuite*</exclude>
               <exclude>**/*$Test*</exclude>
-              <exclude>**/Test*</exclude>
+              <exclude>**/TestAdapter*</exclude>
             </excludes>
           </configuration>
         </plugin>

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractCollectionAdapter.java Tue Jan 29 14:22:13 2008
@@ -4,6 +4,8 @@
 
 import java.io.IOException;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.factory.Factory;
@@ -22,6 +24,7 @@
 import org.apache.abdera.protocol.server.ProviderHelper;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
+import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.protocol.server.Transactional;
 import org.apache.abdera.protocol.server.context.AbstractResponseContext;
 import org.apache.abdera.protocol.server.context.BaseResponseContext;
@@ -37,7 +40,27 @@
              CollectionInfo {
 
   private final static Log log = LogFactory.getLog(AbstractEntityCollectionAdapter.class);
+  
+  private String href;
+  private Map<String,Object> hrefParams = new HashMap<String,Object>();
+ 
+  public AbstractCollectionAdapter() {
+    super();
+  }
 
+  public String getHref() {
+    return href;
+  }
+
+  public void setHref(String href) {
+    this.href = href;
+    hrefParams.put("collection", href);
+  }
+  
+  public String getHref(RequestContext request) {
+    return request.urlFor("feed", hrefParams);
+  }
+  
   public void compensate(RequestContext request, Throwable t) {
   }
 

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractEntityCollectionAdapter.java Tue Jan 29 14:22:13 2008
@@ -20,7 +20,9 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.activation.MimeType;
 
@@ -36,6 +38,7 @@
 import org.apache.abdera.protocol.server.ProviderHelper;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.ResponseContext;
+import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.protocol.server.context.EmptyResponseContext;
 import org.apache.abdera.protocol.server.context.MediaResponseContext;
 import org.apache.abdera.protocol.server.context.ResponseContextException;
@@ -52,26 +55,13 @@
 public abstract class AbstractEntityCollectionAdapter<T> 
   extends AbstractCollectionAdapter {
   private final static Log log = LogFactory.getLog(AbstractEntityCollectionAdapter.class);
-  private String href;
-  
-  public String getHref() {
-    return href;
-  }
-
-  public void setHref(String href) {
-    this.href = href;
-  }
-
-  public String getHref(RequestContext request) {
-    return getHref();
-  }
 
   public abstract T postEntry(String title, IRI id, String summary, Date updated, List<Person> authors, Content content, RequestContext request) throws ResponseContextException;
   
   @Override
   public ResponseContext postMedia(RequestContext request) {
     try {
-      T doc = postMediaEntry(request.getContentType(), request.getSlug(), 
+      T doc = postMedia(request.getContentType(), request.getSlug(), 
                              request.getInputStream(), request);
 
       IRI baseIri = ProviderHelper.resolveBase(request);
@@ -123,7 +113,7 @@
     }
   }
 
-  public T postMediaEntry(MimeType mimeType, String slug, InputStream inputStream, RequestContext request) throws ResponseContextException {
+  public T postMedia(MimeType mimeType, String slug, InputStream inputStream, RequestContext request) throws ResponseContextException {
     throw new UnsupportedOperationException();
   }
 
@@ -162,7 +152,7 @@
 
   public ResponseContext getEntry(RequestContext request) {
     try {
-      Entry entry = getEntryFromCollectionProvider(getFeedIRI(request),
+      Entry entry = getEntryFromCollectionProvider(new IRI(getHref(request)),
                                                    request);
       if (entry != null) {
         return buildGetEntryResponse(request, entry);
@@ -174,10 +164,6 @@
     }
   }
 
-  private IRI getFeedIRI(RequestContext request) {
-    return ProviderHelper.resolveBase(request).resolve("../..");
-  }
-
   public abstract T getEntry(String resourceName, RequestContext request) throws ResponseContextException;
 
   public ResponseContext getFeed(RequestContext request) {
@@ -277,7 +263,7 @@
         return new EmptyResponseContext(404);
       }
       
-      Entry orig_entry = getEntryFromCollectionProvider(entryObj, getFeedIRI(request), request);
+      Entry orig_entry = getEntryFromCollectionProvider(entryObj, new IRI(getHref(request)), request);
       if (orig_entry != null) {
 
         MimeType contentType = request.getContentType();
@@ -363,7 +349,7 @@
 
   protected ResponseContext createMediaEntry(RequestContext request) {
     try {
-      T doc = postMediaEntry(request.getContentType(), request.getSlug(), 
+      T doc = postMedia(request.getContentType(), request.getSlug(), 
                                request.getInputStream(), request);
 
       IRI baseIri = ProviderHelper.resolveBase(request);

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultProvider.java Tue Jan 29 14:22:13 2008
@@ -25,23 +25,39 @@
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.protocol.server.TargetBuilder;
+import org.apache.abdera.protocol.server.TargetType;
 import org.apache.abdera.protocol.server.WorkspaceInfo;
 import org.apache.abdera.protocol.server.WorkspaceManager;
 
 public class DefaultProvider extends AbstractProvider {
 
-  private WorkspaceManager workspaceManager;
-  private Resolver<Target> targetResolver;
-  private Resolver<Subject> subjectResolver;
-
+  protected WorkspaceManager workspaceManager;
+  protected Resolver<Target> targetResolver;
+  protected Resolver<Subject> subjectResolver;
+  protected TargetBuilder targetBuilder;
+  protected RouteManager routeManager;
+  
   public DefaultProvider() {
-    workspaceManager = new DefaultWorkspaceManager();
-    targetResolver = new StructuredTargetResolver(workspaceManager);
+    this("/");
   }
 
   public DefaultProvider(String base) {
+    if (base == null) {
+      base = "/";
+    }
     workspaceManager = new DefaultWorkspaceManager();
-    targetResolver = new StructuredTargetResolver(workspaceManager, base);
+    routeManager = new RouteManager()
+      .addRoute("service", base, TargetType.TYPE_SERVICE)
+      .addRoute("feed", base + ":collection", TargetType.TYPE_COLLECTION)
+      .addRoute("entry", base + ":collection/:entry", TargetType.TYPE_ENTRY)
+      .addRoute("categories", base + ":collection/:entry;categories", TargetType.TYPE_CATEGORIES);
+    
+    targetBuilder = routeManager;
+    targetResolver = routeManager;
+  }
+
+  public RouteManager getRouteManager() {
+    return routeManager;
   }
 
   protected Resolver<Target> getTargetResolver(RequestContext request) {
@@ -78,6 +94,14 @@
 
   public void setWorkspaceManager(WorkspaceManager workspaceManager) {
     this.workspaceManager = workspaceManager;
+  }
+
+  public TargetBuilder getTargetBuilder() {
+    return targetBuilder;
+  }
+
+  public void setTargetBuilder(TargetBuilder targetBuilder) {
+    this.targetBuilder = targetBuilder;
   }
 
   public void addWorkspace(WorkspaceInfo workspace) {

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/DefaultWorkspaceManager.java Tue Jan 29 14:22:13 2008
@@ -1,14 +1,37 @@
 package org.apache.abdera.protocol.server.impl;
 
+import java.util.Iterator;
+
 import org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.CollectionInfo;
 import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.WorkspaceInfo;
 import org.apache.abdera.protocol.server.RequestContext.Scope;
 
 
 public class DefaultWorkspaceManager extends AbstractWorkspaceManager {
 
+  public static final String COLLECTION_ADAPTER_ATTRIBUTE = "collectionProvider";
+
   public CollectionAdapter getCollectionAdapter(RequestContext request) {
-    return (CollectionAdapter) request.getAttribute(Scope.REQUEST, StructuredTargetResolver.COLLECTION_PROVIDER_ATTRIBUTE);
+    String path = request.getTargetPath();
+    
+    // Typically this happens when a Resolver wants to override the CollectionAdapter being used
+    CollectionAdapter ca = (CollectionAdapter) request.getAttribute(Scope.REQUEST, COLLECTION_ADAPTER_ATTRIBUTE);
+    if (ca != null) {
+      return ca;
+    }
+    
+    for (WorkspaceInfo wi : workspaces) {
+      for (CollectionInfo ci : wi.getCollections(request)) {
+        String href = ci.getHref(request);
+        if (href != null && path.startsWith(href)) {
+          return (CollectionAdapter) ci;
+        }
+      }
+    }
+    
+    return null; 
   }
 
 }

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/RouteManager.java Tue Jan 29 14:22:13 2008
@@ -13,6 +13,7 @@
 import org.apache.abdera.i18n.templates.Route;
 import org.apache.abdera.protocol.Request;
 import org.apache.abdera.protocol.Resolver;
+import org.apache.abdera.protocol.server.CollectionAdapter;
 import org.apache.abdera.protocol.server.RequestContext;
 import org.apache.abdera.protocol.server.Target;
 import org.apache.abdera.protocol.server.TargetBuilder;
@@ -45,6 +46,9 @@
   protected Map<String,Route> routes = 
     new HashMap<String,Route>();
 
+  protected Map<Route,CollectionAdapter> route2CA = 
+    new HashMap<Route,CollectionAdapter>();
+  
   public RouteManager addRoute(
     Route route) {
       return addRoute(route,null);
@@ -79,11 +83,26 @@
         type);
   }
   
+  public RouteManager addRoute(
+    String name, 
+    String pattern, 
+    TargetType type,
+    CollectionAdapter collectionAdapter) {
+    
+    Route route = new Route(name,  pattern);
+    route2CA.put(route, collectionAdapter);
+    return addRoute(route, type);
+  }
+  
   public Target resolve(Request request) {
     RequestContext context = (RequestContext) request;
     String uri = context.getTargetPath();
     for(Map.Entry<Route, TargetType> entry : targets.entrySet()) {
       if (entry.getKey().match(uri)) {
+        CollectionAdapter ca = route2CA.get(entry.getKey());
+        if (ca != null) {
+          context.setAttribute(DefaultWorkspaceManager.COLLECTION_ADAPTER_ATTRIBUTE, ca);
+        }
         return getTarget(context, entry.getKey(), uri, entry.getValue());
       }
     }
@@ -111,6 +130,7 @@
         null;
   }
   
+  @SuppressWarnings("unchecked")
   private Context getContext(Object param) {
     Context context = null;
     if (param != null) {
@@ -157,6 +177,7 @@
           params.get(name) :
           super.getParameter(name);
       }
+      @SuppressWarnings("unchecked")
       public String[] getParameterNames() {
         List<String> names = new ArrayList(Arrays.asList(super.getParameterNames()));
         for (String name : params.keySet()) {

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/StructuredTargetResolver.java Tue Jan 29 14:22:13 2008
@@ -17,13 +17,9 @@
 */
 package org.apache.abdera.protocol.server.impl;
 
-import java.util.Iterator;
-import java.util.List;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.abdera.i18n.templates.Context;
-import org.apache.abdera.i18n.templates.DelegatingContext;
 import org.apache.abdera.i18n.text.UrlEncoding;
 import org.apache.abdera.protocol.Request;
 import org.apache.abdera.protocol.Resolver;
@@ -40,27 +36,26 @@
  * Resolves targets based on a simple assumed URI structure. 
  */
 public class StructuredTargetResolver
-  extends TemplateTargetBuilder
   implements Resolver<Target> {
 
-  public static final String COLLECTION_PROVIDER_ATTRIBUTE = "collectionProvider";
   public static final String URI_PARAMETER_ATTRIBUTE_PREFIX = "uriParameter";
 
   private Pattern servicesPattern = Pattern.compile("^/");
 
   private WorkspaceManager workspaceManager;
   
+
   public StructuredTargetResolver(WorkspaceManager workspaceManager) {
-    this.workspaceManager = workspaceManager;
-    setTemplate(TargetType.TYPE_SERVICE, "{target_base}");
-    setTemplate(TargetType.TYPE_COLLECTION, "{target_base}/{collection}");
-    setTemplate(TargetType.TYPE_CATEGORIES, "{target_base}/{collection};categories");
-    setTemplate(TargetType.TYPE_ENTRY, "{target_base}/{collection}/{entryid}");
+    this(workspaceManager, null);
   }
 
   public StructuredTargetResolver(WorkspaceManager workspaceManager, String servicesPattern) {
     this.workspaceManager = workspaceManager;
-    this.servicesPattern = Pattern.compile(servicesPattern);
+    if (servicesPattern != null) {
+      this.servicesPattern = Pattern.compile(servicesPattern);
+    }
+    
+
   }
 
   public Target resolve(Request request) {
@@ -79,9 +74,6 @@
       uriMatcher.reset();
       if (uriMatcher.find()) {
         String path = uri.substring(uriMatcher.start());
-        if (path.startsWith("/")) {
-          path = path.substring(1);
-        }
         int q = path.indexOf("?");
         if (q != -1) {
           path = path.substring(0, q);
@@ -102,7 +94,7 @@
         }
 
         if (collection != null) {
-          context.setAttribute(Scope.REQUEST, COLLECTION_PROVIDER_ATTRIBUTE, collection);
+          context.setAttribute(Scope.REQUEST, DefaultWorkspaceManager.COLLECTION_ADAPTER_ATTRIBUTE, collection);
 
           if (href.equals(path)) {
             tt = TargetType.TYPE_COLLECTION;
@@ -138,49 +130,5 @@
     } else {
       return TargetType.TYPE_ENTRY;
     }
-  }
-
-  public String urlFor(
-    RequestContext request, 
-    Object key, 
-    Object param) {
-      CollectionInfo ci = 
-        (CollectionInfo) request.getAttribute(
-          Scope.REQUEST, 
-          COLLECTION_PROVIDER_ATTRIBUTE);
-      String collection = ci != null ? ci.getHref(request) : null;
-      Context context = 
-        new StructuredContext(
-          TemplateTargetBuilder.getContext(request, param), 
-          collection);
-      return super.urlFor(request, key, context);
-  }
-  
-  @SuppressWarnings("unchecked")
-  private static class StructuredContext 
-    extends DelegatingContext {
-
-    private static final long serialVersionUID = 1L;
-    private final String collection;
-    
-    protected StructuredContext(
-      Context subcontext,
-      String collection) {
-        super(subcontext);
-        this.collection = collection;
-    }
-
-    public Iterator<String> iterator() {
-      List<String> list = TemplateTargetBuilder.asList(super.iterator());
-      if (!list.contains("collection")) list.add("collection");
-      return list.iterator();
-    }
-
-    protected <T> T resolveActual(String var) {
-      if (var.equalsIgnoreCase("collection")) 
-        return (T)collection;
-      return (T)super.resolveActual(var);
-    }
-
   }
 }

Added: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/route/RouteTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/route/RouteTest.java?rev=616540&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/route/RouteTest.java (added)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/route/RouteTest.java Tue Jan 29 14:22:13 2008
@@ -0,0 +1,132 @@
+package org.apache.abdera.protocol.server.route;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.abdera.i18n.templates.HashMapContext;
+import org.apache.abdera.i18n.templates.Route;
+import org.junit.Test;
+
+import junit.framework.Assert;
+
+public class RouteTest extends Assert {
+  @Test
+  public void testSimpleRoute() throws Exception {
+    Route route = new Route("feed", "/:collection");
+    
+    HashMapContext ctx = new HashMapContext();
+    ctx.put("collection", "test");
+    assertEquals("/test", route.expand(ctx));
+    
+    assertTrue(route.match("/foo"));
+    assertFalse(route.match("/foo/test"));
+    assertFalse(route.match("foo"));
+    
+    Map<String, String> vars = route.parse("/test");
+    assertEquals("test", vars.get("collection"));
+  }
+  @Test
+  public void testStaticRoute() throws Exception {
+    Route route = new Route("feed", "/feed");
+    
+    HashMapContext ctx = new HashMapContext();
+    assertEquals("/feed", route.expand(ctx));
+    
+    assertTrue(route.match("/feed"));
+    assertFalse(route.match("/feed/test"));
+    assertFalse(route.match("feed"));
+    
+    Map<String, String> vars = route.parse("/test");
+    assertEquals(0, vars.size());
+  }
+  
+  @Test
+  public void testTwoPathRoute() throws Exception {
+    Route route = new Route("entry", "/:collection/:entry");
+    
+    HashMapContext ctx = new HashMapContext();
+    ctx.put("collection", "c");
+    ctx.put("entry", "e");
+    assertEquals("/c/e", route.expand(ctx));
+    
+    assertFalse(route.match("/foo"));
+    assertTrue(route.match("/foo/test"));
+    assertFalse(route.match("foo"));
+
+    Map<String, String> vars = route.parse("/1/2");
+    assertEquals("1", vars.get("collection"));
+    assertEquals("2", vars.get("entry"));
+    
+    vars = route.parse("/1/");
+    assertEquals("1", vars.get("collection"));
+    assertNull(vars.get("entry"));
+  }
+
+  @Test
+  public void testTwoPathRouteWithSubstitution() throws Exception {
+    Map<String, String> defaults = new HashMap<String,String>();
+    defaults.put("collection", "c");
+    Route route = new Route("entry", "/:collection/:entry", defaults, null);
+    
+    HashMapContext ctx = new HashMapContext();
+    ctx.put("entry", "e");
+    assertEquals("/c/e", route.expand(ctx));
+  }
+
+  @Test
+  public void testDashedRoute() throws Exception {
+    Route route = new Route("entry", ":collection/:entry-:foo");
+    
+    HashMapContext ctx = new HashMapContext();
+    ctx.put("collection", "c");
+    ctx.put("entry", "e");
+    ctx.put("foo", "f");
+    assertEquals("c/e-f", route.expand(ctx));
+    
+    assertTrue(route.match("1/2-3"));
+    assertFalse(route.match("1/2-"));
+    assertFalse(route.match("1/-"));
+  }
+
+  @Test
+  public void testDashedRouteWithSubstitution() throws Exception {
+    Map<String, String> defaults = new HashMap<String,String>();
+    defaults.put("foo", "f");
+    Route route = new Route("entry", ":collection/:entry-:foo", defaults, null);
+    
+    HashMapContext ctx = new HashMapContext();
+    ctx.put("collection", "c");
+    ctx.put("entry", "e");
+    assertEquals("c/e-f", route.expand(ctx));
+    
+    assertTrue(route.match("1/2-3"));
+    assertFalse(route.match("1/2-"));
+    assertFalse(route.match("1/-"));
+  }
+
+  @Test
+  public void testBaseURI() throws Exception {
+    Route route = new Route("entry", "/base/:collection/:entry");
+
+    assertTrue(route.match("/base/test/123"));
+    assertFalse(route.match("/base/test"));
+    assertFalse(route.match("base/test"));
+    
+    Map<String, String> vars = route.parse("/base/1/2");
+    assertEquals("1", vars.get("collection"));
+    assertEquals("2", vars.get("entry"));
+  }
+  
+
+  @Test
+  public void testNonVariablesAtBothEnds() throws Exception {
+    Route route = new Route("entry", "/base/:collection/:entry;categories");
+
+    assertTrue(route.match("/base/test/123;categories"));
+    assertFalse(route.match("/base/test/123"));
+    
+    Map<String, String> vars = route.parse("/base/1/2;categories");
+    assertEquals("1", vars.get("collection"));
+    assertEquals("2", vars.get("entry"));
+  }
+}

Propchange: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/route/RouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/route/RouteTest.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/route/RouteTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProviderTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProviderTest.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProviderTest.java (original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/CustomProviderTest.java Tue Jan 29 14:22:13 2008
@@ -67,7 +67,7 @@
   }
 
   @Test
-  public void testGetService() {
+  public void testGetService() throws IOException {
     ClientResponse resp = client.get("http://localhost:9002/atom");
     assertNotNull(resp);
     assertEquals(ResponseType.SUCCESS, resp.getType());
@@ -77,6 +77,7 @@
 prettyPrint(doc);
 } catch (Exception e) {}
     Service service = doc.getRoot();
+    prettyPrint(service);
     assertEquals(service.getWorkspaces().size(), 1);
     Workspace workspace = service.getWorkspaces().get(0);
     assertEquals(workspace.getCollections().size(), 1);

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/SimpleAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/SimpleAdapter.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/SimpleAdapter.java (original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/custom/SimpleAdapter.java Tue Jan 29 14:22:13 2008
@@ -75,19 +75,12 @@
     Feed feed = (Feed)context.getAttribute(Scope.SESSION, "feed");
     if (feed == null) {
       feed = createFeedBase(context);
-      feed.setBaseUri(getFeedBaseUri(context));
+      feed.setBaseUri(getHref(context));
       context.setAttribute(Scope.SESSION, "feed", feed);
     }
     return feed.getDocument();
   }
- 
-  private String getFeedBaseUri(RequestContext context) {
-    Map<String,String> params = new HashMap<String,String>();
-    params.put("collection", context.getTarget().getParameter("collection"));
-    String uri = context.urlFor(TargetType.TYPE_COLLECTION, params);
-    return context.getResolvedUri().resolve(uri).toString();
-  }
-  
+
   public ResponseContext getFeed(
     RequestContext request) {
       Document<Feed> feed;

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapter.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapter.java (original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapter.java Tue Jan 29 14:22:13 2008
@@ -23,21 +23,21 @@
 public class CustomerAdapter extends AbstractEntityCollectionAdapter<Customer> {
   private static final String ID_PREFIX = "urn:acme:customer:";
   
-  private final static AtomicInteger nextId = new AtomicInteger(1000);
+  private AtomicInteger nextId = new AtomicInteger(1000);
   private Map<Integer, Customer> customers = new HashMap<Integer, Customer>();
   private Factory factory = new Abdera().getFactory();
   
   public String getId(RequestContext request) {
     return "tag:example.org,2007:feed";
   }
-
   
   public ResponseContext getCategories(RequestContext request) {
     return null;
   }
   
   @Override
-  public Customer postEntry(String title, IRI id, String summary, Date updated, List<Person> authors,
+  public Customer postEntry(String title, IRI id, String summary, 
+                            Date updated, List<Person> authors,
                             Content content, RequestContext request) throws ResponseContextException {   
     Customer customer = contentToCustomer(content);
     customers.put(customer.getId(), customer);

Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java (original)
+++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/protocol/server/test/customer/CustomerAdapterTest.java Tue Jan 29 14:22:13 2008
@@ -5,6 +5,7 @@
 
 import javax.xml.namespace.QName;
 
+import junit.framework.Assert;
 import junit.framework.TestCase;
 
 import org.apache.abdera.Abdera;
@@ -22,23 +23,22 @@
 import org.apache.abdera.protocol.server.servlet.AbderaServlet;
 import org.apache.abdera.writer.Writer;
 import org.apache.abdera.writer.WriterFactory;
+import org.junit.After;
+import org.junit.Test;
 import org.mortbay.jetty.Server;
 import org.mortbay.jetty.servlet.Context;
 import org.mortbay.jetty.servlet.ServletHolder;
 
-public class CustomerAdapterTest extends TestCase {
+public class CustomerAdapterTest extends Assert {
 
   private Server server;
   private DefaultProvider customerProvider;
 
-  @Override
-  protected void setUp() throws Exception {
-    super.setUp();
-    
-    customerProvider = new DefaultProvider("^/([^\\/])+/");
+  private void setupAbdera(String base) throws Exception {
+    customerProvider = new DefaultProvider(base);
     
     CustomerAdapter ca = new CustomerAdapter();
-    ca.setHref("foo/acme/customers");
+    ca.setHref("customers");
     
     SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo();
     wi.setTitle("Customer Workspace");
@@ -49,18 +49,33 @@
     initializeJetty();
   }
 
+  @Test
   public void testCustomerProvider() throws Exception {
+    setupAbdera("/");
+    
+    String base = "http://localhost:9002/";
+
+    runTests(base);
+  }
+  
+  @Test
+  public void testCustomerProviderWithDifferentBase() throws Exception {
+    setupAbdera("/base/");
+    
+    String base = "http://localhost:9002/base/";
+
+    runTests(base);
+  }
 
+  private void runTests(String base) throws IOException {
     Abdera abdera = new Abdera();
     Factory factory = abdera.getFactory();
 
     AbderaClient client = new AbderaClient(abdera);
 
-    String base = "http://localhost:9002/";
-
     // Testing of entry creation
-    IRI colUri = new IRI(base).resolve("foo/acme/customers"); // base +
-                                                          // docCollection.getHref().toString();
+    IRI colUri = new IRI(base).resolve("customers"); 
+                                                          
     Entry entry = factory.newEntry();
     entry.setTitle("This is ignored right now");
     entry.setUpdated(new Date());
@@ -74,7 +89,7 @@
 
     RequestOptions opts = new RequestOptions();
     opts.setContentType("application/atom+xml;type=entry");
-    ClientResponse res = client.post(colUri.toString(), entry, opts);
+    ClientResponse res = client.post(colUri.toString() + "?test=foo", entry, opts);
     assertEquals(201, res.getStatus());
 
     // prettyPrint(abdera, res.getDocument());
@@ -89,6 +104,7 @@
 
     // prettyPrint(abdera, res.getDocument());
     org.apache.abdera.model.Document<Entry> entry_doc = res.getDocument();
+    prettyPrint(abdera, entry_doc);
     entry = entry_doc.getRoot();
 
     res = client.get(colUri + "/foobar");
@@ -118,8 +134,8 @@
     server.start();
   }
 
-  @Override
-  protected void tearDown() throws Exception {
+  @After
+  public void tearDown() throws Exception {
     if (server != null) server.stop();
   }
 

Modified: incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/DefaultProviderDefinitionParser.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/DefaultProviderDefinitionParser.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/DefaultProviderDefinitionParser.java (original)
+++ incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/DefaultProviderDefinitionParser.java Tue Jan 29 14:22:13 2008
@@ -36,8 +36,10 @@
 
     @Override
     protected void mapAttribute(BeanDefinitionBuilder bean, Element element, String name, String val) {
-        if (name.equals("servicesPattern")) {
+        if (name.equals("base")) {
             bean.addPropertyValue(name, val);
+        } else if (name.equals("class")) {
+            bean.addPropertyValue("providerClass", val);
         }
     }
 

Modified: incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/ProviderFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/ProviderFactoryBean.java?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/ProviderFactoryBean.java (original)
+++ incubator/abdera/java/trunk/spring/src/main/java/org/apache/abdera/spring/ProviderFactoryBean.java Tue Jan 29 14:22:13 2008
@@ -13,7 +13,7 @@
 
 public class ProviderFactoryBean implements FactoryBean {
     private Class providerClass = DefaultProvider.class;
-    private String servicesPattern;
+    private String base;
     private Collection<WorkspaceInfo> workspaces;
     private Resolver<Target> targetResolver;
     private Resolver<Subject> subjectResolver;
@@ -21,9 +21,9 @@
     public Object getObject() throws Exception {
         DefaultProvider p = null;
         
-        if (servicesPattern != null) {
+        if (base != null) {
             Constructor constructor = providerClass.getConstructor(String.class);
-            p = (DefaultProvider) constructor.newInstance(servicesPattern);
+            p = (DefaultProvider) constructor.newInstance(base);
         } else {
             p = (DefaultProvider) providerClass.newInstance();
         }
@@ -43,7 +43,7 @@
     }
 
     public Class getObjectType() {
-        return DefaultProvider.class;
+        return providerClass;
     }
 
     public boolean isSingleton() {
@@ -58,12 +58,12 @@
         this.providerClass = providerClass;
     }
 
-    public String getServicesPattern() {
-        return servicesPattern;
+    public String getBase() {
+        return base;
     }
 
-    public void setServicesPattern(String servicesPattern) {
-        this.servicesPattern = servicesPattern;
+    public void setBase(String base) {
+        this.base = base;
     }
 
     public Collection<WorkspaceInfo> getWorkspaces() {

Modified: incubator/abdera/java/trunk/spring/src/main/resources/META-INF/schemas/abdera-spring.xsd
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/spring/src/main/resources/META-INF/schemas/abdera-spring.xsd?rev=616540&r1=616539&r2=616540&view=diff
==============================================================================
--- incubator/abdera/java/trunk/spring/src/main/resources/META-INF/schemas/abdera-spring.xsd (original)
+++ incubator/abdera/java/trunk/spring/src/main/resources/META-INF/schemas/abdera-spring.xsd Tue Jan 29 14:22:13 2008
@@ -38,7 +38,7 @@
             <xsd:element name="subjectResolver" type="xsd:anyType" minOccurs="0"/>
           </xsd:sequence>
           <xsd:attribute name="class" type="xsd:string" />
-          <xsd:attribute name="servicesPattern" type="xsd:string"/>
+          <xsd:attribute name="base" type="xsd:string"/>
         </xsd:extension>
       </xsd:complexContent>
     </xsd:complexType>



Mime
View raw message