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

📄 bloguserserviceimpl.java

📁 EasyJF开源Blog系统是一个由EasyJF开源团队组织开发的基于Java平台的开源博客系统。当前Blog已经实现了基本的基本的博客的书写、流量统计、排名、个人像册、RSS、支持自定义模板、静态h
💻 JAVA
字号:
package com.easyjf.blog.logic.impl;


import java.net.URLEncoder;
import java.util.Date;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;


import com.easyjf.blog.domain.BlogInfo;
import com.easyjf.blog.domain.UserInfo;
import com.easyjf.blog.logic.BlogUserService;
import com.easyjf.blog.logic.CurrentUser;
import com.easyjf.util.CommUtil;
import com.easyjf.web.tools.ActiveUser;
import com.easyjf.web.tools.DbPageList;
import com.easyjf.web.tools.IActiveUser;
import com.easyjf.web.tools.IPageList;

public class BlogUserServiceImpl extends DAOSupportService implements
		BlogUserService {
	private String userSite="http://www.easyjf.com/";
	private String checkLoginApp="bbsuser.ejf?easyJWebCommand=remotUserLogin";
	private static BlogUserServiceImpl singleton = new BlogUserServiceImpl();

	public static BlogUserServiceImpl getInstance() {
		return singleton;
	}

	public boolean changePassword(String userName, String oldPassword,
			String newPassword) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean delBlogInfo(String cid) {
		boolean ret = false;
		ret = this.dao.del(getBlogInfo(cid));
		return ret;
	}

	public BlogInfo getBlogInfo(String cid) {

		return (BlogInfo) this.dao.get(BlogInfo.class, cid);
	}

	public BlogInfo getUserBlog(String userName) {
		return (BlogInfo) this.dao.getBy(BlogInfo.class, "userName", userName);
	}

	public IActiveUser login(String userName, String password, String ip) {
		SAXReader reader = new SAXReader();
		ActiveUser user=null;
		try{		
		String url=userSite+checkLoginApp+"&user="+URLEncoder.encode(userName,"utf-8")+"&password="+password+"&ip="+ip;	
		Document doc=reader.read(url);
		Element root=doc.getRootElement();
		List list=root.elements();
		java.util.Map map=new java.util.HashMap();
		for(int i=0;i<list.size();i++)
		{
		Element e=(Element)list.get(i);
		String fieldName=e.attributeValue("name");		
		map.put(fieldName, e.getTextTrim());		
		}
		user=new ActiveUser();
		CommUtil.Map2Obj(map, user);			
		}
		catch(Exception e)
		{
		e.printStackTrace();	
		}		
		return user;
	}

	public IPageList queryBlogInfo(String types, String orderBy,
			int currentPage, int pageSize) {
		String scope = "types=? order by " + orderBy;
		java.util.Collection paras = new java.util.ArrayList();
		paras.add(types);
		DbPageList pList = new DbPageList(BlogInfo.class, scope, paras);
		pList.doList(currentPage, pageSize);
		return pList;
	}

	public IPageList queryEliteBlogInfo(String orderBy, int currentPage,
			int pageSize) {
		String scope = "elite>0 order by " + orderBy;
		java.util.Collection paras = new java.util.ArrayList();
		DbPageList pList = new DbPageList(BlogInfo.class, scope, paras);
		pList.doList(currentPage, pageSize);
		return pList;
	}

	public boolean register(BlogInfo blogInfo) {
		boolean ret = false;
		blogInfo.setUserName(CurrentUser.getActiveUser().getUserName());
		if(getUserBlog(blogInfo.getUserName())!=null)		
			return false;
		blogInfo.setInputTime(new Date());
		blogInfo.setStatus(new Integer(-1));
		blogInfo.setReadTimes(new Integer(0));
		java.util.Collection paras=new java.util.ArrayList();
		paras.add(blogInfo.getUserName());
		paras.add(blogInfo.getDomain());
		Number num=(Number)this.dao.uniqueResult("select count(*) from BlogInfo where userName<>? and domain=?", paras);
		if(num.intValue()>0)return false;	
		//blogInfo.setUpdated(Boolean.TRUE);
		ret = this.dao.save(blogInfo);		
		if(ret)
		{
			try{
			com.easyjf.blog.logic.HTMLGenerater.saveToHTML(blogInfo);
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		return ret;
	}

	public boolean settingBlogInfo(BlogInfo blogInfo) {
		boolean ret = false;
		java.util.Collection paras=new java.util.ArrayList();
		paras.add(blogInfo.getUserName());
		paras.add(blogInfo.getDomain());
		Number num=(Number)this.dao.uniqueResult("select count(*) from BlogInfo where userName<>? and domain=?", paras);
		if(num.intValue()>0)return false;
		ret = this.dao.update(blogInfo);
		return ret;
	}

	public List getTopBlogUser(String types, int elite, String orderBy,
			int topNum) {
		String scope = "1=1 ";
		java.util.Collection paras = new java.util.ArrayList();
		if (types != null && (!"".equals(types))) {
			scope += " and types=?";
			paras.add(types);
		}
		if(elite>0)
		{
			scope+=" and elite>="+elite;
		}
		scope += " order by " + orderBy;
		DbPageList pList = new DbPageList(BlogInfo.class, scope, paras);
		pList.doList(1, topNum);
		return pList.getResult();
	}
	
	public void blogInfoChange(BlogInfo blog) {
		blog.setUpdated(Boolean.TRUE);
		this.dao.update(blog);
	}

	public static void main(String[] args)
	{
		BlogUserServiceImpl service=BlogUserServiceImpl.getInstance();
		service.login("admin","admin.easyjf.com", "127.0.0.1");
	}
}

⌨️ 快捷键说明

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