Java Code Examples for com.opensymphony.xwork2.ActionContext#get()

The following examples show how to use com.opensymphony.xwork2.ActionContext#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogonInterceptor.java    From aliada-tool with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
 * @param  invocation
 *            The ActionInvocation to set.
 * @return Returns the result of the invocation.
 * @throws Exception for the invoke method
 */
public String intercept(final ActionInvocation invocation) throws Exception {

	final ActionContext context = invocation.getInvocationContext();
	HttpServletRequest request = (HttpServletRequest) context
			.get(HTTP_REQUEST);
	HttpSession session = request.getSession(true);

	// Is there a "user" object stored in the user's HttpSession?
	Object user = session.getAttribute(USER_HANDLE);
	if (user == null) {
		// The user has not logged in yet.

		// Is the user attempting to log in right now?
		String loginAttempt = request.getParameter(LOGIN_ATTEMPT);

		/* The user is attempting to log in. */
		if (!StringUtils.isBlank(loginAttempt)) {
			return invocation.invoke();
		}
		return "logon";
	} else {
		return invocation.invoke();
	}
}
 
Example 2
Source File: JsonOutermostBracketsInterceptor.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
	ActionContext context=actionInvocation.getInvocationContext();
	HttpServletResponse response=(HttpServletResponse)context.get(StrutsStatics.HTTP_RESPONSE);
	response.setCharacterEncoding("utf8");
	response.setContentType("text/html");
	PrintWriter writer=response.getWriter();
	writer.print("[");
	writer.flush();
	String forward=actionInvocation.invoke();
	writer.print("]");
	writer.flush();
	return forward;
}
 
Example 3
Source File: NoCacheHeaderInterceptor.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
	ActionContext context=actionInvocation.getInvocationContext();
	HttpServletResponse response=(HttpServletResponse)context.get(StrutsStatics.HTTP_RESPONSE);
	if (response!=null ) {
		response.setHeader("Cache-control", "no-cache, no-store");
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Expires", "0");			
	}
	return actionInvocation.invoke();
}
 
Example 4
Source File: GuiFragmentResult.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Execute this result, using the specified fragment.
 * @param code The code of the fragment
 * @param invocation The invocation
 */
@Override
public void doExecute(String code, ActionInvocation invocation) throws Exception {
	if (null == code) {
		code = conditionalParse(this._code, invocation);
	}
	if (null == code) {
		this.executeDispatcherResult(invocation);
		return;
	}
	ActionContext ctx = invocation.getInvocationContext();
	HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
	IGuiFragmentManager guiFragmentManager =
			(IGuiFragmentManager) ApsWebApplicationUtils.getBean(SystemConstants.GUI_FRAGMENT_MANAGER, req);
	try {
		GuiFragment guiFragment = guiFragmentManager.getGuiFragment(code);
		String output = (null != guiFragment) ? guiFragment.getCurrentGui() : null;
		if (StringUtils.isBlank(output)) {
			_logger.info("The fragment '{}' is not available - Action '{}' - Namespace '{}'", 
					code, invocation.getProxy().getActionName(), invocation.getProxy().getNamespace());
			boolean execution = this.executeDispatcherResult(invocation);
			if (!execution) {
				output = "The fragment '" + code + "' is not available";
			} else {
				return;
			}
		}
		RequestContext reqCtx = (RequestContext) req.getAttribute(RequestContext.REQCTX);
		ExecutorBeanContainer ebc = (ExecutorBeanContainer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_EXECUTOR_BEAN_CONTAINER);
		Writer writer = this.getWriter();
		Template template = new Template(code, new StringReader(output), ebc.getConfiguration());
		template.process(ebc.getTemplateModel(), writer);
	} catch (Throwable t) {
		_logger.error("Error processing GuiFragment result!", t);
		throw new RuntimeException("Error processing GuiFragment result!", t);
	}
}
 
