Skip to content

Instantly share code, notes, and snippets.

@wendal
Created February 9, 2012 06:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wendal/1777745 to your computer and use it in GitHub Desktop.
Save wendal/1777745 to your computer and use it in GitHub Desktop.
Nutz的管理控制台模块
package com.danoo.strato.ui.module.dev;
import java.io.IOException;
import java.util.Properties;
import lombok.Setter;
import org.apache.log4j.PropertyConfigurator;
import org.nutz.aop.interceptor.LoggingMethodInterceptor;
import org.nutz.ioc.Ioc;
import org.nutz.ioc.IocMaking;
import org.nutz.ioc.annotation.InjectName;
import org.nutz.ioc.impl.NutIoc;
import org.nutz.ioc.java.ChainParsing;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.Streams;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.adaptor.VoidAdaptor;
import org.nutz.mvc.annotation.AdaptBy;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.By;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.Filters;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import org.nutz.mvc.filter.CheckDomainSuperUser;
@Filters({@By(type = CheckDomainSuperUser.class)})
@InjectName
@IocBean
@At("/console")
@Ok("ajax")
@Fail("jsp:jsp.error")
public class ConsoleModule {
@Inject("refer:aop_log")
@Setter
private LoggingMethodInterceptor aopLog;
/**
* 设置AopLog的开关,
* @param status 开/关
* @return 总是返回true
*/
@At("/aop/log/*")
public boolean activeAopLog(boolean status) {
aopLog.setLogEvent(status, status, status, status);
return true;
}
/**
* 获取默认的log4j配置
* @return
*/
@At("/log/config/get")
public String readLogConfig() {
return Streams.readAndClose(Streams.utf8r(getClass().getResourceAsStream("/log4j.properties")));
}
/**
* 设置log配置,将req的body当成log4j.properties来处理
*/
@At("/log/config/set")
@AdaptBy(type=VoidAdaptor.class)
public boolean setLogConfig() throws IOException {
Properties p = new Properties();
p.load(Mvcs.getReq().getInputStream());
PropertyConfigurator.configure(p);
return true;
}
/**
* 重置log设置
*/
@At("/log/config/reset")
@AdaptBy(type=VoidAdaptor.class)
public boolean resetLogConfig() throws IOException {
Properties p = new Properties();
p.load(getClass().getResourceAsStream("/log4j.properties"));
p.put("log4j.reset", "true");
PropertyConfigurator.configure(p);
return true;
}
/**
* 执行一个命令,格式采用Ioc容器的Java节点定义
* @see org.nutz.ioc.IocLoader
*/
@At("/exec")
public Object exec(Ioc ioc, @Param("cmd")String cmd){
ChainParsing cp = new ChainParsing(cmd);
IocMaking ing = ((NutIoc)ioc).makeIocMaking(Mvcs.getIocContext(), "$_danoo_exec");
return cp.getNode().eval(ing);
}
//TODO 完成一个页面,以便调用console方法
@At("/index")
@Ok("jsp")
public void index(){}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment