コード例 #1
0
  /**
   * This method is called by the RequestProcessor immediately after populating the CustomerForm
   * only if the validate=true flag is set in the struts-config.xml Do validation here and return
   * ActionErrors if any, to the RequestProcessor
   */
  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();

    // Need to do this explicitly now. Since the Button is not grey and its name is not
    // org.apache.struts...Cancel anymore, and the validate=true still
    // remains in ActionMapping, the call to bypass validation on clicking cancel image
    // has to be performed manually
    if (getCancel().isSelected()) {
      return errors;
    }

    MessageResources msgRes = (MessageResources) request.getAttribute(Globals.MESSAGES_KEY);

    // Firstname cannot be empty
    if (firstName == null || firstName.trim().equals("")) {
      String firstName = msgRes.getMessage("prompt.customer.firstname");
      String[] rplcmntValueArr = {firstName};
      ActionError err = new ActionError("error.required", rplcmntValueArr);
      errors.add("firstName", err);
    }

    // Lastname cannot be empty
    if (lastName == null || lastName.trim().equals("")) {
      String lastName = msgRes.getMessage("prompt.customer.lastname");
      String[] rplcmntValueArr = {lastName};
      ActionError err = new ActionError("error.required", rplcmntValueArr);
      errors.add("lastName", err);
    }

    return errors;
  }
コード例 #2
0
ファイル: Ipk100Action.java プロジェクト: tmtkkwgch/hellogit
  /**
   * <br>
   * [機 能] 削除確認画面設定 <br>
   * [解 説] <br>
   * [備 考]
   *
   * @param map アクションマッピング
   * @param form アクションフォーム
   * @param req リクエスト
   * @return ActionForward
   */
  private ActionForward __doDeleteKnDsp(
      ActionMapping map, Ipk100Form form, HttpServletRequest req) {
    ActionForward forward = null;
    Cmn999Form cmn999Form = new Cmn999Form();
    ActionForward forwardOK = null;
    ActionForward forwardCancel = null;

    // トランザクショントークン設定
    this.saveToken(req);

    // スペック情報削除の削除確認画面パラメータの設定
    MessageResources msgRes = getResources(req);
    cmn999Form.setType(Cmn999Form.TYPE_OKCANCEL);
    cmn999Form.setIcon(Cmn999Form.ICON_INFO);
    cmn999Form.setWtarget(Cmn999Form.WTARGET_BODY);
    forwardOK = map.findForward("ipk100DeleteOk");
    cmn999Form.setUrlOK(forwardOK.getPath());
    forwardCancel = map.findForward("ipk100DeleteCancel");
    cmn999Form.setUrlCancel(forwardCancel.getPath());
    cmn999Form.setMessage(msgRes.getMessage("sakujo.kakunin.once", __getSpecKbn(form, req)));
    cmn999Form.addHiddenParam("backScreen", form.getBackScreen());
    cmn999Form.addHiddenParam("ismSid", form.getIsmSid());
    cmn999Form.addHiddenParam("editMode", form.getEditMode());
    cmn999Form.addHiddenParam("ipk100name", form.getIpk100name());
    cmn999Form.addHiddenParam("ipk100specLevel", form.getIpk100specLevel());
    cmn999Form.addHiddenParam("ipk100scroll", form.getIpk100scroll());
    cmn999Form.addHiddenParam("ipk100biko", form.getIpk100biko());
    cmn999Form.addHiddenParam("specKbn", form.getSpecKbn());
    req.setAttribute("cmn999Form", cmn999Form);
    forward = map.findForward("gf_msg");
    return forward;
  }
コード例 #3
0
ファイル: Resources.java プロジェクト: nykma/ykt4sungard
  /**
   * Gets the message arguments based on the current <code>ValidatorAction</code> and <code>Field
   * </code>.
   *
   * @param application the servlet context
   * @param request the servlet request
   * @param defaultMessages Default message resources
   * @param locale the locale
   * @param args The arguments for the message
   */
  private static String[] getArgValues(
      ServletContext application,
      HttpServletRequest request,
      MessageResources defaultMessages,
      Locale locale,
      Arg[] args) {

    if (args == null || args.length == 0) {
      return null;
    }

    String[] values = new String[args.length];
    for (int i = 0; i < args.length; i++) {
      if (args[i] != null) {
        if (args[i].isResource()) {

          MessageResources messages = defaultMessages;
          if (args[i].getBundle() != null) {
            messages = getMessageResources(application, request, args[i].getBundle());
          }
          values[i] = messages.getMessage(locale, args[i].getKey());

        } else {

          values[i] = args[i].getKey();
        }
      }
    }

    return values;
  }
コード例 #4
0
  /**
   * <br>
   * [機 能] 完了画面設定 <br>
   * [解 説] <br>
   * [備 考]
   *
   * @param map アクションマッピング
   * @param form アクションフォーム
   * @param req リクエスト
   * @param res レスポンス
   * @return ActionForward
   */
  private ActionForward __doCompDsp(
      ActionMapping map, Sml140knForm form, HttpServletRequest req, HttpServletResponse res) {

    ActionForward forward = null;
    Cmn999Form cmn999Form = new Cmn999Form();
    ActionForward urlForward = null;

    // 完了画面パラメータの設定
    MessageResources msgRes = getResources(req);
    cmn999Form.setType(Cmn999Form.TYPE_OK);
    cmn999Form.setIcon(Cmn999Form.ICON_INFO);
    cmn999Form.setWtarget(Cmn999Form.WTARGET_BODY);

    GsMessage gsMsg = new GsMessage();
    String smail = gsMsg.getMessage(req, "cmn.shortmail");

    urlForward = map.findForward("backToList");
    cmn999Form.setUrlOK(urlForward.getPath());
    cmn999Form.setMessage(msgRes.getMessage("sakujo.kanryo.object", smail));

    // hiddenパラメータ
    cmn999Form.addHiddenParam("backScreen", form.getBackScreen());
    cmn999Form.addHiddenParam("sml010ProcMode", form.getSml010ProcMode());
    cmn999Form.addHiddenParam("sml010Sort_key", form.getSml010Sort_key());
    cmn999Form.addHiddenParam("sml010Order_key", form.getSml010Order_key());
    cmn999Form.addHiddenParam("sml010PageNum", form.getSml010PageNum());
    cmn999Form.addHiddenParam("sml010SelectedSid", form.getSml010SelectedSid());
    cmn999Form.addHiddenParam("sml010DelSid", form.getSml010DelSid());
    req.setAttribute("cmn999Form", cmn999Form);

    forward = map.findForward("gf_msg");
    return forward;
  }
コード例 #5
0
  protected void putBundleInScope(int scope, boolean returnNull) {
    MessageResourcesFactory factory = MessageResourcesFactory.createFactory();
    MessageResources messageResources =
        new PropertyMessageResources(factory, "org.apache.struts.taglib.sample");

    messageResources.setReturnNull(returnNull);
    pageContext.setAttribute(Globals.MESSAGES_KEY, messageResources, scope);
  }