Example 5
Source File: SyslogInterceptor.java    From hrms with Apache License 2.0 4 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
	Syslog syslog = new Syslog();
	ActionContext actionContext = actionInvocation.getInvocationContext();
	HttpServletRequest request = (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);
	String accessIp = getIpAddr(request);
	syslog.setAccessIp(accessIp);
	StringBuffer url = request.getRequestURL();
	
	int slash = url.lastIndexOf("/");
	String linkUrl = url.substring(slash+1);
	int point = linkUrl.lastIndexOf(".");
	if (point>0) {
		linkUrl = linkUrl.substring(0,point);
	}
	int bottomLine = linkUrl.lastIndexOf("_");
	String result;
	String userId;
	String actionId = "1";
	String actionStr = linkUrl.substring(linkUrl.lastIndexOf("_")+1);
	if(actionStr.equals("add")) {
		actionId = "2";
	} else if (actionStr.equals("update")) {
		actionId = "3";
	}else if (actionStr.equals("delete")) {
		actionId = "4";
	}
	
	if(linkUrl.equals("user_login")) {
		syslog.setAction("登入");
		result = actionInvocation.invoke();
		userId = actionContext.getSession().get("userId").toString();
	}else {
		userId = actionContext.getSession().get("userId").toString();
		if(linkUrl.equals("user_loginOut")) {
			syslog.setAction("退出");
		}else {
			if (actionId != null && actionId.trim() != "") {
				Action action = (Action) actionService.findById(Integer.valueOf(actionId));
				if (action!=null) {
					syslog.setAction(action.getAction());
				}
			}
		}
		result = actionInvocation.invoke();
	}
	if (bottomLine>0) {
		linkUrl = linkUrl.substring(0,bottomLine);
	}
	if (userId != null && actionId != null && !actionId.equals("1")) {
		syslog.setDate(new Date());
		Module module = moduleService.getModuleByLinkUrl(linkUrl);
		syslog.setModule(module);
		if (result.equals("error")) {
			syslog.setType("错误");
		} else if((result.equals("input"))){
			syslog.setType("警告");
		} else {
			syslog.setType("信息");
		}
		syslog.setUser(userService.findById(Integer.valueOf(userId)));
		if (result.equals("success") || result.equals("error") || result.equals("input")) {
			syslogService.save(syslog);
		}
		return result;
	}
	return "login";
}
 
Example 6
Source File: PermissionInterceptor.java    From hrms with Apache License 2.0 4 votes vote down vote up
@Override
public String intercept(ActionInvocation actionInvocation) throws Exception {
	ActionContext actionContext = actionInvocation.getInvocationContext();
	HttpServletRequest request = (HttpServletRequest) actionContext.get(StrutsStatics.HTTP_REQUEST);
	String userId = actionContext.getSession().get("userId").toString();
	String contextPath = request.getContextPath();
	StringBuffer url = request.getRequestURL();
	int contextPathPost = url.lastIndexOf(contextPath);
	int contextPathLength = contextPath.length();
	String linkUrl = url.substring(contextPathPost + contextPathLength + 1);
	String actionId = "";
	int bottomLine = linkUrl.lastIndexOf("_");
	String action = linkUrl.substring(bottomLine+1);
	if(bottomLine < 0 || action.equals("my")) {
		actionId = "1";
	} else if(action.equals("add")) {
		actionId = "2";
	} else if (action.equals("update")) {
		actionId = "3";
	}else if (action.equals("delete")) {
		actionId = "4";
	} else if (action.equals("approverList") || action.equals("transactorList")) {
		actionId = "5";
	} else {
		actionId = "6";
	}
	if (bottomLine>0) {
		linkUrl = linkUrl.substring(0,bottomLine);
	}
	Module module = moduleService.getModuleByLinkUrl(linkUrl);
	if (userId != null && module!=null) {
		String moduleId = module.getModuleId().toString();
		if (userPermissionService.checkPermission(userId, moduleId,actionId)) {
			return actionInvocation.invoke();
		}
	}
	if (module==null) {
		return actionInvocation.invoke();
	}
	actionContext.put("permissionMessage", "你没有该权限,请先登陆");
	return Action.NONE;
}
 
