cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r392809 - in /cocoon/trunk/core/cocoon-core: COB-INF/ COB-INF/sitemap.xmap COB-INF/test.xml META-INF/MANIFEST.MF META-INF/components.xml src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
Date Sun, 09 Apr 2006 19:26:34 GMT
Author: reinhard
Date: Sun Apr  9 12:26:32 2006
New Revision: 392809

URL: http://svn.apache.org/viewcvs?rev=392809&view=rev
Log:
Initial version of a sitemap servlet that uses the OSGiSpringECMFactory

Added:
    cocoon/trunk/core/cocoon-core/COB-INF/
    cocoon/trunk/core/cocoon-core/COB-INF/sitemap.xmap   (with props)
    cocoon/trunk/core/cocoon-core/COB-INF/test.xml   (with props)
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
  (with props)
Modified:
    cocoon/trunk/core/cocoon-core/META-INF/MANIFEST.MF
    cocoon/trunk/core/cocoon-core/META-INF/components.xml

Added: cocoon/trunk/core/cocoon-core/COB-INF/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/COB-INF/sitemap.xmap?rev=392809&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/COB-INF/sitemap.xmap (added)
+++ cocoon/trunk/core/cocoon-core/COB-INF/sitemap.xmap Sun Apr  9 12:26:32 2006
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright 2006 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.
+-->
+<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+
+  <map:pipelines>
+    <map:pipeline>
+      <map:match pattern="test">
+        <map:generate src="test.xml"/>
+        <map:serialize type="xml"/>
+      </map:match>
+      <map:match pattern="test1">
+        <map:generate src="test.xml"/>
+        <map:serialize type="xml"/>
+      </map:match>      
+    </map:pipeline>
+  </map:pipelines>
+
+</map:sitemap>
+

Propchange: cocoon/trunk/core/cocoon-core/COB-INF/sitemap.xmap
------------------------------------------------------------------------------
    svn:executable = *

Added: cocoon/trunk/core/cocoon-core/COB-INF/test.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/COB-INF/test.xml?rev=392809&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/COB-INF/test.xml (added)
+++ cocoon/trunk/core/cocoon-core/COB-INF/test.xml Sun Apr  9 12:26:32 2006
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Copyright 2006 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.
+-->
+<test>OSGi</test>
\ No newline at end of file

Propchange: cocoon/trunk/core/cocoon-core/COB-INF/test.xml
------------------------------------------------------------------------------
    svn:executable = *

Modified: cocoon/trunk/core/cocoon-core/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/META-INF/MANIFEST.MF?rev=392809&r1=392808&r2=392809&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/META-INF/MANIFEST.MF (original)
+++ cocoon/trunk/core/cocoon-core/META-INF/MANIFEST.MF Sun Apr  9 12:26:32 2006
@@ -116,7 +116,6 @@
  org.apache.cocoon.transformation.helpers,
  org.apache.cocoon.transformation.pagination,
  org.apache.cocoon.util,
- org.apache.cocoon.util.jmx,
  org.apache.cocoon.util.jxpath,
  org.apache.cocoon.util.location,
  org.apache.cocoon.util.test,

Modified: cocoon/trunk/core/cocoon-core/META-INF/components.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/META-INF/components.xml?rev=392809&r1=392808&r2=392809&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/META-INF/components.xml (original)
+++ cocoon/trunk/core/cocoon-core/META-INF/components.xml Sun Apr  9 12:26:32 2006
@@ -36,4 +36,16 @@
       bind="setSettings"/>      
   </scr:component>  
   
+  <scr:component name="org.apache.cocoon.core.sitemap.SitemapServlet">
+    <scr:implementation class="org.apache.cocoon.sitemap.SitemapServlet"/>  
+    <scr:service>
+      <scr:provide interface="javax.servlet.Servlet"/>
+    </scr:service>    
+    <scr:property name="path" value="/sitemap-test"/>
+    <scr:property name="sitemapPath" value="/COB-INF/sitemap.xmap"/>            
+    <scr:reference name="beanFactory"
+      interface="org.apache.cocoon.core.osgi.CocoonSpringBeanRegistry"
+      bind="setBeanFactory"/>         
+  </scr:component>  
+  
 </components>

