1 /** 2 * This file Copyright (c) 2003-2010 Magnolia International 3 * Ltd. (http://www.magnolia-cms.com). All rights reserved. 4 * 5 * 6 * This file is dual-licensed under both the Magnolia 7 * Network Agreement and the GNU General Public License. 8 * You may elect to use one or the other of these licenses. 9 * 10 * This file is distributed in the hope that it will be 11 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the 12 * implied warranty of MERCHANTABILITY or FITNESS FOR A 13 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT. 14 * Redistribution, except as permitted by whichever of the GPL 15 * or MNA you select, is prohibited. 16 * 17 * 1. For the GPL license (GPL), you can redistribute and/or 18 * modify this file under the terms of the GNU General 19 * Public License, Version 3, as published by the Free Software 20 * Foundation. You should have received a copy of the GNU 21 * General Public License, Version 3 along with this program; 22 * if not, write to the Free Software Foundation, Inc., 51 23 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 24 * 25 * 2. For the Magnolia Network Agreement (MNA), this file 26 * and the accompanying materials are made available under the 27 * terms of the MNA which accompanies this distribution, and 28 * is available at http://www.magnolia-cms.com/mna.html 29 * 30 * Any modifications to this file must keep this entire header 31 * intact. 32 * 33 */ 34 package info.magnolia.cms.taglibs; 35 36 import info.magnolia.cms.beans.runtime.MultipartForm; 37 import info.magnolia.cms.core.Content; 38 import info.magnolia.cms.filters.InterceptFilter; 39 import info.magnolia.cms.util.SelectorUtil; 40 import info.magnolia.context.MgnlContext; 41 import org.apache.commons.lang.StringUtils; 42 43 44 /** 45 * @author Sameer Charles 46 * @version 1.1 47 * 48 * @deprecated since 4.0 - should not be used. AggregationState should be useable as a replacement in most cases. 49 */ 50 public class Resource { 51 52 /** 53 * @deprecated since 4.0 - use {@link InterceptFilter#MGNL_PREVIEW_ATTRIBUTE} or rather, use the methods on AggregationState. 54 */ 55 public static final String MGNL_PREVIEW_ATTRIBUTE = InterceptFilter.MGNL_PREVIEW_ATTRIBUTE; 56 57 private static final String GLOBAL_CONTENT_NODE = "contentObjGlobal"; //$NON-NLS-1$ 58 59 private static final String LOCAL_CONTENT_NODE = "contentObj"; //$NON-NLS-1$ 60 61 private static final String LOCAL_CONTENT_NODE_COLLECTION_NAME = "localContentNodeCollectionName"; //$NON-NLS-1$ 62 63 /** 64 * Utility class, don't instantiate. 65 */ 66 protected Resource() { 67 // unused 68 } 69 70 /** 71 * <p> 72 * get Content object as requested from the URI 73 * </p> 74 * @return currently active page, as requested from the URI 75 * 76 * @deprecated use AggregationState 77 */ 78 public static Content getActivePage() { 79 return MgnlContext.getAggregationState().getMainContent(); 80 } 81 82 /** 83 * <p> 84 * get Content object as requested from the URI 85 * </p> 86 * @return currently active page, as requested from the URI 87 */ 88 public static Content getCurrentActivePage() { 89 Content currentActpage = MgnlContext.getAggregationState().getCurrentContent(); 90 if (currentActpage == null) { 91 currentActpage = MgnlContext.getAggregationState().getMainContent(); 92 } 93 return currentActpage; 94 } 95 96 /** 97 * <p> 98 * get ContentNode object as set by the "set" tag 99 * </p> 100 * @return ContentNode , global container specific to the current JSP/Servlet page 101 */ 102 public static Content getGlobalContentNode() { 103 try { 104 return (Content) MgnlContext.getAttribute(Resource.GLOBAL_CONTENT_NODE); 105 } 106 catch (Exception e) { 107 return null; 108 } 109 } 110 111 /** 112 * <p> 113 * get ContentNode object as passed to the include tag 114 * </p> 115 * @return ContentNode , local container specific to the current JSP/Servlet paragraph 116 */ 117 public static Content getLocalContentNode() { 118 return MgnlContext.getAggregationState().getCurrentContent(); 119 } 120 121 /** 122 * 123 */ 124 public static String getLocalContentNodeCollectionName() { 125 try { 126 return (String) MgnlContext.getAttribute(Resource.LOCAL_CONTENT_NODE_COLLECTION_NAME); 127 } 128 catch (Exception e) { 129 return StringUtils.EMPTY; 130 } 131 } 132 133 /** 134 * <p> 135 * this only works for forms which uses enctype=multipart/form-data 136 * </p> 137 * @return initialised multipart form object with the posted data 138 * @deprecated since 4.0 - use WebContext.getPostedForm() 139 */ 140 public static MultipartForm getPostedForm() { 141 return MgnlContext.getPostedForm(); 142 } 143 144 /** 145 * <p> 146 * get selector as requested from the URI. The selector is the part between the handle and the extension. 147 * selector("http://server/a.x.1.f.4.html") = "x.1.f.4" 148 * </p> 149 * <strong>Warning - this might change in the future - see MAGNOLIA-2343 for details.</strong> 150 * @return selector String as requested from the URI 151 * @deprecated since 4.0 - use {@link info.magnolia.cms.util.SelectorUtil#getSelector} 152 */ 153 public static String getSelector() { 154 return SelectorUtil.getSelector(); 155 } 156 157 /** 158 * Get the selector by index 159 * <strong>Warning - this might change in the future - see MAGNOLIA-2343 for details.</strong> 160 * @param index 161 * @return the selector value 162 * @deprecated since 4.0 - use {@link info.magnolia.cms.util.SelectorUtil#getSelector} 163 */ 164 public static String getSelector(int index) { 165 return SelectorUtil.getSelector(index); 166 } 167 168 /** 169 * <p> 170 * removes ContentNode object in resources , scope:page 171 * </p> 172 * 173 * @deprecated not used 174 */ 175 public static void removeGlobalContentNode() { 176 MgnlContext.removeAttribute(Resource.GLOBAL_CONTENT_NODE); 177 } 178 179 /** 180 * removes ContentNode object in resources , scope:TAG 181 */ 182 public static void removeLocalContentNode() { 183 MgnlContext.getAggregationState().setCurrentContent(null); 184 } 185 186 /** 187 * 188 */ 189 public static void removeLocalContentNodeCollectionName() { 190 MgnlContext.removeAttribute(Resource.LOCAL_CONTENT_NODE_COLLECTION_NAME); 191 } 192 193 /** 194 * Restores the request's original <code>actpage</code> attribute (i.e. the one specified by the request URI). 195 */ 196 public static void restoreCurrentActivePage() { 197 setCurrentActivePage(MgnlContext.getAggregationState().getMainContent()); 198 } 199 200 /** 201 * Set the request's <code>actpage</code> attribute to <code>page</code> 202 * @deprecated since 4.0 - use AggregationState. 203 */ 204 public static void setCurrentActivePage(Content page) { 205 MgnlContext.getAggregationState().setCurrentContent(page); 206 } 207 208 /** 209 * <p> 210 * set ContentNode object in resources, scope:page 211 * </p> 212 * @param node to be set 213 */ 214 public static void setGlobalContentNode(Content node) { 215 MgnlContext.setAttribute(Resource.GLOBAL_CONTENT_NODE, node); 216 } 217 218 /** 219 * <p> 220 * set ContentNode object in resources , scope:TAG 221 * </p> 222 * @param node to be set 223 */ 224 public static void setLocalContentNode(Content node) { 225 MgnlContext.getAggregationState().setCurrentContent(node); 226 } 227 228 /** 229 * 230 */ 231 public static void setLocalContentNodeCollectionName(String name) { 232 MgnlContext.setAttribute(Resource.LOCAL_CONTENT_NODE_COLLECTION_NAME, name); 233 } 234 235 /** 236 * Check for preview mode. 237 * @return boolean , true if preview is enabled 238 * @deprecated use {@link info.magnolia.cms.core.AggregationState#isPreviewMode} 239 */ 240 public static boolean showPreview() { 241 return MgnlContext.getAggregationState().isPreviewMode(); 242 } 243 244 /** 245 * @deprecated use AggregationState 246 */ 247 public static void setShowPreview(boolean showPreview){ 248 MgnlContext.getAggregationState().setPreviewMode(showPreview); 249 } 250 251 }