Example 7
Source File: Pdf2Swf.java    From csustRepo with MIT License 4 votes vote down vote up
public  static Boolean pdf2Swf(String spath,String dpath,Integer pageSize){
	File pdfFile = new File(spath);
	File swfFile = new File(dpath);
	Runtime r = Runtime.getRuntime();
	
	if(pageSize==null){
		pageSize=20;
	}
	
	if (!swfFile.exists()) {
		if (pdfFile.exists()) {
			try {
				ActionContext ac = ActionContext.getContext();
				HttpServletRequest request =(HttpServletRequest)ac.get(ServletActionContext.HTTP_REQUEST);
				/*Process p = r.exec(request.getRealPath("/thirdparty/officetranslate/tools/pdf2swf.exe")
						+ " "
						+ pdfFile.getPath()
						+ " -o "
						+ swfFile.getPath() 
						+ " -T9" 
						+ " -p 1-"+pageSize);*/
				StringBuilder commandBuilder=new StringBuilder(
						request.getSession().getServletContext().getRealPath(
								"/thirdparty/officetranslate/tools/pdf2swf.exe"));
				
				commandBuilder.append(" ");
				commandBuilder.append(pdfFile.getPath());
				commandBuilder.append(" -o ");
				commandBuilder.append(swfFile.getPath());
				commandBuilder.append(" -T9 ");
				commandBuilder.append(" -p 1-");
				commandBuilder.append(pageSize);
				/*String command=request.getSession()
						.getServletContext().getRealPath(
								"/thirdparty/officetranslate/tools/pdf2swf.exe")
								+" "
								+pdfFile.getPath()
								+" -o "
								+swfFile.getPath()
								+" -T9 "
								+"";*/
				//command= command.toString().replace("\\", "//");
				System.out.println(commandBuilder.toString());
				Process p=r.exec(commandBuilder.toString());
				/*BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(p.getInputStream()));
				String s=null;
				while((s=bufferedReader.readLine())!=null){
					  try {  
				            p.waitFor();  
				        } catch (InterruptedException e) {  
				            // TODO Auto-generated catch block  
				            e.printStackTrace();  
				            return false;
				        }
				}*/
				p.waitFor();
				System.out.println("转换成功");
				return true;
			} catch (Exception e) {
				e.printStackTrace();
				try {
					throw e;
				} catch (Exception e1) {
					// TODO Auto-generatedcatch block
					e1.printStackTrace();
					return false;
				}
			}
		} else {

			System.out.println("PDF文件不存在,无法转换");
			return false;
		}
	} else {
		System.out.println("已经转为SWF文件,无需再次转换");
	}

	/*if (pdfFile.exists()) {
		pdfFile.delete();
	}*/
	System.out.println("转换成功!!");
	return true;
	//HttpSession session = request.getSession();
	//session.setAttribute("fileName", swfFile.getName());
	//response.sendRedirect(request.getContextPath()
		//	+ "/preview/flexpaper/readFile.jsp");
}
 
Example 8
Source File: LogInterceptor.java    From csustRepo with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext actionContext=invocation.getInvocationContext();
		HttpServletRequest request=(HttpServletRequest) actionContext.get(ServletActionContext.HTTP_REQUEST);
		String actionName=actionContext.getName();
		
		String description=null;
		String type=null;
		
		//取出并遍历所有的permission对象,如果有含有actionName一样的则把对应的操作保存到description
		for (RepPermission permission : list) {
			if(permission.getActionname().equals(actionName)){
				description=permission.getName();
			}
		}
		//根据actionName里面包含的关键字判断操作的类型
		String actionNameLowerCase=actionName.toLowerCase();
		if(actionNameLowerCase.contains("add")){
			type="新增";
		}else if (actionNameLowerCase.contains("delete")) {
			type="删除";
		}else if (actionNameLowerCase.contains("update")
					||actionNameLowerCase.contains("lock")
					||actionNameLowerCase.contains("pass")
					||actionNameLowerCase.contains("modify")) {
			type="修改";
		}else if(actionNameLowerCase.contains("login")){
			type="登录";
			description="登录后台";
		}else if (actionNameLowerCase.contains("logout")) {
			type="登出";
			description="登出后台";
		}
		
		//创建RepLog对象来报错日志信息
		RepLog log=new RepLog();
		log.setOperationtime(new Date());
		log.setOperationip(request.getRemoteAddr());
		
		//执行action并获取执行完成的结果
		String result=invocation.invoke();
		
		String resultLowerCase=null;
		if(result!=null){
			resultLowerCase=result.toLowerCase();
		}
		//根据resultCode判断是否执行成功,不成功的话则什么也 不做
		if(resultLowerCase==null
				||resultLowerCase.equals("faild")
				||resultLowerCase.equals("add")
				||resultLowerCase.equals("edit")
				||resultLowerCase.equals("modify")
				||resultLowerCase.equals("login")
				){
			
		/*
		 * 成功的话根据
		 * description是否为空(即是否是有对应permission的action)
		 * type是否为空(既是否是含有增删改登陆登出的关键字)判断访问的action是否有必要记录。
		 */
		}else if(description!=null&&type!=null){
			RepAdmin admin=(RepAdmin) actionContext.getSession().get(RepAdmin.ADMIN);
			log.setRepAdmin(admin);
			log.setDescription(description);
			log.setOperationtype(type);
			log.setOperator(admin.getUsername());
			logService.add(log);
			
			Integer id=log.getId();
			List<Integer> ids=logService.findByhql(
					"select l.id from RepLog l where l.id<?", 0, id-800000);
			logService.deleteAll(ids);
			
		}
		
//		logService.remove();
		
		
		return result;
			
	}