1 16 19 20 package org.apache.pluto.portalImpl.aggregation; 21 22 import java.io.IOException ; 23 import java.util.Collection ; 24 import java.util.HashMap ; 25 import java.util.Iterator ; 26 import java.util.Map ; 27 28 import javax.servlet.RequestDispatcher ; 29 import javax.servlet.ServletConfig ; 30 import javax.servlet.ServletException ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 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 BASE_ROOT = Config.getParameters().getString( 45 "aggregation.base.dir", 46 "/WEB-INF/aggregation/" 47 ); 48 49 private String id; 50 private ServletConfig 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 id, 58 ServletConfig 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 63 { 64 StringBuffer compId = new StringBuffer (); 65 if (parent != null) { 66 String 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 Map map = new HashMap (); 87 88 Iterator 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 104 public void service(HttpServletRequest request, HttpServletResponse response) 105 throws ServletException , IOException 106 { 107 preService(request, response); 108 109 request.setAttribute(Constants.FRAGMENT, this); 110 String jspName = StringUtils.nameOf(getClass()) + ".jsp"; 111 RequestDispatcher 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 getId() 123 { 124 return id; 125 } 126 127 public Parameters getInitParameters() 128 { 129 return initParameters; 130 } 131 132 abstract public Collection 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 public ServletConfig getServletConfig() 147 { 148 return config; 149 } 150 151 public String getInitParameterValue(String name) 152 { 153 return initParameters.getString(name); 154 } 155 156 157 abstract public void preService(HttpServletRequest request, HttpServletResponse response) 158 throws ServletException , IOException ; 159 160 abstract public void postService(HttpServletRequest request, HttpServletResponse response) 161 throws ServletException , IOException ; 162 163 protected org.apache.pluto.portalImpl.om.page.Fragment getFragmentDescription() 164 { 165 return fragDesc; 166 } 167 } 168 | Popular Tags |