jsp使用自訂標籤taglib分頁系列——TableTag.java __js

來源:互聯網
上載者:User

package com.avantouch.common.web.struts.taglib.table;

import javax.servlet.jsp.JspException;

import org.apache.struts.util.ResponseUtils;

/**
 * <p>Title TableTag.java</p>
 * <p>Description  </p>
 * <p>Copyright:  Copyright (c) 2004 AvanTouch,Inc</p>
 * <p>Company:  AvanTouch,Inc</p>
 * @author:  david 2004-12-6
 * @modifier:
 * @version  1.0
 */
public class TableTag extends TableBase {
 public static final String[] FrameValue =
  {
   "above",
   "below",
   "border",
   "box",
   "hsides",
   "lhs",
   "rhs",
   "void",
   "vsides" };

 public static final String[] RulesValue =
  { "all", "cors", "groups", "none", "rows" };
 private String backgroud = null;
 private String border = null;
 private String cellPadding = null;
 private String cellSpacing = null;
 private String cols = null;
 private String datapagesize = null;
 private String frame = null;
 private String rules = null;
 private String vspace = null;
 private String hspace = null;
 private String summary = null;
 private String caption = null;
 private String width = "65%";
 /**
  * styleClass1_TR and styleClass2_TR associated with TR tag
  */
 private String styleClass1_TR = null;

 private String styleClass2_TR = null;

 /**
  * set td common attributes value
  * <p><code>setTableCommonAttributes</code></p>
  * @param handlers
  * @author david 2004-12-6
  * @Since 1.0
  */
 public void setTableCommonAttributes(StringBuffer handlers) {
  if (border != null && !border.trim().equals("")) {
   handlers.append("  BORDER=/"" + border + "/"");
  }
  if (cellPadding != null && !cellPadding.trim().equals("")) {
   handlers.append("  CELLPADDING=/"" + cellPadding + "/"");
  }
  if (cellSpacing != null && !cellSpacing.trim().equals("")) {
   handlers.append("  CELLSPACING=/"" + cellSpacing + "/"");
  }
  if (width != null && !width.trim().equals("")) {
   handlers.append("  WIDTH=/"" + width + "/"");
  }

  setT_CommonAttributes(handlers);

  if (backgroud != null && !backgroud.trim().equals("")) {
   handlers.append("  BACKGROUD=/"" + backgroud + "/"");
  }
  if (cols != null && !cols.trim().equals("")) {
   handlers.append("  COLS=/"" + cols + "/"");
  }
  if (datapagesize != null && !datapagesize.trim().equals("")) {
   handlers.append("  DATAPAGESIZE=/"" + datapagesize + "/"");
  }

  if (frame != null && !frame.trim().equals("")) {
   handlers.append("  FRAME=/"" + frame + "/"");
  }

  if (summary != null && !summary.trim().equals("")) {
   handlers.append("  SUMMARY=/"" + summary + "/"");
  }
  if (vspace != null && !vspace.trim().equals("")) {
   handlers.append("  VSPACE=/"" + vspace + "/"");
  }
  if (hspace != null && !hspace.trim().equals("")) {
   handlers.append("  HSPACE=/"" + hspace + "/"");
  }
  if (rules != null && !rules.trim().equals("")) {
   handlers.append("  RULES=/"" + rules + "/"");
  }

 } // end setTableCommonAttributes

 /**
  * set table caption
  * <p><code>setTableCaption</code></p>
  * @param buffer
  * @return
  * @author david 2004-12-6
  * @Since 1.0
  */
 public StringBuffer setTableCaption(StringBuffer buffer) {
  StringBuffer buf = buffer;

  if (caption != null && !caption.trim().equals("")) {
   buf.append(" <CAPTION><EM>" + caption + "</EM></CAPTION>/n");
  }
  return buf;

 } // end setTableCaption

 public int doStartTag() throws JspException {
  validateFrame();
  validateDir();
  validateRules();

  StringBuffer buf = new StringBuffer("<TABLE");
  setT_ID(buf);
  setTableCommonAttributes(buf);
  prepareEvents_T(buf);
  buf.append(">/n");

  setTableCaption(buf);

  ResponseUtils.write(pageContext, buf.toString());
  if (styleClass1_TR != null
   && styleClass2_TR != null
   && !styleClass1_TR.trim().equals("")
   && !styleClass2_TR.trim().equals("")) {
   pageContext.setAttribute("TRCALSS1", styleClass1_TR);
   pageContext.setAttribute("TRCALSS2", styleClass2_TR);
   pageContext.setAttribute("currentTRCLASS", "0");
  }
  return (EVAL_BODY_INCLUDE);
 }
 public int doEndTag() throws JspException {
  StringBuffer buf = new StringBuffer("</TABLE>/n");
  ResponseUtils.write(pageContext, buf.toString());
  release();
  // Continue processing this page
  return (EVAL_PAGE);
 }

