Exemplo n.º 1
0
 public List makeRow(String pDataString) {
   ArrayList row;
   if (mFormat != null) {
     // we have a format
     row = new ArrayList(mFormat.getNumFields());
     dbgMsg("makeRow(" + pDataString + "," + mFormat + ")");
     int[] groups = mFormat.getNumFieldsArray();
     dbgMsg(
         "Groups of the format: "
             + StringUtils.collectionToString(ConversionUtils.asList(groups), " "));
     dbgMsg("Row(" + pDataString + "," + mFormat + ")");
     String[] tokens = StringUtils.split(pDataString, columnSeparatorRegex, groups);
     dbgMsg("Tokens: " + StringUtils.arrayToString(tokens, "\n"));
     for (int i = 0; i < tokens.length; i++) {
       row.add(mFormat.makeFieldRep(i, tokens[i]));
     }
   } else {
     // we do not have a format
     String[] tokens = pDataString.split(columnSeparatorRegex);
     // note: -1 indicates that the number of fields is not fixed!
     if (mNumFields != -1 && tokens.length != mNumFields) {
       throw new RuntimeException(
           "Cannot make row: numFieds = " + mNumFields + " != numTokens = " + tokens.length);
     } else {
       row = new ArrayList(Arrays.asList(tokens));
     }
   }
   return row;
 }
Exemplo n.º 2
0
  public JSONObject resetPwd(Map map) throws Exception {
    boolean isSuccess = true;
    String message = "";

    String userId = (String) map.get("userId");

    String email = (String) map.get("email");

    String verifyCode = (String) map.get("verifyCode");
    String verifyCodeInSession = (String) map.get("verifyCodeInSession");

    if (!verifyCode.equals(verifyCodeInSession)) {
      isSuccess = false;
      message = "验证码错误.";
    }

    List userList = null;
    if ((StringUtils.isNotEmpty(userId)) && (StringUtils.isNotEmpty(email))) {
      User paramUser = new User();
      paramUser.setUserId(userId);
      paramUser.setEmail(email);
      userList = selectByCriteria(paramUser);
    }
    if ((userList == null) || (userList.size() != 1)) {
      isSuccess = false;
      message = "用户名或邮箱错误.";
    }

    if (isSuccess) {
      User user = (User) userList.get(0);

      String newPassword = RandomStringUtils.random(6, true, true);

      String title = "密码重置";
      String content = user.getUserId() + ",您好:<br/>您的新密码是:" + newPassword;
      boolean rs = ServletHelp.sendEmail(email, title, content);
      if (rs) {
        User paramUser = new User();
        paramUser.setUserId(userId);
        paramUser.setPassword(MD5Utils.getMD5String(newPassword));
        update(paramUser);
      } else {
        isSuccess = false;
        message = "邮件发送失败.";
      }
    }

    JSONObject res = new JSONObject();
    res.put("success", Boolean.valueOf(isSuccess));
    res.put("message", message);
    return res;
  }
