Esempio n. 1
0
  /**
   * Description of the Method
   *
   * @param s Description of the Parameter
   * @return Description of the Return Value
   */
  protected Element makeInput(WebSession s) {
    Table t = new Table(0).setCellSpacing(0).setCellPadding(0).setBorder(0);
    TR row1 = new TR();
    TR row2 = new TR();
    row1.addElement(new TD(new StringElement(WebGoatI18N.get("Title") + ": ")));

    Input inputTitle = new Input(Input.TEXT, TITLE, "");
    row1.addElement(new TD(inputTitle));

    TD item1 = new TD();
    item1.setVAlign("TOP");
    item1.addElement(new StringElement(WebGoatI18N.get("Message") + ": "));
    row2.addElement(item1);

    TD item2 = new TD();
    TextArea ta = new TextArea(MESSAGE, 5, 60);
    item2.addElement(ta);
    row2.addElement(item2);
    t.addElement(row1);
    t.addElement(row2);

    Element b = ECSFactory.makeButton(WebGoatI18N.get("Submit"));
    ElementContainer ec = new ElementContainer();
    ec.addElement(t);
    ec.addElement(new P().addElement(b));

    return (ec);
  }
  /**
   * Handle actions for the DeleteRecordDelegate.
   *
   * @throws IOException, standard exception thrown by servlet methods.
   * @throws ServletException, standard exception thrown by servlet methods.
   */
  public void run() throws IOException, ServletException {
    try {
      // validate
      Util.argCheckNull(_request);
      Util.argCheckNull(_response);

      // make the cell
      MdnClientCell client = new MdnClientCell();
      client.setAlign(AlignType.CENTER);
      client.setClientTitle(ConfirmDeleteDelegate.TEXT_DELETE_TITLE.getText());
      client.setHelpUrl("/help/mdnhelp.html#bDeleteRecord");

      // table and title
      WslHtmlTable table = new WslHtmlTable();
      client.addElement(table);
      TD cell =
          new TD(MdnHtmlServlet.getTitleElement(ConfirmDeleteDelegate.TEXT_DELETE_TITLE.getText()));
      cell.setColSpan(2);
      TR row = new TR(cell);
      table.addElement(row);

      // get the rec index
      String strIndex = _request.getParameter(MdnHtmlServlet.PV_RECORD_INDEX);
      if (strIndex != null && strIndex.length() > 0) {
        int index = Integer.parseInt(strIndex);

        // get the record
        PagedSelectDelegate psd = (PagedSelectDelegate) getUserState().getCurrentPagedQuery();
        Record rec = psd.getRecord(index);
        if (rec != null) {
          // delete the record
          rec.delete();

          // delegate to query
          int queryId = psd.getQueryId();
          String strQueryId = String.valueOf(queryId);
          delegate(new QueryRecordsDelegate(strQueryId));
          return;
        } else
          table.addElement(
              new TR(new TD(WslHtmlUtil.esc(MdnHtmlServlet.ERR_REC_NOT_FOUND.getText()))));
      } else
        table.addElement(
            new TR(new TD(WslHtmlUtil.esc(MdnHtmlServlet.ERR_REC_NOT_FOUND.getText()))));

      // send output
      outputClientCell(client);
    } catch (Exception e) {
      onError(ERR_DELETE.getText(), e);
    }
  }
