1 13 package info.magnolia.cms.util; 14 15 import info.magnolia.cms.beans.config.ContentRepository; 16 import info.magnolia.cms.beans.runtime.File; 17 import info.magnolia.cms.beans.runtime.MultipartForm; 18 import info.magnolia.cms.core.Aggregator; 19 import info.magnolia.cms.core.Content; 20 import info.magnolia.cms.core.HierarchyManager; 21 import info.magnolia.context.MgnlContext; 22 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpSession ; 25 26 import org.apache.commons.lang.BooleanUtils; 27 import org.apache.commons.lang.StringUtils; 28 29 30 34 public final class Resource { 35 36 39 public static final String MGNL_PREVIEW_ATTRIBUTE = "mgnlPreview"; 41 private static final String GLOBAL_CONTENT_NODE = "contentObjGlobal"; 43 private static final String LOCAL_CONTENT_NODE = "contentObj"; 45 private static final String LOCAL_CONTENT_NODE_COLLECTION_NAME = "localContentNodeCollectionName"; 47 50 private Resource() { 51 } 53 54 61 public static Content getActivePage(HttpServletRequest req) { 62 return (Content) req.getAttribute(Aggregator.ACTPAGE); 63 } 64 65 73 public static String getSelector(HttpServletRequest req) { 74 return (String ) req.getAttribute(Aggregator.SELECTOR); 75 } 76 77 84 public static File getFile(HttpServletRequest req) { 85 return (File) req.getAttribute(Aggregator.FILE); 86 } 87 88 95 public static Content getCurrentActivePage(HttpServletRequest req) { 96 Content currentActpage; 97 currentActpage = (Content) req.getAttribute(Aggregator.CURRENT_ACTPAGE); 98 if (currentActpage == null) { 99 currentActpage = (Content) req.getAttribute(Aggregator.ACTPAGE); 100 } 101 return currentActpage; 102 } 103 104 112 public static HierarchyManager getHierarchyManager(HttpServletRequest req) { 113 return MgnlContext.getHierarchyManager(ContentRepository.WEBSITE); 114 } 115 116 123 public static MultipartForm getPostedForm(HttpServletRequest req) { 124 return (MultipartForm) req.getAttribute("multipartform"); } 126 127 134 public static Content getLocalContentNode(HttpServletRequest req) { 135 try { 136 return (Content) req.getAttribute(Resource.LOCAL_CONTENT_NODE); 137 } 138 catch (Exception e) { 139 return null; 140 } 141 } 142 143 150 public static void setLocalContentNode(HttpServletRequest req, Content node) { 151 req.setAttribute(Resource.LOCAL_CONTENT_NODE, node); 152 } 153 154 160 public static void removeLocalContentNode(HttpServletRequest req) { 161 req.removeAttribute(Resource.LOCAL_CONTENT_NODE); 162 } 163 164 171 public static Content getGlobalContentNode(HttpServletRequest req) { 172 try { 173 return (Content) req.getAttribute(Resource.GLOBAL_CONTENT_NODE); 174 } 175 catch (Exception e) { 176 return null; 177 } 178 } 179 180 187 public static void setGlobalContentNode(HttpServletRequest req, Content node) { 188 req.setAttribute(Resource.GLOBAL_CONTENT_NODE, node); 189 } 190 191 197 public static void removeGlobalContentNode(HttpServletRequest req) { 198 req.removeAttribute(Resource.GLOBAL_CONTENT_NODE); 199 } 200 201 204 public static void setLocalContentNodeCollectionName(HttpServletRequest req, String name) { 205 req.setAttribute(Resource.LOCAL_CONTENT_NODE_COLLECTION_NAME, name); 206 } 207 208 211 public static String getLocalContentNodeCollectionName(HttpServletRequest req) { 212 try { 213 return (String ) req.getAttribute(Resource.LOCAL_CONTENT_NODE_COLLECTION_NAME); 214 } 215 catch (Exception e) { 216 return StringUtils.EMPTY; 217 } 218 } 219 220 223 public static void removeLocalContentNodeCollectionName(HttpServletRequest req) { 224 req.removeAttribute(Resource.LOCAL_CONTENT_NODE_COLLECTION_NAME); 225 } 226 227 232 public static boolean showPreview(HttpServletRequest req) { 233 if (req.getParameter(MGNL_PREVIEW_ATTRIBUTE) != null) { 235 return BooleanUtils.toBoolean(req.getParameter(MGNL_PREVIEW_ATTRIBUTE)); 236 } 237 238 HttpSession httpsession = req.getSession(false); 239 if (httpsession != null) { 240 return BooleanUtils.toBoolean((Boolean ) httpsession.getAttribute(MGNL_PREVIEW_ATTRIBUTE)); 241 } 242 243 return false; 244 } 245 246 249 public static void setCurrentActivePage(HttpServletRequest request, Content page) { 250 request.setAttribute(Aggregator.CURRENT_ACTPAGE, page); 251 } 252 253 256 public static void restoreCurrentActivePage(HttpServletRequest request) { 257 setCurrentActivePage(request, getActivePage(request)); 258 } 259 260 } 261 | Popular Tags |