⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modrepliespageform.java

📁 论坛软件系统亦称电子公告板(BBS)系统
💻 JAVA
字号:
package cn.jsprun.struts.form.posts;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Session;
import org.hibernate.Transaction;
import cn.jsprun.dao.DataBaseDao;
import cn.jsprun.utils.BeanFactory;
import cn.jsprun.utils.Common;
import cn.jsprun.utils.HibernateUtil;
public class ModrepliesPageForm{
	private int currentPage = 1; 
	private int prePage = 0; 
	private int nextPage = 0; 
	private List<Map<String,String>> list = null; 
	private int pageSize = 10; 
	private int totalPage = 0; 
	private int totalSize = 0; 
	private String countSQL = "select count(*) from Posts as p where p.first=0 and p.invisible=-2";
	private String sql = "select p.*,f.name,t.subject as threadsubject from jrun_posts as p left join jrun_forums as f on p.fid=f.fid left join jrun_threads as t on t.tid=p.tid where p.first=0 and p.invisible=-2";
	private StringBuffer sb = null;
	public ModrepliesPageForm() {
		totalSize(); 
		getTotalPage(); 
	
	}

	public ModrepliesPageForm(String countSql, String sql) {
		this.countSQL = countSql;
		this.sql = sql;
		totalSize(); 
		getTotalPage(); 

	}
	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		if (currentPage < 1) {
			currentPage = 1;
		}
		if (currentPage > totalPage) {
			currentPage = totalPage;
		}
		this.currentPage = currentPage;
	}

	public List<Map<String,String>> getList() {
		return this.list;
	}
	private Map<String,String> postsFormat(List<Map<String,String>> smilieslist,Map<String,String> post,String path) {
		String message = post.get("message"); 
		for(Map<String,String> smiles:smilieslist){
			if(message.indexOf(smiles.get("code")+" ")!=-1 || message.indexOf(" "+smiles.get("code"))!=-1){
				StringBuffer buffer = new StringBuffer();
				buffer.append("<img src='"+path+"/images/smilies/");
				buffer.append(smiles.get("directory"));
				buffer.append("/");
				buffer.append(smiles.get("url"));
				buffer.append("' smilieid='");
				buffer.append(smiles.get("id"));
				buffer.append("' border='0' alt='' /> ");
				message = StringUtils.replace(message, smiles.get("code"), buffer.toString());
			}
		}
		if (post.get("attachment").equals("1")) {
			List<Map<String,String>> attachmentlist = ((DataBaseDao) BeanFactory.getBean("dataBaseDao")).executeQuery("select filename,filesize,attachment,isimage from jrun_attachments where pid="+post.get("pid"));
			if (attachmentlist != null && attachmentlist.size() > 0) {
				StringBuffer messageSB = new StringBuffer(message);
				for (Map<String,String> attachments : attachmentlist) {
					String type = "text.gif";
					if(attachments.get("isimage").equals("1")){
						type = "image.gif";
					}
					messageSB.append("<br /><br />附件:<img src='"+path+"/images/attachicons/"+type+"' border='0' class='absmiddle' alt='' /> ");
					messageSB.append(attachments.get("filename"));
					messageSB.append("(");
					int fileSize = Common.toDigit(attachments.get("filesize"));
					if (fileSize < 1024) {
						messageSB.append(fileSize + " Bytes");
					} else if (fileSize > 1024 && fileSize < 1048576) {
						messageSB.append(fileSize / 1024 + " KB");
					} else {
						messageSB.append(fileSize / 1048576 + " MB");
					}
					messageSB.append(")");
					if(attachments.get("isimage").equals("1")){
						messageSB.append("<br /><br /><img src='"+path+"/attachments/"+ attachments.get("attachment")+ "' onload='if(this.width > 400) {this.resized=true; this.width=400;}'>");
					}
				}
				message = messageSB.toString(); 
			}
			attachmentlist=null;
		}
		post.put("message", message);
		return post;
	}
	public void setList(String path) {
		int startid = 0; 
		if (list != null && list.size() > 0)
			list.clear();
		if (this.currentPage < 0) {
			startid = 0;
		} else {
			if (currentPage > this.totalPage) {
				startid = this.totalPage;
				startid = pageSize * (startid - 1);
			} else {
				startid = pageSize * (currentPage - 1);
			}
		}
		list = new ArrayList<Map<String,String>>();
		List<Map<String,String>> postlist = ((DataBaseDao) BeanFactory.getBean("dataBaseDao")).executeQuery(sql+" limit "+startid+","+pageSize);
		List<Map<String,String>> smilieslist = ((DataBaseDao) BeanFactory.getBean("dataBaseDao")).executeQuery("select s.id,s.typeid,s.code,s.url,i.directory from jrun_smilies s left join jrun_imagetypes  i on s.typeid=i.typeid where s.type='smiley'");
		for(Map<String,String> posts:postlist){
			Map<String,String> post = postsFormat(smilieslist,posts,path);
			list.add(post);
		}
		sb = new StringBuffer();
		if (list != null && list.size() > 0) {
			for(Map<String,String>post:postlist){
				sb.append(post.get("pid")+",");
			}
		}
		postlist = null;
	}

	public int getNextPage() {
		return this.currentPage == totalPage ? currentPage : currentPage + 1;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public int getPageSize() {

		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPrePage() {
		return currentPage - 1 == 0 ? 1 : currentPage - 1;
	}

	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public int getTotalPage() {
		if (totalSize > pageSize) {
			if (totalSize % pageSize == 0) {
				setTotalPage((int) ((double) totalSize / (double) pageSize));
			} else {
				setTotalPage((int) (1.0d + (double) totalSize
						/ (double) pageSize));
			}
		} else {
			totalSize = 1;
			setTotalPage(1);
		}
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	private void totalSize() {
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			Transaction tr = session.beginTransaction();
			Object o = (Object) session.createQuery(countSQL).uniqueResult(); 
			totalSize = ((Integer) o).intValue();
			tr.commit(); 
		} catch (Exception e) {
			e.printStackTrace();

		} 
		setTotalSize(totalSize); 
	}

	public int getTotalSize() {

		return totalSize;
	}

	public void setTotalSize(int totalSize) {
		this.totalSize = totalSize;
	}

	public String getCountSQL() {
		return countSQL;
	}

	public void setCountSQL(String countSQL) {
		this.countSQL = countSQL;
	}

	public String getSb() {
		return sb.toString();
	}

	public void setSb(StringBuffer sb) {
		this.sb = sb;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -