List of usage examples for org.springframework.web.context WebApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:eu.earthobservatory.org.StrabonEndpoint.QueryBean.java
public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); // get the context of the servlet context = getServletContext();// ww w.j av a2 s. c o m // get the context of the application WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(context); // the the strabon wrapper strabonWrapper = (StrabonBeanWrapper) applicationContext.getBean("strabonBean"); // get the name of this web application appName = context.getContextPath().replace("/", ""); }
From source file:org.sakaiproject.metaobj.shared.control.XsltArtifactView.java
protected Source createXsltSource(Map map, String string, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { httpServletResponse.setContentType(getContentType()); WebApplicationContext context = getWebApplicationContext(); setUriResolver((URIResolver) context.getBean(uriResolverBeanName)); ToolSession toolSession = SessionManager.getCurrentToolSession(); String homeType = null;//from w w w . ja v a 2 s . c o m ElementBean bean = (ElementBean) map.get("bean"); Element root = null; Map paramsMap = new Hashtable(); for (Enumeration e = httpServletRequest.getParameterNames(); e.hasMoreElements();) { String k = e.nextElement().toString(); // Do not allow reserved parameter names to be overwritten if (!reservedParams.contains(k)) { paramsMap.put(k, httpServletRequest.getParameter(k)); } } httpServletRequest.setAttribute(STYLESHEET_PARAMS, paramsMap); if (toolSession.getAttribute(FormHelper.PREVIEW_HOME_TAG) != null) { paramsMap.put("preview", "true"); } if (toolSession.getAttribute(ResourceToolAction.ACTION_PIPE) != null) { paramsMap.put("fromResources", "true"); } if (httpServletRequest.getAttribute(FormHelper.URL_DECORATION) != null) { paramsMap.put("urlDecoration", httpServletRequest.getAttribute(FormHelper.URL_DECORATION)); } HashMap<String, String> xslParams = new HashMap<String, String>(); xslParams.put(FormHelper.XSL_PRESENTATION_ID, FormHelper.PRESENTATION_ID); xslParams.put(FormHelper.XSL_PRESENTATION_TYPE, FormHelper.PRESENTATION_TEMPLATE_ID); xslParams.put(FormHelper.XSL_PRESENTATION_ITEM_ID, FormHelper.PRESENTATION_ITEM_DEF_ID); xslParams.put(FormHelper.XSL_PRESENTATION_ITEM_NAME, FormHelper.PRESENTATION_ITEM_DEF_NAME); xslParams.put(FormHelper.XSL_FORM_TYPE, ResourceEditingHelper.CREATE_SUB_TYPE); xslParams.put(FormHelper.XSL_ARTIFACT_REFERENCE, ResourceEditingHelper.ATTACHMENT_ID); xslParams.put(FormHelper.XSL_OBJECT_ID, FormHelper.XSL_OBJECT_ID); xslParams.put(FormHelper.XSL_OBJECT_TITLE, FormHelper.XSL_OBJECT_TITLE); xslParams.put(FormHelper.XSL_WIZARD_PAGE_ID, FormHelper.XSL_WIZARD_PAGE_ID); // Load up our XSL parameters according to the mapping into the tool session above. // Note that this is not always one-to-one due to some string/key inconsistencies around the tools. for (Entry<String, String> item : xslParams.entrySet()) { Object val = toolSession.getAttribute(item.getValue()); if (val != null) { paramsMap.put(item.getKey(), val); } } Id id = null; if (bean instanceof Artifact) { root = getStructuredArtifactDefinitionManager().createFormViewXml((Artifact) bean, null); homeType = getHomeType((Artifact) bean); id = ((Artifact) bean).getId(); } else { EditedArtifactStorage sessionBean = (EditedArtifactStorage) httpServletRequest.getSession() .getAttribute(EditedArtifactStorage.EDITED_ARTIFACT_STORAGE_SESSION_KEY); if (sessionBean != null) { root = getStructuredArtifactDefinitionManager() .createFormViewXml((Artifact) sessionBean.getRootArtifact(), null); replaceNodes(root, bean, sessionBean); paramsMap.put("subForm", "true"); homeType = getHomeType(sessionBean.getRootArtifact()); id = sessionBean.getRootArtifact().getId(); } else { return new javax.xml.transform.dom.DOMSource(); } } if (id != null) { paramsMap.put("edit", "true"); paramsMap.put(FormHelper.XSL_ARTIFACT_ID, id.getValue()); } httpServletRequest.setAttribute(STYLESHEET_LOCATION, getStructuredArtifactDefinitionManager().getTransformer(homeType, readOnly)); Errors errors = BindingResultUtils.getBindingResult(map, "bean"); if (errors != null && errors.hasErrors()) { Element errorsElement = new Element("errors"); List errorsList = errors.getAllErrors(); for (Iterator i = errorsList.iterator(); i.hasNext();) { Element errorElement = new Element("error"); ObjectError error = (ObjectError) i.next(); if (error instanceof FieldError) { FieldError fieldError = (FieldError) error; errorElement.setAttribute("field", fieldError.getField()); Element rejectedValue = new Element("rejectedValue"); if (fieldError.getRejectedValue() != null) { rejectedValue.addContent(fieldError.getRejectedValue().toString()); } errorElement.addContent(rejectedValue); } Element message = new Element("message"); message.addContent(context.getMessage(error, getResourceLoader().getLocale())); errorElement.addContent(message); errorsElement.addContent(errorElement); } root.addContent(errorsElement); } if (httpServletRequest.getParameter("success") != null) { Element success = new Element("success"); success.setAttribute("messageKey", httpServletRequest.getParameter("success")); root.addContent(success); } if (toolSession.getAttribute(ResourceEditingHelper.CUSTOM_CSS) != null) { Element uri = new Element("uri"); uri.setText((String) toolSession.getAttribute(ResourceEditingHelper.CUSTOM_CSS)); root.getChild("css").addContent(uri); uri.setAttribute("order", "100"); } if (toolSession.getAttribute(FormHelper.FORM_STYLES) != null) { List styles = (List) toolSession.getAttribute(FormHelper.FORM_STYLES); int index = 101; for (Iterator<String> i = styles.iterator(); i.hasNext();) { Element uri = new Element("uri"); uri.setText(i.next()); root.getChild("css").addContent(uri); uri.setAttribute("order", "" + index); index++; } } Document doc = new Document(root); return new JDOMSource(doc); }
From source file:com.openmeap.services.ApplicationManagementServlet.java
/** * Pulls parameters out of the request and passes them to the ApplicationManagementPortType bean pulled from the WebApplicationContext * //from w w w. j a va 2 s . co m * @param req * @return */ public Result connectionOpenRequest(HttpServletRequest req) { WebApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); ConnectionOpenRequest request = createConnectionOpenRequest(req); Result result = new Result(); try { ConnectionOpenResponse response = ((ApplicationManagementService) context .getBean("applicationManagementService")).connectionOpen(request); result.setConnectionOpenResponse(response); } catch (WebServiceException wse) { Error err = new Error(); err.setCode(wse.getType().asErrorCode()); err.setMessage(wse.getMessage()); result.setError(err); } return result; }
From source file:com.agiletec.aps.tags.ExecWidgetTag.java
protected List<IFrameDecoratorContainer> extractDecorators() throws ApsSystemException { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); WebApplicationContext wac = ApsWebApplicationUtils.getWebApplicationContext(request); List<IFrameDecoratorContainer> containters = new ArrayList<IFrameDecoratorContainer>(); try {//from w ww . j a va 2 s . c om String[] beanNames = wac.getBeanNamesForType(IFrameDecoratorContainer.class); for (int i = 0; i < beanNames.length; i++) { IFrameDecoratorContainer container = (IFrameDecoratorContainer) wac.getBean(beanNames[i]); containters.add(container); } BeanComparator comparator = new BeanComparator("order"); Collections.sort(containters, comparator); } catch (Throwable t) { ApsSystemUtils.logThrowable(t, this, "extractDecorators", "Error extracting widget decorators"); throw new ApsSystemException("Error extracting widget decorators", t); } return containters; }
From source file:de.iai.ilcd.webgui.controller.ui.ProcessesSearchHandler.java
/** * Initialize the handler, get all lists that well be needed *//* w w w . j a v a 2s . co m*/ public ProcessesSearchHandler() { // Load all locations this.allLocations = new ArrayList<SelectItem>(); for (GeographicalArea geoArea : super.getDaoInstance().getAllLocations()) { this.allLocations.add(new SelectItem(geoArea.getAreaCode(), geoArea.getName())); } // Load all years for (Integer refYear : super.getDaoInstance().getReferenceYears()) { if (refYear != null) { this.referenceYears.add(new SelectItem(refYear.toString())); } } // get all types this.types = new ArrayList<SelectItem>(); for (TypeOfProcessValue o : TypeOfProcessValue.values()) { this.types.add(new SelectItem(o, o.value())); } // Load all classes for pick list List<String> allClassesSource = new ArrayList<String>(); List<String> allClassesTarget = new ArrayList<String>(); for (String topClassStr : super.getDaoInstance().getTopClasses()) { for (String subClassStr : super.getDaoInstance().getSubClasses(topClassStr, "1")) { allClassesSource.add(subClassStr); } } this.pickAllClasses = new DualListModel<String>(allClassesSource, allClassesTarget); WebApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()); this.registryService = ctx.getBean(RegistryService.class); }
From source file:no.dusken.common.plugin.velocity.RenderPluginDirective.java
private List<PluginManager<DuskenPlugin>> getPluginManagers(InternalContextAdapter context) { if (pluginManagers == null) { InternalContextAdapter ica = context.getBaseContext(); AbstractRefreshableWebApplicationContext webApplicationContext = (AbstractRefreshableWebApplicationContext) ica .get("org.springframework.web.servlet.DispatcherServlet.CONTEXT"); ServletContext sc = webApplicationContext.getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc); Map<String, PluginManager> beans = wac.getBeansOfType(PluginManager.class); pluginManagers = new LinkedList<PluginManager<DuskenPlugin>>(); //This do seem a bit strange. But I did not manage to get the casting right. for (String name : beans.keySet()) { PluginManager<DuskenPlugin> pluginManager = (PluginManager<DuskenPlugin>) wac.getBean(name); pluginManagers.add(pluginManager); }//from ww w . j av a 2 s .co m } return pluginManagers; }
From source file:net.naijatek.myalumni.util.taglib.BuildDropdownTag.java
/** * doStartTag/* w w w .j ava 2 s .c o m*/ * * @exception JspException * @return int */ public final int doStartTag() throws JspException { WebApplicationContext wac = WebApplicationContextUtils .getWebApplicationContext(pageContext.getServletContext()); xlatService = (IXlatService) wac.getBean(BaseConstants.SERVICE_XLAT_LOOKUP); memberService = (IMemberService) wac.getBean(BaseConstants.SERVICE_MEMBER_LOOKUP); systemConfigService = (ISystemConfigService) wac.getBean(BaseConstants.SERVICE_SYSTEM_CONFIG); return EVAL_BODY_BUFFERED; }
From source file:org.seamless_if.services.servlets.SchedulerServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); WebApplicationContext springContext = WebApplicationContextUtils .getWebApplicationContext(getServletContext()); schedulerDao = (SchedulerService) springContext.getBean("schedulerDao"); // TODO remove test code // create some sample model chains ModelChainInfoTO chainA = new ModelChainInfoTO(); chainA.setName("APES->FSSIM"); chainA.setVersion("1.0"); ModelChainInfoTO chainB = new ModelChainInfoTO(); chainB.setName("FSSIM<->CAPRI"); chainB.setVersion("1.1"); // create some sample workers WorkerTO workerA = new WorkerTO(); workerA.setName("WorkerA"); workerA.addAvailableModelChain(chainA); schedulerDao.registerWorker(workerA); WorkerTO workerB = new WorkerTO(); workerB.setName("WorkerB"); workerB.addAvailableModelChain(chainA); workerB.addAvailableModelChain(chainB); schedulerDao.registerWorker(workerB); // create some sample jobs JobTO jobA = new JobTO(); jobA.setExperimentId(1L);/*w w w.j ava 2 s .c om*/ jobA.setModelChain(chainA); schedulerDao.addJob(jobA); JobTO jobB = new JobTO(); jobB.setExperimentId(2L); jobB.setModelChain(chainB); schedulerDao.addJob(jobB); }
From source file:it.geosolutions.servicebox.ServiceBoxActionServlet.java
/** * Init method of the servlet. Don't forgot override it on the actions and * change the action name//from ww w .j a v a 2 s . c om */ public void init(ServletConfig servletConfig) throws ServletException { this.actionName = this.getClass().getSimpleName(); super.init(servletConfig); String appPropertyFile = getServletContext().getInitParameter(PROPERTY_FILE_PARAM); InputStream inputStream = ServiceBoxActionServlet.class.getResourceAsStream(appPropertyFile); try { properties.load(inputStream); ServletContext context = getServletContext(); WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context); String actionHandler = DEFAULT_ACTION_HANDLER; if (actionName != null && properties != null && properties.containsKey(actionName + "." + DEFAULT_ACTION_HANDLER)) { actionHandler = properties.getProperty(actionName + "." + DEFAULT_ACTION_HANDLER); } serviceBoxActionHandler = (ServiceBoxActionHandler) wac.getBean(actionHandler); initTemporalFolder(); } catch (IOException e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "Error encountered while processing properties file", e); } } finally { try { if (inputStream != null) inputStream.close(); } catch (IOException e) { if (LOGGER.isLoggable(Level.SEVERE)) LOGGER.log(Level.SEVERE, "Error building the action configuration ", e); throw new ServletException(e.getMessage()); } } }