/** * Returns a textual representation for the time that has elapsed. * * @param delta the elapsed time. * @return textual representation for the time that has elapsed. */ public static String getElapsedTime(long delta) { if (delta < JiveConstants.MINUTE) { return LocaleUtils.getLocalizedString("global.less-minute"); } else if (delta < JiveConstants.HOUR) { long mins = delta / JiveConstants.MINUTE; StringBuilder sb = new StringBuilder(); sb.append(mins).append(" "); sb.append( (mins == 1) ? LocaleUtils.getLocalizedString("global.minute") : LocaleUtils.getLocalizedString("global.minutes")); return sb.toString(); } else if (delta < JiveConstants.DAY) { long hours = delta / JiveConstants.HOUR; delta -= hours * JiveConstants.HOUR; long mins = delta / JiveConstants.MINUTE; StringBuilder sb = new StringBuilder(); sb.append(hours).append(" "); sb.append( (hours == 1) ? LocaleUtils.getLocalizedString("global.hour") : LocaleUtils.getLocalizedString("global.hours")); sb.append(", "); sb.append(mins).append(" "); sb.append( (mins == 1) ? LocaleUtils.getLocalizedString("global.minute") : LocaleUtils.getLocalizedString("global.minutes")); return sb.toString(); } else { long days = delta / JiveConstants.DAY; delta -= days * JiveConstants.DAY; long hours = delta / JiveConstants.HOUR; delta -= hours * JiveConstants.HOUR; long mins = delta / JiveConstants.MINUTE; StringBuilder sb = new StringBuilder(); sb.append(days).append(" "); sb.append( (days == 1) ? LocaleUtils.getLocalizedString("global.day") : LocaleUtils.getLocalizedString("global.days")); sb.append(", "); sb.append(hours).append(" "); sb.append( (hours == 1) ? LocaleUtils.getLocalizedString("global.hour") : LocaleUtils.getLocalizedString("global.hours")); sb.append(", "); sb.append(mins).append(" "); sb.append( (mins == 1) ? LocaleUtils.getLocalizedString("global.minute") : LocaleUtils.getLocalizedString("global.minutes")); return sb.toString(); } }
public User createUser(String username, String password, String name, String email) throws UserAlreadyExistsException { if (isReadOnly()) { // Reject the operation since the provider is read-only throw new UnsupportedOperationException(); } try { loadUser(username); // The user already exists since no exception, so: throw new UserAlreadyExistsException("Username " + username + " already exists"); } catch (UserNotFoundException unfe) { // The user doesn't already exist so we can create a new user // Determine if the password should be stored as plain text or encrypted. boolean usePlainPassword = JiveGlobals.getBooleanProperty("user.usePlainPassword"); String encryptedPassword = null; if (!usePlainPassword) { try { encryptedPassword = AuthFactory.encryptPassword(password); // Set password to null so that it's inserted that way. password = null; } catch (UnsupportedOperationException uoe) { // Encrypting the password may have failed if in setup mode. Therefore, // use the plain password. } } Date now = new Date(); Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(INSERT_USER); pstmt.setString(1, username); if (password == null) { pstmt.setNull(2, Types.VARCHAR); } else { pstmt.setString(2, password); } if (encryptedPassword == null) { pstmt.setNull(3, Types.VARCHAR); } else { pstmt.setString(3, encryptedPassword); } if (name == null) { pstmt.setNull(4, Types.VARCHAR); } else { pstmt.setString(4, name); } if (email == null) { pstmt.setNull(5, Types.VARCHAR); } else { pstmt.setString(5, email); } pstmt.setString(6, StringUtils.dateToMillis(now)); pstmt.setString(7, StringUtils.dateToMillis(now)); pstmt.execute(); } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } finally { DbConnectionManager.closeConnection(pstmt, con); } return new User(username, name, email, now, now); } }
private static void markLogFile(String username, RotatingFileTarget target) { List args = new ArrayList(); args.add(username); args.add(JiveGlobals.formatDateTime(new java.util.Date())); target.write(LocaleUtils.getLocalizedString("log.marker_inserted_by", args) + "\n"); }