1 22 23 package org.meshcms.taglib; 24 25 import java.io.*; 26 import java.util.*; 27 import javax.servlet.http.*; 28 import javax.servlet.jsp.*; 29 import javax.servlet.jsp.tagext.*; 30 import org.meshcms.core.*; 31 import org.meshcms.util.*; 32 import com.opensymphony.module.sitemesh.*; 33 import com.opensymphony.module.sitemesh.util.*; 34 35 38 public abstract class AbstractTag extends TagSupport implements RequestConstants { 39 43 public static final String PAGE_MODULES = "page_modules"; 44 45 WebSite webSite; 46 HttpServletRequest request; 47 Path pagePath; 48 UserInfo userInfo; 49 String cp, ap, afp; 50 boolean isEdit; 51 52 58 public int doStartTag() throws JspException { 59 request = (HttpServletRequest) pageContext.getRequest(); 60 webSite = (WebSite) request.getAttribute("webSite"); 61 pagePath = webSite.getRequestedPath(request); 62 userInfo = (UserInfo) 63 pageContext.getAttribute("userInfo", PageContext.SESSION_SCOPE); 64 cp = request.getContextPath(); 65 ap = "/" + webSite.getAdminPath(); 66 afp = cp + ap; 67 isEdit = HitFilter.ACTION_EDIT.equals(request.getParameter(HitFilter.ACTION_NAME)) && 68 userInfo != null && userInfo.canWrite(webSite, pagePath); 69 70 try { 71 if (isEdit) { 72 writeEditTag(); 73 } else { 74 writeTag(); 75 } 76 } catch (IOException ex) { 77 throw new JspException(ex); 78 } 80 81 return getStartTagReturnValue(); 82 } 83 84 91 public int getStartTagReturnValue() { 92 return SKIP_BODY; 93 } 94 95 99 public abstract void writeTag() throws IOException, JspException; 100 101 106 public void writeEditTag() throws IOException, JspException { 107 writeTag(); 108 } 109 110 114 protected Page getPage() { 115 Page p = (Page) pageContext.getAttribute(PAGE, PageContext.PAGE_SCOPE); 116 117 if (p == null) { 118 p = (Page) pageContext.getAttribute(PAGE, PageContext.REQUEST_SCOPE); 119 120 if (p == null) { 121 pageContext.removeAttribute(PAGE, PageContext.PAGE_SCOPE); 122 } else { 123 pageContext.setAttribute(PAGE, p, PageContext.PAGE_SCOPE); 124 } 125 126 pageContext.removeAttribute(PAGE, PageContext.REQUEST_SCOPE); 127 } 128 129 if (p == null) { 130 WebUtils.setBlockCache(request); 132 } 133 134 return p; 135 } 136 137 141 protected Writer getOut() { 142 return OutputConverter.getWriter(pageContext.getOut()); 143 } 144 145 ModuleDescriptor getModuleDescriptor(String location, String name) { 146 ModuleDescriptor md; 147 148 if (name == null) { 149 Map pageModules = (Map) pageContext.getAttribute(PAGE_MODULES); 150 151 if (pageModules == null) { 152 pageModules = new HashMap(); 153 String [] modules = Utils.tokenize 154 (getPage().getProperty(PageAssembler.MODULES_PARAM), ";"); 155 156 if (modules != null) { 157 for (int i = 0; i < modules.length; i++) { 158 ModuleDescriptor md0 = new ModuleDescriptor(modules[i]); 159 160 if (md0.isValid()) { 161 pageModules.put(md0.getLocation(), md0); 162 } 163 } 164 } 165 166 pageContext.setAttribute(PAGE_MODULES, pageModules, PageContext.PAGE_SCOPE); 167 } 168 169 md = (ModuleDescriptor) pageModules.get(location); 170 } else { 171 md = new ModuleDescriptor(name); 172 md.setLocation(location); 173 } 174 175 return md; 176 } 177 } 178
| Popular Tags
|