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

📄 newsdiraction.java

📁 EasyJF官网(www.easyjf.com)全站系统源码使用说明 全站源码是EasyJF开源团队站务组及核心成员共同开发及维护的系统
💻 JAVA
字号:
package com.easyjf.news.action;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.easyjf.news.business.NewsUtil;
import com.easyjf.news.business.NewsDir;
import com.easyjf.util.CommUtil;
import com.easyjf.web.Module;
import com.easyjf.web.Page;
import com.easyjf.web.WebForm;
import com.easyjf.web.tools.DbPageList;
import com.easyjf.web.tools.IPageList;

public class NewsDirAction extends BaseAction {
	private NewsDir parent;
	public void doInit(WebForm form, Module module) {
		// TODO Auto-generated method stub
		String pcid=CommUtil.null2String(form.get("pcid"));		
		parent=NewsDir.read(pcid);
		if(parent!=null)form.addResult("parent",parent);
		else form.addResult("parent",NewsUtil.getRootDir());
		super.doInit(form, module);
	}
public Object doBefore(WebForm form, Module module) {
		//系统后台,添加/删除/修改
	if("list".equals(this.getCommand())||"".equals(this.getCommand())|| "edit".equals(this.getCommand())|| "save".equals(this.getCommand()) || "update".equals(this.getCommand())|| "del".equals(this.getCommand()))
		{
			if(this.getCurrentUser(form)==null){
			form.addResult("msg","您没有登录,或者登录信息已经超时,请重新登录!");
			return new Page("popedomError","/nologin.htm","page");
			}
		}		
		return super.doBefore(form,module);
	}
	
	public IPageList doQuery(WebForm form, int currentPage, int pageSize) {				
		String scope="1=1";
		Collection paras=new ArrayList();
		if(parent!=null){		
		scope+=" and parentSn=?";
		paras.add(parent.getSn());		
		}
		else 
		{
			NewsDir rootDir=NewsUtil.getRootDir();
			if(rootDir!=null){
			scope+=" and parentSn=?";
			paras.add(rootDir.getSn());
			}
		}
		String orderType=CommUtil.null2String(form.get("orderType"));
		String orderField=CommUtil.null2String(form.get("orderField"));			
		if(orderField.equals(""))
		{
		orderField="sequence";
		orderType="asc";				
		}	
		if(!orderField.equals(""))
		{
		scope +=" order by "+orderField;
		if(!orderType.equals(""))scope+=" "+orderType;
		}	
		DbPageList pList=new DbPageList(NewsDir.class,scope,paras);
		pList.doList(currentPage,pageSize);
		return pList;
	}
	public Object form2Obj(WebForm form) {
		String cid=CommUtil.null2String(form.get("cid"));
		NewsDir obj=null;
		if(cid.equals(""))
		{
			obj=(NewsDir)form.toPo(NewsDir.class);			
			obj.setInputUser(this.getCurrentUser(form).getUserName());
			obj.setStatus(new Integer(0));
		}
		else
		{
			obj=NewsDir.read(cid);
			form.toPo(obj);
		}		
		if(obj!=null && ("add".equals(this.getCommand())||"update".equals(this.getCommand())))
		{
			NewsDir dir=NewsDir.readBySn(obj.getParentSn().trim());			
			if(dir!=null)obj.setDirPath(dir.getDirPath().trim()+"@"+obj.getSn().trim());
		}
		return obj;
	}
	
	public void doAfter(WebForm form, Module module) {
		// TODO Auto-generated method stub
		super.doAfter(form, module);
		String method=this.getCommand();
		if("new".equals(method)||"edit".equals(method))
		{
		form.addResult("statusOptions",CommUtil.getSelectOptions(NewsDir.statusTitle,""+form.get("status")));
		form.addResult("typesOptions",CommUtil.getSelectOptions(NewsDir.typesTitle,""+form.get("types")));
		List allDir=NewsUtil.getAllDir();
		if(allDir!=null)
		{
			String[][] dirs =new String[allDir.size()][2];
			for(int i=0;i<allDir.size();i++)
			{
				dirs[i][0]=((NewsDir)allDir.get(i)).getSn().trim();
				dirs[i][1]=((NewsDir)allDir.get(i)).getTitle().trim();
			}
			String sn=CommUtil.null2String(form.get("parentSn")).trim();
			if(sn.equals("")&&(parent!=null))sn=parent.getSn().trim();
			form.addResult("allDirOptions",CommUtil.getSelectOptions(dirs,sn));
		}		
		}
	}
	public Page doInitDir(WebForm form, Module module)
	{	
		String title=(String)form.get("title");
		if(title==null)
		{		
			form.addResult("initDir","true");
			return new Page("initDir","/manage/newsDirEdit.html","template");	
		}
		else//保存
		{
			NewsDir obj=(NewsDir)form2Obj(form);
		    obj.setParentSn("SiteRoot");
		    obj.save();
		    form.addResult("js","top.location.reload();");
		    return new Page("javascript","/manage/javascript.html","template");		    
		}			
	}
	public Page doGetTreeXml(WebForm form, Module module)
	{	
	    	String sn=CommUtil.null2String(form.get("root"));	    	
		    String parent=CommUtil.null2String(form.get("parent"));
		   List list=new ArrayList();
		    if(!sn.equals(""))//读取根目录下的主栏目
			{
		    	NewsDir rootDir=NewsDir.readBySn(sn);
		    	if(rootDir!=null){
		    	Map map=new HashMap();			
				map.put("name",rootDir.getTitle());
				map.put("sn",rootDir.getCid());
				List children=rootDir.children();
				if(children!=null && children.size()>0)map.put("more","true");
				list.add(map);
		    	}
			}
		    else if(!parent.equals(""))//读取子栏目
			{
		    	 NewsDir topDir=NewsDir.read(parent);
		    	 
		    	 if(topDir!=null)
			    	{
			    		List children=topDir.children();
			    		if(children!=null)
			    		{
			    			for(int i=0;i<children.size();i++)
			    			{
			    				Map map=new HashMap();
			    				NewsDir dir=(NewsDir)children.get(i);
			    				map.put("name",dir.getTitle());
			    				map.put("sn",dir.getCid());
			    				List dchildren=dir.children();
			    				if(dchildren!=null && dchildren.size()>0)map.put("more","true");
			    				list.add(map);
			    			}
			    		}		    		
			    	}	
			}
		   	form.addResult("list",list);
		    return new Page("treeXml","/manage/xmlDirTree.xml","template");
	}
}

⌨️ 快捷键说明

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