コード例 #6
0
ファイル: ItemAction.java プロジェクト: Richiexy/JadaSite
  public ActionForward alert(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    String commentId = request.getParameter("commentId");
    String alertType = request.getParameter("alertType");
    Customer customer = getCustomer(request);
    if (customer == null) {
      JSONEscapeObject jsonResult = new JSONEscapeObject();
      jsonResult.put("status", Constants.WEBSERVICE_STATUS_FAILED);
      MessageResources resources = this.getResources(request);
      jsonResult.put("message", resources.getMessage("error.content.signin"));
      String jsonString = jsonResult.toHtmlString();
      streamWebService(response, jsonString);
      return null;
    }

    EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
    Comment comment = (Comment) em.find(Comment.class, Format.getLong(commentId));

    if (alertType.equals(Constants.ALERT_TYPE_MODERATOR)) {
      comment.setModeration(Constants.VALUE_YES);
      em.persist(comment);
    } else {
      Iterator<?> iterator = comment.getAgreeCustomers().iterator();
      while (iterator.hasNext()) {
        Customer c = (Customer) iterator.next();
        if (c.getCustId().equals(customer.getCustId())) {
          iterator.remove();
          break;
        }
      }
      iterator = comment.getDisagreeCustomers().iterator();
      while (iterator.hasNext()) {
        Customer c = (Customer) iterator.next();
        if (c.getCustId().equals(customer.getCustId())) {
          iterator.remove();
          break;
        }
      }
      if (alertType.equals(Constants.ALERT_TYPE_AGREE)) {
        comment.getAgreeCustomers().add(customer);
      } else {
        comment.getDisagreeCustomers().add(customer);
      }
    }

    JSONEscapeObject jsonResult = new JSONEscapeObject();
    jsonResult.put("status", Constants.WEBSERVICE_STATUS_SUCCESS);
    jsonResult.put("agreeCount", comment.getAgreeCustomers().size());
    jsonResult.put("disagreeCount", comment.getDisagreeCustomers().size());
    jsonResult.put("moderation", String.valueOf(comment.getModeration()));
    String jsonString = jsonResult.toHtmlString();
    streamWebService(response, jsonString);
    return null;
  }
コード例 #7
0
ファイル: DefineTag.java プロジェクト: srpras78/study-prj
  /**
   * Retrieve the required property and expose it as a scripting variable.
   *
   * @throws JspException if a JSP exception has occurred
   */
  public int doEndTag() throws JspException {
    // Enforce restriction on ways to declare the new value
    int n = 0;

    if (this.body != null) {
      n++;
    }

    if (this.name != null) {
      n++;
    }

    if (this.value != null) {
      n++;
    }

    if (n > 1) {
      JspException e = new JspException(messages.getMessage("define.value", id));

      TagUtils.getInstance().saveException(pageContext, e);
      throw e;
    }

    // Retrieve the required property value
    Object value = this.value;

    if ((value == null) && (name != null)) {
      value = TagUtils.getInstance().lookup(pageContext, name, property, scope);
    }

    if ((value == null) && (body != null)) {
      value = body;
    }

    if (value == null) {
      JspException e = new JspException(messages.getMessage("define.null", id));

      TagUtils.getInstance().saveException(pageContext, e);
      throw e;
    }

    // Expose this value as a scripting variable
    int inScope = PageContext.PAGE_SCOPE;

    try {
      if (toScope != null) {
        inScope = TagUtils.getInstance().getScope(toScope);
      }
    } catch (JspException e) {
      log.warn("toScope was invalid name so we default to PAGE_SCOPE", e);
    }

    pageContext.setAttribute(id, value, inScope);

    // Continue processing this page
    return (EVAL_PAGE);
  }
