1 15 package org.apache.tapestry.portlet; 16 17 import javax.portlet.PortletConfig; 18 19 import org.apache.hivemind.Resource; 20 import org.apache.tapestry.parse.ISpecificationParser; 21 import org.apache.tapestry.services.ApplicationGlobals; 22 import org.apache.tapestry.spec.ApplicationSpecification; 23 import org.apache.tapestry.spec.IApplicationSpecification; 24 import org.apache.tapestry.web.WebContext; 25 import org.apache.tapestry.web.WebContextResource; 26 27 40 public class PortletApplicationSpecificationInitializer implements PortletApplicationInitializer 41 { 42 private WebContext _context; 43 44 private ApplicationGlobals _globals; 45 46 private ISpecificationParser _parser; 47 48 public void initialize(PortletConfig portletConfig) 49 { 50 String name = portletConfig.getPortletName(); 51 52 Resource resource = findApplicationSpecification(name); 53 54 IApplicationSpecification specification = resource == null ? constructStandinSpecification(name) 55 : _parser.parseApplicationSpecification(resource); 56 57 _globals.storeSpecification(specification); 58 } 59 60 private Resource findApplicationSpecification(String name) 61 { 62 String expectedName = name + ".application"; 63 64 Resource webInfLocation = new WebContextResource(_context, "/WEB-INF/"); 65 Resource webInfAppLocation = webInfLocation.getRelativeResource(name + "/"); 66 67 Resource result = check(webInfAppLocation, expectedName); 68 if (result != null) 69 return result; 70 71 return check(webInfLocation, expectedName); 72 } 73 74 private Resource check(Resource resource, String name) 75 { 76 Resource result = resource.getRelativeResource(name); 77 78 if (result.getResourceURL() != null) 79 return result; 80 81 return null; 82 } 83 84 private IApplicationSpecification constructStandinSpecification(String name) 85 { 86 ApplicationSpecification result = new ApplicationSpecification(); 87 88 90 Resource virtualLocation = new WebContextResource(_context, "/WEB-INF/" + name 91 + ".application"); 92 93 result.setSpecificationLocation(virtualLocation); 94 95 result.setName(name); 96 97 return result; 98 } 99 100 public void setContext(WebContext context) 101 { 102 _context = context; 103 } 104 105 public void setGlobals(ApplicationGlobals globals) 106 { 107 _globals = globals; 108 } 109 110 public void setParser(ISpecificationParser parser) 111 { 112 _parser = parser; 113 } 114 } | Popular Tags |