List of usage examples for javax.servlet ServletContext getAttribute
public Object getAttribute(String name);
null
if there is no attribute by that name. From source file:org.hdiv.util.HDIVUtil.java
/** * Return the <code>LinkUrlProcessor</code> instance. * // w w w .j a va 2 s . c om * @param servletContext * {@link ServletContext} instance * @return {@link LinkUrlProcessor} instance */ public static LinkUrlProcessor getLinkUrlProcessor(ServletContext servletContext) { LinkUrlProcessor urlProcessor = (LinkUrlProcessor) servletContext .getAttribute(LINKURLPROCESSOR_SERVLETCONTEXT_KEY); if (urlProcessor == null) { throw new HDIVException("LinkUrlProcessor has not been initialized in servlet context"); } return urlProcessor; }
From source file:org.hdiv.util.HDIVUtil.java
/** * Return the <code>FormUrlProcessor</code> instance. * /*from w w w .j a va 2s . c o m*/ * @param servletContext * {@link ServletContext} instance * @return {@link FormUrlProcessor} instance */ public static FormUrlProcessor getFormUrlProcessor(ServletContext servletContext) { FormUrlProcessor urlProcessor = (FormUrlProcessor) servletContext .getAttribute(FORMURLPROCESSOR_SERVLETCONTEXT_KEY); if (urlProcessor == null) { throw new HDIVException("FormUrlProcessor has not been initialized in servlet context"); } return urlProcessor; }
From source file:com.googlecode.psiprobe.tools.ApplicationUtils.java
public static List getApplicationAttributes(Context context) { List attrs = new ArrayList(); ServletContext servletCtx = context.getServletContext(); for (Enumeration e = servletCtx.getAttributeNames(); e.hasMoreElements();) { String attrName = (String) e.nextElement(); Object attrValue = servletCtx.getAttribute(attrName); Attribute attr = new Attribute(); attr.setName(attrName);//from www . ja v a2 s .co m attr.setValue(attrValue); attr.setType(ClassUtils.getQualifiedName(attrValue.getClass())); attrs.add(attr); } return attrs; }
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.Authenticate.java
/** * The servlet context should contain a map from User URIs to * {@link HttpSession}s. Get a reference to it, creating it if necessary. *///from w w w. j a va 2s .c o m @SuppressWarnings("unchecked") public static Map<String, HttpSession> getUserURISessionMapFromContext(ServletContext ctx) { Map<String, HttpSession> m = (Map<String, HttpSession>) ctx.getAttribute(USER_SESSION_MAP_ATTR); if (m == null) { m = new HashMap<String, HttpSession>(); ctx.setAttribute(USER_SESSION_MAP_ATTR, m); } return m; }
From source file:org.apache.hive.http.HttpServer.java
/** * Checks the user has privileges to access to instrumentation servlets. * <p>/*from w w w . j av a 2 s . c o m*/ * If <code>hadoop.security.instrumentation.requires.admin</code> is set to FALSE * (default value) it always returns TRUE. * </p> * <p> * If <code>hadoop.security.instrumentation.requires.admin</code> is set to TRUE * it will check if the current user is in the admin ACLS. If the user is * in the admin ACLs it returns TRUE, otherwise it returns FALSE. * </p> * * @param servletContext the servlet context. * @param request the servlet request. * @param response the servlet response. * @return TRUE/FALSE based on the logic described above. */ @InterfaceAudience.LimitedPrivate("hive") public static boolean isInstrumentationAccessAllowed(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws IOException { Configuration conf = (Configuration) servletContext.getAttribute(CONF_CONTEXT_ATTRIBUTE); boolean access = true; boolean adminAccess = conf .getBoolean(CommonConfigurationKeys.HADOOP_SECURITY_INSTRUMENTATION_REQUIRES_ADMIN, false); if (adminAccess) { access = hasAdministratorAccess(servletContext, request, response); } return access; }
From source file:org.apache.ofbiz.widget.WidgetWorker.java
public static void buildHyperlinkUrl(Appendable externalWriter, String target, String targetType, Map<String, String> parameterMap, String prefix, boolean fullPath, boolean secure, boolean encode, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException { // We may get an encoded request like: /projectmgr/control/EditTaskContents?workEffortId=10003 // Try to reducing a possibly encoded string down to its simplest form: /projectmgr/control/EditTaskContents?workEffortId=10003 // This step make sure the following appending externalLoginKey operation to work correctly String localRequestName = StringEscapeUtils.unescapeHtml(target); localRequestName = UtilHttp.encodeAmpersands(localRequestName); Appendable localWriter = new StringWriter(); if ("intra-app".equals(targetType)) { if (request != null && response != null) { ServletContext servletContext = request.getSession().getServletContext(); RequestHandler rh = (RequestHandler) servletContext.getAttribute("_REQUEST_HANDLER_"); externalWriter/*w w w. j a v a 2s . c o m*/ .append(rh.makeLink(request, response, "/" + localRequestName, fullPath, secure, encode)); } else if (prefix != null) { externalWriter.append(prefix); externalWriter.append(localRequestName); } else { externalWriter.append(localRequestName); } } else if ("inter-app".equals(targetType)) { String fullTarget = localRequestName; localWriter.append(fullTarget); String externalLoginKey = (String) request.getAttribute("externalLoginKey"); if (UtilValidate.isNotEmpty(externalLoginKey)) { if (fullTarget.indexOf('?') == -1) { localWriter.append('?'); } else { localWriter.append("&"); } localWriter.append("externalLoginKey="); localWriter.append(externalLoginKey); } } else if ("content".equals(targetType)) { appendContentUrl(localWriter, localRequestName, request); } else if ("plain".equals(targetType)) { localWriter.append(localRequestName); } else { localWriter.append(localRequestName); } if (UtilValidate.isNotEmpty(parameterMap)) { String localUrl = localWriter.toString(); externalWriter.append(localUrl); boolean needsAmp = true; if (localUrl.indexOf('?') == -1) { externalWriter.append('?'); needsAmp = false; } for (Map.Entry<String, String> parameter : parameterMap.entrySet()) { String parameterValue = null; if (parameter.getValue() instanceof String) { parameterValue = parameter.getValue(); } else { Object parameterObject = parameter.getValue(); // skip null values if (parameterObject == null) continue; if (parameterObject instanceof String[]) { // it's probably a String[], just get the first value String[] parameterArray = (String[]) parameterObject; parameterValue = parameterArray[0]; Debug.logInfo("Found String array value for parameter [" + parameter.getKey() + "], using first value: " + parameterValue, module); } else { // not a String, and not a String[], just use toString parameterValue = parameterObject.toString(); } } if (needsAmp) { externalWriter.append("&"); } else { needsAmp = true; } externalWriter.append(parameter.getKey()); externalWriter.append('='); UtilCodec.SimpleEncoder simpleEncoder = (UtilCodec.SimpleEncoder) context.get("simpleEncoder"); if (simpleEncoder != null && parameterValue != null) { externalWriter.append(simpleEncoder .encode(URLEncoder.encode(parameterValue, Charset.forName("UTF-8").displayName()))); } else { externalWriter.append(parameterValue); } } } else { externalWriter.append(localWriter.toString()); } }
From source file:net.ontopia.topicmaps.webed.impl.utils.TagUtils.java
public static Map getSchemaRegistry(ServletContext servletContext) { Map schemas = (Map) servletContext.getAttribute(Constants.AA_SCHEMAS); if (schemas != null) return schemas; // Read in schemas for the topicmaps and provide them to the app context String schemasRootDir = servletContext.getInitParameter(Constants.SCTXT_SCHEMAS_ROOTDIR); if (schemasRootDir != null) schemasRootDir = servletContext.getRealPath(schemasRootDir); schemas = new HashMap(); if (schemasRootDir == null) { servletContext.setAttribute(Constants.AA_SCHEMAS, schemas); log.debug("No schema directory configured; registry empty"); return schemas; }/*from ww w .j a va 2 s.c om*/ log.debug("Reading schemas from " + schemasRootDir); TopicMapRepositoryIF repository = NavigatorUtils.getTopicMapRepository(servletContext); Collection refkeys = repository.getReferenceKeys(); Iterator iter = refkeys.iterator(); while (iter.hasNext()) { String refkey = (String) iter.next(); TopicMapReferenceIF reference = repository.getReferenceByKey(refkey); String tmid = reference.getId(); try { OSLSchemaReader reader = new OSLSchemaReader(new File(schemasRootDir, tmid + ".osl")); OSLSchema schema = (OSLSchema) reader.read(); schemas.put(tmid, schema); log.info("Loaded schema for " + tmid); } catch (java.io.IOException e) { log.info("Warning: " + e.getMessage()); } catch (SchemaSyntaxException e) { log.error("Schema syntax error: " + e.getMessage()); Locator loc = e.getErrorLocation(); log.error("Location: " + loc.getSystemId() + ":" + loc.getLineNumber() + ":" + loc.getColumnNumber() + "."); } } servletContext.setAttribute(Constants.AA_SCHEMAS, schemas); return schemas; }
From source file:org.apache.hive.http.HttpServer.java
/** * Does the user sending the HttpServletRequest have the administrator ACLs? If * it isn't the case, response will be modified to send an error to the user. * * @param servletContext//from www .j av a2 s . com * @param request * @param response used to send the error response if user does not have admin access. * @return true if admin-authorized, false otherwise * @throws IOException */ static boolean hasAdministratorAccess(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws IOException { Configuration conf = (Configuration) servletContext.getAttribute(CONF_CONTEXT_ATTRIBUTE); // If there is no authorization, anybody has administrator access. if (!conf.getBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, false)) { return true; } String remoteUser = request.getRemoteUser(); if (remoteUser == null) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthenticated users are not " + "authorized to access this page."); return false; } if (servletContext.getAttribute(ADMINS_ACL) != null && !userHasAdministratorAccess(servletContext, remoteUser)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "User " + remoteUser + " is unauthorized to access this page."); return false; } return true; }
From source file:org.apache.struts.validator.Resources.java
/** * Retrieve <code>ValidatorResources</code> for the current module. * * @param application Application Context * @param request The ServletRequest *//*from w ww .ja v a2 s.c o m*/ public static ValidatorResources getValidatorResources(ServletContext application, HttpServletRequest request) { String prefix = ModuleUtils.getInstance().getModuleConfig(request, application).getPrefix(); return (ValidatorResources) application.getAttribute(ValidatorPlugIn.VALIDATOR_KEY + prefix); }
From source file:org.apache.pluto.driver.services.container.EventProviderImpl.java
/** * factory method gets the EventProvider out of the Request, or sets a new * one//from w w w. ja va 2s . co m * * @param request * The {@link HttpServletRequest} of the EventProvider * @param response * The {@link HttpServletResponse} of the EventProvider * @return The corresponding EventProvierImpl instance */ public static EventProviderImpl getEventProviderImpl(HttpServletRequest request, PortletWindow portletWindow) { EventProviderImpl eventProvider = (EventProviderImpl) request.getAttribute(Constants.PROVIDER); if (eventProvider == null) { eventProvider = new EventProviderImpl(); eventProvider.request = request; PortalRequestContext context = PortalRequestContext.getContext(request); eventProvider.response = context.getResponse(); ServletContext servletContext = context.getServletContext(); eventProvider.container = (PortletContainer) servletContext .getAttribute(AttributeKeys.PORTLET_CONTAINER); request.setAttribute(Constants.PROVIDER, eventProvider); } try { eventProvider = (EventProviderImpl) eventProvider.clone(); } catch (CloneNotSupportedException e) { throw new IllegalStateException(e); } eventProvider.portletWindow = portletWindow; return eventProvider; }