@Override
  protected ModelAndView onSubmit(
      HttpServletRequest request,
      HttpServletResponse response,
      Object command,
      BindException errors)
      throws Exception {
    logger.debug("onSubmit - START");
    // used as a container for info/error messages
    ArrayList<String> infoMessages = new ArrayList<String>();
    ArrayList<String> errorMessages = new ArrayList<String>();

    ModelAndView mav = new ModelAndView(IConstant.FORM_VIEW_MESSAGES);

    try {
      boolean isDeleteAction = false;

      // check if i have deleteAll action
      if (request.getParameter(ACTION) != null && DELETEALL.equals(request.getParameter(ACTION))) {
        handleDeleteAll(request, command, infoMessages, errorMessages);
        isDeleteAction = true;
      }
      if (request.getParameter(ACTION) != null && PAGINATION.equals(request.getParameter(ACTION))) {
        mav = handlePagination(request, errorMessages, command);
      } else {
        mav = handleSearch(request, command, errorMessages, isDeleteAction);
      }
    } catch (BusinessException bexc) {
      logger.error(bexc.getMessage(), bexc);
      errorMessages.add(
          messageSource.getMessage(
              SEARCH_ERROR,
              new Object[] {
                bexc.getCode(), ControllerUtils.getInstance().getFormattedCurrentTime()
              },
              RequestContextUtils.getLocale(request)));
    } catch (Exception e) {
      logger.error("", e);
      errorMessages.add(
          messageSource.getMessage(
              SEARCH_EXCEPTION_ERROR,
              new Object[] {ControllerUtils.getInstance().getFormattedCurrentTime()},
              RequestContextUtils.getLocale(request)));
    }

    // setting all messages on response
    setErrors(request, errorMessages);
    setMessages(request, infoMessages);

    mav.addAllObjects(referenceData(request, command, errors));
    logger.debug("onSubmit - END");
    return mav;
  }
  @ModelAttribute
  public void frontUrl(ModelMap model, HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    // model.addAttribute("frontUrl", request.getContextPath() + "/resources");
    userLoad(model);
    model.addAttribute("frontUrl", request.getContextPath() + "/resources");
    // System.out.println("xDamsController.frontUrl() multiAccount: " + multiAccount);
    // System.out.println("xDamsController.frontUrl() model.get(\"userBean\"): " +
    // model.get("userBean"));
    if (multiAccount && model.get("userBean") != null) {
      model.addAttribute(
          "frontUrl",
          request.getContextPath()
              + "/resources/"
              + ((UserBean) model.get("userBean")).getAccountRef());
    }

    // System.out.println("xDamsController.frontUrl() model.get(\"frontUrl\"): " +
    // model.get("frontUrl"));
    model.addAttribute("contextPath", request.getContextPath());
    String userAgent = ((HttpServletRequest) request).getHeader("User-Agent");
    if (userAgent.toLowerCase().contains("msie")) {
      response.addHeader("X-UA-Compatible", "IE=edge");
    }

    try {
      Locale locale = RequestContextUtils.getLocale(request);
      ((UserBean) model.get("userBean")).setLanguage(locale.getLanguage());
    } catch (Exception e) {
      // TODO: handle exception
    }
    model.put("realPath", WebUtils.getRealPath(servletContext, ""));
  }
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
      throws ServletException {
    boolean result = super.preHandle(request, response, handler);

    ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(request);

    String newTheme = themeResolver.resolveThemeName(request);

    if (!validThemes.contains(newTheme)) {
      // not found.
      logger.error("Invalid theme passed in: " + newTheme);
      try {
        response.sendRedirect("accessDenied.jsp");

        return false;
      } catch (IOException e) {
        throw new ServletException("Could not redirect to accessDenied page.", e);
      }
    } else if (request.getParameter(this.paramName) != null) {
      // found.  redirect to page without "param=.." extension.
      logger.warn("New theme set: " + newTheme + ".  Redirecting to login.htm");
      try {
        response.sendRedirect("login.htm");
      } catch (IOException e) {
        throw new ServletException("Could not redirect to login page.", e);
      }
    }

    return result;
  }
