/** * Check the request and return true if there is a parts iterator attribute present. This attribute * will have been put there by the Sling Engine ParameterSupport class. If its not present, the request * is not streamed and cant be processed by this class. Check this first before using this class. * @param request the request. * @return true if the request can be streamed. */ public boolean isRequestStreamed(SlingHttpServletRequest request) { return request.getAttribute("request-parts-iterator") != null; }
/** * Get Error Status Code from Request or Default (500) if no status code can be found. * * @param request * @return */ public int getStatusCode(SlingHttpServletRequest request) { Integer statusCode = (Integer) request.getAttribute(SlingConstants.ERROR_STATUS); if (statusCode != null) { return statusCode; } else { return ErrorPageHandlerService.DEFAULT_STATUS_CODE; } }
protected static boolean isMarked(SlingHttpServletRequest request) { return request.getAttribute(REQUEST_ATTR_KEY) != null; }
/** * Get Error Status Code from Request or Default (500) if no status code can be found. * * @param request * @return */ @Override public int getStatusCode(SlingHttpServletRequest request) { Integer statusCode = (Integer) request.getAttribute(SlingConstants.ERROR_STATUS); if (statusCode != null) { return statusCode; } else { return ErrorPageHandlerService.DEFAULT_STATUS_CODE; } }
/** * Check whether changes should be written back * @param request The http request * @return {@code true} If session handling should be skipped */ protected boolean isSkipSessionHandling(SlingHttpServletRequest request) { return Boolean.parseBoolean((String) request.getAttribute(SlingPostConstants.ATTR_SKIP_SESSION_HANDLING)) == true; }
/** * Check whether changes should be written back * @param request The http request * @return {@code true} If committing be skipped */ private boolean isSkipSessionHandling(SlingHttpServletRequest request) { return Boolean.parseBoolean((String) request.getAttribute(SlingPostConstants.ATTR_SKIP_SESSION_HANDLING)) == true; }
public static WCMMode getMode(SlingHttpServletRequest req) { if (req.getAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME) == null) { return WCMMode.DISABLED; } else { String mode = String.valueOf(req.getAttribute(WCMMode.REQUEST_ATTRIBUTE_NAME)); try { return WCMMode.valueOf(mode); } catch (IllegalArgumentException ex) { return WCMMode.DISABLED; } } }
/** * Retrieves the delegation history from the Request * * @param request * @return the delegation history set (of resource types previously targeted by this Servlet) */ @SuppressWarnings("unchecked") private Set<String> getDelegationHistory(final SlingHttpServletRequest request) { Set<String> history = new HashSet<String>(); final Object tmp = request.getAttribute(REQUEST_ATTR_DELEGATION_HISTORY); if(history.getClass().isInstance(tmp)) { return (Set<String>)tmp; } else { return history; } }
private boolean isFirstInChain(final SlingHttpServletRequest request) { if (request.getAttribute(REQ_ATTR_PREVIOUSLY_PROCESSED) != null) { return false; } else { request.setAttribute(REQ_ATTR_PREVIOUSLY_PROCESSED, true); return true; } }
/** * Get the versioning configuration. * @param request The http request * @return The versioning configuration */ protected VersioningConfiguration getVersioningConfiguration(SlingHttpServletRequest request) { VersioningConfiguration versionableConfiguration = (VersioningConfiguration) request.getAttribute(VersioningConfiguration.class.getName()); return versionableConfiguration != null ? versionableConfiguration : new VersioningConfiguration(); }
private boolean isFirstInChain(final SlingHttpServletRequest request) { if (request.getAttribute(REQ_ATTR_PREVIOUSLY_PROCESSED) != null) { return false; } else { request.setAttribute(REQ_ATTR_PREVIOUSLY_PROCESSED, true); return true; } }
/** * Get the versioning configuration. * @param request The http request * @return The versioning configuration */ protected VersioningConfiguration getVersioningConfiguration(final SlingHttpServletRequest request) { VersioningConfiguration versionableConfiguration = (VersioningConfiguration) request.getAttribute(VersioningConfiguration.class.getName()); return versionableConfiguration != null ? versionableConfiguration : new VersioningConfiguration(); }
SlingHttpServletRequest request = ...; SlingBindings bindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName()); SlingScriptHelper sling = bindings.getSling(); // here you can use your JSP code
public String getHello() { return (String) getRequest().getAttribute("hello"); }
protected boolean accepts(SlingHttpServletRequest request) { if (request.getAttribute(REQ_ATTR) != null) { // Cyclic loop log.warn("Identified a cyclic loop in the ACS Commons CQ Include Namespace prefix Servlet for [ {} ]", request.getRequestURI()); return false; } for (int i = 0; i <= NAME_PROPERTY_SELECTOR_INDEX; i++) { if (StringUtils.isBlank(PathInfoUtil.getSelector(request, i))) { // Missing necessary selectors; the first N - 1 should be redundant since the selectors are specified // in the Servlet registration return false; } } return true; }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof SlingHttpServletRequest) { SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request; if (ArrayUtils.contains(VALID_METHODS, slingRequest.getMethod())) { Object editEnabled = slingRequest.getAttribute(CMSConstants.ATTR_EDIT_ENABLED); if (!"true".equals(editEnabled) && !CMSUtils.isPublished(slingRequest.getResource())) { ((HttpServletResponse) response).sendError(404); return; } } } chain.doFilter(request, response); }
/** * Gets or sets and gets the original WCMMode for the Request. * * @param request the Request * @return the original WCMMode for the Request */ private WCMMode getOrSetFirstWCMMode(final SlingHttpServletRequest request) { WCMMode wcmMode = (WCMMode) request.getAttribute(ATTR_FILTER); if (wcmMode == null) { wcmMode = WCMMode.fromRequest(request); request.setAttribute(ATTR_FILTER, wcmMode); } return wcmMode; }
/** * Gets or sets and gets the original WCMMode for the Request. * * @param request the Request * @return the original WCMMode for the Request */ private WCMMode getOrSetFirstWCMMode(final SlingHttpServletRequest request) { WCMMode wcmMode = (WCMMode) request.getAttribute(ATTR_FILTER); if (wcmMode == null) { wcmMode = WCMMode.fromRequest(request); request.setAttribute(ATTR_FILTER, wcmMode); } return wcmMode; }
public List<Tag> getTags() { TagManager tagMgr = request.getResourceResolver().adaptTo(TagManager.class); Resource resource = (Resource) request.getAttribute("result"); log.debug("Loading tags from {}@{}", resource.getPath(), property); List<Tag> tags = new ArrayList<Tag>(); String[] values = resource.getValueMap().get(property, String[].class); if (values != null) { for (String value : values) { tags.add(tagMgr.resolve(value)); } } log.debug("Loaded {} tags", tags.size()); return tags; } }
@Override public final Form getForm(final String formName, final SlingHttpServletRequest request) { if (this.doHandlePost(formName, request)) { // Read the request from the POST parameters return this.getPostForm(formName, request); } else { final String key = this.getLookupKey(formName); final Object obj = request.getAttribute(key); if (obj instanceof Form) { return this.getProtectedForm((Form) obj); } else { log.info("Unable to find Form in Request attribute: [ {} => {} ]", key, obj); return new FormImpl(formName, request.getResource().getPath()); } } }