abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r619778 - /incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/
Date Fri, 08 Feb 2008 06:35:35 GMT
Author: jmsnell
Date: Thu Feb  7 22:35:29 2008
New Revision: 619778

URL: http://svn.apache.org/viewvc?rev=619778&view=rev
Log:
Incorporate the concepts from https://issues.apache.org/jira/browse/ABDERA-97

This was refactored into the form of a new "ManagedProvider" in order to keep it from affecting
all Provider implementations, the AbderaServlet, etc.  BasicProvider now extends ManagedProvider.
 BasicAdapter extends ManagedCollectionAdapter.

Added:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/AbstractServerConfiguration.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/BasicServerConfiguration.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/CollectionAdapterConfiguration.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/CollectionAdapterManager.java
      - copied, changed from r619685, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/CollectionAdapterManager.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/Configuration.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/FeedConfiguration.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedCollectionAdapter.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedProvider.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedWorkspace.java
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ServerConfiguration.java

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/AbstractServerConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/AbstractServerConfiguration.java?rev=619778&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/AbstractServerConfiguration.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/AbstractServerConfiguration.java
Thu Feb  7 22:35:29 2008
@@ -0,0 +1,89 @@
+/*
+* 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.
+*/
+package org.apache.abdera.protocol.server.provider.managed;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.abdera.protocol.server.RequestContext;
+
+public abstract class AbstractServerConfiguration 
+  extends ServerConfiguration {
+  
+  private final String host;
+  private final int port;
+  private final boolean secure;
+  
+  protected AbstractServerConfiguration(RequestContext request) {
+    Object ohost = request.getProperty(RequestContext.Property.SERVERNAME);
+    Object oport = request.getProperty(RequestContext.Property.SERVERPORT);
+    Object osec = request.getProperty(RequestContext.Property.SECURE);
+    host = ohost != null ? (String)ohost : "localhost";
+    port = oport != null ? ((Integer)oport).intValue() : 9002;
+    secure = osec != null ? ((Boolean)osec).booleanValue() : false;
+  }
+   
+  @Override
+  public String getAdapterConfigLocation() {
+    return "abdera/adapter/config/";
+  }
+
+  @Override
+  public String getFeedConfigLocation() {
+    return "abdera/adapter/";
+  }
+
+  @Override
+  public String getFeedConfigSuffix() {
+    return ".properties";
+  }
+
+  @Override
+  public int getPort() {
+    return port;
+  }
+
+  @Override
+  public String getServerUri() {
+    StringBuilder buf = new StringBuilder();
+    buf.append(secure ? "https://" : "http://");
+    buf.append(host);
+    if (port != 80) {
+      buf.append(":");
+      buf.append(port);
+    }
+    return buf.toString();
+  }
+
+  @Override
+  public FeedConfiguration loadFeedConfiguration(String feedId) throws IOException {
+    String fileName = getFeedConfigLocation() + feedId + getFeedConfigSuffix();
+    InputStream in =
+      Thread.currentThread()
+        .getContextClassLoader()
+        .getResourceAsStream(fileName);
+    if (in == null)
+      throw new FileNotFoundException();
+    Properties props = new Properties();
+    props.load(in);
+    in.close();
+    return FeedConfiguration.getFeedConfiguration(feedId, props, this);
+  }
+}

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/BasicServerConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/BasicServerConfiguration.java?rev=619778&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/BasicServerConfiguration.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/BasicServerConfiguration.java
Thu Feb  7 22:35:29 2008
@@ -0,0 +1,38 @@
+/*
+* 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.
+*/
+package org.apache.abdera.protocol.server.provider.managed;
+
+import org.apache.abdera.protocol.server.RequestContext;
+
+public class BasicServerConfiguration 
+  extends AbstractServerConfiguration {
+
+  public BasicServerConfiguration(RequestContext request) {
+    super(request);
+  }
+
+  @Override
+  public String getFeedNamespace() {
+    return "http://abdera.apache.org/0.4/";
+  }
+
+  @Override
+  public String getFeedNamespacePrefix() {
+    return "a";
+  }
+}
\ No newline at end of file

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/CollectionAdapterConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/CollectionAdapterConfiguration.java?rev=619778&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/CollectionAdapterConfiguration.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/CollectionAdapterConfiguration.java
Thu Feb  7 22:35:29 2008
@@ -0,0 +1,41 @@
+/*
+* 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.
+*/
+package org.apache.abdera.protocol.server.provider.managed;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+
+public class CollectionAdapterConfiguration 
+  extends Configuration {
+
+  private final String fileLocation;
+  private final ServerConfiguration serverConfiguration;
+  public CollectionAdapterConfiguration(
+    ServerConfiguration serverConfiguration,
+    String fileLocation) {
+      this.fileLocation = fileLocation;
+      this.serverConfiguration = serverConfiguration;
+  }
+
+  FileInputStream getConfigAsFileInputStream() 
+    throws IOException {
+      String filePath
+        = serverConfiguration.getAdapterConfigLocation() + fileLocation;
+      return Configuration.loadFileAsInputStream(filePath);
+  }
+}

