You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2004/08/30 16:04:44 UTC
svn commit: rev 37202 - in cocoon/branches/BRANCH_2_1_X/src: blocks/eventcache/java/org/apache/cocoon/caching/impl blocks/jms/java/org/apache/cocoon/samples/jms blocks/jms/samples/database blocks/linkrewriter/java/org/apache/cocoon/transformation blocks/linkrewriter/samples/bookdemo/docs java/org/apache/cocoon/acting java/org/apache/cocoon/selection
Author: cziegeler
Date: Mon Aug 30 07:04:43 2004
New Revision: 37202
Added:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/acting/HttpCacheAction.java (contents, props changed)
Modified:
cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/caching/impl/StoreEventRegistryImpl.java
cocoon/branches/BRANCH_2_1_X/src/blocks/jms/java/org/apache/cocoon/samples/jms/HTTPTrigger.java
cocoon/branches/BRANCH_2_1_X/src/blocks/jms/java/org/apache/cocoon/samples/jms/JMSTrigger.java
cocoon/branches/BRANCH_2_1_X/src/blocks/jms/samples/database/sitemap.xmap
cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/LinkRewriterTransformer.java
cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/VariableRewriterTransformer.java
cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/samples/bookdemo/docs/book.xml
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/ExceptionSelector.java
Log:
Merging more blocks and core classes
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/caching/impl/StoreEventRegistryImpl.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/caching/impl/StoreEventRegistryImpl.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/caching/impl/StoreEventRegistryImpl.java Mon Aug 30 07:04:43 2004
@@ -24,29 +24,29 @@
/**
* This implementation of <code>EventRegistry</code> stores its <code>EventRegistryDataWrapper</code>
- * in the <code>PersistentStore</code> defined in cocoon.xconf.
+ * in the default <code>Store</code> defined in cocoon.xconf.
*
* @since 2.1
* @author <a href="mailto:ghoward@apache.org">Geoff Howard</a>
- * @version CVS $Id: StoreEventRegistryImpl.java,v 1.8 2004/05/19 08:44:26 cziegeler Exp $
+ * @version CVS $Id$
*/
-public class StoreEventRegistryImpl
- extends AbstractDoubleMapEventRegistry
+public class StoreEventRegistryImpl extends AbstractDoubleMapEventRegistry
implements Serviceable {
+
private static final String EVENTREGISTRYKEY = "EVENTREGWRAPPER";
private ServiceManager m_manager;
- private Store m_persistentStore;
+ private Store m_store;
protected void persist(EventRegistryDataWrapper wrapper) {
EventRegistryDataWrapper ecdw = wrapRegistry();
try {
- m_persistentStore.store(EVENTREGISTRYKEY, ecdw);
+ m_store.store(EVENTREGISTRYKEY, ecdw);
} catch (IOException e) {
getLogger().warn("Unable to persist Event Registry");
}
- this.m_manager.release(this.m_persistentStore);
+ this.m_manager.release(this.m_store);
m_manager = null;
- m_persistentStore = null;
+ m_store = null;
}
/**
@@ -54,19 +54,18 @@
*/
public void service(ServiceManager manager) throws ServiceException {
this.m_manager = manager;
- this.m_persistentStore = (Store) manager.lookup(Store.ROLE);
+ this.m_store = (Store) manager.lookup(Store.ROLE);
}
/**
* Recover the datawrapper from the Store.
*/
protected boolean recover() {
- Object o = m_persistentStore.get(EVENTREGISTRYKEY);
- m_persistentStore.remove(EVENTREGISTRYKEY);
+ Object o = m_store.get(EVENTREGISTRYKEY);
+ m_store.remove(EVENTREGISTRYKEY);
if (o != null && o instanceof EventRegistryDataWrapper) {
if (getLogger().isInfoEnabled()) {
- getLogger().info(
- "Retrieving EventRegistry from PersistentStore.");
+ getLogger().info("Retrieving EventRegistry from Store.");
}
unwrapRegistry((EventRegistryDataWrapper) o);
return true;
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/jms/java/org/apache/cocoon/samples/jms/HTTPTrigger.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/jms/java/org/apache/cocoon/samples/jms/HTTPTrigger.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/jms/java/org/apache/cocoon/samples/jms/HTTPTrigger.java Mon Aug 30 07:04:43 2004
@@ -22,7 +22,7 @@
import org.hsqldb.Trigger;
/**
- * @version CVS $Id: HTTPTrigger.java,v 1.6 2004/03/05 13:01:57 bdelacretaz Exp $
+ * @version CVS $Id$
* @author <a href="mailto:chaul@apache.org">chaul</a>
*/
public class HTTPTrigger implements Trigger {
@@ -49,6 +49,14 @@
// not much we can do here.
throw new RuntimeException("Cannot execute trigger: "+e.getMessage());
}
+ }
+
+ /* (non-Javadoc)
+ * @see org.hsqldb.Trigger#fire(int, java.lang.String, java.lang.String, java.lang.Object[], java.lang.Object[])
+ */
+ public void fire(int arg0, String arg1, String arg2, Object[] arg3, Object[] arg4) {
+ // TODO Auto-generated method stub
+
}
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/jms/java/org/apache/cocoon/samples/jms/JMSTrigger.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/jms/java/org/apache/cocoon/samples/jms/JMSTrigger.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/jms/java/org/apache/cocoon/samples/jms/JMSTrigger.java Mon Aug 30 07:04:43 2004
@@ -36,7 +36,7 @@
* Example Trigger for HSQLDB doing cache invalidation through the eventcache
* block and JMS messages.
*
- * @version CVS $Id: JMSTrigger.java,v 1.6 2004/03/05 13:01:57 bdelacretaz Exp $
+ * @version CVS $Id$
* @author <a href="mailto:haul@apache.org">haul</a>
*/
public class JMSTrigger implements Trigger {
@@ -156,5 +156,13 @@
} catch (Exception e) {
e.printStackTrace();
}
+ }
+
+ /* (non-Javadoc)
+ * @see org.hsqldb.Trigger#fire(int, java.lang.String, java.lang.String, java.lang.Object[], java.lang.Object[])
+ */
+ public void fire(int arg0, String arg1, String arg2, Object[] arg3, Object[] arg4) {
+ // TODO Auto-generated method stub
+
}
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/jms/samples/database/sitemap.xmap
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/jms/samples/database/sitemap.xmap (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/jms/samples/database/sitemap.xmap Mon Aug 30 07:04:43 2004
@@ -91,7 +91,7 @@
<map:match pattern="jms-invalidate">
<map:match type="host-matcher" pattern="localhost">
<map:act type="jmsevent">
- <map:parameter name="event" value="action|{request-param:table}"/>
+ <map:parameter name="message" value="action|{request-param:table}"/>
</map:act>
<map:read src="invalidated.xml"/>
</map:match>
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/LinkRewriterTransformer.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/LinkRewriterTransformer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/LinkRewriterTransformer.java Mon Aug 30 07:04:43 2004
@@ -29,7 +29,7 @@
import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.components.language.markup.xsp.XSPModuleHelper;
+import org.apache.cocoon.components.modules.input.InputModuleHelper;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.transformation.helpers.VariableConfiguration;
import org.apache.regexp.RE;
@@ -171,6 +171,10 @@
* <dt>bad-link-str</dt>
* <dd>String to use for links with a correct InputModule prefix, but no value
* therein. Defaults to the original URI.</dd>
+ *
+ * <dt>namespace-uri</dt>
+ * <dd>The namespace uri of elements whose attributes are considered for
+ * transformation. Defaults to the empty namespace ("").</dd>
* </dl>
*
* <p>
@@ -211,12 +215,10 @@
* both 'link-attrs' and 'link-attr' configuration.
*
* <p>
- * <b>NOTE:</b> Currently, only links in the default ("") namespace are converted.
*
- * @version CVS $Id: LinkRewriterTransformer.java,v 1.12 2004/04/22 12:15:48 vgritsenko Exp $
+ * @version CVS $Id$
*/
-public class LinkRewriterTransformer
- extends AbstractSAXTransformer
+public class LinkRewriterTransformer extends AbstractSAXTransformer
implements Initializable, Disposable {
private final static String NAMESPACE = "";
@@ -237,6 +239,7 @@
private String origBadLinkStr;
private String origInSchemes;
private String origOutSchemes;
+ private String origNamespaceURI;
/**
* A map where keys are those attributes which are considered 'links'.
@@ -278,7 +281,7 @@
*/
private Map linkAttrs;
- private XSPModuleHelper modHelper;
+ private InputModuleHelper modHelper;
/**
@@ -293,6 +296,8 @@
this.origInSchemes = conf.getChild("schemes").getValue("");
this.origOutSchemes = conf.getChild("exclude-schemes").getValue("http https ftp news mailto");
+ this.origNamespaceURI = conf.getChild("namespace-uri").getValue(NAMESPACE);
+
/*
* Setup origLinkAttrs map from the original Configuration:
* 1. Parse link-attrs Configuration
@@ -337,8 +342,7 @@
* Initiate resources prior to this component becoming active.
*/
public void initialize() throws Exception {
- this.namespaceURI = NAMESPACE;
- this.modHelper = new XSPModuleHelper();
+ this.modHelper = new InputModuleHelper();
this.modHelper.setup(this.manager);
}
@@ -355,6 +359,8 @@
this.badLinkStr = parameters.getParameter("bad-link-str", // per-request config
this.origBadLinkStr); // else fall back to per-instance config
+ this.namespaceURI = parameters.getParameter("namespace-uri", this.origNamespaceURI);
+
this.inSchemes = split(parameters.getParameter("schemes", this.origInSchemes), " ");
this.outSchemes = split(parameters.getParameter("exclude-schemes", this.origOutSchemes), " ");
@@ -372,6 +378,7 @@
getLogger().debug("link-attrs = " + linkAttrs);
getLogger().debug("schemes = " + inSchemes);
getLogger().debug("exclude-schemes = " + outSchemes);
+ getLogger().debug("namespace-uri = " + namespaceURI);
}
// Generate conf
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/VariableRewriterTransformer.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/VariableRewriterTransformer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/java/org/apache/cocoon/transformation/VariableRewriterTransformer.java Mon Aug 30 07:04:43 2004
@@ -28,7 +28,7 @@
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.components.language.markup.xsp.XSPModuleHelper;
+import org.apache.cocoon.components.modules.input.InputModuleHelper;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.transformation.helpers.VariableConfiguration;
import org.xml.sax.Attributes;
@@ -134,7 +134,7 @@
* Note that currently, only links in the default ("") namespace are converted.
*
* @author <a href="mailto:jefft@apache.org">Jeff Turner</a>
- * @version CVS $Id: VariableRewriterTransformer.java,v 1.7 2004/03/05 13:01:59 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class VariableRewriterTransformer
extends AbstractSAXTransformer implements Initializable, Disposable
@@ -156,7 +156,7 @@
* Recreated once per invocation. */
private Configuration conf;
- private XSPModuleHelper modHelper;
+ private InputModuleHelper modHelper;
private String badLinkStr;
@@ -175,7 +175,7 @@
*/
public void initialize() throws Exception {
this.namespaceURI = NAMESPACE;
- this.modHelper = new XSPModuleHelper();
+ this.modHelper = new InputModuleHelper();
modHelper.setup(this.manager);
}
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/samples/bookdemo/docs/book.xml
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/samples/bookdemo/docs/book.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/linkrewriter/samples/bookdemo/docs/book.xml Mon Aug 30 07:04:43 2004
@@ -45,7 +45,7 @@
<menu-item label="Changes" href="changes.html"/>
<menu-item label="Todo" href="todo.html"/>
<menu-item label="Planning notes" href="plan/index.html"/>
- <external label="Patch queue" href="http://nagoya.apache.org/bugzilla/buglist.cgi?bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&email1=&emailtype1=substring&emailassigned_to1=1&email2=&emailtype2=substring&emailreporter2=1&bugidtype=include&bug_id=&changedin=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&product=Cocoon+2&short_desc=%5BPATCH%5D&short_desc_type=allwordssubstr&long_desc=&long_desc_type=allwordssubstr&bug_file_loc=&bug_file_loc_type=allwordssubstr&keywords=&keywords_type=anywords&field0-0-0=noop&type0-0-0=noop&value0-0-0=&namedcmd=Cocoon+all&newqueryname=cocoon+patch+queue&tofooter=1&order=Reuse+same+sort+as+last+time"/>
+ <external label="Patch queue" href="http://issues.apache.org/bugzilla/buglist.cgi?bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&email1=&emailtype1=substring&emailassigned_to1=1&email2=&emailtype2=substring&emailreporter2=1&bugidtype=include&bug_id=&changedin=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&product=Cocoon+2&short_desc=%5BPATCH%5D&short_desc_type=allwordssubstr&long_desc=&long_desc_type=allwordssubstr&bug_file_loc=&bug_file_loc_type=allwordssubstr&keywords=&keywords_type=anywords&field0-0-0=noop&type0-0-0=noop&value0-0-0=&namedcmd=Cocoon+all&newqueryname=cocoon+patch+queue&tofooter=1&order=Reuse+same+sort+as+last+time"/>
</menu>
<menu label="Community">
@@ -57,7 +57,7 @@
</menu>
<menu label="Project">
- <external label="Bug Database" href="http://nagoya.apache.org/bugzilla/index.html"/>
+ <external label="Bug Database" href="http://issues.apache.org/bugzilla/index.html"/>
<external label="Code Repository" href="http://cvs.apache.org/viewcvs.cgi/cocoon-2.1/"/>
<external label="Dev Snapshots" href="http://xml.apache.org/from-cvs/cocoon-2.1/"/>
</menu>
Added: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/acting/HttpCacheAction.java
==============================================================================
--- (empty file)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/acting/HttpCacheAction.java Mon Aug 30 07:04:43 2004
@@ -0,0 +1,150 @@
+/*
+ * Copyright 1999-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.cocoon.acting;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Redirector;
+import org.apache.cocoon.environment.Response;
+import org.apache.cocoon.environment.SourceResolver;
+import org.apache.commons.lang.time.DateUtils;
+import org.apache.commons.lang.time.FastDateFormat;
+
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This action adds the <code>Last-Modified</code>, <code>Expires</code> and
+ * <code>Cache-Control</code> HTTP headers to the response.
+ *
+ * <p>
+ * This action will add the <code>Last-Modified</code> header to the response
+ * with the time in which the request was executed, and an <code>Expires</code>
+ * header at a specified time difference. Additionally, it will provide an
+ * extra <code>Cache-Control</code> indicating the maximum age of the request
+ * as a delta between the expiration and last modification dates.
+ * </p>
+ * <p>
+ * This is useful (for example) when Cocoon is proxyied by a Web Server such
+ * as Apache HTTPD running mod_cache, to indicate for each request how long
+ * the output should be cached for.
+ * </p>
+ * <p>
+ * To configure the difference between <code>Last-Modified</code> and
+ * <code>Expires</code> this <code>Action</code> can be configured specifying
+ * days, hours, minutes, and seconds in this way:
+ * </p>
+ * <pre>
+ * <map:action>s
+ * <map:action name="xyz" src="org.apache.cocoon.acting.HttpCacheAction>"
+ * <days>1</day>s
+ * <hours>2</hour>s
+ * <minutes>3</minute>s
+ * <seconds>4</second>s
+ * </map:actio>n
+ * </map:action>s
+ * </pre>
+ * <p>
+ * Using this example configuration, the <code>Expires</code> header will
+ * specify a date one day, two hours, three minutes and four seconds after
+ * the time of the request (which will be in <code>Last-Modified</code>).
+ * </p>
+ * <p>
+ * Note that if any of the parameters mentioned above is <b>zero</b> or
+ * <b>less than zero</b> this action will modify the behaviour of the
+ * resulting <code>Cache-Control</code> header to emit the keyword
+ * <code>no-cache</code>.
+ * </p>
+ * <p>
+ * This action will also return the three headers it added as sitemap
+ * parameters called <code>last-modified</code>, <code>expires</code> and
+ * <code>cache-control</code> (all lowercase).
+ * </p>
+ *
+ * @author <a href="mailto:pier@apache.org">Pier Fumagalli</a>
+ * @version CVS $Id: HttpCacheAction.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class HttpCacheAction extends AbstractConfigurableAction implements ThreadSafe {
+
+ private FastDateFormat formatter = null;
+ int days = 0;
+ int hours = 0;
+ int minutes = 0;
+ int seconds = 0;
+
+ public void configure(Configuration configuration)
+ throws ConfigurationException {
+ super.configure(configuration);
+
+ // RFC-822 Date with a GMT based time zone
+ this.formatter = FastDateFormat.getInstance("EEE, dd MMM yyyy kk:mm:ss zzz", DateUtils.UTC_TIME_ZONE);
+ this.days = configuration.getChild("days").getValueAsInteger(0);
+ this.hours = configuration.getChild("hours").getValueAsInteger(0);
+ this.minutes = configuration.getChild("minutes").getValueAsInteger(0);
+ this.seconds = configuration.getChild("seconds").getValueAsInteger(0);
+ }
+
+ public Map act(Redirector redirector, SourceResolver resolver,
+ Map objectModel, String source, Parameters parameters)
+ throws Exception {
+ Response response = ObjectModelHelper.getResponse(objectModel);
+ Calendar calendar = Calendar.getInstance(DateUtils.UTC_TIME_ZONE);
+ Map values = new HashMap(3);
+
+ /* Get the current time and output as the last modified header */
+ String value = this.formatter.format(calendar);
+ long maxage = calendar.getTime().getTime();
+ response.setHeader("Last-Modified", value);
+ values.put("last-modified", value);
+
+ /* Advance the time as much as required */
+ calendar.add(Calendar.DATE, this.days);
+ calendar.add(Calendar.HOUR, this.hours);
+ calendar.add(Calendar.MINUTE, this.minutes);
+ calendar.add(Calendar.SECOND, this.seconds);
+
+ /* Recalculate time and age to see what changed */
+ maxage = calendar.getTime().getTime() - maxage;
+
+ /* If we got more than one second everything is quite normal */
+ if (maxage > 1000) {
+ value = this.formatter.format(calendar);
+ response.setHeader("Expires", value);
+ values.put("expires", value);
+
+ value = "max-age=" + Long.toString(maxage / 1000l);
+ response.setHeader("Cache-Control", value);
+ values.put("cache-control", value);
+
+ /* If we got less than one second (even negatives) no cache */
+ } else {
+ /* We still hold the old value from Last-Modified here */
+ response.setHeader("Expires", value);
+ values.put("expires", value);
+
+ response.setHeader("Cache-Control", "no-cache");
+ values.put("cache-control", "no-cache");
+ }
+
+ /* Return the headers */
+ return(Collections.unmodifiableMap(values));
+ }
+}
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/ExceptionSelector.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/ExceptionSelector.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/selection/ExceptionSelector.java Mon Aug 30 07:04:43 2004
@@ -52,7 +52,7 @@
* @author <a href="mailto:bluetkemeier@s-und-n.de">Björn Lütkemeier</a>
* @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
* @since 2.1
- * @version CVS $Id: ExceptionSelector.java,v 1.7 2004/03/05 13:02:57 bdelacretaz Exp $
+ * @version CVS $Id$
*/
public class ExceptionSelector extends AbstractSwitchSelector implements Configurable {
@@ -160,7 +160,7 @@
return result;
}
- class FindResult {
+ static class FindResult {
private String name;
private Throwable throwable;