コード例 #8
0
ファイル: DispatchAction.java プロジェクト: phani6292/struts
  /**
   * Dispatch to the specified method.
   *
   * @since Struts 1.1
   */
  protected ActionForward dispatchMethod(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response,
      String name)
      throws Exception {

    // Make sure we have a valid method name to call.
    // This may be null if the user hacks the query string.
    if (name == null) {
      return this.unspecified(mapping, form, request, response);
    }

    // Identify the method object to be dispatched to
    Method method = null;
    try {
      method = getMethod(name);
    } catch (NoSuchMethodException e) {
      String message = messages.getMessage("dispatch.method", mapping.getPath(), name);
      log.error(message, e);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
      return (null);
    }

    ActionForward forward = null;
    try {
      Object args[] = {mapping, form, request, response};
      forward = (ActionForward) method.invoke(this, args);
    } catch (ClassCastException e) {
      String message = messages.getMessage("dispatch.return", mapping.getPath(), name);
      log.error(message, e);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
      return (null);
    } catch (IllegalAccessException e) {
      String message = messages.getMessage("dispatch.error", mapping.getPath(), name);
      log.error(message, e);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
      return (null);
    } catch (InvocationTargetException e) {
      // Rethrow the target exception if possible so that the
      // exception handling machinery can deal with it
      Throwable t = e.getTargetException();
      if (t instanceof Exception) {
        throw ((Exception) t);
      } else {
        String message = messages.getMessage("dispatch.error", mapping.getPath(), name);
        log.error(message, e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
        return (null);
      }
    }

    // Return the returned ActionForward instance
    return (forward);
  }
コード例 #9
0
  /**
   * メッセージリソースに対してメッセージキーを指定することで エラーメッセージを取得する。
   *
   * @param req HTTPリクエスト
   * @param se SystemException
   * @param resources メッセージリソース
   * @return エラーメッセージ
   */
  private String getErrorMessage(
      HttpServletRequest req, SystemException se, MessageResources resources) {
    String errorCode = se.getErrorCode();
    // メッセージキーが指定されていないとき、nullを返却する。
    if (errorCode == null) {
      return null;
    }

    String[] options = se.getOptions();
    if (options == null) {
      return resources.getMessage(req.getLocale(), errorCode);
    }
    return resources.getMessage(req.getLocale(), errorCode, options);
  }
コード例 #10
0
 /**
  * @see
  *     es.pode.modificador.presentacion.configurar.cambios.navegarETB.NavegarETBController#selectActionRutas(org.apache.struts.action.ActionMapping,
  *     es.pode.modificador.presentacion.configurar.cambios.navegarETB.SelectActionRutasForm,
  *     javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
  */
 public final java.lang.String selectActionRutas(
     ActionMapping mapping,
     es.pode.modificador.presentacion.configurar.cambios.navegarETB.SelectActionRutasForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   String result = null;
   String posicion = form.getPosicion();
   String idTermino = form.getIdTermino();
   String action = form.getAction();
   if (logger.isDebugEnabled())
     logger.debug("selectActionRutas con idTermino = " + idTermino + " : posicion = " + posicion);
   if (resources
       .getMessage(
           (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE),
           "tesauro.seleccionar.ruta.padre.aceptar")
       .equals(action)) {
     // Modifico el objeto en sesion para que quede con la ruta padre elegida
     TaxonomiaVO taxonomia = this.getTesauroSession(request).getTaxonomia();
     JerarquiaVO[] jerarquia = taxonomia.getJerarquia();
     taxonomia.setJerarquia(null);
     int iPosicion = Integer.parseInt(posicion);
     TaxonVO[] taxonPath = jerarquia[iPosicion].getJerarquia();
     taxonomia.setTaxonPath(taxonPath);
     this.getTesauroSession(request).setTaxonomia(taxonomia);
     result = "Aceptar";
   } else {
     result = "Cancelar";
   }
   return result;
 }
コード例 #11
0
ファイル: Resources.java プロジェクト: nykma/ykt4sungard
  /**
   * Gets the locale sensitive message based on the <code>ValidatorAction</code> message and the
   * <code>Field</code>'s arg objects.
   *
   * @param messages The Message resources
   * @param locale The locale
   * @param va The Validator Action
   * @param field The Validator Field
   */
  public static String getMessage(
      MessageResources messages, Locale locale, ValidatorAction va, Field field) {

    String args[] = getArgs(va.getName(), messages, locale, field);
    String msg = field.getMsg(va.getName()) != null ? field.getMsg(va.getName()) : va.getMsg();

    return messages.getMessage(locale, msg, args);
  }
コード例 #12
0
ファイル: Resources.java プロジェクト: nykma/ykt4sungard
  /**
   * Gets the <code>Locale</code> sensitive value based on the key passed in.
   *
   * @param messages The Message resources
   * @param locale The locale.
   * @param key Key used to lookup the message
   */
  public static String getMessage(MessageResources messages, Locale locale, String key) {
    String message = null;

    if (messages != null) {
      message = messages.getMessage(locale, key);
    }

    return (message == null) ? "" : message;
  }
コード例 #13
0
  /**
   * Method validate
   *
   * @param mapping
   * @param request
   * @return ActionErrors
   */
  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {

    ActionErrors errors = new ActionErrors();

    MessageResources resources = BaseForm.getResources();

    if (username == null || username.length() == 0) {
      errors.add(
          "password", new ActionMessage("error.required", resources.getMessage("user.username")));
    }

    if (password == null || password.length() == 0) {
      errors.add(
          "password", new ActionMessage("error.required", resources.getMessage("user.password")));
    }

    return errors;
  }
コード例 #14
0
  /**
   * This is the action called from the Struts framework.
   *
   * @param mapping The ActionMapping used to select this instance.
   * @param request The HTTP Request we are processing.
   * @return
   */
  @Override
  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    MessageResources messages =
        MessageResources.getMessageResources("com.myapp.struts.ApplicationResource");
    Locale locale = request.getLocale();

    if (getValores() == null || getValores().length < 1) {
      errors.add(
          "valores",
          new ActionMessage("errors.required", messages.getMessage(locale, "texto.valores")));
    }

    if (getSstock() == null || getSstock().length() < 1) {
      stock = -1;
    } else {
      try {
        stock = Integer.parseInt(getSstock());
      } catch (Exception Ex) {
        errors.add(
            "stock",
            new ActionMessage("errors.integer", messages.getMessage(locale, "texto.stock")));
      }
    }

    if (getSprecio() != null && getSprecio().length() > 0) {
      try {
        Pattern pat = Pattern.compile("^[0-9]+([,.][0-9]{1,2})?$");
        Matcher mat = pat.matcher(getSprecio());

        if (mat.find()) {
          precio = new BigDecimal(getSprecio().replace(',', '.'));
        } else {
          errors.add("precio", new ActionMessage("errors.precio.mask"));
        }
      } catch (Exception Ex) {
        errors.add(
            "precio",
            new ActionMessage("errors.float", messages.getMessage(locale, "texto.precio")));
      }
    }

    return errors;
  }
コード例 #15
0
ファイル: MessageTag.java プロジェクト: srpras78/study-prj
  /**
   * Process the start tag.
   *
   * @throws JspException if a JSP exception has occurred
   */
  public int doStartTag() throws JspException {
    String key = this.key;

    if (key == null) {
      // Look up the requested property value
      Object value = TagUtils.getInstance().lookup(pageContext, name, property, scope);

      if ((value != null) && !(value instanceof String)) {
        JspException e = new JspException(messages.getMessage("message.property", key));

        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
      }

      key = (String) value;
    }

    // Construct the optional arguments array we will be using
    Object[] args = new Object[] {arg0, arg1, arg2, arg3, arg4};

    // Retrieve the message string we are looking for
    String message =
        TagUtils.getInstance().message(pageContext, this.bundle, this.localeKey, key, args);

    if (message == null) {
      Locale locale = TagUtils.getInstance().getUserLocale(pageContext, this.localeKey);
      String localeVal = (locale == null) ? "default locale" : locale.toString();
      JspException e =
          new JspException(
              messages.getMessage(
                  "message.message",
                  "\"" + key + "\"",
                  "\"" + ((bundle == null) ? "(default bundle)" : bundle) + "\"",
                  localeVal));

      TagUtils.getInstance().saveException(pageContext, e);
      throw e;
    }

    TagUtils.getInstance().write(pageContext, message);

    return (SKIP_BODY);
  }
コード例 #16
0
ファイル: ColSelectTag.java プロジェクト: bellingard/squale
  /** @see javax.servlet.jsp.tagext.Tag#doEndTag() */
  public int doEndTag() throws JspException {
    final String pageAccess = (String) pageContext.getAttribute("access");

    if ((pageAccess != null) && pageAccess.equals(Access.READONLY) && !forceReadWrite) {
      return SKIP_BODY;
    }

    // Recupere la locale de la page
    final Locale localeRequest = (Locale) pageContext.getSession().getAttribute(Globals.LOCALE_KEY);

    // Recuperer le fichier des Bundle
    final MessageResources resources =
        (MessageResources) pageContext.getServletContext().getAttribute(Globals.MESSAGES_KEY);

    final ColSelect c = new ColSelect();

    if (key == null) {
      key = "selected";
    }

    c.setKey(key);
    c.setProperty(property);
    c.setWidth(width);
    c.setPageContext(pageContext);
    c.setEnableSingleSelect(enableSingleSelect);
    c.setWriteTD(false);
    c.setOnclick(onclick);
    c.setDisabledProperty(disabledProperty);
    c.setSpecialHeader(showSelectAllHeader);
    c.setSpecialHeaderTitle(
        resources.getMessage(localeRequest, "welcom.internal.selectAll.tootip"));
    c.setToolTip(resources.getMessage(localeRequest, toolTipKey));
    if (GenericValidator.isBlankOrNull(c.getToolTip())) {
      c.setToolTip(toolTipKey);
    }
    if (getBodyContent() != null) {
      c.setCurrentValue(getBodyContent().getString().trim());
    }

    colsTag.addCellule(c);

    return EVAL_PAGE;
  }