Copied: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/CollectionAdapterManager.java
(from r619685, incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/CollectionAdapterManager.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/CollectionAdapterManager.java?p2=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/CollectionAdapterManager.java&p1=incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/CollectionAdapterManager.java&r1=619685&r2=619778&rev=619778&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/CollectionAdapterManager.java
(original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/CollectionAdapterManager.java
Thu Feb  7 22:35:29 2008
@@ -15,18 +15,15 @@
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */
-package org.apache.abdera.protocol.server.impl;
+package org.apache.abdera.protocol.server.provider.managed;
 
 import java.io.File;
 import java.io.FileFilter;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
 import java.lang.reflect.Constructor;
 import java.net.URL;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Properties;
 import java.util.logging.Logger;
 
 import org.apache.abdera.Abdera;
@@ -37,51 +34,39 @@
   public static Logger logger =
     Logger.getLogger(CollectionAdapterManager.class.getName());
 
-  protected static final String PROP_NAME_ADAPTER_CLASS = "adapterClassName";
-  protected static final String PROPERTIES_PATH = "abdera/adapter/";
-  protected static final String PROPERTIES_FILE_SUFFIX = ".properties";
-
   // maps a feed id to an adapter instance
-  protected Map<String, CollectionAdapter> adapterInstanceMap =
+  protected static Map<String, CollectionAdapter> adapterInstanceMap =
       new HashMap<String, CollectionAdapter>();
 
   protected final Abdera abdera;
+  protected final ServerConfiguration config;
 
-  public CollectionAdapterManager(Abdera abdera) {
-    this.abdera = abdera;
+  public CollectionAdapterManager(
+    Abdera abdera,
+    ServerConfiguration config) {
+      this.abdera = abdera;
+      this.config = config;
   }
   
   public CollectionAdapter getAdapter(
     String feedId) 
       throws Exception {
-    CollectionAdapter adapter = 
-      adapterInstanceMap.get(feedId);
-    if (adapter != null)
-      return adapter;
-
-    // load the feed properties file
-    Properties properties = loadFeedInfo(feedId);
-    String className = properties.getProperty(PROP_NAME_ADAPTER_CLASS);
-    if (className == null) {
-      logger.warning("property '" + PROP_NAME_ADAPTER_CLASS +
-          "' not found for feed '" + feedId + "'");
-      throw new RuntimeException();
-    }
-
-    return createAdapterInstance(feedId, className, properties);
-   }
+    FeedConfiguration feedConfiguration = config.loadFeedConfiguration(feedId);
+    return createAdapterInstance(feedConfiguration, abdera);
+  }
 
-  public Map<String,Properties> listAdapters() throws Exception {
-    Map<String,Properties> results = new HashMap<String,Properties>();
+  public Map<String, FeedConfiguration> listAdapters() throws Exception {
+    Map<String, FeedConfiguration> results = new HashMap<String, FeedConfiguration>();
     Enumeration<URL> e = 
       Thread.currentThread()
         .getContextClassLoader()
-        .getResources(PROPERTIES_PATH);
+        .getResources(config.getFeedConfigLocation());
     while (e.hasMoreElements()) {
       URL url = e.nextElement();
       File file = new File(url.toURI());
       if (!file.exists()) {
-        throw new RuntimeException("Could not convert properties path to a File! \"" + file.getAbsolutePath()
+ "\" does not exist.");
+        throw new RuntimeException(
+          "Could not convert properties path to a File! \"" + file.getAbsolutePath() + "\"
does not exist.");
       }
       File[] files = 
         file.listFiles(
@@ -94,12 +79,12 @@
       if (files != null) {
         for (File _file : files) {
           String name = _file.getName();
-          int i = name.indexOf(PROPERTIES_FILE_SUFFIX);
+          int i = name.indexOf(config.getFeedConfigSuffix());
           String id = i > -1 ? name.substring(0,i) : null;
           if (id != null) {
-            Properties properties = loadFeedInfo(id);
-            if (properties != null)
-              results.put(id,properties);
+            FeedConfiguration feedConfiguration = loadFeedInfo(id);
+            if (null != feedConfiguration)
+              results.put(id, feedConfiguration);
           }
         }
       }
@@ -107,33 +92,22 @@
     return results;
   }
   
-  protected Properties loadFeedInfo(String feedId)
-    throws Exception {
-    String fileName = PROPERTIES_PATH + feedId + PROPERTIES_FILE_SUFFIX;
-    InputStream in =       
-      Thread.currentThread()
-        .getContextClassLoader()
-        .getResourceAsStream(fileName);
-    if (in == null) {
-      throw new FileNotFoundException();
-    }
-    Properties props = new Properties();
-    props.load(in);
-    in.close();
-    return props;
+  protected FeedConfiguration loadFeedInfo(
+    String feedId)
+      throws Exception {
+    return config.loadFeedConfiguration(feedId);
   }
 
-  protected synchronized CollectionAdapter createAdapterInstance(
-    String feedId,
-    String className, 
-    Properties properties) 
+  protected static synchronized CollectionAdapter createAdapterInstance(
+    FeedConfiguration config, 
+    Abdera abdera) 
       throws Exception {
-    CollectionAdapter basicAdapter = adapterInstanceMap.get(feedId);
+    CollectionAdapter basicAdapter = adapterInstanceMap.get(config.getFeedId());
     if (basicAdapter != null) {
       return basicAdapter;
     }
     ClassLoader cl = Thread.currentThread().getContextClassLoader();
-    Class<?> adapterClass = cl.loadClass(className);
+    Class<?> adapterClass = cl.loadClass(config.getAdapterClassName());
     Constructor<?>[] ctors = adapterClass.getConstructors();
     for (Constructor<?> element : ctors) {
       logger.finest("Public constructor found: " +
@@ -143,17 +117,14 @@
       adapterClass.getConstructor(
         new Class[] {
           Abdera.class,
-          Properties.class, 
-          String.class});
+          FeedConfiguration.class});
     c.setAccessible(true);
     CollectionAdapter adapterInstance = 
       (CollectionAdapter) c.newInstance(
-        abdera, 
-        properties,
-        feedId);
+        abdera, config);
 
     // put this adapter instance in adapterInstanceMap
-    adapterInstanceMap.put(feedId, adapterInstance);
+    adapterInstanceMap.put(config.getFeedId(), adapterInstance);
     return adapterInstance;
   }
 

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/Configuration.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/Configuration.java?rev=619778&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/Configuration.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/Configuration.java
Thu Feb  7 22:35:29 2008
@@ -0,0 +1,50 @@
+/*
+* 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.
+*/
+package org.apache.abdera.protocol.server.provider.managed;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+public abstract class Configuration {
+
+  static Properties loadFileAsProperties(
+    String fileLocation)
+      throws IOException {
+    Properties props = new Properties();
+    props.load(new FileInputStream(fileLocation));
+    return props;
+  }
+
+  static FileInputStream loadFileAsInputStream(
+    String fileLocation)
+      throws IOException {
+    return new FileInputStream(fileLocation);
+  }
+
+  static String getProperty(
+    Properties prop, 
+    String key) {
+      String val = prop.getProperty(key);
+      if (val == null)
+        throw new RuntimeException();
+      return val;
+  }  
+
+  protected Configuration() {}
+}

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/FeedConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/FeedConfiguration.java?rev=619778&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/FeedConfiguration.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/FeedConfiguration.java
Thu Feb  7 22:35:29 2008
@@ -0,0 +1,169 @@
+/*
+* 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.
+*/
+package org.apache.abdera.protocol.server.provider.managed;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.abdera.model.Collection;
+import org.apache.abdera.protocol.server.CategoriesInfo;
+import org.apache.abdera.protocol.server.CollectionInfo;
+import org.apache.abdera.protocol.server.RequestContext;
+
+public class FeedConfiguration 
+  extends Configuration
+  implements CollectionInfo {
+  public static final String PROP_NAME_ADAPTER_CLASS = "adapterClassName";
+  public static final String PROP_SUB_URI_NAME = "subUri";
+  public static final String PROP_AUTHOR_NAME = "author";
+  public static final String PROP_TITLE_NAME = "title";
+  public static final String PROP_ACCEPTS = "accepts";
+  public static final String PROP_FEED_CONFIG_LOCATION_NAME = "configFile";
+
+  public static final String ENTRY_ELEM_NAME_ID = "id";
+  public static final String ENTRY_ELEM_NAME_TITLE = "title";
+  public static final String ENTRY_ELEM_NAME_AUTHOR = "author";
+  public static final String ENTRY_ELEM_NAME_UPDATED = "updated";
+
+  private final String feedId;
+  private final String subUri;
+  private final String adapterClassName;
+  private final String feedConfigLocation;
+  private final ServerConfiguration serverConfiguration;
+  private String feedTitle = "unknown";
+  private String feedAuthor = "unknown";
+  private Map<Object, Object> optionalProperties;
+  private final CollectionAdapterConfiguration adapterConfiguration;
+
+  public FeedConfiguration(
+    String feedId, 
+    String subUri,
+    String adapterClassName, 
+    String feedConfigLocation,
+    ServerConfiguration serverConfiguration) {
+      this.feedId = feedId;
+      this.subUri = subUri;
+      this.adapterClassName = adapterClassName;
+      this.feedConfigLocation = feedConfigLocation;
+      this.adapterConfiguration = 
+        new CollectionAdapterConfiguration(
+          serverConfiguration, 
+          feedConfigLocation);
+      this.serverConfiguration = serverConfiguration;
+  }
+  
+  public static FeedConfiguration getFeedConfiguration(
+    String feedId,
+    Properties properties, 
+    ServerConfiguration serverConfiguration) {
+      FeedConfiguration feedConfiguration = new FeedConfiguration(feedId,
+          Configuration.getProperty(properties, PROP_SUB_URI_NAME),
+          Configuration.getProperty(properties, PROP_NAME_ADAPTER_CLASS),
+          Configuration.getProperty(properties, PROP_FEED_CONFIG_LOCATION_NAME),
+          serverConfiguration);
+      if (properties.containsKey(PROP_AUTHOR_NAME)) {
+        feedConfiguration.setFeedAuthor(
+            Configuration.getProperty(properties, PROP_AUTHOR_NAME));      
+      }
+  
+      if (properties.containsKey(PROP_TITLE_NAME)) {
+        feedConfiguration.setFeedTitle(
+            Configuration.getProperty(properties, PROP_TITLE_NAME));      
+      }
+      feedConfiguration.optionalProperties = properties;
+      return feedConfiguration;
+  }
+
+  public String getAdapterClassName() {
+    return adapterClassName;
+  }
+
+  public String getFeedAuthor() {
+    return feedAuthor;
+  }
+
+  public String getFeedConfigLocation() {
+    return feedConfigLocation;
+ }
+
+  public String getFeedId() {
+    return feedId;
+  }
+  
+  public String getFeedTitle() {
+    return feedTitle;
+  }
+  
+  public String getSubUri() {
+    return subUri;
+  }
+  
+  public void setFeedAuthor(String feedAuthor) {
+    this.feedAuthor = feedAuthor;
+  }
+
+  public void setFeedTitle(String feedTitle) {
+    this.feedTitle = feedTitle;
+  }
+  
+  public String getFeedUri() {
+    return serverConfiguration.getServerUri() + "/" + getSubUri();
+  }
+
+  public Object hasProperty(String key) {
+    return optionalProperties.containsKey(key);
+  }
+
+  public Object getProperty(String key) {
+    return optionalProperties.get(key);
+  }
+  
+  public CollectionAdapterConfiguration getAdapterConfiguration() {
+    return adapterConfiguration;
+  }
+
+  public Collection asCollectionElement(RequestContext request) {
+    Collection collection = request.getAbdera().getFactory().newCollection();
+    collection.setHref(getHref(request));
+    collection.setTitle(getTitle(request));
+    collection.setAccept(getAccepts(request));
+    for (CategoriesInfo catsinfo : getCategoriesInfo(request)) {
+      collection.addCategories(catsinfo.asCategoriesElement(request));
+    }
+    return collection;
+  }
+
+  public String[] getAccepts(RequestContext request) {
+    Object accepts = optionalProperties.get(PROP_ACCEPTS);
+    if (accepts == null || !(accepts instanceof String)) 
+      return new String[] {"application/atom+xml;type=entry"};
+    return ((String)accepts).split("\\s*,\\s*");
+  }
+
+  public CategoriesInfo[] getCategoriesInfo(RequestContext request) {
+    return new CategoriesInfo[0];
+  }
+
+  public String getHref(RequestContext request) {
+    return getFeedUri();
+  }
+
+  public String getTitle(RequestContext request) {
+    return getFeedTitle();
+  }
+}
\ No newline at end of file

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedCollectionAdapter.java?rev=619778&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedCollectionAdapter.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedCollectionAdapter.java
Thu Feb  7 22:35:29 2008
@@ -0,0 +1,45 @@
+/*
+* 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.
+*/
+package org.apache.abdera.protocol.server.provider.managed;
+
+import org.apache.abdera.Abdera;
+import org.apache.abdera.protocol.server.CollectionAdapter;
+import org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter;
+
+public abstract class ManagedCollectionAdapter
+  extends AbstractCollectionAdapter
+  implements CollectionAdapter {
+  
+  protected final FeedConfiguration config;
+  protected final Abdera abdera;
+  
+  protected ManagedCollectionAdapter(
+    Abdera abdera,
+    FeedConfiguration config) {
+      this.config = config;
+      this.abdera = abdera;
+  }
+  
+  public Abdera getAbdera() {
+    return this.abdera;
+  }
+  
+  public FeedConfiguration getConfiguration() {
+    return this.config;
+  }
+}

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedProvider.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedProvider.java?rev=619778&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedProvider.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedProvider.java
Thu Feb  7 22:35:29 2008
@@ -0,0 +1,40 @@
+/*
+* 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.
+*/
+package org.apache.abdera.protocol.server.provider.managed;
+
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.impl.AbstractWorkspaceProvider;
+
+public abstract class ManagedProvider 
+  extends AbstractWorkspaceProvider {
+  
+  protected abstract ServerConfiguration getServerConfiguration(
+    RequestContext request);
+  
+  protected ManagedProvider() {
+    addWorkspace(new ManagedWorkspace(this));
+  }
+  
+  public CollectionAdapterManager getCollectionAdapterManager(
+    RequestContext request) {
+      return new CollectionAdapterManager(
+        abdera, 
+        getServerConfiguration(request));
+  }
+  
+}

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedWorkspace.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedWorkspace.java?rev=619778&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedWorkspace.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ManagedWorkspace.java
Thu Feb  7 22:35:29 2008
@@ -0,0 +1,69 @@
+/*
+* 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.
+*/
+package org.apache.abdera.protocol.server.provider.managed;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.abdera.model.Workspace;
+import org.apache.abdera.protocol.server.CollectionInfo;
+import org.apache.abdera.protocol.server.RequestContext;
+import org.apache.abdera.protocol.server.WorkspaceInfo;
+
+public class ManagedWorkspace 
+  implements WorkspaceInfo {
+  
+  private final ManagedProvider provider;
+  
+  private String title = "Abdera";
+  
+  public ManagedWorkspace(ManagedProvider provider) {
+    this.provider = provider;
+  }
+  
+  public Collection<CollectionInfo> getCollections(RequestContext request) {
+    CollectionAdapterManager cam = provider.getCollectionAdapterManager(request);
+    List<CollectionInfo> collections = new ArrayList<CollectionInfo>();
+    try {
+      Map<String, FeedConfiguration> map = cam.listAdapters();
+      for (FeedConfiguration config : map.values())
+        collections.add(config);
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+    return collections;
+  }
+
+  public String getTitle(RequestContext request) {
+    return title;
+  }
+
+  public void setTitle(String title) {
+    this.title = title;
+  }
+  
+  public Workspace asWorkspaceElement(RequestContext request) {
+    Workspace workspace = request.getAbdera().getFactory().newWorkspace();
+    workspace.setTitle(getTitle(null));
+    for (CollectionInfo collection : getCollections(request))
+      workspace.addCollection(collection.asCollectionElement(request));
+    return workspace;
+  }
+}

Added: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ServerConfiguration.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ServerConfiguration.java?rev=619778&view=auto
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ServerConfiguration.java
(added)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/managed/ServerConfiguration.java
Thu Feb  7 22:35:29 2008
@@ -0,0 +1,39 @@
+/*
+* 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.
+*/
+package org.apache.abdera.protocol.server.provider.managed;
+
+public abstract class ServerConfiguration 
+  extends Configuration {
+
+  public abstract int getPort();
+
+  public abstract String getServerUri();
+  
+  public abstract String getFeedNamespace();
+
+  public abstract String getFeedNamespacePrefix();
+  
+  public abstract String getFeedConfigLocation();
+
+  public abstract String getFeedConfigSuffix();
+
+  public abstract String getAdapterConfigLocation();
+  
+  public abstract FeedConfiguration loadFeedConfiguration(String feedId) throws Exception;
+  
+}



Mime
View raw message