Exemple #4
0
  /**
   * Expose the tool attributes, according to corresponding bean property settings.
   *
   * <p>Do not override this method unless for further tools driven by bean properties. Override one
   * of the <code>exposeHelpers</code> methods to add custom helpers.
   *
   * @param velocityContext Velocity context that will be passed to the template
   * @param request current HTTP request
   * @throws Exception if there's a fatal error while we're adding model attributes
   * @see #setVelocityFormatterAttribute
   * @see #setDateToolAttribute
   * @see #setNumberToolAttribute
   * @see #exposeHelpers(Map, HttpServletRequest)
   * @see #exposeHelpers(org.apache.velocity.context.Context, HttpServletRequest,
   *     HttpServletResponse)
   */
  protected void exposeToolAttributes(Context velocityContext, HttpServletRequest request)
      throws Exception {
    // Expose generic attributes.
    if (this.toolAttributes != null) {
      for (Iterator it = this.toolAttributes.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry entry = (Map.Entry) it.next();
        String attributeName = (String) entry.getKey();
        Class toolClass = (Class) entry.getValue();
        try {
          Object tool = toolClass.newInstance();
          initTool(tool, velocityContext);
          velocityContext.put(attributeName, tool);
        } catch (Exception ex) {
          throw new NestedServletException(
              "Could not instantiate Velocity tool '" + attributeName + "'", ex);
        }
      }
    }

    // Expose VelocityFormatter attribute.
    if (this.velocityFormatterAttribute != null) {
      velocityContext.put(this.velocityFormatterAttribute, new VelocityFormatter(velocityContext));
    }

    // Expose locale-aware DateTool/NumberTool attributes.
    if (this.dateToolAttribute != null || this.numberToolAttribute != null) {
      Locale locale = RequestContextUtils.getLocale(request);
      if (this.dateToolAttribute != null) {
        velocityContext.put(this.dateToolAttribute, new LocaleAwareDateTool(locale));
      }
      if (this.numberToolAttribute != null) {
        velocityContext.put(this.numberToolAttribute, new LocaleAwareNumberTool(locale));
      }
    }
  }
  @Override
  public ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    String pathInfo = request.getPathInfo();
    String model = parseModelName(request);

    Locale locale = RequestContextUtils.getLocale(request);
    IModelEditor editor = sahaProjectRegistry.getModelEditor(model);
    IModelReader reader = sahaProjectRegistry.getModelReader(model);
    IConfigService config = sahaProjectRegistry.getConfig(model);
    String view = parseViewName(pathInfo);
    if (editor != null || view.equals("saha3/manage")) {
      ModelAndView mav = new ModelAndView(view);
      mav.addObject("model", model);
      mav.addObject("lang", locale.getLanguage());
      if (config != null) {
        mav.addObject("aboutLink", config.getAboutLink());
        mav.addObject("helpText", SahaHelpManager.getHelpString(view));
      }
      return handleRequest(request, response, reader, editor, config, locale, mav);
    } else {
      response.sendRedirect("manage.shtml?model=" + URLEncoder.encode(model, "UTF-8"));
      return null;
      /*			ModelAndView mav = new ModelAndView(SAHA_TEMPLATE_BASE + "/manage");
      mav.addObject("sparqlConfiguration", sahaProjectRegistry.getSPARQLConfig(model));
      mav.addObject("model", model);
      mav.addObject("lang", locale.getLanguage());
      return mav; */
    }
  }
 /**
  * Utility method for creating a GrailsDataBinder instance
  *
  * @param target The target object to bind to
  * @param objectName The name of the object
  * @param request A request instance
  * @return A GrailsDataBinder instance
  */
 public static GrailsDataBinder createBinder(
     Object target, String objectName, HttpServletRequest request) {
   GrailsDataBinder binder = createBinder(target, objectName);
   Locale locale = RequestContextUtils.getLocale(request);
   registerCustomEditors(binder, locale);
   return binder;
 }
  @Override
  protected ModelAndView onSubmit(
      HttpServletRequest request,
      HttpServletResponse response,
      Object command,
      BindException errors)
      throws Exception {
    logger.debug("onSubmit - START");
    ModelAndView mav = new ModelAndView(IConstant.FORM_VIEW_MESSAGES);
    Currency currency = (Currency) command;

    Locale locale = RequestContextUtils.getLocale(request);
    ArrayList<String> errorMessages = new ArrayList<String>();
    ArrayList<String> infoMessages = new ArrayList<String>();

    // check if the currency has a currencyId
    if (currency.getCurrencyId() != -1) {
      // if I have currencyId, it means that I have "update" action
      logger.debug("onSubmit - handleUpdate");
      mav = handleUpdate(currency, request, locale, errorMessages, infoMessages);
    } else {
      // if I don't have currency, it means that I have "add" action
      logger.debug("onSubmit - handleAdd");
      mav = handleAdd(currency, request, locale, errorMessages, infoMessages);
    }

    setErrors(request, errorMessages);
    setMessages(request, infoMessages);

    mav.addAllObjects(referenceData(request, currency, errors));
    logger.debug("onSubmit - END");
    return mav;
  }
  @Override
  protected ModelAndView onSubmit(
      final HttpServletRequest request,
      final HttpServletResponse response,
      final Object command,
      final BindException errors)
      throws Exception {

    final TrackCommand trackCommand = (TrackCommand) command;
    final String trackingIdString = trackCommand.getTrackingId();
    final Cargo cargo = trackingService.track(new TrackingId(trackingIdString));

    final Map<String, CargoTrackingViewAdapter> model = new HashMap();
    if (cargo != null) {
      final MessageSource messageSource = getApplicationContext();
      final Locale locale = RequestContextUtils.getLocale(request);
      model.put("cargo", new CargoTrackingViewAdapter(cargo, messageSource, locale));
    } else {
      errors.rejectValue(
          "trackingId",
          "cargo.unknown_id",
          new Object[] {trackCommand.getTrackingId()},
          "Unknown tracking id");
    }
    return showForm(request, response, errors, model);
  }
 @RequestMapping(value = "/changeLang", method = RequestMethod.GET)
 public String changeLocale(
     @RequestParam String language, HttpServletRequest req, HttpServletResponse resp) {
   LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(req);
   localeResolver.setLocale(req, resp, StringUtils.parseLocaleString(language));
   return "redirect:/";
 }
