关闭

页面模板的标记封装

435人阅读 评论(0) 收藏 举报

package component.tags;

 

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import java.util.Vector;
/**
 * <p>页面模板的标记封装</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author
 * @version 1.0
 */

public class TemplateSelectTag extends TagSupport{

  //TagLib 属性
   private String mtemplatetype;   //备用 "page"--页面模板  "plugin"--插件模板
   private String mtemplateid;     // 当前选中的nodeid
   private String mselectname;     // select 列表框的名称
   private String mhasdisable;     // 是否禁止选择
   private String mupnodeid;

  // 属性初始化
  public void settemplatetype(String value)
  {
    this.mtemplatetype = value;
  }
  public void settemplateid(String value)
  {
     this.mtemplateid = value;
  }
  public void setselectname(String value)
  {
     this.mselectname = value;
  }

  public void sethasdisable(String value)
  {
     this.mhasdisable = value;
  }
  public void setupnodeid(String value)
  {
    this.mupnodeid = value;
  }

 // 处理标记
 public int doStartTag() throws JspException
 {

   String strReturnSelect="";
   try
   {
     //是否设置为Disable
     if(mhasdisable.equals("true"))
     {
       strReturnSelect="<select name='" + mselectname +"' disabled>/n";
     }
     else
     {
       strReturnSelect="<select name='" + mselectname +"'>/n";
     }
     if(mtemplatetype.equals("page"))
     {
        strReturnSelect += getPageOption();
     }
     if(mtemplatetype.equals("plugin"))
     {
       strReturnSelect += getPluginOption();
     }
     strReturnSelect+="</select>/n";
     pageContext.getOut().print(strReturnSelect);

   }
   catch(java.io.IOException ex)
   {
     throw new JspException(ex.getMessage());
   }
   return SKIP_BODY;
 }

  private String getPageOption()
  {
      // 从数据库加载
      String strReturnSelect="";
      TemplateManager mgr = (TemplateManager)RequestHelper.getBean("templateManager",this.pageContext.getServletContext());
      try
      {
         Vector vpage = new Vector();
         vpage = mgr.loadPageTemplate();
         for(int i=0;i<vpage.size();i++)
         {
            PageTemplate obj = (PageTemplate)vpage.get(i);
            if(mtemplateid.equals(obj.pageid))
            {
              strReturnSelect += "<option value='" + obj.pageid + "' selected>" +
                        obj.name + "</option>/n";
             }
            else
            {
              strReturnSelect += "<option value='" + obj.pageid + "'>" + obj.name +
                    "</option>/n";
            }
         }
      }
      catch(Exception e)
      {
         System.out.print("取页面模板错误:"+e.getMessage());
      }
      return strReturnSelect;
  }

  private String getPluginOption()
  {
    // 从数据库加载
     Node node=new Node();
     node.setNODEID(mupnodeid);
     DbConnection con=null;
     DataAccess da=new DataAccess();
     String strReturnSelect="";
     TemplateManager mgr = (TemplateManager)RequestHelper.getBean("templateManager",this.pageContext.getServletContext());
     String siteId="";
     try
     {
        con = RequestHelper.getConnection(this.pageContext.getServletContext());
        da.select(con,new String[]{"NODEID"},node) ;
        siteId=node.getFULLNAME();
        siteId=siteId.substring(1);
        siteId=siteId.substring(0,siteId.indexOf("/"));
        //System.out.println(siteId);

        Vector vplugin = new Vector();
        vplugin = mgr.loadPlugin();
        String fullName="";
        for(int i=0;i<vplugin.size();i++)
        {
           PubPlugin obj = (PubPlugin)vplugin.get(i);
           //@todo siteid ="4" 作为公共组件判断条件需要修改
           if(siteId.equals(obj.SITEID)||obj.SITEID.equals("4"))
           {
             if (mtemplateid.equals(obj.PLUGINID)) {
               strReturnSelect += "<option value='" + obj.PLUGINID + "' selected>" +
                   obj.PLUGINNAME + "</option>/n";
             }
             else {
               strReturnSelect += "<option value='" + obj.PLUGINID + "'>" +
                   obj.PLUGINNAME +
                   "</option>/n";
             }
           }
        }

     }
     catch(Exception e)
     {
        System.out.print("取插件库错误:"+e.getMessage());
     }
     finally
     {
       con.close();
     }
     return strReturnSelect;
  }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:173543次
    • 积分:3274
    • 等级:
    • 排名:第10726名
    • 原创:153篇
    • 转载:10篇
    • 译文:1篇
    • 评论:23条
    最新评论