package com.baidu.ueditor; import java.util.Map; import javax.servlet.http.HttpServletRequest; import com.baidu.ueditor.define.ActionMap; import com.baidu.ueditor.define.AppInfo; import com.baidu.ueditor.define.BaseState; import com.baidu.ueditor.define.State; import com.baidu.ueditor.hunter.FileManager; import com.baidu.ueditor.hunter.ImageHunter; import com.baidu.ueditor.upload.Uploader; public class ActionEnter { private HttpServletRequest request = null; private String rootPath = null; private String contextPath = null; private String actionType = null; private ConfigManager configManager = null; public ActionEnter ( HttpServletRequest request, String rootPath ) { this.request = request; this.rootPath = rootPath; this.actionType = request.getParameter( "action" ); this.contextPath = request.getContextPath(); this.configManager = ConfigManager.getInstance( this.rootPath, this.contextPath, request.getRequestURI() ); } public String exec () { String callbackName = this.request.getParameter("callback"); if ( callbackName != null ) { if ( !validCallbackName( callbackName ) ) { return new BaseState( false, AppInfo.ILLEGAL ).toJSONString(); } return callbackName+"("+this.invoke()+");"; } else { return this.invoke(); } } public String invoke() { if ( actionType == null || !ActionMap.mapping.containsKey( actionType ) ) { return new BaseState( false, AppInfo.INVALID_ACTION ).toJSONString(); } if ( this.configManager == null || !this.configManager.valid() ) { return new BaseState( false, AppInfo.CONFIG_ERROR ).toJSONString(); } State state = null; int actionCode = ActionMap.getType( this.actionType ); Map<String, Object> conf = null; switch ( actionCode ) { case ActionMap.CONFIG: return this.configManager.getAllConfig().toString(); case ActionMap.UPLOAD_IMAGE: case ActionMap.UPLOAD_SCRAWL: case ActionMap.UPLOAD_VIDEO: case ActionMap.UPLOAD_FILE: conf = this.configManager.getConfig( actionCode ); state = new Uploader( request, conf ).doExec(); break; case ActionMap.CATCH_IMAGE: conf = configManager.getConfig( actionCode ); String[] list = this.request.getParameterValues( (String)conf.get( "fieldName" ) ); state = new ImageHunter( conf ).capture( list ); break; case ActionMap.LIST_IMAGE: case ActionMap.LIST_FILE: conf = configManager.getConfig( actionCode ); int start = this.getStartIndex(); state = new FileManager( conf ).listFile( start ); break; } return state.toJSONString(); } public int getStartIndex () { String start = this.request.getParameter( "start" ); try { return Integer.parseInt( start ); } catch ( Exception e ) { return 0; } } /** * callback参数验证 */ public boolean validCallbackName ( String name ) { if ( name.matches( "^[a-zA-Z_]+[\\w0-9_]*$" ) ) { return true; } return false; } }
最近下载更多
luqi40281518 LV7
2023年10月7日
zxc131313 LV12
2022年12月9日
907552380 LV13
2022年6月6日
hezienjoy LV3
2022年6月4日
Lmfbaby LV9
2022年5月29日
T1247965890 LV8
2022年3月9日
20190615 LV7
2022年3月4日
waityou2000317 LV4
2022年2月17日
Dderde LV8
2021年11月19日
lvhaowen LV20
2021年11月8日
最近浏览更多
g815835618 LV2
4月12日
阿萨大大123213 LV2
2月24日
yxzzxy LV3
2月18日
iiiiiiixiiiiii LV1
2023年12月28日
pangzhihui LV12
2023年12月23日
fff2003 LV6
2023年11月18日
随手一个用户名 LV1
2023年10月13日
luqi40281518 LV7
2023年10月7日
2549484213
2023年9月23日
暂无贡献等级
czdczd LV3
2023年9月9日