KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > util > AbstractDaisyApple


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.frontend.util;
17
18 import org.apache.cocoon.components.flow.apples.AppleController;
19 import org.apache.cocoon.components.flow.apples.AppleRequest;
20 import org.apache.cocoon.components.flow.apples.AppleResponse;
21 import org.apache.cocoon.components.flow.apples.StatelessAppleController;
22 import org.apache.cocoon.environment.Request;
23 import org.apache.avalon.framework.context.Contextualizable;
24 import org.apache.avalon.framework.context.Context;
25 import org.apache.avalon.framework.context.ContextException;
26 import org.outerj.daisy.frontend.WikiHelper;
27 import EDU.oswego.cs.dl.util.concurrent.Mutex;
28
29 /**
30  * Base class for Apple controllers in the Daisy Wiki.
31  */

32 public abstract class AbstractDaisyApple implements AppleController, Contextualizable {
33     private Mutex mutex = new Mutex();
34     private String JavaDoc mountPoint;
35     private String JavaDoc layoutType;
36     private String JavaDoc skin;
37     private String JavaDoc continuationId;
38     private Context context;
39
40     public void contextualize(Context context) throws ContextException {
41         this.context = context;
42         if (!(this instanceof StatelessAppleController))
43             continuationId = (String JavaDoc)context.get("continuation-id");
44     }
45
46     public final void process(AppleRequest appleRequest, AppleResponse appleResponse) throws Exception JavaDoc {
47         if (needsMutex())
48             mutex.attempt(10000);
49         try {
50             Request request = appleRequest.getCocoonRequest();
51             mountPoint = WikiHelper.getMountPoint(request);
52             layoutType = WikiHelper.getLayoutType(request);
53             skin = WikiHelper.getSkin(request);
54
55             processInternal(appleRequest, appleResponse);
56         } finally {
57             if (needsMutex())
58                 mutex.release();
59         }
60     }
61
62     protected abstract void processInternal(AppleRequest appleRequest, AppleResponse appleResponse) throws Exception JavaDoc;
63
64     protected String JavaDoc getMountPoint() {
65         return mountPoint;
66     }
67
68     protected String JavaDoc getLayoutType() {
69         return layoutType;
70     }
71
72     protected String JavaDoc getLayoutType(String JavaDoc defaultLayoutType) {
73         if (layoutType == null)
74             return defaultLayoutType;
75         else
76             return layoutType;
77     }
78
79     protected String JavaDoc getSkin() {
80         return skin;
81     }
82
83     protected String JavaDoc getContinuationId() {
84         return continuationId;
85     }
86
87     protected boolean needsMutex() {
88         return !(this instanceof StatelessAppleController);
89     }
90
91     protected Context getContext() {
92         return context;
93     }
94 }
95
Popular Tags