1 26 package org.ofbiz.webapp.region; 27 28 import java.net.URL ; 29 import javax.servlet.jsp.JspException ; 30 import javax.servlet.jsp.tagext.TagSupport ; 31 32 40 public class RegionTag extends TagSupport { 41 protected Region regionObj = null; 42 protected String template = null; 43 private String region = null; 44 45 public void setTemplate(String template) { 46 this.template = template; 47 } 48 49 public void setRegion(String region) { 50 this.region = region; 51 } 52 53 protected boolean findRegionByKey() throws JspException { 54 URL regionFile = null; 55 56 try { 57 regionFile = pageContext.getServletContext().getResource("/WEB-INF/regions.xml"); 58 } catch (java.net.MalformedURLException e) { 59 throw new IllegalArgumentException ("regions.xml file URL invalid: " + e.getMessage()); 60 } 61 62 if (region != null) { 63 regionObj = RegionManager.getRegion(regionFile, region); 64 if (regionObj == null) { 65 throw new JspException ("can't find page definition attribute with this key: " + region); 66 } 67 } 68 return regionObj != null; 69 } 70 71 protected void createRegionFromTemplate(String id) throws JspException { 72 if (template == null) 73 throw new JspException ("can't find template"); 74 75 regionObj = new Region(id, template); 76 } 77 78 protected void createRegionFromRegion(String id) throws JspException { 79 findRegionByKey(); 80 81 if (regionObj == null) 82 return; 83 84 regionObj = new Region(id, regionObj.getContent(), regionObj.getSections()); 86 } 87 88 public void put(Section section) { 89 regionObj.put(section); 90 } 91 92 public void release() { 93 super.release(); 94 regionObj = null; 95 region = null; 96 template = null; 97 } 98 } 99 | Popular Tags |