Exemple #10
0
  protected void processAjaxRequest(
      Form form, HttpServletRequest request, HttpServletResponse response) throws IOException {

    AjaxResponse ajaxResponse = new AjaxResponse(response);
    if (form != null) {
      form.getFormContext().setWriter(response.getWriter());
      form.setFormListener(ajaxResponse);
      if (isEventRequest(request)) {
        processEventRequest(form, request);
      } else {
        processForm(form, request);
      }
      form.setFormListener(null);
    } else {
      String message =
          messageSource.getMessage(
              "error.sessionExpired",
              null,
              "Your session has expired",
              RequestContextUtils.getLocale(request));

      ajaxResponse.alert(message);
    }
    ajaxResponse.close();
  }
Exemple #11
0
 protected String getMessage(String code, Object[] args) {
   HttpServletRequest request =
       ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
   LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
   Locale locale = localeResolver.resolveLocale(request);
   return getRes().getMessage(code, args, locale);
 }
  @Override
  protected Object formBackingObject(HttpServletRequest request) throws Exception {
    logger.debug("formBackingObject - START");

    // used as a container for info/error messages
    ArrayList<String> errorMessages = new ArrayList<String>();

    Currency currency = null;

    try {
      // check if i have to edit the currency
      if (ServletRequestUtils.getIntParameter(request, ID) != null
          && ServletRequestUtils.getStringParameter(request, IConstant.REQ_ACTION) != null
          && IConstant.CMD_GET.equals(
              ServletRequestUtils.getStringParameter(request, IConstant.REQ_ACTION))) {
        logger.debug("formBackingObject: GET");

        // get the currency with the specified currencyId
        currency =
            handleGet(
                ServletRequestUtils.getIntParameter(request, ID).intValue(),
                errorMessages,
                request);
        if (currency == null) {
          currency = new Currency();
        }
      } else {
        logger.debug("formBackingObject: ADD");
        currency = new Currency();

        // setting the organizationId for the new record
        Integer organizationId =
            (Integer) ControllerUtils.getInstance().getOrganisationIdFromSession(request);
        if (organizationId != null) {
          currency.setOrganizationId(organizationId);
        }
      }

      // if the view will be rendered in a panel we display only some fields
      request.setAttribute(GET_FROM_PANEL, request.getParameter(GET_FROM_PANEL));
      request.setAttribute(FROM_EXCHANGE, request.getParameter(FROM_EXCHANGE));
      request.setAttribute(FROM_COST_SHEET, request.getParameter(FROM_COST_SHEET));
      request.setAttribute(FROM_TEAM_MEMBER_DETAIL, request.getParameter(FROM_TEAM_MEMBER_DETAIL));
      request.setAttribute(FROM_PERSON_DETAIL, request.getParameter(FROM_PERSON_DETAIL));
      request.setAttribute(FROM_PROJECT_DETAIL, request.getParameter(FROM_PROJECT_DETAIL));
      request.setAttribute(FROM_ACTIVITY_PANEL, request.getParameter(FROM_ACTIVITY_PANEL));

    } catch (Exception e) {
      logger.error("formBackingObject", e);
      errorMessages.add(
          messageSource.getMessage(
              GET_ERROR,
              new Object[] {null, ControllerUtils.getInstance().getFormattedCurrentTime()},
              RequestContextUtils.getLocale(request)));
    }

    logger.debug("formBackingObject - END");
    return currency;
  }
  /**
   * Handles the return from a multi-value lookup, processing any select line values and invoking
   * the configured view helper service to create the lines for those values in the model
   * collection.
   *
   * <p>There are two supported strategies for returning the selected lines. One, if the lookup view
   * and the caller are within the same application container, Springs input flash map is used. If
   * however, the lookup view is outside the caller, then just a standard request parameter is used.
   *
   * @param form form instance containing the model data
   * @param request http request object being handled
   */
  protected void processMultiValueReturn(final UifFormBase form, HttpServletRequest request) {
    final String lookupCollectionId = request.getParameter(UifParameters.LOOKUP_COLLECTION_ID);

    final String lookupCollectionName = request.getParameter(UifParameters.LOOKUP_COLLECTION_NAME);
    if (StringUtils.isBlank(lookupCollectionName)) {
      throw new RuntimeException(
          "Lookup collection name is required for processing multi-value lookup results");
    }

    final String multiValueReturnFields =
        request.getParameter(UifParameters.MULIT_VALUE_RETURN_FILEDS);
    String selectedLineValuesParam = request.getParameter(UifParameters.SELECTED_LINE_VALUES);

    String flashMapSelectedLineValues = "";
    if (RequestContextUtils.getInputFlashMap(request) != null) {
      flashMapSelectedLineValues =
          (String)
              RequestContextUtils.getInputFlashMap(request).get(UifParameters.SELECTED_LINE_VALUES);
    }

    if (!StringUtils.isBlank(flashMapSelectedLineValues)) {
      selectedLineValuesParam = flashMapSelectedLineValues;
    }

    final String selectedLineValues = selectedLineValuesParam;

    Runnable runnable =
        new Runnable() {
          @Override
          public void run() {
            // invoked view helper to populate the collection from lookup results
            ViewLifecycle.getHelper()
                .processMultipleValueLookupResults(
                    form,
                    lookupCollectionId,
                    lookupCollectionName,
                    multiValueReturnFields,
                    selectedLineValues);
          }
        };

    ViewLifecycle.encapsulateLifecycle(
        form.getView(), form, form.getViewPostMetadata(), null, request, runnable);
  }
 @Override
 protected ModelAndView handleRequestInternal(
     HttpServletRequest request, HttpServletResponse response) throws Exception {
   OutputStream out = response.getOutputStream();
   response.setContentType("text/javascript");
   byte[] buffer = getContents(RequestContextUtils.getLocale(request));
   out.write(buffer);
   out.close();
   return null;
 }
