Changeset 171
- Timestamp:
- 02/18/06 00:27:22
- Files:
-
- trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalTimezonesImpl.java (modified) (13 diffs)
- trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalTimezones.java (modified) (5 diffs)
- trunk/calendar3/docs/todo.txt (modified) (1 diff)
- trunk/calendar3/dumprestore/build.xml (modified) (1 diff)
- trunk/calendar3/dumprestore/src/org/bedework/dumprestore/restore/TimezonesImpl.java (modified) (9 diffs)
- trunk/calendar3/dumprestore/src/org/bedework/dumprestore/restore/rules/FilterRule.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalTimezonesImpl.java
r27 r171 59 59 import org.bedework.calfacade.BwUser; 60 60 import org.bedework.calfacade.BwTimeZone; 61 import org.bedework.calfacade.CalFacadeBadDateException;62 61 import org.bedework.calfacade.CalFacadeException; 63 import org.bedework.calfacade.CalFacadeUtil;64 62 import org.bedework.calfacade.ifs.CalTimezones; 65 63 import org.bedework.calfacade.ifs.Calintf; … … 69 67 import net.fortuna.ical4j.model.Component; 70 68 import net.fortuna.ical4j.model.component.VTimeZone; 71 import net.fortuna.ical4j.model.parameter.TzId;72 import net.fortuna.ical4j.model.property.DtEnd;73 69 import net.fortuna.ical4j.model.TimeZone; 74 70 … … 76 72 import java.util.HashMap; 77 73 import java.util.Iterator; 78 79 import org.apache.log4j.Logger;80 74 81 75 /** Handle timezones for bedework. … … 83 77 * @author Mike Douglass douglm@rpi.edu 84 78 */ 85 class CalTimezonesImpl implements CalTimezones {79 class CalTimezonesImpl extends CalTimezones { 86 80 private Calintf cal; 87 81 private BwRWStats stats; 88 82 89 private transient Logger log;90 91 83 private boolean publicAdmin; 92 private boolean debug;93 94 private String defaultTimeZoneId;95 private transient TimeZone defaultTimeZone;96 97 private static class TimezoneInfo {98 TimeZone tz;99 100 boolean publick;101 102 /* If tz was derived from a db object, this is the data */103 VTimeZone vtz;104 }105 106 /* Map of user TimezoneInfo */107 private HashMap timezones = new HashMap();108 84 109 85 private static volatile HashMap systemTimezones = new HashMap(); … … 114 90 CalTimezonesImpl(Calintf cal, BwStats stats, boolean publicAdmin, boolean debug) 115 91 throws CalFacadeException { 92 super(debug); 116 93 this.cal = cal; 117 94 this.stats = (BwRWStats)stats; 118 95 this.publicAdmin = publicAdmin; 119 this.debug = debug;120 96 121 97 // Force fetch of timezones … … 136 112 137 113 TimezoneInfo tzinfo = (TimezoneInfo)timezones.get(tzid); 114 TimeZone tz = new TimeZone(vtz); 138 115 139 116 if (tzinfo == null) { 140 tzinfo = new TimezoneInfo(); 141 } 142 143 tzinfo.vtz = vtz; 144 tzinfo.tz = new TimeZone(vtz); 145 timezones.put(tzid, tzinfo); 146 } 147 148 public void registerTimeZone(String id, TimeZone timezone) 149 throws CalFacadeException { 150 if (debug) { 151 trace("register timezone with id " + id); 152 } 153 154 TimezoneInfo tzinfo = (TimezoneInfo)timezones.get(id); 155 156 if (tzinfo == null) { 157 tzinfo = new TimezoneInfo(); 158 tzinfo.tz = timezone; 159 timezones.put(id, tzinfo); 117 tzinfo = new TimezoneInfo(tz, vtz); 118 timezones.put(tzid, tzinfo); 160 119 } else { 161 tzinfo. tz = timezone;120 tzinfo.init(tz, vtz); 162 121 } 163 122 } … … 177 136 } 178 137 179 tzinfo = new TimezoneInfo(); 180 181 tzinfo.vtz = vTimeZone; 182 tzinfo.tz = new TimeZone(vTimeZone); 138 tzinfo = new TimezoneInfo(new TimeZone(vTimeZone), vTimeZone); 183 139 timezones.put(id, tzinfo); 184 140 } 185 141 186 if (tzinfo. publick) {142 if (tzinfo.getPublick()) { 187 143 stats.incSystemTzFetches(); 188 144 } 189 145 190 146 if ((defaultTimeZone == null) && id.equals(defaultTimeZoneId)) { 191 defaultTimeZone = tzinfo.tz; 192 } 193 194 return tzinfo.tz; 195 } 196 197 public TimeZone getDefaultTimeZone() throws CalFacadeException { 198 if ((defaultTimeZone == null) && (defaultTimeZoneId != null)) { 199 defaultTimeZone = getTimeZone(defaultTimeZoneId); 200 } 201 202 return defaultTimeZone; 203 } 204 205 public void setDefaultTimeZoneId(String id) throws CalFacadeException { 206 defaultTimeZone = null; 207 defaultTimeZoneId = id; 208 } 209 210 public String getDefaultTimeZoneId() throws CalFacadeException { 211 return defaultTimeZoneId; 147 defaultTimeZone = tzinfo.getTz(); 148 } 149 150 return tzinfo.getTz(); 212 151 } 213 152 … … 219 158 TimezoneInfo tzinfo = lookup(id); 220 159 221 if ((tzinfo != null) && (tzinfo. vtz!= null)) {222 return tzinfo. vtz;160 if ((tzinfo != null) && (tzinfo.getVtz() != null)) { 161 return tzinfo.getVtz(); 223 162 } 224 163 … … 228 167 } 229 168 230 tzinfo = new TimezoneInfo(); 231 232 tzinfo.vtz = vTimeZone; 233 tzinfo.tz = new TimeZone(vTimeZone); 169 tzinfo = new TimezoneInfo(new TimeZone(vTimeZone), vTimeZone); 234 170 timezones.put(id, tzinfo); 235 171 … … 249 185 // force refresh now 250 186 lookup("not-a-timezone"); 251 }252 253 public String getUtc(String time, String tzid, TimeZone tz) throws CalFacadeException {254 //if (debug) {255 // trace("Get utc for " + time + " tzid=" + tzid + " tz =" + tz);256 //}257 if (CalFacadeUtil.isISODateTimeUTC(time)) {258 // Already UTC259 return time;260 }261 262 if (CalFacadeUtil.isISODateTime(time)) {263 try {264 DtEnd dte = new DtEnd();265 266 if ((tz == null) && (tzid != null)) {267 tz = getTimeZone(tzid);268 269 //if (debug) {270 // trace("--------Got timezone " + tz);271 //}272 273 if (tz == null) {274 throw new CalFacadeBadDateException();275 }276 } else if ((tz != null) && (tzid == null)) {277 tzid = tz.getID();278 }279 280 if (tzid != null) {281 dte.getParameters().add(new TzId(tzid));282 dte.setTimeZone(tz);283 }284 285 dte.setValue(time);286 dte.setUtc(true);287 288 return dte.getValue();289 } catch (Throwable t) {290 t.printStackTrace();291 throw new CalFacadeBadDateException();292 }293 }294 295 if (CalFacadeUtil.isISODate(time)) {296 return time + "T000000Z";297 }298 299 throw new CalFacadeBadDateException();300 187 } 301 188 … … 324 211 } 325 212 326 tzinfo = new TimezoneInfo(); 327 328 tzinfo.vtz = vtz; 329 tzinfo.tz = new TimeZone(vtz); 213 tzinfo = new TimezoneInfo(new TimeZone(vtz), vtz, true); 330 214 systemTimezones.put(btz.getTzid(), tzinfo); 331 215 } … … 338 222 tzinfo = (TimezoneInfo)systemTimezones.get(id); 339 223 340 if (tzinfo != null) { 341 tzinfo.publick = true; 342 } else { 224 if (tzinfo == null) { 343 225 tzinfo = (TimezoneInfo)timezones.get(id); 344 226 } … … 346 228 return tzinfo; 347 229 } 348 349 /* Get a logger for messages350 */351 private Logger getLogger() {352 if (log == null) {353 log = Logger.getLogger(this.getClass());354 }355 356 return log;357 }358 359 private void trace(String msg) {360 getLogger().debug("trace: " + msg);361 }362 230 } 363 231 trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalTimezones.java
r27 r171 55 55 package org.bedework.calfacade.ifs; 56 56 57 import org.apache.log4j.Logger; 57 58 import org.bedework.calfacade.BwUser; 59 import org.bedework.calfacade.CalFacadeBadDateException; 58 60 import org.bedework.calfacade.CalFacadeException; 61 import org.bedework.calfacade.CalFacadeUtil; 59 62 60 63 import net.fortuna.ical4j.model.TimeZone; 61 64 import net.fortuna.ical4j.model.component.VTimeZone; 65 import net.fortuna.ical4j.util.TimeZones; 62 66 63 67 import java.io.Serializable; 68 import java.text.DateFormat; 69 import java.text.SimpleDateFormat; 70 import java.util.Calendar; 71 import java.util.HashMap; 64 72 65 73 /** Handle caching, retrieval and registration of timezones. … … 68 76 * 69 77 */ 70 public interface CalTimezones extends Serializable { 78 public abstract class CalTimezones implements Serializable { 79 private transient Logger log; 80 81 protected boolean debug; 82 83 protected String defaultTimeZoneId; 84 protected transient TimeZone defaultTimeZone; 85 86 protected static class TimezoneInfo { 87 TimeZone tz; 88 89 /* If tz was derived from a db object, this is the data */ 90 VTimeZone vtz; 91 92 boolean publick; 93 94 /** 95 * @param tz 96 * @param vtz 97 */ 98 public TimezoneInfo(TimeZone tz, VTimeZone vtz) { 99 init(tz, vtz); 100 } 101 102 /** Constructor 103 * 104 * @param tz 105 * @param vtz 106 * @param publick 107 */ 108 public TimezoneInfo(TimeZone tz, VTimeZone vtz, boolean publick) { 109 this.tz = tz; 110 this.vtz = vtz; 111 this.publick = publick; 112 } 113 114 /** (Re)init the object 115 * 116 * @param tz 117 * @param vtz 118 */ 119 public void init(TimeZone tz, VTimeZone vtz) { 120 this.tz = tz; 121 this.vtz = vtz; 122 } 123 124 public TimeZone getTz() { 125 return tz; 126 } 127 128 public VTimeZone getVtz() { 129 return vtz; 130 } 131 132 /** 133 * @return true for public timezone 134 */ 135 public boolean getPublick() { 136 return publick; 137 } 138 } 139 140 /* Map of user TimezoneInfo */ 141 protected HashMap timezones = new HashMap(); 142 143 protected CalTimezones(boolean debug) { 144 this.debug = debug; 145 } 146 71 147 /** Save a timezone definition in the database. The timezone is in the 72 148 * form of a complete calendar definition containing a single VTimeZone … … 79 155 * @throws CalFacadeException 80 156 */ 81 public void saveTimeZone(String tzid, VTimeZone vtz)157 public abstract void saveTimeZone(String tzid, VTimeZone vtz) 82 158 throws CalFacadeException; 83 159 … … 88 164 * @throws CalFacadeException 89 165 */ 90 public void registerTimeZone(String id, TimeZone timezone) 91 throws CalFacadeException; 166 public void registerTimeZone(String id, TimeZone timezone) 167 throws CalFacadeException { 168 if (debug) { 169 trace("register timezone with id " + id); 170 } 171 172 TimezoneInfo tzinfo = (TimezoneInfo)timezones.get(id); 173 174 if (tzinfo == null) { 175 tzinfo = new TimezoneInfo(timezone, null); 176 timezones.put(id, tzinfo); 177 } else { 178 tzinfo.tz = timezone; 179 } 180 } 92 181 93 182 /** Get a timezone object given the id. This will return transient objects … … 98 187 * @throws CalFacadeException 99 188 */ 100 public TimeZone getTimeZone(final String id) throws CalFacadeException; 101 102 /** Get the default timezone for this system. 103 * 104 * @return default TimeZone or null for none set. 105 * @throws CalFacadeException 106 */ 107 public TimeZone getDefaultTimeZone() throws CalFacadeException; 108 109 /** Set the default timezone id for this system. 110 * 111 * @param id 112 * @throws CalFacadeException 113 */ 114 public void setDefaultTimeZoneId(String id) throws CalFacadeException; 115 116 /** Get the default timezone id for this system. 117 * 118 * @return String id 119 * @throws CalFacadeException 120 */ 121 public String getDefaultTimeZoneId() throws CalFacadeException; 122 123 /** Find a timezone object in the database given the id. 124 * 125 * @param id 126 * @param owner event owner or null for current user 127 * @return VTimeZone with id or null 128 * @throws CalFacadeException 129 */ 130 public VTimeZone findTimeZone(final String id, BwUser owner) throws CalFacadeException; 131 132 /** Clear all public timezone objects 133 * 134 * <p>Will remove all public timezones in preparation for a replacement 135 * (presumably) 136 * 137 * @throws CalFacadeException 138 */ 139 public void clearPublicTimezones() throws CalFacadeException; 140 141 /** Refresh the public timezone table - presumably after a call to clearPublicTimezones. 142 * and many calls to saveTimeZone. 143 * 144 * @throws CalFacadeException 145 */ 146 public void refreshTimezones() throws CalFacadeException; 147 148 /** Given a String time value and a possibly null tzid and/or timezone 149 * will return a UTC formatted value. The supplied time should be of the 150 * form yyyyMMdd or yyyyMMddThhmmss or yyyyMMddThhmmssZ 151 * 152 * <p>The last form will be returned untouched, the first will have T000000Z 153 * appended and the second will be converted to the equivalent UTC time. 154 * 155 * <p>The returned value is used internally as a value for indexes and 156 * recurrence ids. 157 * 158 * <p>Both tzid and tz null mean this is local or floating time 159 * 160 * @param time String time to convert. 161 * @param tzid String tzid. 162 * @param tz If set used in preference to tzid. 163 * @return String always of form yyyyMMddThhmmssZ 164 * @throws CalFacadeException for bad parameters or timezone 165 */ 166 public String getUtc(String time, String tzid, TimeZone tz) throws CalFacadeException; 189 public abstract TimeZone getTimeZone(final String id) throws CalFacadeException; 190 191 /** Get the default timezone for this system. 192 * 193 * @return default TimeZone or null for none set. 194 * @throws CalFacadeException 195 */ 196 public TimeZone getDefaultTimeZone() throws CalFacadeException { 197 if ((defaultTimeZone == null) && (defaultTimeZoneId != null)) { 198 defaultTimeZone = getTimeZone(defaultTimeZoneId); 199 } 200 201 return defaultTimeZone; 202 } 203 204 /** Set the default timezone id for this system. 205 * 206 * @param id 207 * @throws CalFacadeException 208 */ 209 public void setDefaultTimeZoneId(String id) throws CalFacadeException { 210 defaultTimeZone = null; 211 defaultTimeZoneId = id; 212 } 213 214 /** Get the default timezone id for this system. 215 * 216 * @return String id 217 * @throws CalFacadeException 218 */ 219 public String getDefaultTimeZoneId() throws CalFacadeException { 220 return defaultTimeZoneId; 221 } 222 223 /** Find a timezone object in the database given the id. 224 * 225 * @param id 226 * @param owner event owner or null for current user 227 * @return VTimeZone with id or null 228 * @throws CalFacadeException 229 */ 230 public abstract VTimeZone findTimeZone(final String id, BwUser owner) throws CalFacadeException; 231 232 /** Clear all public timezone objects 233 * 234 * <p>Will remove all public timezones in preparation for a replacement 235 * (presumably) 236 * 237 * @throws CalFacadeException 238 */ 239 public abstract void clearPublicTimezones() throws CalFacadeException; 240 241 /** Refresh the public timezone table - presumably after a call to clearPublicTimezones. 242 * and many calls to saveTimeZone. 243 * 244 * @throws CalFacadeException 245 */ 246 public abstract void refreshTimezones() throws CalFacadeException; 247 248 private static DateFormat formatTd = new SimpleDateFormat("yyyyMMdd'T'HHmmss"); 249 private static Calendar cal = Calendar.getInstance(); 250 private static java.util.TimeZone utctz; 251 private static java.util.TimeZone lasttz; 252 private static String lasttzid; 253 static { 254 try { 255 utctz = TimeZone.getTimeZone(TimeZones.UTC_ID); 256 } catch (Throwable t) { 257 throw new RuntimeException("Unable to initialise UTC timezone"); 258 } 259 cal.setTimeZone(utctz); 260 } 261 262 /** Given a String time value and a possibly null tzid and/or timezone 263 * will return a UTC formatted value. The supplied time should be of the 264 * form yyyyMMdd or yyyyMMddThhmmss or yyyyMMddThhmmssZ 265 * 266 * <p>The last form will be returned untouched, it's already UTC. 267 * 268 * <p>the first will have T000000 appended to the parameter value then the 269 * first and second will be converted to the equivalent UTC time. 270 * 271 * <p>The returned value is used internally as a value for indexes and 272 * recurrence ids. 273 * 274 * <p>Both tzid and tz null mean this is local or floating time 275 * 276 * @param time String time to convert. 277 * @param tzid String tzid. 278 * @param tz If set used in preference to tzid. 279 * @return String always of form yyyyMMddThhmmssZ 280 * @throws CalFacadeException for bad parameters or timezone 281 */ 282 public synchronized String getUtc(String time, String tzid, TimeZone tz) 283 throws CalFacadeException { 284 /* XXX We probably need the ownerid to determine exactly which timezone 285 */ 286 //if (debug) { 287 // trace("Get utc for " + time + " tzid=" + tzid + " tz =" + tz); 288 //} 289 if (CalFacadeUtil.isISODateTimeUTC(time)) { 290 // Already UTC 291 return time; 292 } 293 294 if (CalFacadeUtil.isISODate(time)) { 295 time += "T000000"; 296 } else if (!CalFacadeUtil.isISODateTime(time)) { 297 throw new CalFacadeBadDateException(); 298 } 299 300 try { 301 boolean tzchanged = false; 302 303 if (tz == null) { 304 if (tzid == null) { 305 if ((lasttzid != null) || (lasttz == null)) { 306 lasttz = TimeZone.getDefault(); 307 tzchanged = true; 308 } 309 } else { 310 if ((lasttzid == null) || (!lasttzid.equals(tzid))) { 311 lasttz = getTimeZone(tzid); 312 if (lasttz == null) { 313 lasttzid = null; 314 throw new CalFacadeBadDateException(); 315 } 316 tzchanged = true; 317 } 318 } 319 } else { 320 // tz supplied 321 if (tz != lasttz) { 322 /* Yes, that's a !=. I'm looking for it being the same object. 323 * If I were sure that equals were correct and fast I'd use 324 * that. 325 */ 326 tzchanged = true; 327 tzid = tz.getID(); 328 lasttz = tz; 329 } 330 } 331 332 333 if (tzchanged) { 334 if (debug) { 335 trace("**********tzchanged for tzid " + tzid); 336 } 337 formatTd.setTimeZone(lasttz); 338 lasttzid = tzid; 339 } 340 341 cal.setTime(formatTd.parse(time)); 342 343 StringBuffer sb = new StringBuffer(); 344 digit4(sb, cal.get(Calendar.YEAR)); 345 digit2(sb, cal.get(Calendar.MONTH) + 1); // Month starts at 0 346 digit2(sb, cal.get(Calendar.DAY_OF_MONTH)); 347 sb.append('T'); 348 digit2(sb, cal.get(Calendar.HOUR_OF_DAY)); 349 digit2(sb, cal.get(Calendar.MINUTE)); 350 digit2(sb, cal.get(Calendar.SECOND)); 351 sb.append('Z'); 352 return sb.toString(); 353 } catch (Throwable t) { 354 t.printStackTrace(); 355 throw new CalFacadeBadDateException(); 356 } 357 } 358 359 /* ==================================================================== 360 * protected methods 361 * ==================================================================== */ 362 363 protected void digit2(StringBuffer sb, int val) throws CalFacadeException { 364 if (val > 99) { 365 throw new CalFacadeBadDateException(); 366 } 367 if (val < 10) { 368 sb.append("0"); 369 } 370 sb.append(val); 371 } 372 373 protected void digit4(StringBuffer sb, int val) throws CalFacadeException { 374 if (val > 9999) { 375 throw new CalFacadeBadDateException(); 376 } 377 if (val < 10) { 378 sb.append("000"); 379 } else if (val < 100) { 380 sb.append("00"); 381 } else if (val < 1000) { 382 sb.append("0"); 383 } 384 sb.append(val); 385 } 386 387 388 /* Get a logger for messages 389 */ 390 protected Logger getLogger() { 391 if (log == null) { 392 log = Logger.getLogger(this.getClass()); 393 } 394 395 return log; 396 } 397 398 protected void trace(String msg) { 399 getLogger().debug("trace: " + msg); 400 } 167 401 } trunk/calendar3/docs/todo.txt
r170 r171 19 19 20 20 Switch displays and ensure they turn up. 21 -------------------------------------------------------------------------------- 22 Restore makes a date type then turns it into datetime. Screws tz caching. 23 Save values and fix up at end? 24 -------------------------------------------------------------------------------- 25 2.3.2 dump needs to dump filters before events. 21 26 -------------------------------------------------------------------------------- 22 27 update quickstart stuff trunk/calendar3/dumprestore/build.xml
r75 r171 262 262 <arg value="-usergroupsClass" /> 263 263 <arg value="${org.bedework.syspar.usergroupsclass}" /> 264 <jvmarg value="-mx128m" /> 265 <jvmarg value="-ms128m" /> 264 266 <!-- 265 267 <jvmarg value="-Xrunyjpagent:cpu=times,onexit=cpu" /> trunk/calendar3/dumprestore/src/org/bedework/dumprestore/restore/TimezonesImpl.java
r99 r171 57 57 import org.bedework.calfacade.BwUser; 58 58 import org.bedework.calfacade.BwTimeZone; 59 import org.bedework.calfacade.CalFacadeBadDateException;60 59 import org.bedework.calfacade.CalFacadeException; 61 import org.bedework.calfacade.CalFacadeUtil;62 60 import org.bedework.calfacade.ifs.CalTimezones; 63 61 64 62 import net.fortuna.ical4j.model.component.VTimeZone; 65 63 import net.fortuna.ical4j.model.TimeZone; 66 import net.fortuna.ical4j.util.TimeZones;67 68 import java.text.DateFormat;69 import java.text.SimpleDateFormat;70 import java.util.Calendar;71 import java.util.HashMap;72 73 import org.apache.log4j.Logger;74 64 75 65 /** Handle timezones for bedework restore program. 76 *77 * <p>At the moment this does nothing as we have no timezones in the 2.378 * version. This needs to act as a repository for all timezones as we restore79 * them.80 66 * 81 67 * @author Mike Douglass douglm@rpi.edu 82 68 */ 83 class TimezonesImpl implements CalTimezones { 84 private transient Logger log; 85 86 private boolean debug; 69 class TimezonesImpl extends CalTimezones { 87 70 private boolean publick = true; // current mode 88 71 private BwUser user; 89 72 90 private String defaultTimeZoneId;91 private transient TimeZone defaultTimeZone;92 93 73 private RestoreIntf ri; 94 74 95 private static class TimezoneInfo { 96 TimeZone tz; 97 98 boolean publick; 99 100 /* If tz was derived from a db object, this is the data */ 101 VTimeZone vtz; 102 } 103 104 /* Map of user TimezoneInfo */ 105 private HashMap timezones = new HashMap(); 106 107 private static volatile HashMap systemTimezones = new HashMap(); 75 // private static volatile HashMap systemTimezones = new HashMap(); 108 76 //private static volatile boolean systemTimezonesInitialised = false; 109 110 //private transient Logger log;111 77 112 78 TimezonesImpl(boolean debug, BwUser user, RestoreIntf ri) 113 79 throws CalFacadeException { 114 this.debug = debug;80 super(debug); 115 81 this.user = user; 116 82 this.ri = ri; … … 142 108 */ 143 109 144 BwTimeZone tz = new BwTimeZone();145 146 tz.setTzid(tzid);147 tz.setPublick(publick);148 tz.setOwner(user);110 BwTimeZone btz = new BwTimeZone(); 111 112 btz.setTzid(tzid); 113 btz.setPublick(publick); 114 btz.setOwner(user); 149 115 150 116 StringBuffer sb = new StringBuffer(); … … 156 122 sb.append("END:VCALENDAR\n"); 157 123 158 tz.setVtimezone(sb.toString());124 btz.setVtimezone(sb.toString()); 159 125 160 126 try { 161 ri.restoreTimezone( tz);127 ri.restoreTimezone(btz); 162 128 } catch (Throwable t) { 163 129 throw new CalFacadeException(t); … … 165 131 166 132 TimezoneInfo tzinfo = (TimezoneInfo)timezones.get(tzid); 133 TimeZone tz = new TimeZone(vtz); 167 134 168 135 if (tzinfo == null) { 169 tzinfo = new TimezoneInfo(); 170 } 171 172 tzinfo.vtz = vtz; 173 tzinfo.tz = new TimeZone(vtz); 174 timezones.put(tzid, tzinfo); 175 } 176 177 public void registerTimeZone(String id, TimeZone timezone) 178 throws CalFacadeException { 179 if (debug) { 180 trace("register timezone with id " + id); 181 } 182 183 TimezoneInfo tzinfo = (TimezoneInfo)timezones.get(id); 184 185 if (tzinfo == null) { 186 tzinfo = new TimezoneInfo(); 187 tzinfo.tz = timezone; 188 timezones.put(id, tzinfo); 136 tzinfo = new TimezoneInfo(tz, vtz); 137 timezones.put(tzid, tzinfo); 189 138 } else { 190 tzinfo. tz = timezone;139 tzinfo.init(tz, vtz); 191 140 } 192 141 } … … 210 159 */ 211 160 212 return tzinfo.tz; 213 } 214 215 public TimeZone getDefaultTimeZone() throws CalFacadeException { 216 if ((defaultTimeZone == null) && (defaultTimeZoneId != null)) { 217 defaultTimeZone = getTimeZone(defaultTimeZoneId); 218 } 219 220 return defaultTimeZone; 221 } 222 223 public void setDefaultTimeZoneId(String id) throws CalFacadeException { 224 defaultTimeZone = null; 225 defaultTimeZoneId = id; 226 } 227 228 public String getDefaultTimeZoneId() throws CalFacadeException { 229 return defaultTimeZoneId; 161 return tzinfo.getTz(); 230 162 } 231 163 … … 237 169 TimezoneInfo tzinfo = lookup(id); 238 170 239 if ((tzinfo != null) && (tzinfo. vtz!= null)) {240 return tzinfo. vtz;171 if ((tzinfo != null) && (tzinfo.getVtz() != null)) { 172 return tzinfo.getVtz(); 241 173 } 242 174 … … 264 196 synchronized (this) { 265 197 //systemTimezonesInitialised = false; 266 systemTimezones = new HashMap();198 // systemTimezones = new HashMap(); 267 199 } 268 200 … … 270 202 lookup("not-a-timezone"); 271 203 } 272 273 private static DateFormat formatTd = new SimpleDateFormat("yyyyMMdd'T'HHmmss"); 274 private static Calendar cal = Calendar.getInstance(); 275 private static java.util.TimeZone utctz; 276 private static java.util.TimeZone lasttz; 277 private static String lasttzid; 278 static { 279 try { 280 utctz = TimeZone.getTimeZone(TimeZones.UTC_ID); 281 } catch (Throwable t) { 282 throw new RuntimeException("Unable to initialise UTC timezone"); 283 } 284 cal.setTimeZone(utctz); 285 } 286 287 public synchronized String getUtc(String time, String tzid, TimeZone tz) throws CalFacadeException { 288 /* XXX We probably need the ownerid to determine exactly which timezone 289 */ 290 //if (debug) { 291 // trace("Get utc for " + time + " tzid=" + tzid + " tz =" + tz); 292 //} 293 if (CalFacadeUtil.isISODateTimeUTC(time)) { 294 // Already UTC 295 return time; 296 } 297 298 if (CalFacadeUtil.isISODateTime(time)) { 299 try { 300 boolean tzchanged = false; 301 302 if (tz == null) { 303 if (tzid == null) { 304 if ((lasttzid != null) || (lasttz == null)) { 305 lasttz = TimeZone.getDefault(); 306 tzchanged = true; 307 } 308 } else { 309 if ((lasttzid == null) || (!lasttzid.equals(tzid))) { 310 lasttz = getTimeZone(tzid); 311 if (lasttz == null) { 312 lasttzid = null; 313 throw new CalFacadeBadDateException(); 314 } 315 tzchanged = true; 316 } 317 } 318 } else { 319 // tz supplied 320 if (tz != lasttz) { 321 /* Yes, that's a !=. I'm looking for it being the same object. 322 * If I were sure that equals were correct and fast I'd use 323 * that. 324 */ 325 tzchanged = true; 326 tzid = tz.getID(); 327 lasttz = tz; 328 } 329 } 330 331 332 if (tzchanged) { 333 if (debug) { 334 trace("**********tzchanged"); 335 } 336 formatTd.setTimeZone(lasttz); 337 lasttzid = tzid; 338 } 339 340 cal.setTime(formatTd.parse(time)); 341 342 StringBuffer sb = new StringBuffer(); 343 digit4(sb, cal.get(Calendar.YEAR)); 344 digit2(sb, cal.get(Calendar.MONTH) + 1); // Month starts at 0 345 digit2(sb, cal.get(Calendar.DAY_OF_MONTH)); 346 sb.append('T'); 347 digit2(sb, cal.get(Calendar.HOUR_OF_DAY)); 348 digit2(sb, cal.get(Calendar.MINUTE)); 349 digit2(sb, cal.get(Calendar.SECOND)); 350 sb.append('Z'); 351 return sb.toString(); 352 } catch (Throwable t) { 353 t.printStackTrace(); 354 throw new CalFacadeBadDateException(); 355 } 356 } 357 358 if (CalFacadeUtil.isISODate(time)) { 359 return time + "T000000Z"; 360 } 361 362 throw new CalFacadeBadDateException(); 363 } 364 204 365 205 /* ==================================================================== 366 206 * Private methods 367 207 * ==================================================================== */ 368 369 private void digit2(StringBuffer sb, int val) throws CalFacadeException {370 if (val > 99) {371 throw new CalFacadeBadDateException();372 }373 if (val < 10) {374 sb.append("0");375 }376 sb.append(val);377 }378 379 private void digit4(StringBuffer sb, int val) throws CalFacadeException {380 if (val > 9999) {381 throw new CalFacadeBadDateException();382 }383 if (val < 10) {384 sb.append("000");385 } else if (val < 100) {386 sb.append("00");387 } else if (val < 1000) {388 sb.append("0");389 }390 sb.append(val);391 }392 208 393 209 private TimezoneInfo lookup(String id) throws CalFacadeException { … … 425 241 */ 426 242 427 tzinfo = (TimezoneInfo)systemTimezones.get(id);428 429 if (tzinfo != null) {430 tzinfo.publick = true;431 } else {243 // tzinfo = (TimezoneInfo)systemTimezones.get(id); 244 245 // if (tzinfo != null) { 246 // tzinfo.publick = true; 247 // } else { 432 248 tzinfo = (TimezoneInfo)timezones.get(id); 433 }249 // } 434 250 435 251 return tzinfo; 436 252 } 437 438 /* Get a logger for messages439 */440 private Logger getLogger() {441 if (log == null) {442 log = Logger.getLogger(this.getClass());443 }444 445 return log;446 }447 448 private void trace(String msg) {449 getLogger().debug("trace: " + msg);450 }451 253 } trunk/calendar3/dumprestore/src/org/bedework/dumprestore/restore/rules/FilterRule.java
r75 r171 108 108 globals.calLeaves.add(entity); 109 109 globals.catCalTbl.put(catf.getCategory().getId(), cal); 110 if (globals.debug) { 111 trace("Save calendar with id " + cal.getId()); 112 } 110 113 } else if (entity instanceof BwCreatorFilter) { 111 114 cal.setCalendarCollection(true); … … 137 140 globals.calMapErrors++; 138 141 } else if (entity instanceof RestoreGlobals.AliasFilter) { 142 error("Unable to map filter " + entity); 143 cal = null; 144 globals.calMapErrors++; 145 } else { 139 146 error("Unable to map filter " + entity); 140 147 cal = null;
