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

📄 basicinfoserviceimpl.java

📁 野蔷薇论坛源码 java 自己看看吧。 学习用
💻 JAVA
字号:
/* 
 * Created on 2007-1-13
 * Last modified on 2007-9-26
 * Powered by YeQiangWei.com
 */
package com.yeqiangwei.club.service.util.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.yeqiangwei.club.param.BaseParameter;
import com.yeqiangwei.club.service.model.BasicInfoModel;
import com.yeqiangwei.club.service.util.BasicInfoService;
import com.yeqiangwei.club.cache.Cache;
import com.yeqiangwei.club.cache.singleton.CacheFactory;
import com.yeqiangwei.club.dao.BasicInfoDAO;
import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;

import org.apache.log4j.Logger;

import com.yeqiangwei.util.StringHelper;
import com.yeqiangwei.util.TypeChange;
import com.yeqiangwei.util.Validator;
import com.yeqiangwei.club.dao.model.BasicInfo;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.exception.DAOException;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.io.File;

/**
 * 社区基本配置信息
 * @author yeqiangwei
 */
public class  BasicInfoServiceImpl  implements BasicInfoService{
	
	private static final Logger logger = Logger.getLogger(BasicInfoServiceImpl.class);
	
	private Cache cache = CacheFactory.creator("BASICINFO");
	
	public static void main(String args[]){
		BasicInfoServiceImpl b = new BasicInfoServiceImpl();
		//BasicInfoModel m = b.findOnly();
		System.out.println(b.cookieDomain());
	}
	

	public String cookieDomain() {
		String domain = this.findOnly().getUrl();
		domain = domain.replace("http://","");
		if(domain.indexOf("/")!=-1){
			domain = StringHelper.substring(domain,0,domain.lastIndexOf("/"),"");
		}else{
			domain = StringHelper.substring(domain,0,domain.length(),"");
		}
		domain = StringHelper.substring(domain,domain.indexOf(".")+1,domain.length(),"");
		return domain;
	}
	

	public BasicInfoModel findById(int id) {
		BasicInfoModel model = (BasicInfoModel) cache.get("BasicInfoModel");
		if(Validator.isEmpty(model)){
			model = new BasicInfoModel();
			BasicInfo item = this.getBasicInfoDAO().findById(id);
			BeanUtils.copyProperties(model,item);
		}
		return model;
	} 
	
	public void createOrUpdate(BasicInfoModel model) throws ClubException {
		if(model.getBasicInfoId()==0){
			this.create(model);
		}else{
			this.update(model);
		}
	}

	public void create(BasicInfoModel model) throws ClubException {
		if(!Validator.isEmpty(model)){
			BasicInfo item = new BasicInfo();
			BeanUtils.copyProperties(item,model);
			try {
				this.getBasicInfoDAO().create(item);
			} catch (DAOException e) {
				logger.error(e.toString());
				throw new ClubException(MessageUtils.getMessage("error_system"));
			}
			cache.put("BasicInfoModel",model);
		}
	}

	public void update(BasicInfoModel model) throws ClubException {
		if(!Validator.isEmpty(model)){
			BasicInfo item = new BasicInfo();
			BeanUtils.copyProperties(item,model);
			try {
				this.getBasicInfoDAO().update(item);
			} catch (DAOException e) {
				logger.error(e.toString());
				throw new ClubException(MessageUtils.getMessage("error_system"));
			}
			cache.put("BasicInfoModel",model);
		}
	}
	
	public BasicInfoModel findOnly() {
		BasicInfoModel model = (BasicInfoModel) cache.get("BasicInfoModel");
		if(Validator.isEmpty(model)){
			model = new BasicInfoModel();
			BasicInfo item = this.getBasicInfoDAO().findOnly();
			BeanUtils.copyProperties(model,item);
			cache.put("BasicInfoModel",model);
		}
		return model;
	}
	
	public int delete(BasicInfoModel model) {
		int c = 0;
		try{
			BasicInfo item = new BasicInfo();
			BeanUtils.copyProperties(item,model);
			c = this.getBasicInfoDAO().delete(item);
			cache.remove("BasicInfoModel");
		}catch(Exception e){
			logger.error(e.toString());
		}
		return c;
	}

	public int delete(String[] ids) {
		int c = 0;
		try{
			List<Integer> list = new ArrayList<Integer>();
			for(int i=0; i<ids.length; i++){
				int id = TypeChange.stringToInt(ids[i]);
				list.add(new Integer(id));
			}
			c = this.getBasicInfoDAO().delete(list);
		}catch(Exception e){
			logger.error(e.toString());
		}
		return c;
	}

	public List<BasicInfoModel> findByParameter(BaseParameter param) {
		return null;
	}

	public long countByParameter(BaseParameter param) {
		return 0;
	}

	public BasicInfoDAO getBasicInfoDAO() {
		return DAOWrapper.<BasicInfoDAO>getSingletonInstance(DAOLocator.BASICINFO);
	}


	public String getCss() {
		String css = (String) cache.get("CSS");
		if(Validator.isEmpty(css)){
			StringBuffer path = new StringBuffer(findOnly().getSitePath());
			if(!path.toString().endsWith(File.separator)){
				path.append(File.separator);
			}
			path.append(findOnly().getCssPath());
			if(!path.toString().endsWith(File.separator)){
				path.append(File.separator);
			}
			try {
				css = File.readText(path.toString()+"master.css","utf-8");
				css += File.readText(path.toString()+"layout.css","utf-8");
				css += File.readText(path.toString()+"colors.css","utf-8");
				css += File.readText(path.toString()+"themes.css","utf-8");
				File.createFile(path.toString()+"YeQiangWeiStyle.css", css, "utf-8", true);
			} catch (IOException e) {
				logger.error(e.toString());
			}
			css = css.replace("\r","").replace("\n","");
			cache.put("CSS",css);
		}
		return css;
	}

}

⌨️ 快捷键说明

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