Exemple #15
0
 @RequestMapping(value = "/canviaIdioma", method = RequestMethod.GET)
 public String canviaIdioma(
     @RequestParam String idioma,
     HttpServletRequest request,
     HttpSession session,
     HttpServletResponse response) {
   LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
   localeResolver.setLocale(request, response, new Locale(idioma));
   session.setAttribute("data", obtenirData(localeResolver.resolveLocale(request)));
   return "redirect:/";
 }
  @RequestMapping(value = "/mainpage", method = RequestMethod.GET)
  public String goMainPage(HttpServletRequest request) {

    Map<String, ?> map = RequestContextUtils.getInputFlashMap(request);
    if (map != null) {
      logger.info("redirect!");
    } else {
      logger.info("update!");
    }

    return "main";
  }
  protected String parseValue(
      HttpServletRequest request, HttpServletResponse response, String control) {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("user", SecurityUtils.getLoginUser());
    model.putAll(SecurityUtils.getShiroUser().getAttributes());

    WebApplicationContext context = RequestContextUtils.getWebApplicationContext(request);
    SimpleHash simpleHash =
        freeMarkerParse.buildTemplateModel(model, context.getServletContext(), request, response);

    return freeMarkerParse.renderString(control, simpleHash);
  }
 /**
  * Obtains the PropertyEditorRegistry instance.
  *
  * @return The PropertyEditorRegistry
  */
 public PropertyEditorRegistry getPropertyEditorRegistry() {
   final HttpServletRequest servletRequest = getCurrentRequest();
   PropertyEditorRegistry registry =
       (PropertyEditorRegistry)
           servletRequest.getAttribute(GrailsApplicationAttributes.PROPERTY_REGISTRY);
   if (registry == null) {
     registry = new PropertyEditorRegistrySupport();
     GrailsDataBinder.registerCustomEditors(
         this, registry, RequestContextUtils.getLocale(servletRequest));
     servletRequest.setAttribute(GrailsApplicationAttributes.PROPERTY_REGISTRY, registry);
   }
   return registry;
 }
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {
    logger.debug("handleRequestInternal - START ");

    // used as a container for error messages
    ArrayList<String> errorMessages = new ArrayList<String>();

    ModelAndView mav = new ModelAndView(getView());

    // the user that logs in
    UserAuth userAuth =
        (UserAuth) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

    // adding to model the time unit nomenclator
    mav.addObject(IConstant.NOM_TIME_UNIT, TSContext.getFromContext(IConstant.NOM_TIME_UNIT));

    try {
      // add the organization available currencies
      List<Currency> currencies =
          BLCurrency.getInstance().getByOrganizationId(userAuth.getOrganisationId());
      if (currencies != null && currencies.size() > 0) {
        List<IntString> nomCurrencies = new ArrayList<IntString>();
        for (Currency currency : currencies) {
          IntString entry = new IntString();
          entry.setValue(currency.getCurrencyId());
          entry.setLabel(currency.getName());
          nomCurrencies.add(entry);
        }
        mav.addObject(ORG_CURRENCIES, nomCurrencies);
      }

      // if the view will be rendered in a panel we display only some fields
      request.setAttribute(GET_FROM_PANEL, request.getParameter(GET_FROM_PANEL));

    } catch (BusinessException bexc) {
      logger.error(bexc.getMessage(), bexc);
      errorMessages.add(
          messageSource.getMessage(
              GET_ORG_CURRENCIES_ERROR,
              new Object[] {
                bexc.getCode(), ControllerUtils.getInstance().getFormattedCurrentTime()
              },
              RequestContextUtils.getLocale(request)));
    }

    setErrors(request, errorMessages);

    logger.debug("handleRequestInternal - END ");

    return mav;
  }
 /**
  * 此方法描述的是:
  *
  * @author: zhangjh
  * @version: 2015年4月29日 下午5:35:09
  */
 @RequestMapping(value = "/edit", method = RequestMethod.POST)
 @ResponseBody
 public Map<String, Object> edit(
     BondingLaminationCoatingInfo areaInfo,
     HttpServletRequest request,
     HttpServletResponse respones) {
   bondingLaminationCoatingService.edit(areaInfo);
   ApplicationContext appContext = RequestContextUtils.getWebApplicationContext(request);
   BondingLaminationCoatingServiceHelper.SINGLETONE.refreshSelect(appContext);
   Map<String, Object> resultMap = new HashMap<String, Object>();
   resultMap.put("code", "0");
   resultMap.put("message", "更新成功");
   return resultMap;
 }
  /**
   * Convert model to request parameters and redirect to the given URL.
   *
   * @see #appendQueryProperties
   * @see #sendRedirect
   */
  @Override
  protected void renderMergedOutputModel(
      Map<String, Object> model, HttpServletRequest request, HttpServletResponse response)
      throws IOException {

    String targetUrl = createTargetUrl(model, request);

    FlashMap flashMap = RequestContextUtils.getOutputFlashMap(request);
    if (!CollectionUtils.isEmpty(flashMap)) {
      String targetPath = WebUtils.extractUrlPath(targetUrl.toString());
      flashMap.setTargetRequestPath(targetPath);
      if (this.exposeModelAttributes) {
        flashMap.addTargetRequestParams(model);
      }
    }

    sendRedirect(request, response, targetUrl.toString(), this.http10Compatible);
  }
  /**
   * Gets a Currency with all its components
   *
   * @author Coni
   * @param currencyId
   * @param errorMessages
   * @param request
   * @return
   */
  public Currency handleGet(
      int currencyId, ArrayList<String> errorMessages, HttpServletRequest request) {
    logger.debug("handleGet - START");
    Currency currency = null;
    try {
      currency = BLCurrency.getInstance().getAll(currencyId);
    } catch (BusinessException be) {
      logger.error("handleGet", be);
      errorMessages.add(
          messageSource.getMessage(
              GET_ERROR,
              new Object[] {be.getCode(), ControllerUtils.getInstance().getFormattedCurrentTime()},
              RequestContextUtils.getLocale(request)));
    }

    logger.debug("handleGet - START");
    return currency;
  }
  /**
   * Adds to model required nomenclators
   *
   * @author Coni
   */
  @SuppressWarnings("unchecked")
  protected Map referenceData(HttpServletRequest request, Object command, Errors errors)
      throws Exception {
    logger.debug("referenceData - start");
    Map model = new HashMap();
    ArrayList<String> errorMessages = new ArrayList<String>();

    try {
      // adding to model the action from the request
      String action = ServletRequestUtils.getStringParameter(request, IConstant.REQ_ACTION);
      model.put(IConstant.REQ_ACTION, action);

      // put the back url
      String backUrl = ServletRequestUtils.getStringParameter(request, BACK_URL);

      String servletPath = request.getServletPath();
      String nextBackUrl =
          URLEncoder.encode(
              servletPath
                  .substring(1, servletPath.length())
                  .concat("?")
                  .concat(request.getQueryString()),
              "UTF-8");

      logger.debug("BACK_URL = " + backUrl);
      logger.debug("NEXT_BACK_URL = " + nextBackUrl);

      model.put(BACK_URL, backUrl);
      model.put(NEXT_BACK_URL, nextBackUrl);
      if (backUrl != null) {
        model.put(ENCODE_BACK_URL, URLEncoder.encode(backUrl, "UTF-8"));
      }
    } catch (Exception e) {
      logger.error("referenceData", e);
      errorMessages.add(
          messageSource.getMessage(
              GENERAL_ERROR,
              new Object[] {null, ControllerUtils.getInstance().getFormattedCurrentTime()},
              RequestContextUtils.getLocale(request)));
    }
    setErrors(request, errorMessages);
    logger.debug("referenceData - end");
    return model;
  }
 /**
  * 此方法描述的是:
  *
  * @author: zhangjh
  * @version: 2015年4月29日 下午5:35:09
  */
 @RequestMapping(value = "/new", method = RequestMethod.POST)
 @ResponseBody
 public Map<String, Object> add(
     BondingLaminationCoatingInfo areaInfo,
     HttpServletRequest request,
     HttpServletResponse reareaonse) {
   String currentNo = bondingLaminationCoatingService.queryCurrentSeqNo();
   // 设置ID
   areaInfo.setNatrualkey(
       BuildSeqNoHelper.SINGLETONE.getNextSeqNo(
           TableNameConstant.BLC_INFO, currentNo, incrementNumber));
   bondingLaminationCoatingService.add(areaInfo);
   ApplicationContext appContext = RequestContextUtils.getWebApplicationContext(request);
   BondingLaminationCoatingServiceHelper.SINGLETONE.refreshSelect(appContext);
   Map<String, Object> resultMap = new HashMap<String, Object>();
   resultMap.put("code", "0");
   resultMap.put("message", "新增成功");
   return resultMap;
 }
 /** {@inheritDoc} */
 @Override
 public boolean preHandle(
     final HttpServletRequest request, final HttpServletResponse response, final Object handler)
     throws ServletException {
   String newLocale = request.getParameter(this.paramName);
   if (newLocale != null) {
     final LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
     if (localeResolver == null) {
       throw new IllegalStateException(
           "No LocaleResolver found: not in a DispatcherServlet request?");
     }
     if (!acceptedLocales.contains(newLocale)) {
       newLocale = getDefaultLocale();
     }
     if (!request.getLocale().getLanguage().equals(new Locale(newLocale).getLanguage()))
       LOGGER.info("Switching to new Locale: " + newLocale);
     localeResolver.setLocale(request, response, StringUtils.parseLocaleString(newLocale));
   }
   // Proceed in any case.
   return true;
 }
