1 13 package info.magnolia.cms.taglibs; 14 15 import info.magnolia.cms.beans.config.ParagraphManager; 16 import info.magnolia.cms.beans.config.Server; 17 import info.magnolia.cms.core.Content; 18 import info.magnolia.cms.gui.inline.ButtonEdit; 19 import info.magnolia.cms.security.Permission; 20 import info.magnolia.cms.util.Resource; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.jsp.JspWriter ; 24 import javax.servlet.jsp.tagext.TagSupport ; 25 26 import org.apache.commons.lang.StringUtils; 27 import org.slf4j.Logger; 28 import org.slf4j.LoggerFactory; 29 30 31 36 public class EditButton extends TagSupport { 37 38 41 private static final long serialVersionUID = 222L; 42 43 46 private static Logger log = LoggerFactory.getLogger(EditButton.class); 47 48 private String nodeName; 49 50 private String nodeCollectionName; 51 52 private String paragraph; 53 54 private String label; 55 56 private String displayHandler; 57 58 private boolean small = true; 59 60 63 public int doStartTag() { 64 this.displayHandler = StringUtils.EMPTY; 65 return EVAL_BODY_INCLUDE; 66 } 67 68 71 public int doEndTag() { 72 HttpServletRequest request = (HttpServletRequest ) this.pageContext.getRequest(); 73 74 if (Server.isAdmin() && Resource.getActivePage(request).isGranted(Permission.SET)) { 75 76 try { 77 if (this.getNodeCollectionName() != null && this.getNodeName() == null) { 78 return EVAL_PAGE; 80 } 81 JspWriter out = pageContext.getOut(); 82 ButtonEdit button = new ButtonEdit(((HttpServletRequest ) pageContext.getRequest())); 83 button.setPath(this.getPath()); 84 button.setParagraph(this.getParagraph()); 85 button.setNodeCollectionName(this.getNodeCollectionName()); 86 button.setNodeName(this.getNodeName()); 87 button.setDefaultOnclick((HttpServletRequest ) this.pageContext.getRequest()); 88 if (this.getLabel() != null) { 89 button.setLabel(this.getLabel()); 90 } 91 if (this.small) { 92 button.setSmall(true); 93 } 94 button.drawHtml(out); 95 } 96 catch (Exception e) { 97 log.error(e.getMessage(), e); 98 } 99 } 100 return EVAL_PAGE; 101 } 102 103 107 public void setContentNodeName(String name) { 108 this.nodeName = name; 109 } 110 111 114 private String getNodeName() { 115 if (this.nodeName == null) { 116 if (Resource.getLocalContentNode(((HttpServletRequest ) pageContext.getRequest())) == null) { 117 return null; 118 } 119 return Resource.getLocalContentNode(((HttpServletRequest ) pageContext.getRequest())).getName(); 120 } 121 return this.nodeName; 122 } 123 124 128 public void setContentNodeCollectionName(String name) { 129 this.nodeCollectionName = name; 130 } 131 132 135 private String getNodeCollectionName() { 136 if (this.nodeCollectionName == null) { 137 return Resource.getLocalContentNodeCollectionName(((HttpServletRequest ) pageContext.getRequest())); 138 } 139 return this.nodeCollectionName; 140 } 141 142 146 public void setParFile(String type) { 147 this.setParagraph(type); 148 } 149 150 154 public void setParagraph(String type) { 155 this.paragraph = type; 156 } 157 158 161 private String getParagraph() { 162 if (this.paragraph == null) { 163 164 return Resource.getLocalContentNode(((HttpServletRequest ) pageContext.getRequest())).getNodeData( 165 "paragraph").getString(); 167 } 168 return this.paragraph; 169 } 170 171 175 public void setTemplate(String path) { 176 this.displayHandler = path; 177 } 178 179 182 public String getTemplate() { 183 if (this.displayHandler == null) { 184 Content localContainer = Resource.getLocalContentNode(((HttpServletRequest ) pageContext.getRequest())); 185 String templateName = localContainer.getNodeData("paragraph").getString(); return ParagraphManager.getInstance().getInfo(templateName).getTemplatePath(); 187 } 188 return this.displayHandler; 189 } 190 191 195 private String getPath() { 196 try { 197 return Resource.getCurrentActivePage(((HttpServletRequest ) pageContext.getRequest())).getHandle(); 198 } 199 catch (Exception re) { 200 return StringUtils.EMPTY; 201 } 202 } 203 204 208 public void setEditLabel(String label) { 209 this.setLabel(label); 210 } 211 212 216 public void setLabel(String label) { 217 this.label = label; 218 } 219 220 223 private String getLabel() { 224 return this.label; 225 } 226 227 231 public void setSmall(boolean small) { 232 this.small = small; 233 } 234 235 238 public void release() { 239 this.nodeName = null; 240 this.nodeCollectionName = null; 241 this.paragraph = null; 242 this.label = null; 243 this.displayHandler = null; 244 this.small = true; 245 super.release(); 246 } 247 } 248 | Popular Tags |