Exemplo n.º 3
0
 /**
  * 解压缩Cookie
  *
  * @param cookie Cookie
  * @throws IOException
  */
 public static final void unCompressCookie(Cookie cookie) throws IOException {
   ByteArrayOutputStream bos = new ByteArrayOutputStream();
   if (StringUtils.isEmpty(cookie.getValue())) {
     return;
   }
   byte[] compress = new BASE64Decoder().decodeBuffer(cookie.getValue());
   InflaterInputStream iis = new InflaterInputStream(new ByteArrayInputStream(compress));
   try {
     byte[] b = new byte[1024];
     int count;
     while ((count = iis.read(b)) >= 0) {
       bos.write(b, 0, count);
     }
     iis.close();
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (ObjectUtils.isNotNull(iis)) {
       try {
         iis.close();
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
     if (ObjectUtils.isNotNull(bos)) {
       try {
         bos.close();
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
   }
 }
Exemplo n.º 4
0
 /**
  * 压缩Cookie
  *
  * @param cookie Cookie
  * @param response HttpServletResponse
  */
 public static final void compressCookie(Cookie cookie, HttpServletResponse response) {
   if (new NullChecker().add(cookie).add(response).hasNull()) {
     return;
   }
   String value = cookie.getValue();
   if (StringUtils.isEmpty(value)) {
     return;
   }
   ByteArrayOutputStream bos = new ByteArrayOutputStream();
   DeflaterOutputStream dos = new DeflaterOutputStream(bos);
   try {
     dos.write(value.getBytes());
     dos.close();
     String compress = new BASE64Encoder().encode(bos.toByteArray());
     bos.close();
     response.addCookie(new Cookie("compress", compress));
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     if (ObjectUtils.isNotNull(dos)) {
       try {
         dos.close();
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
     if (ObjectUtils.isNotNull(bos)) {
       try {
         bos.close();
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
   }
 }
Exemplo n.º 5
0
 public String toString() {
   if (mAtomicParts == null) {
     return super.toString();
   } else {
     return StringUtils.collectionToString(mAtomicParts, " ");
   }
 }
Exemplo n.º 6
0
 @Test
 public void test7() {
   Layout l = Layout.createDefault();
   String s = StringUtils.insertWhitespaces(l.serialize(), 1.0f, 3);
   Layout ls = Layout.deserialize(s);
   assertThat(ls, not(sameInstance(l)));
   assertThat(ls, equalTo(l));
   assertThat(ls.equals(l), is(true));
   assertThat(ls.hashCode(), equalTo(l.hashCode()));
 }
Exemplo n.º 7
0
 /**
  * 获取Cookie值
  *
  * @param cookies Cookie数组
  * @param name 键
  * @return name对应的value
  */
 public static final String getCookie(Cookie[] cookies, String name) {
   if (ObjectUtils.isEmpty(cookies) || StringUtils.isEmpty(name)) {
     return null;
   }
   for (Cookie cookie : cookies) {
     if (name.equals(cookie.getName())) {
       return cookie.getValue();
     }
   }
   return null;
 }
Exemplo n.º 8
0
  public JSONArray selectAlbumForTree(String parentId) {
    JSONArray res = new JSONArray();

    Album paramAlbum = new Album();
    if (StringUtils.isNotEmpty(parentId)) {
      paramAlbum.setParentId(Integer.valueOf(Integer.parseInt(parentId)));
    }

    List albumList = new ArrayList();
    albumList = selectByCriteria(paramAlbum);
    res = getAlbumTreeFromList(albumList, parentId);
    return res;
  }
Exemplo n.º 9
0
  public static String encryptMD5(String s) {
    String rvalue = "";
    try {
      MessageDigest digest = MessageDigest.getInstance("MD5");
      byte[] ret = digest.digest(s.getBytes());
      rvalue = StringUtils.getHexString(ret);

      return rvalue;
    } catch (NoSuchAlgorithmException ex) {
      Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      return rvalue;
    }
  }
Exemplo n.º 10
0
 public String usage() {
   String progName = mProgName != null ? mProgName : "progname";
   String optsString1 =
       (mValidOptionNames != null && mValidOptionNames.size() > 0) ? " <options>" : "";
   String nonOptArgsString =
       (mNonOptParamNames != null && mNonOptParamNames.size() > 0)
           ? " <" + StringUtils.listToString(mNonOptParamNames, "> <") + ">"
           : "";
   String optsString2 =
       (mValidOptionNames != null && mValidOptionNames.size() > 0)
           ? "\nOPTIONS:\n" + optsWithValString() + "\n" + optsWithoutValString()
           : "";
   return "Usage: " + progName + optsString1 + nonOptArgsString + optsString2;
 }
Exemplo n.º 11
0
  public void insert(User user) {
    String userId = SessionUtils.getCurrentUserId();
    if (StringUtils.isEmpty(userId)) {
      userId = user.getUserId();
    }

    user.setPassword(MD5Utils.getMD5String(user.getPassword()));

    user.setDelflag("1");

    Timestamp sysdate = new Timestamp(System.currentTimeMillis());
    user.setCreateUser(userId);
    user.setCreateTime(sysdate);
    user.setUpdateUser(userId);
    user.setUpdateTime(sysdate);
    this.userDao.insert(user);
  }
Exemplo n.º 12
0
 public String toString() {
   // @todo: improve?
   List fields = formatFields();
   return StringUtils.listToString(fields, " ");
 }
Exemplo n.º 13
0
 public String toString(int[] pFieldWidhts) {
   List fields = formatFields();
   return StringUtils.formatList(fields, pFieldWidhts);
 }
Exemplo n.º 14
0
  public JSONObject register(Map map) throws Exception {
    boolean isSuccess = true;
    String errorMsg = "";

    User paramUser = new User();
    BeanUtils.populate(paramUser, map);
    paramUser.setBirthday(DateUtils.formatStr2Date(paramUser.getBirthdayStr(), "yyyy-MM-dd"));
    paramUser.setStatus("1");
    if ((StringUtils.isEmpty(SessionUtils.getUserRole()))
        || ("3".equals(SessionUtils.getUserRole()))) {
      paramUser.setRole("3");
    }

    String userId = map.get("userId").toString();

    String password = map.get("password").toString();

    String repassword = map.get("repassword").toString();

    String verifyCode = map.get("verifyCode").toString();
    String verifyCodeInSession = map.get("verifyCodeInSession").toString();

    if ("1".equals(SessionUtils.getUserRole())) {
      if ((!"2".equals(paramUser.getRole())) && (!"3".equals(paramUser.getRole()))) {
        isSuccess = false;
        errorMsg = "角色设置错误.";
      }
    } else if (!"3".equals(paramUser.getRole())) {
      isSuccess = false;
      errorMsg = "角色设置错误.";
    }

    if (!password.equals(repassword)) {
      isSuccess = false;
      errorMsg = "两次输入的密码不一致.";
    }

    if (!verifyCode.equals(verifyCodeInSession)) {
      isSuccess = false;
      errorMsg = "验证码错误.";
    }

    List<User> userList = selectByCriteria(new User());
    if (userList != null) {
      for (User user : userList) {
        if (userId.equals(user.getUserId())) {
          isSuccess = false;
          errorMsg = "账号已存在.";
          break;
        }
        if (paramUser.getEmail().equals(user.getEmail())) {
          isSuccess = false;
          errorMsg = "邮箱已被使用.";
          break;
        }
      }
    }

    if (isSuccess) {
      insert(paramUser);

      Map userMetaMap = new HashMap();
      userMetaMap.put("theme", (String) map.get("theme"));
      userMetaMap.put("homePage", (String) map.get("homePage"));
      userMetaMap.put("showTodo", (String) map.get("showTodo"));
      userMetaMap.put("showNote", (String) map.get("showNote"));
      userMetaMap.put("showPicture", (String) map.get("showPicture"));
      userMetaMap.put("showAccount", (String) map.get("showAccount"));
      userMetaMap.put("showFeed", (String) map.get("showFeed"));
      userMetaMap.put("showDocument", (String) map.get("showDocument"));
      if ("3".equals(paramUser.getRole())) userMetaMap.put("showSystem", "off");
      else {
        userMetaMap.put("showSystem", "on");
      }
      this.userMetaService.insert(userId, userMetaMap);

      String uploadFilePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/document", new String[] {userId}));
      FileUtils.createDirs(uploadFilePath);

      String uploadPicturePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/picture", new String[] {userId}));
      FileUtils.createDirs(uploadPicturePath);

      FileUtils.createDirs(uploadPicturePath + "/" + "thumbnail");

      String feedFilePath =
          ServletHelp.getRealPath(
              (HttpServletRequest) map.get("request"),
              MessageUtils.setParamMessage("/websrc/file/{0}/feed", new String[] {userId}));
      FileUtils.createDirs(feedFilePath);
    }

    JSONObject res = new JSONObject();
    res.put("success", Boolean.valueOf(isSuccess));
    res.put("message", errorMsg);
    return res;
  }
Exemplo n.º 15
0
 /**
  * *************************************************************************** A string containing
  * the class names returned by classes(), joined by dots.
  */
 public String classChain() {
   if (classes == null) {
     return "";
   }
   return StringUtils.join(classes, ".");
 }