public String ShowMyFriends() {
   ActionContext ctx = ActionContext.getContext();
   Object o = ctx.getSession().get("userName");
   Map map = ctx.getParameters();
   Object o2 = map.get("pageIndex");
   Integer pageIndex = 0;
   if (o2 != null) {
     pageIndex = Integer.parseInt(((String[]) o2)[0]);
   }
   if (o == null) return "Log";
   ScholarUser user = accountService.GetScholarUserByName(o.toString());
   List<ScholarUser> suList = new ArrayList<ScholarUser>();
   suList.addAll(user.getFriends());
   List<ScholarUser> tempList = new ArrayList<ScholarUser>();
   int startIndex = pageIndex * this.userPageSize;
   for (int i = 0; i < this.userPageSize; i++) {
     if ((i + startIndex) >= suList.size()) break;
     tempList.add(suList.get(i + startIndex));
   }
   ctx.put("friendList", tempList);
   int totalPage = user.getFriends().size() / this.userPageSize;
   if (user.getFriends().size() % this.userPageSize > 0) totalPage++;
   ctx.put("totalPage", totalPage);
   return "SUC";
 }
 public String ToAddFriendPage() {
   ActionContext ctx = ActionContext.getContext();
   Map params = ctx.getParameters();
   String[] list = (String[]) params.get("friendsId");
   System.out.println("friendsId:" + list[0]);
   return "SUC";
 }
  public String ShowPersonalInfo() {
    ActionContext ctx = ActionContext.getContext();
    Map params = ctx.getParameters();
    String[] list = (String[]) params.get("friendsId");
    System.out.println("friendsId:" + list[0]);

    ScholarUser user = accountService.GetScholarUserById(Integer.parseInt(list[0]));
    ctx.put("User", user);
    return "SUC";
  }
 @Override
 public String intercept(ActionInvocation invocation) throws Exception {
   // TODO Auto-generated method stub
   ActionContext actionContext = invocation.getInvocationContext();
   Map<String, Object> map = actionContext.getParameters();
   for (Map.Entry<String, Object> entry : map.entrySet()) {
     String value = ((String[]) (entry.getValue()))[0];
     entry.setValue(StringEscapeUtils.escapeHtml4(value));
   }
   return invocation.invoke();
 }
 public String ShowAllPeople() {
   ActionContext ctx = ActionContext.getContext();
   Map map = ctx.getParameters();
   Object o2 = map.get("pageIndex");
   Integer pageIndex = 0;
   if (o2 != null) {
     pageIndex = Integer.parseInt(((String[]) o2)[0]);
   }
   List<ScholarUser> suList = accountService.GetAllUser(pageIndex);
   ctx.put("friendList", suList);
   int totalUser = accountService.getTotalUserNum();
   int totalPage = totalUser / this.userPageSize;
   if (totalUser % this.userPageSize > 0) totalPage++;
   ctx.put("totalPage", totalPage);
   return "SUC";
 }
  public String AddOneFriendEx() {
    ActionContext ctx = ActionContext.getContext();
    Object o = ctx.getSession().get("userName");
    if (o == null) return "LOG";
    Map map = ctx.getParameters();
    String[] friendIDs = (String[]) map.get("friendsId");
    if (friendIDs == null) return "NOF";
    Integer friendId = Integer.parseInt(friendIDs[0]);

    String sourceUserName = o.toString();
    ScholarUser friend = accountService.GetScholarUserById(friendId);
    String friendName = friend.getUserName();
    boolean flag = friendService.AddOneFriend(sourceUserName, friendName);
    if (flag) return "SUC";
    else return "ERR";
  }
  /**
   * Sets action properties based on the interfaces an action implements. Things like application
   * properties, parameters, session attributes, etc are set based on the implementing interface.
   *
   * @param invocation an encapsulation of the action execution state.
   * @throws Exception if an error occurs when setting action properties.
   */
  public String intercept(ActionInvocation invocation) throws Exception {
    final Object action = invocation.getAction();
    final ActionContext context = invocation.getInvocationContext();

    if (action instanceof ServletRequestAware) {
      HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
      ((ServletRequestAware) action).setServletRequest(request);
    }

    if (action instanceof ServletResponseAware) {
      HttpServletResponse response = (HttpServletResponse) context.get(HTTP_RESPONSE);
      ((ServletResponseAware) action).setServletResponse(response);
    }

    if (action instanceof ParameterAware) {
      ((ParameterAware) action).setParameters(context.getParameters());
    }

    if (action instanceof ApplicationAware) {
      ((ApplicationAware) action).setApplication(context.getApplication());
    }

    if (action instanceof SessionAware) {
      ((SessionAware) action).setSession(context.getSession());
    }

    if (action instanceof RequestAware) {
      ((RequestAware) action).setRequest((Map) context.get("request"));
    }

    if (action instanceof PrincipalAware) {
      HttpServletRequest request = (HttpServletRequest) context.get(HTTP_REQUEST);
      if (request != null) {
        // We are in servtlet environment, so principal information resides in HttpServletRequest
        ((PrincipalAware) action).setPrincipalProxy(new ServletPrincipalProxy(request));
      }
    }
    if (action instanceof ServletContextAware) {
      ServletContext servletContext = (ServletContext) context.get(SERVLET_CONTEXT);
      ((ServletContextAware) action).setServletContext(servletContext);
    }
    return invocation.invoke();
  }
  public String intercept(ActionInvocation invocation) throws Exception {
    ActionContext ac = invocation.getInvocationContext();

    HttpServletRequest request = (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);

    if (!(request instanceof MultiPartRequestWrapper)) {
      if (LOG.isDebugEnabled()) {
        ActionProxy proxy = invocation.getProxy();
        LOG.debug(
            getTextMessage(
                "struts.messages.bypass.request",
                new String[] {proxy.getNamespace(), proxy.getActionName()}));
      }

      return invocation.invoke();
    }

    ValidationAware validation = null;

    Object action = invocation.getAction();

    if (action instanceof ValidationAware) {
      validation = (ValidationAware) action;
    }

    MultiPartRequestWrapper multiWrapper = (MultiPartRequestWrapper) request;

    if (multiWrapper.hasErrors()) {
      for (String error : multiWrapper.getErrors()) {
        if (validation != null) {
          validation.addActionError(error);
        }

        if (LOG.isWarnEnabled()) {
          LOG.warn(error);
        }
      }
    }

    // bind allowed Files
    Enumeration fileParameterNames = multiWrapper.getFileParameterNames();
    while (fileParameterNames != null && fileParameterNames.hasMoreElements()) {
      // get the value of this input tag
      String inputName = (String) fileParameterNames.nextElement();

      // get the content type
      String[] contentType = multiWrapper.getContentTypes(inputName);

      if (isNonEmpty(contentType)) {
        // get the name of the file from the input tag
        String[] fileName = multiWrapper.getFileNames(inputName);

        if (isNonEmpty(fileName)) {
          // get a File object for the uploaded File
          File[] files = multiWrapper.getFiles(inputName);
          if (files != null && files.length > 0) {
            List<File> acceptedFiles = new ArrayList<File>(files.length);
            List<String> acceptedContentTypes = new ArrayList<String>(files.length);
            List<String> acceptedFileNames = new ArrayList<String>(files.length);
            String contentTypeName = inputName + "ContentType";
            String fileNameName = inputName + "FileName";

            for (int index = 0; index < files.length; index++) {
              if (acceptFile(
                  action,
                  files[index],
                  fileName[index],
                  contentType[index],
                  inputName,
                  validation)) {
                acceptedFiles.add(files[index]);
                acceptedContentTypes.add(contentType[index]);
                acceptedFileNames.add(fileName[index]);
              }
            }

            if (!acceptedFiles.isEmpty()) {
              Map<String, Object> params = ac.getParameters();

              params.put(inputName, acceptedFiles.toArray(new File[acceptedFiles.size()]));
              params.put(
                  contentTypeName,
                  acceptedContentTypes.toArray(new String[acceptedContentTypes.size()]));
              params.put(
                  fileNameName, acceptedFileNames.toArray(new String[acceptedFileNames.size()]));
            }
          }
        } else {
          if (LOG.isWarnEnabled()) {
            LOG.warn(
                getTextMessage(action, "struts.messages.invalid.file", new String[] {inputName}));
          }
        }
      } else {
        if (LOG.isWarnEnabled()) {
          LOG.warn(
              getTextMessage(
                  action, "struts.messages.invalid.content.type", new String[] {inputName}));
        }
      }
    }

    // invoke action
    return invocation.invoke();
  }
 /**
  * Gets the parameter map to apply from wherever appropriate
  *
  * @param ac The action context
  * @return The parameter map to apply
  */
 protected Map<String, Object> retrieveParameters(ActionContext ac) {
   return ac.getParameters();
 }