KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > aggregation > AbstractFragment


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
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 /*
17
18  */

19
20 package org.apache.pluto.portalImpl.aggregation;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Map JavaDoc;
27
28 import javax.servlet.RequestDispatcher JavaDoc;
29 import javax.servlet.ServletConfig JavaDoc;
30 import javax.servlet.ServletException JavaDoc;
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33
34 import org.apache.pluto.portalImpl.aggregation.navigation.Navigation;
35 import org.apache.pluto.portalImpl.core.PortalURL;
36 import org.apache.pluto.portalImpl.om.page.Property;
37 import org.apache.pluto.portalImpl.services.config.Config;
38 import org.apache.pluto.portalImpl.util.Parameters;
39 import org.apache.pluto.util.StringUtils;
40
41 public abstract class AbstractFragment
42 implements org.apache.pluto.portalImpl.aggregation.Fragment {
43
44     public final static String JavaDoc BASE_ROOT = Config.getParameters().getString(
45                                                "aggregation.base.dir",
46                                                "/WEB-INF/aggregation/"
47                                            );
48
49     private String JavaDoc id;
50     private ServletConfig JavaDoc config;
51     private org.apache.pluto.portalImpl.aggregation.Fragment parent;
52     private org.apache.pluto.portalImpl.om.page.Fragment fragDesc;
53     private Parameters initParameters;
54     private Navigation navigation;
55
56
57     public AbstractFragment(String JavaDoc id,
58                             ServletConfig JavaDoc config,
59                             org.apache.pluto.portalImpl.aggregation.Fragment parent,
60                             org.apache.pluto.portalImpl.om.page.Fragment fragDesc,
61                             org.apache.pluto.portalImpl.aggregation.navigation.Navigation navigation)
62     throws Exception JavaDoc
63     {
64         StringBuffer JavaDoc compId = new StringBuffer JavaDoc();
65         if (parent != null) {
66             String JavaDoc parentID = parent.getId();
67             if (parentID != null) {
68                 compId.append(parentID);
69                 compId.append("_");
70             }
71
72         }
73
74         if (id != null) {
75             compId.append(id);
76             this.id = compId.toString();
77         }
78
79         this.config = config;
80         this.parent = parent;
81         this.fragDesc = fragDesc;
82         this.navigation = navigation;
83
84         if (this.fragDesc != null) {
85             // prepare properties - SHESMER:TODO needs to be done better, the additonal Map should not be necessary
86
Map JavaDoc map = new HashMap JavaDoc();
87
88             Iterator JavaDoc iterator = this.fragDesc.getProperties().iterator();
89
90             while (iterator.hasNext()) {
91                 Property property = (Property)iterator.next();
92
93                 map.put(property.getName(), property.getValue());
94             }
95
96             initParameters = new Parameters(map);
97         }
98
99         org.apache.pluto.portalImpl.services.pageregistry.PageRegistry.addFragment(this);
100     }
101
102     // org.apache.pluto.portalImpl.aggregation.Fragment implementation.
103

104     public void service(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
105     throws ServletException JavaDoc, IOException JavaDoc
106     {
107         preService(request, response);
108
109         request.setAttribute(Constants.FRAGMENT, this);
110         String JavaDoc jspName = StringUtils.nameOf(getClass()) + ".jsp";
111         RequestDispatcher JavaDoc rd = getServletConfig().getServletContext().getRequestDispatcher(BASE_ROOT+jspName);
112         rd.include(request, response);
113
114         postService(request, response);
115     }
116
117     public org.apache.pluto.portalImpl.aggregation.Fragment getParent()
118     {
119         return parent;
120     }
121
122     public String JavaDoc getId()
123     {
124         return id;
125     }
126
127     public Parameters getInitParameters()
128     {
129         return initParameters;
130     }
131
132     abstract public Collection JavaDoc getChildFragments();
133
134     abstract public void addChild(org.apache.pluto.portalImpl.aggregation.Fragment child);
135
136     public Navigation getNavigation()
137     {
138         return navigation;
139     }
140
141     abstract public void createURL(PortalURL url);
142
143     abstract public boolean isPartOfURL(PortalURL url);
144
145     // additional methods.
146
public ServletConfig JavaDoc getServletConfig()
147     {
148         return config;
149     }
150
151     public String JavaDoc getInitParameterValue(String JavaDoc name)
152     {
153         return initParameters.getString(name);
154     }
155
156
157     abstract public void preService(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
158     throws ServletException JavaDoc, IOException JavaDoc;
159
160     abstract public void postService(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
161     throws ServletException JavaDoc, IOException JavaDoc;
162
163     protected org.apache.pluto.portalImpl.om.page.Fragment getFragmentDescription()
164     {
165         return fragDesc;
166     }
167 }
168
Popular Tags