incubator-graffito-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r159073 - in incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito: portlets/util/ServiceAccessor.java servlets/ servlets/FileServlet.java servlets/SpringInitializerServlet.java
Date Fri, 25 Mar 2005 22:47:43 GMT
Author: taylor
Date: Fri Mar 25 14:47:42 2005
New Revision: 159073

URL: http://svn.apache.org/viewcvs?view=rev&rev=159073
Log:
added simple Spring integration 

Added:
    incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/servlets/
    incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/servlets/FileServlet.java
    incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/servlets/SpringInitializerServlet.java
Modified:
    incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/util/ServiceAccessor.java

Modified: incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/util/ServiceAccessor.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/util/ServiceAccessor.java?view=diff&r1=159072&r2=159073
==============================================================================
--- incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/util/ServiceAccessor.java
(original)
+++ incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/portlets/util/ServiceAccessor.java
Fri Mar 25 14:47:42 2005
@@ -59,7 +59,7 @@
         return springFactory;
     }
 
-    static void initializeSpring(InputStream is)
+    static public void initializeSpring(InputStream is)
     throws IOException
     {
         springFactory = new XmlBeanFactory(new InputStreamResource(is));

Added: incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/servlets/FileServlet.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/servlets/FileServlet.java?view=auto&rev=159073
==============================================================================
--- incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/servlets/FileServlet.java
(added)
+++ incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/servlets/FileServlet.java
Fri Mar 25 14:47:42 2005
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.servlets;
+        
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.portals.graffito.ContentModelService;
+import org.apache.portals.graffito.exception.ContentManagementException;
+import org.apache.portals.graffito.model.Document;
+
+import org.apache.portals.graffito.portlets.util.ServiceAccessor;
+
+public class FileServlet extends HttpServlet {
+	
+	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException
+	{
+		String uri = request.getParameter("uri");
+		
+		ContentModelService cms = ServiceAccessor.getModelService();
+		try {
+			Document doc = cms.getDocument(uri);
+			response.setContentType(doc.getContentType());
+			
+			drain(doc.getContent().getContentStream(), response.getOutputStream());
+		} catch (ContentManagementException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+		
+	}
+	
+	private static final int BLOCK_SIZE = 4096;
+
+    public static void drain(InputStream r,OutputStream w) throws IOException
+    {
+        byte[] bytes=new byte[BLOCK_SIZE];
+        try
+        {
+          int length=r.read(bytes);
+          while(length!=-1)
+          {
+              if(length!=0)
+                  {
+                      w.write(bytes,0,length);
+                  }
+              length=r.read(bytes);
+          }
+      }
+      finally
+      {
+        bytes=null;
+      }
+
+    }
+
+}

Added: incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/servlets/SpringInitializerServlet.java
URL: http://svn.apache.org/viewcvs/incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/servlets/SpringInitializerServlet.java?view=auto&rev=159073
==============================================================================
--- incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/servlets/SpringInitializerServlet.java
(added)
+++ incubator/graffito/trunk/applications/graffito-portlets/src/java/org/apache/portals/graffito/servlets/SpringInitializerServlet.java
Fri Mar 25 14:47:42 2005
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2000-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.portals.graffito.servlets;
+
+import java.io.InputStream;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+
+import org.apache.portals.graffito.portlets.util.ServiceAccessor;
+
+/**
+ * Initialize Spring at servlet startup
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @version $Id: SpringInitializerServlet.java,v 1.2 2005/02/16 22:58:36 david Exp $
+ */
+public class SpringInitializerServlet
+    extends HttpServlet
+{        
+    public static final long serialVersionUID = 1;
+
+    
+    public synchronized final void init(ServletConfig config) 
+    throws ServletException
+    {
+        synchronized (this.getClass())
+        {            
+            super.init(config);
+            ServletContext context = getServletContext();
+
+            try
+            {
+                String assembly = getInitParameter("assembly");                
+                InputStream is = context.getResourceAsStream(assembly);                 
              
+                ServiceAccessor.initializeSpring(is);                                
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+                throw new ServletException("Failed to load Spring assembly", e);
+            }
+        }
+    }
+
+    public final void destroy()
+    {
+    }
+    
+}
\ No newline at end of file



Mime
View raw message