コード例 #1
0
ファイル: SlidenewsTag.java プロジェクト: Mrchenkeyu/Practice
 /** 标签体处理 */
 public void doTag() throws JspException, IOException {
   // 使用WebApplicationContextUtils工具类获取Spring IOC容器中的dao实例
   dao =
       (BaseDAOImpl)
           WebApplicationContextUtils.getRequiredWebApplicationContext(
                   ((PageContext) getJspContext()).getServletContext())
               .getBean("dao");
   // 构造查询新闻列表的HQL语句
   if (newstype.equals("4")) { // 所有类型
     hql =
         " from News as a where a.status=1 and a.newscolumns.columnCode in("
             + Tools.formatString(section)
             + ") and a.isPicNews=1 order by a.priority desc,a.id desc";
   } else {
     hql =
         " from News as a where a.status=1 and a.newscolumns.columnCode in("
             + Tools.formatString(section)
             + ") and a.newsType="
             + newstype
             + " and a.isPicNews=1 order by a.priority desc,a.id desc";
   }
   StringBuffer sb = new StringBuffer();
   List list = dao.query(hql, 1, number);
   if (list == null || list.size() == 0) {
     // 输出处理结果到页面上
     getJspContext().getOut().println("");
     return;
   }
   Iterator it = list.iterator();
   sb.append("    <script language=javascript>\n");
   sb.append("	var focus_width" + slideno + "=" + width + ";     /*幻灯片新闻图片宽度*/\n");
   sb.append("	var focus_height" + slideno + "=" + height + ";    /*幻灯片新闻图片高度*/\n");
   sb.append("	var text_height" + slideno + "=20;    /*幻灯片新闻文字标题高度*/\n");
   sb.append(
       "	var swf_height"
           + slideno
           + " = focus_height"
           + slideno
           + "+text_height"
           + slideno
           + ";\n");
   sb.append("	var pics" + slideno + " = '';\n");
   sb.append("	var links" + slideno + " = '';\n");
   sb.append("	var texts" + slideno + " = '';\n");
   sb.append("	function ati" + slideno + "(url, img, title)\n");
   sb.append("	{\n");
   sb.append("		if(pics" + slideno + " != '')\n");
   sb.append("		{\n");
   sb.append("			pics" + slideno + " = \"|\" + pics" + slideno + ";\n");
   sb.append("			links" + slideno + " = \"|\" + links" + slideno + ";\n");
   sb.append("			texts" + slideno + " = \"|\" + texts" + slideno + ";\n");
   sb.append("		}");
   sb.append("		pics" + slideno + " = escape(img) + pics" + slideno + ";\n");
   sb.append("		links" + slideno + " = escape(url) + links" + slideno + ";\n");
   sb.append("		texts" + slideno + " = title + texts" + slideno + ";\n");
   sb.append("	}\n");
   sb.append("    </script>\n");
   sb.append("    <script language=javascript>	\n");
   while (it.hasNext()) {
     obj = (News) it.next();
     if (obj.getTitle().length() > titlelen) {
       sb.append(
           "      ati"
               + slideno
               + "('"
               + baseurl
               + obj.getHtmlPath()
               + "', '"
               + baseurl
               + "/"
               + obj.getPicture().trim()
               + "', '"
               + Tools.cutString(obj.getTitle(), titlelen * 2)
               + "');\n");
     } else {
       sb.append(
           "      ati"
               + slideno
               + "('"
               + baseurl
               + obj.getHtmlPath()
               + "', '"
               + baseurl
               + "/"
               + obj.getPicture().trim()
               + "', '"
               + obj.getTitle()
               + "');\n");
     }
   }
   sb.append(
       "	document.write('<embed src=\""
           + baseurl
           + "/js/pixviewer.swf\" wmode=\"opaque\" FlashVars=\"pics='+pics"
           + slideno
           + "+'&links='+links"
           + slideno
           + "+'&texts='+texts"
           + slideno
           + "+'&borderwidth='+focus_width"
           + slideno
           + "+'&borderheight='+focus_height"
           + slideno
           + "+'&textheight='+text_height"
           + slideno
           + "+'\" menu=\"false\" bgcolor=\"#DADADA\" quality=\"high\" width=\"'+ focus_width"
           + slideno
           + "+'\" height=\"'+ swf_height"
           + slideno
           + " +'\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\"/>');	\n");
   sb.append("</script>\n");
   // 输出处理结果到页面上
   getJspContext().getOut().println(sb);
 }