 /**
  * Release all allocated resources.
  */
 public void release() {
  super.release();
  backgroud = null;
  border = null;
  cellPadding = null;
  cellSpacing = null;
  cols = null;
  datapagesize = null;
  frame = null;
  rules = null;
  vspace = null;
  hspace = null;
  summary = null;
  caption = null;
  width = "65%";
  styleClass1_TR = null;
  styleClass2_TR = null;
  if (styleClass1_TR != null) {
   pageContext.removeAttribute("TRCALSS1");
   pageContext.removeAttribute("TRCALSS2");
   pageContext.removeAttribute("currentTRCLASS");
  }
 } // end release
 public String getBackgroud() {
  return backgroud;
 }
 public void setBackgroud(String backgroud) {
  this.backgroud = backgroud;
 }
 public String getBorder() {
  return border;
 }
 public void setBorder(String border) {
  this.border = border;
 }
 public String getCaption() {
  return caption;
 }
 public void setCaption(String caption) {
  this.caption = caption;
 }
 public String getCellPadding() {
  return cellPadding;
 }
 public void setCellPadding(String cellPadding) {
  this.cellPadding = cellPadding;
 }
 public String getCellSpacing() {
  return cellSpacing;
 }
 public void setCellSpacing(String cellSpacing) {
  this.cellSpacing = cellSpacing;
 }
 public String getCols() {
  return cols;
 }
 public void setCols(String cols) {
  this.cols = cols;
 }
 public String getDatapagesize() {
  return datapagesize;
 }
 public void setDatapagesize(String datapagesize) {
  this.datapagesize = datapagesize;
 }
 public String getFrame() {
  return frame;
 }
 public void setFrame(String frame) {
  this.frame = frame;
 }
 public String getHspace() {
  return hspace;
 }
 public void setHspace(String hspace) {
  this.hspace = hspace;
 }
 public String getRules() {
  return rules;
 }
 public void setRules(String rules) {
  this.rules = rules;
 }
 public String getStyleClass1_TR() {
  return styleClass1_TR;
 }
 public void setStyleClass1_TR(String styleClass1_TR) {
  this.styleClass1_TR = styleClass1_TR;
 }
 public String getStyleClass2_TR() {
  return styleClass2_TR;
 }
 public void setStyleClass2_TR(String styleClass2_TR) {
  this.styleClass2_TR = styleClass2_TR;
 }
 public String getSummary() {
  return summary;
 }
 public void setSummary(String summary) {
  this.summary = summary;
 }
 public String getVspace() {
  return vspace;
 }
 public void setVspace(String vspace) {
  this.vspace = vspace;
 }
 public String getWidth() {
  return width;
 }
 public void setWidth(String width) {
  this.width = width;
 }
 /**
  * validate frame's value 
  * p><code>validateFrame</code></p>
  * @throws JspException
  * @author david 2004-12-1
  * @Since 1.0
  */
 public void validateFrame() throws JspException {
  if (frame == null || frame.trim().equals("")) {
   return;
  }
  int i = 0;
  for (; i < FrameValue.length; i++) {
   if (frame.equalsIgnoreCase(FrameValue[i]))
    break;
  }
  if (i >= FrameValue.length) {
   throw new JspException(
    frame
     + ":Frame's value is lawless(above,below,border,box,hsides,lhs,rhs,void,vsides)!");
  }
 } // end validateFrame

 /**
  * validate rules's value 
  * <p><code>validateRules</code></p>
  * @throws JspException
  * @author david 2004-12-1
  * @Since 1.0
  */
 public void validateRules() throws JspException {
  if (rules == null || rules.trim().equals("")) {
   return;
  }
  int i = 0;
  for (; i < RulesValue.length; i++) {
   if (rules.equalsIgnoreCase(RulesValue[i]))
    break;
  }
  if (i >= RulesValue.length) {
   throw new JspException(
    rules
     + ":Rules's value is lawless(all,cols,groups,none,rows)!");
  }
 } // end validateRules
} // end TableTag
 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.