1 25 26 package org.snipsnap.snip; 27 28 import org.radeox.util.i18n.ResourceManager; 29 import org.snipsnap.container.Components; 30 import org.snipsnap.user.UserManager; 31 32 import java.sql.Timestamp ; 33 import java.text.MessageFormat ; 34 35 42 43 public class Modified { 44 String cUser, mUser; 45 Timestamp cTime, mTime; 46 47 public Modified(String cUser, String mUser, Timestamp cTime, Timestamp mTime) { 48 this.cUser = cUser; 49 this.mUser = mUser; 50 this.cTime = cTime; 51 this.mTime = mTime; 52 } 53 54 public Modified() { 55 } 56 57 public String getcUser() { 58 return cUser; 59 } 60 61 public void setcUser(String cUser) { 62 this.cUser = cUser; 63 } 64 65 public String getmUser() { 66 return mUser; 67 } 68 69 public void setmUser(String mUser) { 70 this.mUser = mUser; 71 } 72 73 public Timestamp getcTime() { 74 return cTime; 75 } 76 77 public void setcTime(Timestamp cTime) { 78 this.cTime = cTime; 79 } 80 81 public Timestamp getmTime() { 82 return mTime; 83 } 84 85 public void setmTime(Timestamp mTime) { 86 this.mTime = mTime; 87 } 88 89 95 public String toString() { 96 MessageFormat mf = new MessageFormat (ResourceManager.getString("i18n.messages", "modified.info"), 97 ResourceManager.getLocale("i18n.messages")); 98 99 UserManager um = (UserManager) Components.getComponent(UserManager.class); 100 return mf.format(new Object []{ 101 um.exists(cUser) ? SnipLink.createLink(cUser) : cUser, 102 um.exists(mUser) ? SnipLink.createLink(mUser) : mUser, 103 getNiceTime(mTime) 104 }); 105 } 106 107 111 public String getShort() { 112 MessageFormat mf = new MessageFormat (ResourceManager.getString("i18n.messages", "modified.info.short"), 113 ResourceManager.getLocale("i18n.messages")); 114 UserManager um = (UserManager) Components.getComponent(UserManager.class); 115 return mf.format(new Object [] { 116 um.exists(cUser) ? SnipLink.createLink(cUser) : cUser, 117 getNiceTime(mTime) 118 }); 119 } 120 121 132 public static String getNiceTime(Timestamp time) { 133 if (time == null) { 134 return ""; 135 } 136 java.util.Date now = new java.util.Date (); 137 return getNiceTime(now.getTime(), time.getTime()); 138 139 } 140 141 public static String getNiceTime(long now, long time) { 142 long secs = (now - time) / 1000; 144 long mins = secs / 60; int min = (int) mins % 60; long hours = mins / 60; int hour = (int) hours % 24; int days = (int) hours / 24; int day = days % 365; int years = days / 365; 153 StringBuffer nice = new StringBuffer (); 154 if (secs < 60) { 155 nice.append(ResourceManager.getString("i18n.messages", "modified.time.just")); 156 } else { 157 if (hours == 0) { 158 MessageFormat mf = new MessageFormat (ResourceManager.getString("i18n.messages", "modified.time.minutes"), 159 ResourceManager.getLocale("i18n.messages")); 160 mf.format(new Object []{new Long (min)}, nice, null); 161 } else if (days == 0) { 162 MessageFormat mf = new MessageFormat (ResourceManager.getString("i18n.messages", "modified.time.hours"), 163 ResourceManager.getLocale("i18n.messages")); 164 mf.format(new Object []{new Long (hour), new Long (min)}, nice, null); 165 } else if(years == 0) { 166 MessageFormat mf = new MessageFormat (ResourceManager.getString("i18n.messages", "modified.time.days"), 167 ResourceManager.getLocale("i18n.messages")); 168 mf.format(new Object []{new Long (days)}, nice, null); 169 } else { 170 MessageFormat mf = new MessageFormat (ResourceManager.getString("i18n.messages", "modified.time.years"), 171 ResourceManager.getLocale("i18n.messages")); 172 mf.format(new Object []{new Long (years), new Long (day)}, nice, null); 173 } 174 } 175 return nice.toString(); 176 } 177 } 178 | Popular Tags |