コード例 #17
0
ファイル: CambioClaveForm.java プロジェクト: cmorenogg/alsigm
  public ActionErrors validate(MessageResources resources, Locale locale) {
    ActionErrors errors = new ActionErrors();

    if (Utilidades.isNuloOVacio(username)) {
      errors.add(
          ActionErrors.GLOBAL_MESSAGE,
          new ActionError("errors.required", resources.getMessage(locale, "cambioClave.username")));
      return errors;
    }

    if (Utilidades.isNuloOVacio(currentPassword)) {
      errors.add(
          ActionErrors.GLOBAL_MESSAGE,
          new ActionError(
              "errors.required", resources.getMessage(locale, "cambioClave.currentPassword")));
      return errors;
    }

    if (Utilidades.isNuloOVacio(newPassword)) {
      errors.add(
          ActionErrors.GLOBAL_MESSAGE,
          new ActionError(
              "errors.required", resources.getMessage(locale, "cambioClave.newPassword")));
      return errors;
    }

    if (Utilidades.isNuloOVacio(newPasswordConfirm)) {
      errors.add(
          ActionErrors.GLOBAL_MESSAGE,
          new ActionError(
              "errors.required", resources.getMessage(locale, "cambioClave.newPasswordConfirm")));
      return errors;
    }

    if (!newPasswordConfirm.equals(newPassword)) {
      errors.add(
          ActionErrors.GLOBAL_MESSAGE, new ActionError("cambioClave.error.clavesNoCoinciden"));
      return errors;
    }

    return errors;
  }
コード例 #18
0
ファイル: Ipk100Action.java プロジェクト: tmtkkwgch/hellogit
 /**
  * <br>
  * [機 能] 削除完了画面設定 <br>
  * [解 説] <br>
  * [備 考]
  *
  * @param map アクションマッピング
  * @param form アクションフォーム
  * @param req リクエスト
  * @return ActionForward
  */
 private ActionForward __doDeleteCompDsp(
     ActionMapping map, Ipk100Form form, HttpServletRequest req) {
   ActionForward forward = null;
   Cmn999Form cmn999Form = new Cmn999Form();
   ActionForward forwardOK = null;
   // スペック情報の削除確認画面パラメータの設定
   MessageResources msgRes = getResources(req);
   cmn999Form.setType(Cmn999Form.TYPE_OK);
   cmn999Form.setIcon(Cmn999Form.ICON_INFO);
   cmn999Form.setWtarget(Cmn999Form.WTARGET_BODY);
   forwardOK = map.findForward("ipk100DeleteComp");
   cmn999Form.setUrlOK(forwardOK.getPath());
   cmn999Form.setMessage(msgRes.getMessage("sakujo.kanryo.object", __getSpecKbn(form, req)));
   cmn999Form.addHiddenParam("backScreen", form.getBackScreen());
   req.setAttribute("cmn999Form", cmn999Form);
   forward = map.findForward("gf_msg");
   cmn999Form.addHiddenParam("ismSid", form.getIsmSid());
   cmn999Form.addHiddenParam("specKbn", form.getSpecKbn());
   return forward;
 }
コード例 #19
0
ファイル: DispatchAction.java プロジェクト: phani6292/struts
  /**
   * Method which is dispatched to when there is no value for specified request parameter included
   * in the request. Subclasses of <code>DispatchAction</code> should override this method if they
   * wish to provide default behavior different than producing an HTTP "Bad Request" error.
   */
  protected ActionForward unspecified(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    String message =
        messages.getMessage("dispatch.parameter", mapping.getPath(), mapping.getParameter());
    log.error(message);
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
    return (null);
  }
コード例 #20
0
ファイル: SizeTag.java プロジェクト: BackupTheBerlios/emayor
  /**
   * Retrieve the required property and expose it as a scripting variable.
   *
   * @exception JspException if a JSP exception has occurred
   */
  public int doStartTag() throws JspException {

    // Retrieve the required property value
    Object value = this.collection;
    if (value == null) {
      if (name == null) {
        // Must specify either a collection attribute or a name
        // attribute.
        JspException e = new JspException(messages.getMessage("size.noCollectionOrName"));
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
      }

      value = TagUtils.getInstance().lookup(pageContext, name, property, scope);
    }

    // Identify the number of elements, based on the collection type
    int size = 0;
    if (value == null) {
      JspException e = new JspException(messages.getMessage("size.collection"));
      TagUtils.getInstance().saveException(pageContext, e);
      throw e;
    } else if (value.getClass().isArray()) {
      size = Array.getLength(value);
    } else if (value instanceof Collection) {
      size = ((Collection) value).size();
    } else if (value instanceof Map) {
      size = ((Map) value).size();
    } else {
      JspException e = new JspException(messages.getMessage("size.collection"));
      TagUtils.getInstance().saveException(pageContext, e);
      throw e;
    }

    // Expose this size as a scripting variable
    pageContext.setAttribute(this.id, new Integer(size), PageContext.PAGE_SCOPE);
    return (SKIP_BODY);
  }
コード例 #21
0
ファイル: Resources.java プロジェクト: nykma/ykt4sungard
  /**
   * Gets the <code>ActionMessage</code> based on the <code>ValidatorAction</code> message and the
   * <code>Field</code>'s arg objects.
   *
   * @param validator the Validator
   * @param request the servlet request
   * @param va Validator action
   * @param field the validator Field
   */
  public static ActionMessage getActionMessage(
      Validator validator, HttpServletRequest request, ValidatorAction va, Field field) {

    Msg msg = field.getMessage(va.getName());
    if (msg != null && !msg.isResource()) {
      return new ActionMessage(msg.getKey(), false);
    }

    String msgKey = null;
    String msgBundle = null;
    if (msg == null) {
      msgKey = va.getMsg();
    } else {
      msgKey = msg.getKey();
      msgBundle = msg.getBundle();
    }

    if (msgKey == null || msgKey.length() == 0) {
      return new ActionMessage("??? " + va.getName() + "." + field.getProperty() + " ???", false);
    }

    ServletContext application =
        (ServletContext) validator.getParameterValue(SERVLET_CONTEXT_PARAM);
    MessageResources messages = getMessageResources(application, request, msgBundle);
    Locale locale = RequestUtils.getUserLocale(request, null);

    Arg[] args = field.getArgs(va.getName());
    String[] argValues = getArgValues(application, request, messages, locale, args);

    ActionMessage actionMessage = null;
    if (msgBundle == null) {
      actionMessage = new ActionMessage(msgKey, argValues);
    } else {
      String message = messages.getMessage(locale, msgKey, argValues);
      actionMessage = new ActionMessage(message, false);
    }
    return actionMessage;
  }