Exemple #26
0
  @Override
  protected void renderMergedOutputModel(
      Map<String, Object> model, HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    setTimeZoneForDateTimeFilter();

    String templateFile = getServletContext().getRealPath(getUrl());
    {
      // ThemeResolver themeResolver = RequestContextUtils
      // .getThemeResolver(request);
      // String theme = themeResolver.resolveThemeName(request);
      // if (logger.isDebugEnabled()) {
      // logger.debug("Current theme is " + theme);
      // }
      // templateFile = theme + File.separator + getUrl();
      // templateFile = getServletContext().getRealPath(templateFile);
    }
    Locale locale = RequestContextUtils.getLocale(request);
    response.setContentType(getContentType());
    engine.process(templateFile, model, response.getWriter(), locale);
  }
  public Object resolveArgument(
      MethodParameter parameter,
      ModelAndViewContainer mavContainer,
      NativeWebRequest webRequest,
      WebDataBinderFactory binderFactory)
      throws IOException {

    Class<?> paramType = parameter.getParameterType();
    if (WebRequest.class.isAssignableFrom(paramType)) {
      return webRequest;
    }

    HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
    if (ServletRequest.class.isAssignableFrom(paramType)
        || MultipartRequest.class.isAssignableFrom(paramType)) {
      Object nativeRequest = webRequest.getNativeRequest(paramType);
      if (nativeRequest == null) {
        throw new IllegalStateException(
            "Current request is not of type [" + paramType.getName() + "]: " + request);
      }
      return nativeRequest;
    } else if (HttpSession.class.isAssignableFrom(paramType)) {
      return request.getSession();
    } else if (Principal.class.isAssignableFrom(paramType)) {
      return request.getUserPrincipal();
    } else if (Locale.class.equals(paramType)) {
      return RequestContextUtils.getLocale(request);
    } else if (InputStream.class.isAssignableFrom(paramType)) {
      return request.getInputStream();
    } else if (Reader.class.isAssignableFrom(paramType)) {
      return request.getReader();
    } else {
      // should never happen..
      Method method = parameter.getMethod();
      throw new UnsupportedOperationException(
          "Unknown parameter type: " + paramType + " in method: " + method);
    }
  }
 @Override
 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
     throws ServletException, EuropeanaQueryException {
   Language oldLocale = ControllerUtil.getLocale(request);
   String newLocale = request.getParameter(this.paramName);
   if (newLocale != null) {
     if (newLocale.contains("*")) {
       throw new EuropeanaQueryException(QueryProblem.UNABLE_TO_CHANGE_LANGUAGE.toString());
     }
     LocaleResolver localeResolver = RequestContextUtils.getLocaleResolver(request);
     if (localeResolver == null) {
       throw new IllegalStateException(
           "No LocaleResolver found: not in a DispatcherServlet request?");
     }
     LocaleEditor localeEditor = new LocaleEditor();
     localeEditor.setAsText(newLocale);
     localeResolver.setLocale(request, response, (Locale) localeEditor.getValue());
     clickStreamLogger.logLanguageChange(
         request, oldLocale, ClickStreamLogger.UserAction.LANGUAGE_CHANGE);
   }
   // Proceed in any case.
   return true;
 }
