1 13 package info.magnolia.cms.taglibs; 14 15 import info.magnolia.cms.beans.config.Server; 16 import info.magnolia.cms.core.Content; 17 import info.magnolia.cms.gui.inline.BarEdit; 18 import info.magnolia.cms.security.Permission; 19 import info.magnolia.cms.util.Resource; 20 21 import java.io.IOException ; 22 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.jsp.tagext.TagSupport ; 25 26 import org.apache.commons.lang.StringUtils; 27 import org.apache.commons.lang.exception.NestableRuntimeException; 28 29 30 35 public class EditBar extends TagSupport { 36 37 40 private static final long serialVersionUID = 222L; 41 42 private String nodeName; 43 44 private String nodeCollectionName; 45 46 private String paragraph; 47 48 private String editLabel; 49 50 private String deleteLabel; 51 52 private String moveLabel; 53 54 57 private boolean adminOnly; 58 59 63 public void setContentNodeName(String name) { 64 this.nodeName = name; 65 } 66 67 71 public void setContentNodeCollectionName(String name) { 72 this.nodeCollectionName = name; 73 } 74 75 79 public void setParagraph(String type) { 80 this.paragraph = type; 81 } 82 83 87 public void setEditLabel(String label) { 88 this.editLabel = label; 89 } 90 91 95 public void setDeleteLabel(String label) { 96 this.deleteLabel = label; 97 } 98 99 public void setMoveLabel(String label) { 100 this.moveLabel = label; 101 } 102 103 107 public void setAdminOnly(boolean adminOnly) { 108 this.adminOnly = adminOnly; 109 } 110 111 114 public int doStartTag() { 115 return EVAL_BODY_INCLUDE; 116 } 117 118 121 public int doEndTag() { 122 123 if (!adminOnly || Server.isAdmin()) { 124 125 HttpServletRequest request = (HttpServletRequest ) this.pageContext.getRequest(); 126 127 if (Server.isAdmin() && Resource.getActivePage(request).isGranted(Permission.SET)) { 128 try { 129 BarEdit bar = new BarEdit((HttpServletRequest ) this.pageContext.getRequest()); 130 131 Content localContentNode = Resource.getLocalContentNode((HttpServletRequest ) this.pageContext 132 .getRequest()); 133 134 if (this.paragraph == null) { 135 Content contentParagraph = localContentNode; 136 if (contentParagraph != null) { 137 this.paragraph = contentParagraph.getMetaData().getTemplate(); 138 } 139 } 140 bar.setParagraph(this.paragraph); 141 142 if (this.nodeCollectionName == null) { 143 this.nodeCollectionName = StringUtils.defaultString(Resource 144 .getLocalContentNodeCollectionName((HttpServletRequest ) this.pageContext.getRequest())); 145 } 146 bar.setNodeCollectionName(this.nodeCollectionName); 147 148 if (this.nodeName == null) { 149 if (localContentNode != null) { 150 this.nodeName = localContentNode.getName(); 151 } 152 } 153 bar.setNodeName(this.nodeName); 154 155 try { 156 String path; 157 if (localContentNode != null){ 158 path = localContentNode.getHandle(); 159 if(path.endsWith(this.nodeCollectionName + "/" + this.nodeName )){ 160 path = StringUtils.removeEnd(path, "/" + this.nodeCollectionName + "/" + this.nodeName); 161 } 162 } 163 else{ 164 path = Resource.getCurrentActivePage((HttpServletRequest ) this.pageContext.getRequest()).getHandle(); 165 } 166 bar.setPath(path); 167 } 168 catch (Exception re) { 169 bar.setPath(StringUtils.EMPTY); 170 } 171 172 bar.setDefaultButtons(); 173 174 if (this.editLabel != null) { 175 if (StringUtils.isEmpty(this.editLabel)) { 176 bar.setButtonEdit(null); 177 } 178 else { 179 bar.getButtonEdit().setLabel(this.editLabel); 180 } 181 } 182 183 if (this.moveLabel != null) { 184 if (StringUtils.isEmpty(this.moveLabel)) { 185 bar.setButtonMove(null); 186 } 187 else { 188 bar.getButtonMove().setLabel(this.moveLabel); 189 } 190 } 191 192 if (this.deleteLabel != null) { 193 if (StringUtils.isEmpty(this.deleteLabel)) { 194 bar.setButtonDelete(null); 195 } 196 else { 197 bar.getButtonDelete().setLabel(this.deleteLabel); 198 } 199 } 200 bar.placeDefaultButtons(); 201 bar.drawHtml(pageContext.getOut()); 202 } 203 catch (IOException e) { 204 throw new NestableRuntimeException(e); 205 } 206 } 207 } 208 reset(); 209 210 return EVAL_PAGE; 211 } 212 213 protected void reset(){ 214 this.nodeName = null; 215 this.nodeCollectionName = null; 216 this.paragraph = null; 217 this.editLabel = null; 218 this.deleteLabel = null; 219 this.moveLabel = null; 220 this.adminOnly = false; 221 } 222 223 } 224 | Popular Tags |