コード例 #22
0
ファイル: Resources.java プロジェクト: nykma/ykt4sungard
  /**
   * Gets the <code>Locale</code> sensitive value based on the key passed in.
   *
   * @param application the servlet context
   * @param request the servlet request
   * @param defaultMessages The default Message resources
   * @param locale The locale
   * @param va The Validator Action
   * @param field The Validator Field
   */
  public static String getMessage(
      ServletContext application,
      HttpServletRequest request,
      MessageResources defaultMessages,
      Locale locale,
      ValidatorAction va,
      Field field) {

    Msg msg = field.getMessage(va.getName());
    if (msg != null && !msg.isResource()) {
      return msg.getKey();
    }

    String msgKey = null;
    String msgBundle = null;
    MessageResources messages = defaultMessages;
    if (msg == null) {
      msgKey = va.getMsg();
    } else {
      msgKey = msg.getKey();
      msgBundle = msg.getBundle();
      if (msg.getBundle() != null) {
        messages = getMessageResources(application, request, msg.getBundle());
      }
    }

    if (msgKey == null || msgKey.length() == 0) {
      return "??? " + va.getName() + "." + field.getProperty() + " ???";
    }

    // Get the arguments
    Arg[] args = field.getArgs(va.getName());
    String[] argValues = getArgValues(application, request, messages, locale, args);

    // Return the message
    return messages.getMessage(locale, msgKey, argValues);
  }
コード例 #23
0
ファイル: ParameterTag.java プロジェクト: nykma/ykt4sungard
  /**
   * Retrieve the required property and expose it as a scripting variable.
   *
   * @exception JspException if a JSP exception has occurred
   */
  public int doStartTag() throws JspException {

    // Deal with a single parameter value
    if (multiple == null) {
      String value = pageContext.getRequest().getParameter(name);
      if ((value == null) && (this.value != null)) {
        value = this.value;
      }

      if (value == null) {
        JspException e = new JspException(messages.getMessage("parameter.get", name));
        TagUtils.getInstance().saveException(pageContext, e);
        throw e;
      }

      pageContext.setAttribute(id, value);
      return (SKIP_BODY);
    }

    // Deal with multiple parameter values
    String values[] = pageContext.getRequest().getParameterValues(name);
    if ((values == null) || (values.length == 0)) {
      if (this.value != null) {
        values = new String[] {this.value};
      }
    }

    if ((values == null) || (values.length == 0)) {
      JspException e = new JspException(messages.getMessage("parameter.get", name));
      TagUtils.getInstance().saveException(pageContext, e);
      throw e;
    }

    pageContext.setAttribute(id, values);
    return (SKIP_BODY);
  }
コード例 #24
0
 /**
  * @see
  *     es.pode.modificador.presentacion.configurar.cambios.navegarETB.NavegarETBController#selectAction(org.apache.struts.action.ActionMapping,
  *     es.pode.modificador.presentacion.configurar.cambios.navegarETB.SelectActionForm,
  *     javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
  */
 public final java.lang.String selectAction(
     ActionMapping mapping,
     es.pode.modificador.presentacion.configurar.cambios.navegarETB.SelectActionForm form,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   String action = form.getAction();
   if (logger.isDebugEnabled()) logger.debug("action = " + action);
   String result = null;
   if (resources
       .getMessage(
           (Locale) request.getSession().getAttribute(ConstantesAgrega.DEFAULT_LOCALE),
           "tesauro.navegar.aceptar")
       .equals(action)) {
     result = "Aceptar";
   } else {
     this.removeTesauroSession(request);
     result = "Volver";
   }
   return result;
 }
コード例 #25
0
ファイル: DispatchAction.java プロジェクト: phani6292/struts
  /**
   * Process the specified HTTP request, and create the corresponding HTTP response (or forward to
   * another web component that will create it). Return an <code>ActionForward</code> instance
   * describing where and how control should be forwarded, or <code>null</code> if the response has
   * already been completed.
   *
   * @param mapping The ActionMapping used to select this instance
   * @param form The optional ActionForm bean for this request (if any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   * @exception Exception if an exception occurs
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // Identify the request parameter containing the method name
    String parameter = mapping.getParameter();
    if (parameter == null) {
      String message = messages.getMessage("dispatch.handler", mapping.getPath());
      log.error(message);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
      return (null);
    }

    // Identify the method name to be dispatched to.
    // dispatchMethod() will call unspecified() if name is null
    String name = request.getParameter(parameter);

    // Invoke the named method, and return the result
    return dispatchMethod(mapping, form, request, response, name);
  }
コード例 #26
0
ファイル: Rng020Action.java プロジェクト: tmtkkwgch/hellogit
  /**
   * <br>
   * [機 能] 完了メッセージ画面遷移時のパラメータを設定 <br>
   * [解 説] <br>
   * [備 考]
   *
   * @param map マッピング
   * @param req リクエスト
   * @param form アクションフォーム
   * @return ActionForward
   */
  private ActionForward __setCompPageParam(
      ActionMapping map, HttpServletRequest req, Rng020Form form) {

    Cmn999Form cmn999Form = new Cmn999Form();
    ActionForward urlForward = null;

    cmn999Form.setType(Cmn999Form.TYPE_OK);
    MessageResources msgRes = getResources(req);
    cmn999Form.setIcon(Cmn999Form.ICON_INFO);
    cmn999Form.setWtarget(Cmn999Form.WTARGET_BODY);
    if (form.getRng130searchFlg() == 1) {
      urlForward = map.findForward("search");
    } else {
      urlForward = map.findForward("rng010");
    }
    cmn999Form.setUrlOK(urlForward.getPath());

    // メッセージセット
    String msgState = null;
    if (form.getRngCmdMode() == RngConst.RNG_CMDMODE_ADD) {
      msgState = "touroku.kanryo.object";
    } else if (form.getRngCmdMode() == RngConst.RNG_CMDMODE_EDIT) {
      msgState = "hensyu.kanryo.object";
    }
    GsMessage gsMsg = new GsMessage();
    String msg = gsMsg.getMessage(req, "rng.62");

    cmn999Form.setMessage(msgRes.getMessage(msgState, msg));

    cmn999Form.addHiddenParam("rngProcMode", form.getRngProcMode());
    cmn999Form.addHiddenParam("rng010orderKey", form.getRng010orderKey());
    cmn999Form.addHiddenParam("rng010sortKey", form.getRng010sortKey());
    cmn999Form.addHiddenParam("rng010pageTop", form.getRng010pageTop());
    cmn999Form.addHiddenParam("rng010pageBottom", form.getRng010pageBottom());

    cmn999Form.addHiddenParam("rngKeyword", form.getRngKeyword());
    cmn999Form.addHiddenParam("rng130Type", form.getRng130Type());
    cmn999Form.addHiddenParam("sltGroupSid", form.getSltGroupSid());
    cmn999Form.addHiddenParam("sltUserSid", form.getSltUserSid());
    cmn999Form.addHiddenParam("rng130keyKbn", form.getRng130keyKbn());
    cmn999Form.addHiddenParam("rng130searchSubject1", form.getRng130searchSubject1());
    cmn999Form.addHiddenParam("rng130searchSubject2", form.getRng130searchSubject2());
    cmn999Form.addHiddenParam("sltSortKey1", form.getSltSortKey1());
    cmn999Form.addHiddenParam("rng130orderKey1", form.getRng130orderKey1());
    cmn999Form.addHiddenParam("sltSortKey2", form.getSltSortKey2());
    cmn999Form.addHiddenParam("rng130orderKey2", form.getRng130orderKey1());
    cmn999Form.addHiddenParam("sltApplYearFr", form.getSltApplYearFr());
    cmn999Form.addHiddenParam("sltApplMonthFr", form.getSltApplMonthFr());
    cmn999Form.addHiddenParam("sltApplDayFr", form.getSltApplDayFr());
    cmn999Form.addHiddenParam("sltApplYearTo", form.getSltApplYearTo());
    cmn999Form.addHiddenParam("sltApplMonthTo", form.getSltApplMonthTo());
    cmn999Form.addHiddenParam("sltApplDayTo", form.getSltApplDayTo());
    cmn999Form.addHiddenParam("sltLastManageYearFr", form.getSltLastManageYearFr());
    cmn999Form.addHiddenParam("sltLastManageMonthFr", form.getSltLastManageMonthFr());
    cmn999Form.addHiddenParam("sltLastManageDayFr", form.getSltLastManageDayFr());
    cmn999Form.addHiddenParam("sltLastManageYearTo", form.getSltLastManageYearTo());
    cmn999Form.addHiddenParam("sltLastManageMonthTo", form.getSltLastManageMonthTo());
    cmn999Form.addHiddenParam("sltLastManageDayTo", form.getSltLastManageDayTo());
    cmn999Form.addHiddenParam("rng130pageTop", form.getRng130pageTop());
    cmn999Form.addHiddenParam("rng130pageBottom", form.getRng130pageBottom());

    cmn999Form.addHiddenParam("svRngKeyword", form.getSvRngKeyword());
    cmn999Form.addHiddenParam("svRng130Type", form.getSvRng130Type());
    cmn999Form.addHiddenParam("svGroupSid", form.getSvGroupSid());
    cmn999Form.addHiddenParam("svUserSid", form.getSvUserSid());
    cmn999Form.addHiddenParam("svRng130keyKbn", form.getSvRng130keyKbn());
    cmn999Form.addHiddenParam("svRng130searchSubject1", form.getSvRng130searchSubject1());
    cmn999Form.addHiddenParam("svRng130searchSubject2", form.getSvRng130searchSubject2());
    cmn999Form.addHiddenParam("svSortKey1", form.getSvSortKey1());
    cmn999Form.addHiddenParam("svRng130orderKey1", form.getSvRng130orderKey1());
    cmn999Form.addHiddenParam("svSortKey2", form.getSvSortKey2());
    cmn999Form.addHiddenParam("svRng130orderKey2", form.getSvRng130orderKey1());
    cmn999Form.addHiddenParam("svApplYearFr", form.getSvApplYearFr());
    cmn999Form.addHiddenParam("svApplMonthFr", form.getSvApplMonthFr());
    cmn999Form.addHiddenParam("svApplDayFr", form.getSvApplDayFr());
    cmn999Form.addHiddenParam("svApplYearTo", form.getSvApplYearTo());
    cmn999Form.addHiddenParam("svApplMonthTo", form.getSvApplMonthTo());
    cmn999Form.addHiddenParam("svApplDayTo", form.getSvApplDayTo());
    cmn999Form.addHiddenParam("svLastManageYearFr", form.getSvLastManageYearFr());
    cmn999Form.addHiddenParam("svLastManageMonthFr", form.getSvLastManageMonthFr());
    cmn999Form.addHiddenParam("svLastManageDayFr", form.getSvLastManageDayFr());
    cmn999Form.addHiddenParam("svLastManageYearTo", form.getSvLastManageYearTo());
    cmn999Form.addHiddenParam("svLastManageMonthTo", form.getSvLastManageMonthTo());
    cmn999Form.addHiddenParam("svLastManageDayTo", form.getSvLastManageDayTo());
    cmn999Form.addHiddenParam("rng130searchFlg", form.getRng130searchFlg());

    req.setAttribute("cmn999Form", cmn999Form);

    return map.findForward("gf_msg");
  }
