01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.samples;
18:
19: import java.io.IOException;
20: import java.io.Serializable;
21:
22: import org.apache.cocoon.ProcessingException;
23: import org.apache.cocoon.caching.validity.EventValidity;
24: import org.apache.cocoon.caching.validity.NamedEvent;
25: import org.apache.cocoon.environment.ObjectModelHelper;
26: import org.apache.cocoon.environment.Request;
27: import org.apache.cocoon.reading.ResourceReader;
28: import org.apache.excalibur.source.SourceValidity;
29:
30: /**
31: * @author Max Pfingsthorn (mpfingsthorn@hippo.nl)
32: *
33: */
34: public class EventAwareReader extends ResourceReader {
35:
36: public void generate() throws IOException, ProcessingException {
37: try {
38: long DELAY_SECS = this .parameters.getParameterAsLong(
39: "DELAY_SECS", 2);
40: Thread.sleep(DELAY_SECS * 1000L);
41: } catch (InterruptedException ie) {
42: // Not much that can be done...
43: }
44: super .generate();
45: }
46:
47: public Serializable getKey() {
48: final Request request = ObjectModelHelper
49: .getRequest(this .objectModel);
50: // for our test, pages having the same value of "pageKey" will share
51: // the same cache location
52: String key = request.getParameter("pageKey");
53: return ((key == null || "".equals(key)) ? "foo" : key);
54: }
55:
56: public SourceValidity getValidity() {
57: final Request request = ObjectModelHelper
58: .getRequest(this .objectModel);
59: String key = request.getParameter("pageKey");
60: return new EventValidity(new NamedEvent((key == null || ""
61: .equals(key)) ? "foo" : key));
62: }
63:
64: }
|