Added: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java?rev=392809&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
(added)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
Sun Apr  9 12:26:32 2006
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2006 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.cocoon.sitemap;
+
+import java.io.IOException;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.ProcessingUtil;
+import org.apache.cocoon.Processor;
+import org.apache.cocoon.components.LifecycleHelper;
+import org.apache.cocoon.components.treeprocessor.TreeProcessor;
+import org.apache.cocoon.core.Settings;
+import org.apache.cocoon.core.osgi.CocoonSpringBeanRegistry;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.http.HttpContext;
+import org.apache.cocoon.environment.http.HttpEnvironment;
+import org.apache.cocoon.environment.internal.EnvironmentHelper;
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * @version $Id$
+ */
+public class SitemapServlet extends HttpServlet {
+
+	private static final String DEFAULT_CONTAINER_ENCODING = "ISO-8859-1";
+	private static final String DEFAULT_SITEMAP_PATH = "/COB-INF/sitemap.xmap";	
+	private static final String SITEMAP_PATH_PROPERTY = "sitemapPath";
+
+	private CocoonSpringBeanRegistry beanFactory;
+	private Logger logger;
+	private String sitemapPath = DEFAULT_SITEMAP_PATH;
+    protected Context cocoonContext;
+	private Processor processor;	
+	private Settings settings;
+
+    public void init(ServletConfig config) throws ServletException {
+    	super.init(config);
+    	
+    	// get components from the beanFactory
+    	this.logger = (Logger) this.beanFactory.getBean("org.apache.avalon.framework.logger.Logger");
+    	this.settings = (Settings) this.beanFactory.getBean(Settings.ROLE);
+        ServiceManager serviceManager = (ServiceManager) 
+    		this.beanFactory.getBean("org.apache.avalon.framework.service.ServiceManager");   
	
+    	
+    	// create the Cocoon context out of the Servlet context
+        this.cocoonContext = new HttpContext(config.getServletContext());  
+        
+        // get the Avalon context
+        org.apache.avalon.framework.context.Context avalonContext = (org.apache.avalon.framework.context.Context)

+        	this.beanFactory.getBean(ProcessingUtil.CONTEXT_ROLE);
+        
+        // create the processor
+        try {
+			TreeProcessor treeProcessor = (TreeProcessor) 
+				this.getClass().getClassLoader().loadClass(TreeProcessor.class.getName()).newInstance();
+            treeProcessor.setBeanFactory(this.beanFactory);			
+            this.processor = (Processor) LifecycleHelper.setupComponent(treeProcessor,
+                    this.logger,
+                    avalonContext,
+                    serviceManager,
+                    createTreeProcessorConfiguration());
+		} catch (Exception e) {
+            throw new ServletException(e);
+		}
+		
+    }
+
+	private Configuration createTreeProcessorConfiguration() {
+		DefaultConfiguration treeProcessorConf = new DefaultConfiguration("treeProcessorConfiguration");
+        treeProcessorConf.setAttribute("check-reload", true);
+        treeProcessorConf.setAttribute("file", this.sitemapPath);
+        
+//        DefaultConfiguration sitemapFileConf = new DefaultConfiguration("file");
+//        sitemapFileConf.setValue(this.sitemapPath);
+//        treeProcessorConf.addChild(sitemapFileConf);
+		return treeProcessorConf;
+	}	
+    
+	protected void service(HttpServletRequest request, HttpServletResponse response) 
+		throws ServletException, IOException {
+		
+		Environment environment = createCocoonEnvironment(request, response);
+		try {
+	        EnvironmentHelper.enterProcessor(this.processor, environment);			
+			this.processor.process(environment);
+		} catch (Exception e) {
+			throw new ServletException(e);
+		} finally { 
+            EnvironmentHelper.leaveProcessor();	
+	    } 
+	}    
+	
+    protected Environment createCocoonEnvironment(HttpServletRequest req, 
+    		HttpServletResponse res) throws IOException  {
+    	
+		String uri = req.getPathInfo();
+
+		String formEncoding = req.getParameter("cocoon-form-encoding");
+		if (formEncoding == null) {
+			formEncoding = this.settings.getFormEncoding();
+		}
+		HttpEnvironment env = new HttpEnvironment(uri, req, res, this.getServletContext(),
+				this.cocoonContext, DEFAULT_CONTAINER_ENCODING, formEncoding);
+		
+		env.enableLogging(this.logger);
+		return env;
+	}
+
+	protected void setBeanFactory(CocoonSpringBeanRegistry beanFactory) {
+		this.beanFactory = beanFactory;
+	}
+	
+	public void setSitemapPath(String sitemapPath) {
+		this.sitemapPath = sitemapPath;
+	}	
+
+	protected void activate(ComponentContext componentContext) throws Exception {
+		this.setSitemapPath((String) componentContext.getProperties().get(SITEMAP_PATH_PROPERTY));
		
+	}
+	
+}

Propchange: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/sitemap/SitemapServlet.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message