コード例 #27
0
  /**
   * Process the specified HTTP request, and create the corresponding HTTP response (or forward to
   * another web component that will create it). Return an <code>ActionForward</code> instance
   * describing where and how control should be forwarded, or <code>null</code> if the response has
   * already been completed.
   *
   * @param mapping The ActionMapping used to select this instance
   * @param actionForm The optional ActionForm bean for this request (if any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   * @exception IOException if an input/output error occurs
   * @exception ServletException if a servlet exception occurs
   */
  public ActionForward perform(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws IOException, ServletException {

    // Look up the components we will be using as needed
    if (mserver == null) {
      mserver = ((ApplicationServlet) getServlet()).getServer();
    }
    if (resources == null) {
      resources = getServlet().getResources();
    }
    HttpSession session = request.getSession();
    Locale locale = (Locale) session.getAttribute(Action.LOCALE_KEY);

    // Has this transaction been cancelled?
    if (isCancelled(request)) {
      return (mapping.findForward("List Users Setup"));
    }

    // Check the transaction token
    if (!isTokenValid(request)) {
      response.sendError(
          HttpServletResponse.SC_BAD_REQUEST, resources.getMessage(locale, "users.error.token"));
      return (null);
    }

    // Perform any extra validation that is required
    UsersForm usersForm = (UsersForm) form;
    String databaseName = usersForm.getDatabaseName();
    String users[] = usersForm.getUsers();
    if (users == null) {
      users = new String[0];
    }

    // Perform "Delete User" transactions as required
    try {

      ObjectName dname = new ObjectName(databaseName);
      String signature[] = new String[1];
      signature[0] = "java.lang.String";
      Object params[] = new String[1];

      for (int i = 0; i < users.length; i++) {
        ObjectName oname = new ObjectName(users[i]);
        params[0] = oname.getKeyProperty("username");
        mserver.invoke(dname, "removeUser", params, signature);
      }

    } catch (Throwable t) {

      getServlet().log(resources.getMessage(locale, "users.error.invoke", "removeUser"), t);
      response.sendError(
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          resources.getMessage(locale, "users.error.invoke", "removeUser"));
      return (null);
    }

    // Save the updated database information
    try {

      ObjectName dname = new ObjectName(databaseName);
      mserver.invoke(dname, "save", new Object[0], new String[0]);

    } catch (Throwable t) {

      getServlet().log(resources.getMessage(locale, "users.error.invoke", "save"), t);
      response.sendError(
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          resources.getMessage(locale, "users.error.invoke", "save"));
      return (null);
    }

    // Proceed to the list users screen
    return (mapping.findForward("Users List Setup"));
  }
コード例 #28
0
ファイル: RadioTag.java プロジェクト: mumitr0ll/struts1
/**
 * Tag for input fields of type "radio".
 *
 * @version $Rev$ $Date: 2005-06-14 14:26:17 -0400 (Tue, 14 Jun 2005) $
 */
public class RadioTag extends BaseHandlerTag {
  // ----------------------------------------------------- Instance Variables

  /** The message resources for this package. */
  protected static MessageResources messages =
      MessageResources.getMessageResources(Constants.Package + ".LocalStrings");

  /** The name of the bean containing our underlying property. */
  protected String name = Constants.BEAN_KEY;

  /** The property name for this field. */
  protected String property = null;

  /** The body content of this tag (if any). */
  protected String text = null;

  /** The server value for this option. */
  protected String value = null;

  /**
   * Name of the bean (in some scope) that will return the value of the radio tag.
   *
   * <p>If an iterator is used to render a series of radio tags, this field may be used to specify
   * the name of the bean exposed by the iterator. In this case, the value attribute is used as the
   * name of a property on the <code>idName</code> bean that returns the value of the radio tag in
   * this iteration.
   */
  protected String idName = null;

  public String getName() {
    return (this.name);
  }

  public void setName(String name) {
    this.name = name;
  }

  // ------------------------------------------------------------- Properties

  /** Return the property name. */
  public String getProperty() {
    return (this.property);
  }

  /**
   * Set the property name.
   *
   * @param property The new property name
   */
  public void setProperty(String property) {
    this.property = property;
  }

  /** Return the server value. */
  public String getValue() {
    return (this.value);
  }

  /**
   * Set the server value.
   *
   * @param value The new server value
   */
  public void setValue(String value) {
    this.value = value;
  }

  /**
   * Return the idName.
   *
   * @since Struts 1.1
   */
  public String getIdName() {
    return (this.idName);
  }

  /**
   * Set the idName.
   *
   * @param idName The new idName
   * @since Struts 1.1
   */
  public void setIdName(String idName) {
    this.idName = idName;
  }

  // --------------------------------------------------------- Public Methods

  /**
   * Generate the required input tag. [Indexed property since Struts 1.1]
   *
   * @throws JspException if a JSP exception has occurred
   */
  public int doStartTag() throws JspException {
    String radioTag = renderRadioElement(serverValue(), currentValue());

    TagUtils.getInstance().write(pageContext, radioTag);

    this.text = null;

    return (EVAL_BODY_TAG);
  }

  /**
   * Return the String to be used in the radio tag's <code>value</code> attribute that gets sent to
   * the server on form submission.
   *
   * @throws JspException
   */
  private String serverValue() throws JspException {
    // Not using indexed radio buttons
    if (this.idName == null) {
      return this.value;
    }

    String serverValue = this.lookupProperty(this.idName, this.value);

    return (serverValue == null) ? "" : serverValue;
  }

  /**
   * Acquire the current value of the bean specified by the <code>name</code> attribute and the
   * property specified by the <code>property</code> attribute. This radio button with this value
   * will be checked.
   *
   * @throws JspException
   */
  private String currentValue() throws JspException {
    String current = this.lookupProperty(this.name, this.property);

    return (current == null) ? "" : current;
  }

  /**
   * Renders an HTML &lt;input type="radio"&gt; element.
   *
   * @param serverValue The data to be used in the tag's <code>value</code> attribute and sent to
   *     the server when the form is submitted.
   * @param checkedValue If the serverValue equals this value the radio button will be checked.
   * @return A radio input element.
   * @throws JspException
   * @since Struts 1.1
   */
  protected String renderRadioElement(String serverValue, String checkedValue) throws JspException {
    StringBuffer results = new StringBuffer("<input type=\"radio\"");

    prepareAttribute(results, "name", prepareName());
    prepareAttribute(results, "accesskey", getAccesskey());
    prepareAttribute(results, "tabindex", getTabindex());
    prepareAttribute(results, "value", TagUtils.getInstance().filter(serverValue));

    if (serverValue.equals(checkedValue)) {
      results.append(" checked=\"checked\"");
    }

    results.append(prepareEventHandlers());
    results.append(prepareStyles());
    prepareOtherAttributes(results);
    results.append(getElementClose());

    return results.toString();
  }

  /**
   * Save the associated label from the body content.
   *
   * @throws JspException if a JSP exception has occurred
   */
  public int doAfterBody() throws JspException {
    if (this.bodyContent != null) {
      String value = this.bodyContent.getString().trim();

      if (value.length() > 0) {
        this.text = value;
      }
    }

    return (SKIP_BODY);
  }

  /**
   * Optionally render the associated label from the body content.
   *
   * @throws JspException if a JSP exception has occurred
   */
  public int doEndTag() throws JspException {
    // Render any description for this radio button
    if (this.text != null) {
      TagUtils.getInstance().write(pageContext, text);
    }

    return (EVAL_PAGE);
  }

  /**
   * Prepare the name element
   *
   * @return The element name.
   */
  protected String prepareName() throws JspException {
    if (property == null) {
      return null;
    }

    // * @since Struts 1.1
    if (indexed) {
      StringBuffer results = new StringBuffer();

      prepareIndex(results, name);
      results.append(property);

      return results.toString();
    }

    return property;
  }

  /** Release any acquired resources. */
  public void release() {
    super.release();
    idName = null;
    name = Constants.BEAN_KEY;
    property = null;
    text = null;
    value = null;
  }
}
コード例 #29
0
ファイル: CompareTagBase.java プロジェクト: nykma/ykt4sungard
  /**
   * Evaluate the condition that is being tested by this particular tag, and return <code>true
   * </code> if the nested body content of this tag should be evaluated, or <code>false</code> if it
   * should be skipped. This method must be implemented by concrete subclasses.
   *
   * @param desired1 First desired value for a true result (-1, 0, +1)
   * @param desired2 Second desired value for a true result (-1, 0, +1)
   * @exception JspException if a JSP exception occurs
   */
  protected boolean condition(int desired1, int desired2) throws JspException {

    // Acquire the value and determine the test type
    int type = -1;
    double doubleValue = 0.0;
    long longValue = 0;
    if ((type < 0) && (value.length() > 0)) {
      try {
        doubleValue = Double.parseDouble(value);
        type = DOUBLE_COMPARE;
      } catch (NumberFormatException e) {;
      }
    }
    if ((type < 0) && (value.length() > 0)) {
      try {
        longValue = Long.parseLong(value);
        type = LONG_COMPARE;
      } catch (NumberFormatException e) {;
      }
    }
    if (type < 0) {
      type = STRING_COMPARE;
    }

    // Acquire the unconverted variable value
    Object variable = null;
    if (cookie != null) {
      Cookie cookies[] = ((HttpServletRequest) pageContext.getRequest()).getCookies();
      if (cookies == null) cookies = new Cookie[0];
      for (int i = 0; i < cookies.length; i++) {
        if (cookie.equals(cookies[i].getName())) {
          variable = cookies[i].getValue();
          break;
        }
      }
    } else if (header != null) {
      variable = ((HttpServletRequest) pageContext.getRequest()).getHeader(header);
    } else if (name != null) {
      Object bean = TagUtils.getInstance().lookup(pageContext, name, scope);
      if (property != null) {
        if (bean == null) {
          JspException e = new JspException(messages.getMessage("logic.bean", name));
          TagUtils.getInstance().saveException(pageContext, e);
          throw e;
        }
        try {
          variable = PropertyUtils.getProperty(bean, property);
        } catch (InvocationTargetException e) {
          Throwable t = e.getTargetException();
          if (t == null) t = e;
          TagUtils.getInstance().saveException(pageContext, t);
          throw new JspException(
              messages.getMessage("logic.property", name, property, t.toString()));
        } catch (Throwable t) {
          TagUtils.getInstance().saveException(pageContext, t);
          throw new JspException(
              messages.getMessage("logic.property", name, property, t.toString()));
        }
      } else {
        variable = bean;
      }
    } else if (parameter != null) {
      variable = pageContext.getRequest().getParameter(parameter);
    } else {
      JspException e = new JspException(messages.getMessage("logic.selector"));
      TagUtils.getInstance().saveException(pageContext, e);
      throw e;
    }
    if (variable == null) {
      variable = ""; // Coerce null to a zero-length String
    }

    // Perform the appropriate comparison
    int result = 0;
    if (type == DOUBLE_COMPARE) {
      try {
        double doubleVariable = Double.parseDouble(variable.toString());
        if (doubleVariable < doubleValue) result = -1;
        else if (doubleVariable > doubleValue) result = +1;
      } catch (NumberFormatException e) {
        result = variable.toString().compareTo(value);
      }
    } else if (type == LONG_COMPARE) {
      try {
        long longVariable = Long.parseLong(variable.toString());
        if (longVariable < longValue) result = -1;
        else if (longVariable > longValue) result = +1;
      } catch (NumberFormatException e) {
        result = variable.toString().compareTo(value);
      }
    } else {
      result = variable.toString().compareTo(value);
    }

    // Normalize the result
    if (result < 0) result = -1;
    else if (result > 0) result = +1;

    // Return true if the result matches either desired value
    return ((result == desired1) || (result == desired2));
  }
コード例 #30
0
ファイル: CompareTagBase.java プロジェクト: nykma/ykt4sungard
/**
 * Abstract base class for comparison tags. Concrete subclasses need only define values for desired1
 * and desired2.
 *
 * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
 */
public abstract class CompareTagBase extends ConditionalTagBase {

  // ----------------------------------------------------- Instance Variables

  /** We will do a double/float comparison. */
  protected static final int DOUBLE_COMPARE = 0;

  /** We will do a long/int comparison. */
  protected static final int LONG_COMPARE = 1;

  /** We will do a String comparison. */
  protected static final int STRING_COMPARE = 2;

  /** The message resources for this package. */
  protected static MessageResources messages =
      MessageResources.getMessageResources("org.apache.struts.taglib.logic.LocalStrings");

  // ------------------------------------------------------------ Properties

  /** The value to which the variable specified by other attributes of this tag will be compared. */
  public String value = null;

  public String getValue() {
    return (this.value);
  }

  public void setValue(String value) {
    this.value = value;
  }

  // --------------------------------------------------------- Public Methods

  /** Release all allocated resources. */
  public void release() {

    super.release();
    value = null;
  }

  // ------------------------------------------------------ Protected Methods

  /**
   * Evaluate the condition that is being tested by this particular tag, and return <code>true
   * </code> if the nested body content of this tag should be evaluated, or <code>false</code> if it
   * should be skipped. This method must be implemented by concrete subclasses.
   *
   * @exception JspException if a JSP exception occurs
   */
  protected abstract boolean condition() throws JspException;

  /**
   * Evaluate the condition that is being tested by this particular tag, and return <code>true
   * </code> if the nested body content of this tag should be evaluated, or <code>false</code> if it
   * should be skipped. This method must be implemented by concrete subclasses.
   *
   * @param desired1 First desired value for a true result (-1, 0, +1)
   * @param desired2 Second desired value for a true result (-1, 0, +1)
   * @exception JspException if a JSP exception occurs
   */
  protected boolean condition(int desired1, int desired2) throws JspException {

    // Acquire the value and determine the test type
    int type = -1;
    double doubleValue = 0.0;
    long longValue = 0;
    if ((type < 0) && (value.length() > 0)) {
      try {
        doubleValue = Double.parseDouble(value);
        type = DOUBLE_COMPARE;
      } catch (NumberFormatException e) {;
      }
    }
    if ((type < 0) && (value.length() > 0)) {
      try {
        longValue = Long.parseLong(value);
        type = LONG_COMPARE;
      } catch (NumberFormatException e) {;
      }
    }
    if (type < 0) {
      type = STRING_COMPARE;
    }

    // Acquire the unconverted variable value
    Object variable = null;
    if (cookie != null) {
      Cookie cookies[] = ((HttpServletRequest) pageContext.getRequest()).getCookies();
      if (cookies == null) cookies = new Cookie[0];
      for (int i = 0; i < cookies.length; i++) {
        if (cookie.equals(cookies[i].getName())) {
          variable = cookies[i].getValue();
          break;
        }
      }
    } else if (header != null) {
      variable = ((HttpServletRequest) pageContext.getRequest()).getHeader(header);
    } else if (name != null) {
      Object bean = TagUtils.getInstance().lookup(pageContext, name, scope);
      if (property != null) {
        if (bean == null) {
          JspException e = new JspException(messages.getMessage("logic.bean", name));
          TagUtils.getInstance().saveException(pageContext, e);
          throw e;
        }
        try {
          variable = PropertyUtils.getProperty(bean, property);
        } catch (InvocationTargetException e) {
          Throwable t = e.getTargetException();
          if (t == null) t = e;
          TagUtils.getInstance().saveException(pageContext, t);
          throw new JspException(
              messages.getMessage("logic.property", name, property, t.toString()));
        } catch (Throwable t) {
          TagUtils.getInstance().saveException(pageContext, t);
          throw new JspException(
              messages.getMessage("logic.property", name, property, t.toString()));
        }
      } else {
        variable = bean;
      }
    } else if (parameter != null) {
      variable = pageContext.getRequest().getParameter(parameter);
    } else {
      JspException e = new JspException(messages.getMessage("logic.selector"));
      TagUtils.getInstance().saveException(pageContext, e);
      throw e;
    }
    if (variable == null) {
      variable = ""; // Coerce null to a zero-length String
    }

    // Perform the appropriate comparison
    int result = 0;
    if (type == DOUBLE_COMPARE) {
      try {
        double doubleVariable = Double.parseDouble(variable.toString());
        if (doubleVariable < doubleValue) result = -1;
        else if (doubleVariable > doubleValue) result = +1;
      } catch (NumberFormatException e) {
        result = variable.toString().compareTo(value);
      }
    } else if (type == LONG_COMPARE) {
      try {
        long longVariable = Long.parseLong(variable.toString());
        if (longVariable < longValue) result = -1;
        else if (longVariable > longValue) result = +1;
      } catch (NumberFormatException e) {
        result = variable.toString().compareTo(value);
      }
    } else {
      result = variable.toString().compareTo(value);
    }

    // Normalize the result
    if (result < 0) result = -1;
    else if (result > 0) result = +1;

    // Return true if the result matches either desired value
    return ((result == desired1) || (result == desired2));
  }
}