Exemple #29
0
  /** @return A found BeanFactory configuration */
  private BeanFactory getBeanFactory() {
    // If someone has set a resource name then we need to load that.
    if (configLocation != null && configLocation.length > 0) {
      log.info(
          "Spring BeanFactory via ClassPathXmlApplicationContext using "
              + configLocation.length
              + "configLocations.");
      return new ClassPathXmlApplicationContext(configLocation);
    }

    ServletContext srvCtx = ServerContextFactory.get().getServletContext();

    HttpServletRequest request = null;
    try {
      request = WebContextFactory.get().getHttpServletRequest();
    } catch (Exception ex) {
      // Probably on boot time
    }

    return request != null
        ? RequestContextUtils.getWebApplicationContext(request, srvCtx)
        : WebApplicationContextUtils.getWebApplicationContext(srvCtx);
  }
Exemple #30
0
 /**
  * Returns the Spring bean with name <code>beanName</code> and of type <code>beanClass</code>.
  *
  * @param <T> type of the bean
  * @param httpRequest the http request
  * @param beanName name of the bean
  * @param beanClass expected type of the bean
  * @return the bean matching the given arguments or <code>null</code> if no bean could be resolved
  */
 public static <T> T getSpringBean(
     final HttpServletRequest httpRequest, final String beanName, final Class<T> beanClass) {
   return RequestContextUtils.getWebApplicationContext(
           httpRequest, httpRequest.getSession().getServletContext())
       .getBean(beanName, beanClass);
 }