View Javadoc

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 org.apache.pluto.portalImpl.om.page.*;
23  import org.apache.pluto.portalImpl.core.*;
24  import org.apache.pluto.portalImpl.util.Parameters;
25  import org.apache.pluto.portalImpl.aggregation.navigation.Navigation;
26  import org.apache.pluto.portalImpl.services.config.Config;
27  
28  import org.apache.pluto.util.StringUtils;
29  
30  import java.util.*;
31  import java.io.*;
32  import javax.servlet.*;
33  import javax.servlet.http.*;
34  
35  public abstract class AbstractFragment 
36  implements org.apache.pluto.portalImpl.aggregation.Fragment {
37  
38      public final static String BASE_ROOT = Config.getParameters().getString(
39                                                 "aggregation.base.dir",
40                                                 "/WEB-INF/aggregation/"
41                                             );
42  
43      private String id;
44      private ServletConfig config;
45      private org.apache.pluto.portalImpl.aggregation.Fragment parent;
46      private org.apache.pluto.portalImpl.om.page.Fragment fragDesc;
47      private Parameters initParameters;
48      private Navigation navigation;
49  
50  
51      public AbstractFragment(String id,
52                              ServletConfig config, 
53                              org.apache.pluto.portalImpl.aggregation.Fragment parent,
54                              org.apache.pluto.portalImpl.om.page.Fragment fragDesc,
55                              org.apache.pluto.portalImpl.aggregation.navigation.Navigation navigation)
56      throws Exception 
57      {
58          StringBuffer compId = new StringBuffer();
59          if (parent != null) {
60              String parentID = parent.getId();
61              if (parentID != null) {
62                  compId.append(parentID);
63                  compId.append("_");
64              }
65  
66          }
67  
68          if (id != null) {
69              compId.append(id);
70              this.id = compId.toString();
71          }
72  
73          this.config = config;
74          this.parent = parent;
75          this.fragDesc = fragDesc;
76          this.navigation = navigation;
77  
78          if (this.fragDesc != null) {
79              // prepare properties - SHESMER:TODO needs to be done better, the additonal Map should not be necessary
80              Map map = new HashMap();
81  
82              Iterator iterator = this.fragDesc.getProperties().iterator();
83  
84              while (iterator.hasNext()) {
85                  Property property = (Property)iterator.next();
86  
87                  map.put(property.getName(), property.getValue());
88              }
89  
90              initParameters = new Parameters(map);
91          }
92  
93          org.apache.pluto.portalImpl.services.pageregistry.PageRegistry.addFragment(this);
94      }
95  
96      // org.apache.pluto.portalImpl.aggregation.Fragment implementation.
97  
98      public void service(HttpServletRequest request, HttpServletResponse response)
99      throws ServletException, IOException
100     {
101         preService(request, response);
102 
103         request.setAttribute(Constants.FRAGMENT, this);
104         String jspName = StringUtils.nameOf(getClass()) + ".jsp";
105         RequestDispatcher rd = getServletConfig().getServletContext().getRequestDispatcher(BASE_ROOT+jspName);
106         rd.include(request, response);
107 
108         postService(request, response);
109     }
110 
111     public org.apache.pluto.portalImpl.aggregation.Fragment getParent()
112     {
113         return parent;
114     }
115 
116     public String getId()
117     {
118         return id;
119     }
120 
121     public Parameters getInitParameters()
122     {
123         return initParameters;
124     }
125 
126     abstract public Collection getChildFragments();
127 
128     abstract public void addChild(org.apache.pluto.portalImpl.aggregation.Fragment child);
129 
130     public Navigation getNavigation()
131     {
132         return navigation;
133     }
134 
135     abstract public void createURL(PortalURL url);
136 
137     abstract public boolean isPartOfURL(PortalURL url);
138 
139     // additional methods.
140     public ServletConfig getServletConfig()
141     {
142         return config;
143     }
144 
145     public String getInitParameterValue(String name)
146     {
147         return initParameters.getString(name);
148     }
149 
150 
151     abstract public void preService(HttpServletRequest request, HttpServletResponse response)
152     throws ServletException, IOException;
153 
154     abstract public void postService(HttpServletRequest request, HttpServletResponse response)
155     throws ServletException, IOException;
156 
157     protected org.apache.pluto.portalImpl.om.page.Fragment getFragmentDescription()
158     {
159         return fragDesc;
160     }
161 }