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

📄 postspageform.java

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

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 PostsPageForm {
	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 Threads as t where t.displayorder=-2 and t.moderated=0 ";

	private String sql = "select p.*,f.name from jrun_posts as p left join jrun_threads as t on p.tid=t.tid left join jrun_forums as f on p.fid=f.fid where p.first=1 and t.displayorder=-2 and t.moderated=0 ";

	private StringBuffer sb = new StringBuffer();

	public PostsPageForm() {
		totalSize(); 
		getTotalPage(); 
	}
	public PostsPageForm(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(Map<String,String> p,String path,List<Map<String,String>> smilieslist) {
		String message = p.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 (p.get("attachment").equals("1")) {
			List<Map<String,String>> attachmentlist = ((DataBaseDao) BeanFactory.getBean("dataBaseDao")).executeQuery("select filename,filesize,attachment,isimage from jrun_attachments where pid="+p.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;
		}
		p.put("message", message);
		return p;
	}

	private List<Map<String,String>> postsListFormat(List<Map<String,String>> postsList,String path) {
		List<Map<String,String>> postsFormList = new ArrayList<Map<String,String>>();
		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' order by s.displayorder");
		if (postsList.size() <= 0) {
			return null;
		} else {
			for(Map<String,String> post:postsList){
				Map<String,String> posts = postsFormat(post,path,smilieslist);
				postsFormList.add(posts);
			}
		}
		smilieslist = null;
		postsList = null;
		return postsFormList;
	}

	public void setList(String path) {
		int startid = 0; 
		if (list != null)
			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<Map<String,String>> postlist = ((DataBaseDao) BeanFactory.getBean("dataBaseDao")).executeQuery(sql+" limit "+startid+","+pageSize);
		list = postsListFormat(postlist,path);
		sb = new StringBuffer();
		if (list != null && list.size() > 0) {
			for(Map<String,String> post:list){
				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 {
			setTotalPage(1);
		}
		return totalPage;
	}

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

	private void totalSize() {
		Transaction tr = null;
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			tr = session.beginTransaction();
			Object o = (Object) session.createQuery(countSQL).uniqueResult();  
			totalSize = ((Integer) o).intValue();
		} catch (Exception e) {
			if (tr != null && tr.isActive()) {
				tr.rollback();
				tr = null;
			}
			e.printStackTrace();
		} finally {
			if (tr != null) {
				tr.commit();
			}
		}
		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 + -