Esempio n. 3
0
  /** output HTML for button */
  protected void endHTML(PrintWriter out) {
    Span span = new Span();
    Table table = new Table();
    TR top = new TR();
    TD topLeft = new TD();
    TD topCenter = new TD();
    TD topRight = new TD();
    TR middle = new TR();
    TD midLeft = new TD();
    TD midCenter = new TD();
    TD midRight = new TD();
    TR bottom = new TR();
    TD botLeft = new TD();
    TD botCenter = new TD();
    TD botRight = new TD();
    Span textContainer = new Span();
    org.apache.ecs.html.Button button = new org.apache.ecs.html.Button();
    boolean disabled = getContext().processBool(getId() + ".disabled");

    // build table
    table.addElement(top);
    top.addElement(topLeft);
    top.addElement(topCenter);
    top.addElement(topRight);

    table.addElement(middle);
    middle.addElement(midLeft);
    middle.addElement(midCenter);
    middle.addElement(midRight);

    table.addElement(bottom);
    bottom.addElement(botLeft);
    bottom.addElement(botCenter);
    bottom.addElement(botRight);

    // set pixels
    IMG spacer = new IMG("./images/wgt/1.gif");
    spacer.setWidth(1);
    spacer.setHeight(1);
    topLeft.addElement(new IMG("./images/wgt/1.gif"));
    topCenter.addElement(new IMG("./images/wgt/1.gif"));
    topRight.addElement(new IMG("./images/wgt/1.gif"));
    midLeft.addElement(new IMG("./images/wgt/1.gif"));
    midRight.addElement(new IMG("./images/wgt/1.gif"));
    botLeft.addElement(new IMG("./images/wgt/1.gif"));
    botCenter.addElement(new IMG("./images/wgt/1.gif"));
    botRight.addElement(new IMG("./images/wgt/1.gif"));

    // format table
    table.setCellPadding(0);
    table.setCellSpacing(0);
    table.setBorder(0);

    // set classes
    topLeft.setClass("btn_lt");
    topCenter.setClass("btn_ct");
    topRight.setClass("btn_rt");
    midLeft.setClass("btn_lm");
    midCenter.setClass("btn_cm");
    midRight.setClass("btn_rm");
    botLeft.setClass("btn_lb");
    botCenter.setClass("btn_cb");
    botRight.setClass("btn_rb");

    button.setClass("btn_btn");
    button.setID(getId() + "_btn");
    midCenter.addElement(button);
    textContainer.setID(id4Text());
    textContainer.setClass("btn_txt");

    if (StringUtils.isNotEmpty(getSrc())) {
      if (StringUtils.isEmpty(this.getLabel())) {
        button.setStyle(
            "width:"
                + iconWidth
                + "px;height:"
                + iconHeight
                + "px;background: transparent url("
                + getSrc()
                + ") no-repeat; background-position: center;");
      } else {
        button.setStyle("background: transparent url(" + getSrc() + ") no-repeat;");
      }
    }

    if (StringUtils.isNotEmpty(this.getLabel())) {
      if (StringUtils.isNotEmpty(getSrc()) && iconWidth > -1) {
        if (displayMode == DISPLAY_MODE_VERTICAL) {
          // image top
          String s = button.getAttribute("style");
          s =
              s
                  + "background-position: center top;padding-top:"
                  + String.valueOf(iconHeight)
                  + "px;";
          button.setStyle(s);
        } else {
          // image left
          textContainer.setStyle("padding-left: " + String.valueOf(iconWidth) + "px;");
        }
      }
      textContainer.addElement(this.getLabel());
      button.addElement(textContainer);
    }

    // this.getStyle().add("table-layout", "fixed");

    if (this.hasStyle()) {
      table.setStyle(this.getStyleAsString());
    }

    midCenter.setID(getId());
    // midCenter.setOnClick(JSUtil.jsFireEvent(getId(),
    //		ClientEvent.TYPE_ACTION)
    //		+ " return false;");
    button.setOnClick(JSUtil.jsFireEvent(getId(), ClientEvent.TYPE_ACTION) + " return false;");
    // action goes to onClick handler
    if (getConfirmMsg() != null) {
      button.setOnClick(
          JSUtil.jsConfirm(
              TextService.getString(getConfirmMsg()),
              JSUtil.jsFireEvent(getId(), ClientEvent.TYPE_ACTION)));
    } else {
      button.setOnClick(JSUtil.jsFireEvent(getId(), ClientEvent.TYPE_ACTION) + " return false;");
    }

    // table.output(out);
    span.addElement(table);
    span.setID(getId() + "_sspan");
    if (block && isVisible()) {
      span.setStyle("display:block;");
    }

    span.output(out);

    this.initJaveScript();
  }