?? createnewshtml.java
字號:
package com.buildhtml;
import com.saas.sys.log.Logger;
import tools.util.FileIO;
import tools.util.StrReplace;
import tools.util.StringUtil;
import com.saas.biz.attachMgr.Attachinfo;
import com.saas.biz.newsMgr.NewsInfo;
import com.saas.sys.exp.SaasApplicationException;
import com.saas.biz.productclassMgr.Productclass;
import java.util.*;
/**
* Created by caiwch
* User: wang
* Date: 2007-11-13
* Time: 16:55:15
*/
public class CreateNewsHtml
{
Logger log = new Logger(this);
FileAndString FileString =new FileAndString();
public void buildIndex( String rootpath )throws SaasApplicationException
{
String str = "";
String strTemp = "";
String filepath = rootpath+ "/" + "news/index.html";
String templatePath = rootpath +"/" + "templates/news.html";
String templateStr = FileIO.LoadFile( templatePath );
log.LOG_INFO( "filepath" + filepath );
log.LOG_INFO( "templatePath" + templatePath );
String []tab = { "{#include:top#}", "{#include:bottom#}"};
str = StrReplace.replace( templateStr,tab[0],FileString.f2s( rootpath + "/top.html" ) );
str = StrReplace.replace( str,tab[1],FileString.f2s( rootpath + "/footer.html" ) );
//級別資訊***********************
log.LOG_INFO("級別資訊");
String initStr = "<tr><td height=\"22\"><a href=\"{#link#}\" class=\"news\">{#title#}</a> </td><td class=\"zi\">[{#date#}]</td></tr> "+
"<tr><td height=\"1\" class=\"xian\"></td><td class=\"xian\"></td></tr>";
String []images = { "{#image:1#}","{#image:2#}","{#image:3#}","{#image:4#}","{#image:5#}" };
strTemp = "";
NewsInfo news = new NewsInfo();
ArrayList nwsList = news.genNewsByLevel( 5 );
if( nwsList != null && nwsList.size() > 0 )
{
for( int i = 0; i < nwsList.size(); i++ )
{
HashMap nwsmap = ( HashMap )nwsList.get( i );
String news_id = nwsmap.get( "news_id" ).toString();
String cust_id = nwsmap.get( "cust_id" ).toString();
String title = "";
String publish_date = "";
if( nwsmap.get( "title" ) != null )
{
title = nwsmap.get( "title" ).toString();
if( title.length() > 10 )
{
title = StringUtil.getLimitLengthString(title,"",22 );
}
}
if( nwsmap.get( "publish_date" ) != null )
{
publish_date = nwsmap.get( "publish_date" ).toString();
if( publish_date.length() > 10 )
{
publish_date = publish_date.substring( 2, 10 );
}
}
String file_path = new NewsInfo().getCustAttachPath( news_id, "0");
if( file_path == "" || file_path == null )
{
file_path = "/upload/default.gif";
}
str = StrReplace.replace(str,images[i], file_path );
strTemp = strTemp + initStr;
strTemp = StrReplace.replace( strTemp, "{#link#}", "zixun_list_content.jsp?news_id="+news_id );///////////////////////////////////////////////////////////
strTemp = StrReplace.replace( strTemp, "{#title#}", title );
strTemp = StrReplace.replace( strTemp, "{#date#}", publish_date );
}
}
str = StrReplace.replace( str, "{#Level:Information#}", strTemp );
log.LOG_INFO( "今日要聞" );
initStr = "<div align=center><a href=\"{#href#}\" class=\"ABC\">{#title#}</a></div>{#content#}";
String initStr1 = "<li>[<span class=\"zi\">{#newtype#}</span>]<a href = \"{#href#}\" class=\"news\">{#title#}</a></li>";
strTemp = "";
String strTemp1 = "";
String strTemp2 = "";
ArrayList newList = news.genNewsByToday( 9 );
if( newList != null && newList.size() > 0 )
{
for( int i = 0; i < newList.size(); i++ )
{
HashMap map = ( HashMap )newList.get( i );
String news_id ="";
String news_type = "",class_type="";
String title = "";
String content = "";
if( map.get( "news_id" ) != null )
{
news_id = map.get( "news_id" ).toString();
}
if( map.get( "title" ) != null )
{
title = map.get( "title" ).toString();
if( title.length() > 10 )
{
title = StringUtil.getLimitLengthString(title,"",30 );
}
}
if( map.get( "content" ) != null )
{
content = map.get( "content" ).toString();
if( content.length() > 40 )
content = StringUtil.getLimitLengthString(content,"",80 ) + "...";
}
if (map.get("news_type") != null)
{
news_type = map.get("news_type").toString();
ArrayList list=new Productclass().genUpclassByClassId( news_type );
if(list !=null && list.size()>0)
{
HashMap claMap=(HashMap)list.get(0);
if( claMap.get( "class_name" ) != null )
{
class_type = claMap.get("class_name").toString();
}
}
}
if( i == 0 )
{
strTemp = strTemp + initStr;
strTemp = StrReplace.replace( strTemp, "{#href#}", "zixun_list_content.jsp?news_id="+news_id );///////////////////////////////////////////////////////////
strTemp = StrReplace.replace( strTemp, "{#title#}", title );
strTemp = StrReplace.replace( strTemp, "{#content#}", content );
}
else if( i >=1 && i < newList.size() )
{
strTemp1 = strTemp1 + initStr1;
strTemp1 = StrReplace.replace( strTemp1, "{#newtype#}", class_type );
strTemp1 = StrReplace.replace( strTemp1, "{#href#}", "zixun_list_content.jsp?news_id="+news_id );///////////////////////////////////////////////////////////
strTemp1 = StrReplace.replace( strTemp1, "{#title#}", title );
}
}
}
str = StrReplace.replace( str, "{#Today:title:contnet#}", strTemp );
str = StrReplace.replace( str, "{#today:list#}", strTemp1 );
//最新資訊
log.LOG_INFO( "最新資訊" );
initStr = "<li><a href=\"{#href#}\" title=\"{#long:title#}\" class=\"news\">·{#title#}</a> </li>";
strTemp = "";
ArrayList newsList = news.genNews();
// log.LOG_INFO( "" + newsList );
if( newsList != null && newsList.size() > 0 )
{
for( int i = 0; i < newsList.size(); i++ )
{
HashMap map = ( HashMap )newsList.get( i );
String news_id ="";
String title = "";
String sub_title = "";
if( map.get( "news_id" ) != null )
{
news_id = map.get( "news_id" ).toString();
}
if( map.get( "title" ) != null )
{
title = map.get( "title" ).toString();
if( title.length() > 15 )
{
sub_title = StringUtil.getLimitLengthString(title,"",30 ) + "..";
}
else
{
sub_title = title;
}
}
strTemp = strTemp + initStr;
strTemp = StrReplace.replace( strTemp, "{#href#}", "zixun_list_content.jsp?news_id="+news_id );///////////////////////////////////////////////////////////
strTemp = StrReplace.replace( strTemp, "{#title#}", sub_title );
strTemp = StrReplace.replace( strTemp, "{#long:title#}", title );
}
}
str = StrReplace.replace( str, "{#Latest:news#}", strTemp );
//顯示方式一的新聞
log.LOG_INFO( "顯示方式一的新聞" );
String []className = { "{#first:class_name#}", "{#second:class_name#}", "{#third:class_name#}","{#forth:class_name#}","{#five:class_name#}","{#six:class_name#}" };
String []classtitle1 = { "{#first:picture:name:1#}", "{#second:picture:name:1#}", "{#third:picture:name:1#}", "{#forth:picture:name:1#}", "{#five:picture:name:1#}", "{#six:picture:name:1#}" };
String []classtitle2 = { "{#first:title:8#}", "{#second:title:8#}", "{#third:title:8#}", "{#forth:title:8#}", "{#five:title:8#}", "{#six:title:8#}" };
initStr ="<tr><td width=\"8%\" align=\"center\"><img src=\"/zone_b2b/images/sup_08.gif\" width=\"13\" height=\"13\" /></td>"+
"<td width=\"80%\" class=\"bthong\">{#big:title#}</td><td width=\"12%\"><a href=\"{#href#}\" class=\"zhong\">更多>></a></td></tr>";
initStr1 = "<tr><td height=\"101\" align=\"center\"><img src=\"{#src1#}\" width=\"100\" height=\"100\"></td></tr>"+
"<tr><td><a href=\"{#href1#}\"class=\"bt1\">{#small:title#}</a><br> {#content#}</td></tr>";
String initStr2 = "<tr><td height=\"24\"><img src=\"/zone_b2b/images/zse.gif\" width=\"5\" height=\"9\" align=\"absmiddle\" /> <a href=\"{#href2#}\">{#title#}</a></td></tr>"+
"<tr><td height=\"1\" class=\"xian\"></td></tr>";
ArrayList classList = new Productclass().genClassByRsrv_str1( "1", 6 );
if( classList != null && classList.size() > 0 )
{
for( int i = 0; i < classList.size(); i++ )
{
strTemp ="";
HashMap map = ( HashMap )classList.get( i );
String class_id ="";
String class_name ="";
if( map.get( "class_id" ) != null )
{
class_id = map.get( "class_id" ).toString();
}
if( map.get( "class_name" ) != null )
{
class_name = map.get( "class_name" ).toString();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -