Example #1
0
  // doGet, doPost delegate to this method
  @SuppressWarnings("unchecked")
  public void doPGU(HttpServletRequest request, HttpServletResponse response, String method) {
    initVelocity();

    // parse command and arguments from request path
    String pathinfo = request.getPathInfo();
    if (pathinfo == null) {
      pathinfo = "";
    }

    System.out.println("REQUEST: " + pathinfo);

    String cmd = null;

    StringTokenizer kk = new StringTokenizer(pathinfo, "/");
    int i = 0;
    Vector[] args = {new Vector<String>(), new Vector<String>()};
    if (kk.countTokens() != 0) {
      cmd = kk.nextToken();
      while (kk.hasMoreTokens()) {
        String kkk = URLDecoder.decode(kk.nextToken());
        System.out.println("[" + method + "] PATHINFO[" + i + "]: " + kkk);
        args[i % 2].add(kkk);
        i++;
      }
    }

    // Default-cmd == index
    if (cmd == null || cmd.equals("")) {
      cmd = "index";
    }

    if ("keyinfo".equals(cmd)) {
      handleKeyInfo(request, response, method, cmd, args);
    } else if ("keygraph".equals(cmd)) {
      handleKeyGraph(request, response, method, cmd, args);
    } else if ("index".equals(cmd)) {
      RenderVelocityAction action = new RenderVelocityAction(request, response, method, "index.vm");
      handleAction(action, cmd, args, request);
    } else if ("echo".equals(cmd)) {
      RenderVelocityAction action = new RenderVelocityAction(request, response, method, "echo.vm");
      handleAction(action, cmd, args, request);
    } else if ("ajax_nodes_edges".equals(cmd)) {

      Element res = new Element("nodes_edges");
      // add key
      String keyid = getValueString("keyid", args);
      if (keyid != null) {
        System.out.println("ajax_nodes_edges:: keyid=" + keyid);
        Vector<String> keyids = new Vector<String>();
        // key basics
        OSDXKey key = getBackend().getKey(keyid);
        if (key != null) {
          res.addContent(key.getSimplePubKeyElement());
          keyids.add(key.getKeyID());

          // add keylogs and fromKeys
          Vector<KeyLog> logs = getBackend().getKeyLogsToID(key.getKeyID());
          if (logs != null && logs.size() > 0) {
            for (KeyLog l : logs) {
              if (!keyids.contains(l.getKeyIDFrom())) {
                OSDXKey fromkey = getBackend().getKey(l.getKeyIDFrom());
                if (fromkey != null) {
                  res.addContent(fromkey.getSimplePubKeyElement());
                  keyids.add(fromkey.getKeyID());
                }
              }
              res.addContent(l.toElement(false));
            }
          }
        }
      }
      response.setContentType("text/xml");
      try {
        PrintWriter out = response.getWriter();
        out.println(Document.buildDocument(res).toStringCompact());
        out.flush();
        out.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Example #2
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse)
      throws Exception {

    LazyValidatorForm frm = (LazyValidatorForm) actionForm;
    LoginInfo loginInfo = (LoginInfo) httpServletRequest.getSession().getAttribute("loginInfo");
    if (formCanceled(frm)) {
      return actionMapping.findForward(SUCCESS);
    }
    resetFocusControl(frm, CANCEL);
    ActionMessages msgs = new ActionMessages();
    DocInvTransactionInfo inf = new DocInvTransactionInfo();
    if (!formSaved(frm)) {
      setFormMode(frm, ((String) httpServletRequest.getParameter(BROWSE_ACTION)));
      setFormId(frm, (String) httpServletRequest.getParameter(BROWSE_ID));
      try {
        short officeCode = loginInfo.getOfficeCode();
        if (!loginInfo.userHasAccess(getFormId(frm), getFormMode(frm))) {
          if (isFormInModifyMode(frm)
              && loginInfo.userHasAccess(getFormId(frm), Constants.ActionType.ENQUERY)) {
            setFormMode(frm, Constants.ActionType.ENQUERY);
          } else {
            throw new Exception(INVALID_ACCESS);
          }
        }
        if (!isFormInAddMode(frm)) {
          String formKey = (String) httpServletRequest.getParameter(BROWSE_KEY);
          frm.set("formKey", formKey);
          StringTokenizer st = new StringTokenizer(formKey, Constants.DATA_SEPARATOR);
          officeCode = Short.parseShort(st.nextToken());
          String eventType = st.nextToken();
          String docType = st.nextToken();
          String docSeri = st.nextToken().trim();
          int docStartSrno = Integer.parseInt(st.nextToken());
          inf = Inventory.getDetails(officeCode, eventType, docType, docSeri, docStartSrno);
          frm.set(ASSIGN_DATE, DateUtils.revFormatDate(inf.getEventDate()));
          frm.set(DOC_SERI, inf.getDocSeri());
          frm.set(DOC_START_SRNO, Integer.toString(inf.getDocStartSrno()));
          frm.set(DOC_END_SRNO, Integer.toString(inf.getDocEndSrno()));
        }
        if (isFormInAddMode(frm)) {
          frm.set(ASSIGN_DATE, DateUtils.fDateRevFormatted());
          resetFocusControl(frm, DOC_SERI);
        }

      } catch (Exception ex) {
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
      }
      return actionMapping.findForward(EDIT);

    } else {
      String assignDate = ((String) frm.get(ASSIGN_DATE)).trim();
      if (Utils.isEmpty(assignDate)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "تاريخ تخصيص");
        setFocusControl(frm, ASSIGN_DATE);
      } else if (!DateUtils.isValidRevFormattedFDate(assignDate)
          || Integer.parseInt(DateUtils.unformatRevFormattedFdate(assignDate))
              > Integer.parseInt(DateUtils.fDate())) {
        addError(msgs, FIELD_INVALID, "تاريخ تخصيص");
        setFocusControl(frm, ASSIGN_DATE);
      } else {
        inf.setEventDate(DateUtils.unformatRevFormattedFdate(assignDate));
      }
      inf.setOfficeCode(loginInfo.getOfficeCode());
      inf.setEventType(Constants.EventType.ASSIGN);

      String docSeri = Utils.charVal2((String) frm.get(DOC_SERI));
      if (Utils.isEmpty(docSeri)) {
        addError(msgs, FIELD_INVALID, "سري كارتهاي شناسايي");
        setFocusControl(frm, DOC_SERI);
      } else {
        inf.setDocSeri(docSeri);
        frm.set(DOC_SERI, docSeri);
      }
      String docStartSrno = ((String) frm.get(DOC_START_SRNO)).trim();
      if (Utils.isEmpty(docStartSrno)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال شروع");
        setFocusControl(frm, DOC_START_SRNO);
      }
      String docEndSrno = ((String) frm.get(DOC_END_SRNO)).trim();
      if (Utils.isEmpty(docEndSrno)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال خاتمه");
        setFocusControl(frm, DOC_END_SRNO);
      } else {
        if (!Utils.isValidNumber(docStartSrno, 6) || !Utils.isValidNumber(docEndSrno, 6)) {
          addError(msgs, FIELD_INVALID, "محدوده سريال كارت شناسايي");
          setFocusControl(frm, DOC_START_SRNO);
        } else {
          if (Integer.parseInt(docStartSrno) > Integer.parseInt(docEndSrno)) {
            addError(msgs, FIELD_INVALID, "محدوده سريال كارت شناسايي");
            setFocusControl(frm, DOC_START_SRNO);
          } else {
            inf.setDocStartSrno(Integer.parseInt(docStartSrno));
            inf.setDocEndSrno(Integer.parseInt(docEndSrno));
          }
        }
      }

      inf.setMamoorId("9991");
      inf.setUserId(loginInfo.getUserId());
      inf.setDocType(Constants.DocType.ID_CARD_CENTRAL_BANK);

      if (!msgs.isEmpty()) {
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
      resetFocusControl(frm, CANCEL);
      // Save Data
      try {
        String eventErrorCode = null;
        if (isFormInDeleteMode(frm)) {
          eventErrorCode = Inventory.deleteAssign(inf);
        } else {
          eventErrorCode = Inventory.addAssign(inf);
        }
        if (!Utils.isEmpty(eventErrorCode)) {
          StringTokenizer st = new StringTokenizer(eventErrorCode, Constants.FIELD_SEPARATOR);
          int countErrorToken = st.countTokens();
          for (int countError = 1; countError <= countErrorToken; countError++) {
            addError(msgs, st.nextToken());
          }
          saveErrors(httpServletRequest, msgs);
          return actionMapping.findForward(EDIT);
        } else {
          httpServletRequest.setAttribute(BROWSE_KEY, inf.getKey());
          return actionMapping.findForward(SUCCESS);
        }
      } catch (Exception ex) {
        resetFocusControl(frm, CANCEL);
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
    }
  }