abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dand...@apache.org
Subject svn commit: r634484 - in /incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/employee: AppServer.java EmployeeCollectionAdapter.java
Date Fri, 07 Mar 2008 00:50:55 GMT
Author: dandiep
Date: Thu Mar  6 16:50:53 2008
New Revision: 634484

URL: http://svn.apache.org/viewvc?rev=634484&view=rev
Log:
More snippet stuff

Modified:
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/employee/AppServer.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/employee/EmployeeCollectionAdapter.java

Modified: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/employee/AppServer.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/employee/AppServer.java?rev=634484&r1=634483&r2=634484&view=diff
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/employee/AppServer.java
(original)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/employee/AppServer.java
Thu Mar  6 16:50:53 2008
@@ -11,7 +11,8 @@
 import org.mortbay.jetty.servlet.ServletHolder;
 
 public class AppServer {
-  
+
+
   public static void main(String... args) throws Exception {
     int port = 9002;
     try {
@@ -19,29 +20,28 @@
     } catch (Exception e) {}
     Server server = new Server(port);
     Context context = new Context(server, "/", Context.SESSIONS);
-    ServletHolder servletHolder = new ServletHolder(initServlet());
+    ServletHolder servletHolder = new ServletHolder(new EmployeeProviderServlet());
     context.addServlet(servletHolder, "/*");
     server.start();
     server.join();
   }
   
-  private static HttpServlet initServlet() {
-    EmployeeCollectionAdapter ca = new EmployeeCollectionAdapter();
-    ca.setHref("employee");    
-    
-    SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo();
-    wi.setTitle("Employee Directory Workspace");
-    wi.addCollection(ca);    
-    
-    final DefaultProvider p = new DefaultProvider("/");  
-    p.addWorkspace(wi);    
-    
-    return new AbderaServlet() {
-      private static final long serialVersionUID = 0L;
-      protected Provider createProvider() {
-        p.init(getAbdera(), null);
-        return p;
-      }
-    };
+  // START SNIPPET: servlet
+  public static final class EmployeeProviderServlet extends AbderaServlet {
+    protected Provider createProvider() {
+      EmployeeCollectionAdapter ca = new EmployeeCollectionAdapter();
+      ca.setHref("employee");    
+      
+      SimpleWorkspaceInfo wi = new SimpleWorkspaceInfo();
+      wi.setTitle("Employee Directory Workspace");
+      wi.addCollection(ca);    
+      
+      DefaultProvider provider = new DefaultProvider("/");  
+      provider.addWorkspace(wi);    
+      
+      provider.init(getAbdera(), null);
+      return provider;
+    }
   }
+  // END SNIPPET: servlet
 }

Modified: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/employee/EmployeeCollectionAdapter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/employee/EmployeeCollectionAdapter.java?rev=634484&r1=634483&r2=634484&view=diff
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/employee/EmployeeCollectionAdapter.java
(original)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/appserver/employee/EmployeeCollectionAdapter.java
Thu Mar  6 16:50:53 2008
@@ -92,7 +92,7 @@
 
   public Object getContent(Employee entry, RequestContext request) {
     Content content = factory.newContent();
-    Element employeeEl = factory.newElement(new QName("employee"));
+    Element employeeEl = factory.newElement(new QName("div"));
     employeeEl.setAttributeValue(new QName("name"), entry.getName());
    
     content.setValueElement(employeeEl);
@@ -103,34 +103,23 @@
   public Employee postEntry(String title, IRI id, String summary, 
                             Date updated, List<Person> authors,
                             Content content, RequestContext request) throws ResponseContextException
{   
-    Employee employee = contentToEmployee(content);
+    Employee employee = new Employee();
+    employee.setName(content.getText().trim());
+    employee.setId(nextId.getAndIncrement());
     employees.put(employee.getId(), employee);
     
     return employee;
   }
   
-  public void putEntry(Employee entry, String title, Date updated, 
+  public void putEntry(Employee employee, String title, Date updated, 
                        List<Person> authors, String summary,
                        Content content, RequestContext request) throws ResponseContextException
{
-    contentToEmployee(content, entry);
+    employee.setName(content.getText().trim());
   }
 
   public void deleteEntry(String resourceName, RequestContext request) throws ResponseContextException
{
     Integer id = getIdFromResourceName(resourceName);
     employees.remove(id);
-  }
-
-  private Employee contentToEmployee(Content content) {
-    Employee employee = new Employee();
-    
-    return contentToEmployee(content, employee);
-  }
-
-  private Employee contentToEmployee(Content content, Employee employee) {
-    Element firstChild = content.getFirstChild();
-    employee.setName(firstChild.getAttributeValue("name"));
-    employee.setId(nextId.incrementAndGet());
-    return employee;
   }
   // END SNIPPET: methods
 }



Mime
View raw message