Changeset 96
- Timestamp:
- 02/06/06 17:11:41
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/calendar3/dumprestore/src/org/bedework/dumprestore/restore/TimezonesImpl.java
r48 r96 56 56 57 57 import org.bedework.calfacade.BwUser; 58 //import org.bedework.calfacade.BwTimeZone;59 58 import org.bedework.calfacade.BwTimeZone; 60 59 import org.bedework.calfacade.CalFacadeBadDateException; … … 62 61 import org.bedework.calfacade.CalFacadeUtil; 63 62 import org.bedework.calfacade.ifs.CalTimezones; 64 //import org.bedework.icalendar.IcalTranslator; 65 66 //import net.fortuna.ical4j.model.Calendar; 67 //import net.fortuna.ical4j.model.Component; 63 68 64 import net.fortuna.ical4j.model.component.VTimeZone; 69 import net.fortuna.ical4j.model.parameter.TzId;70 import net.fortuna.ical4j.model.property.DtEnd;71 65 import net.fortuna.ical4j.model.TimeZone; 72 73 //import java.util.Collection; 66 import net.fortuna.ical4j.util.TimeZones; 67 68 import java.text.DateFormat; 69 import java.text.SimpleDateFormat; 70 import java.util.Calendar; 74 71 import java.util.HashMap; 75 //import java.util.Iterator;76 72 77 73 import org.apache.log4j.Logger; … … 275 271 } 276 272 277 public String getUtc(String time, String tzid, TimeZone tz) throws CalFacadeException { 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 } 285 286 public synchronized String getUtc(String time, String tzid, TimeZone tz) throws CalFacadeException { 287 /* XXX We probably need the ownerid to determine exactly which timezone 288 */ 278 289 //if (debug) { 279 290 // trace("Get utc for " + time + " tzid=" + tzid + " tz =" + tz); … … 286 297 if (CalFacadeUtil.isISODateTime(time)) { 287 298 try { 288 DtEnd dte = new DtEnd(); 289 290 if ((tz == null) && (tzid != null)) { 291 tz = getTimeZone(tzid); 292 293 //if (debug) { 294 // trace("--------Got timezone " + tz); 295 //} 296 297 if (tz == null) { 298 throw new CalFacadeBadDateException(); 299 boolean tzchanged = false; 300 301 if (tz == null) { 302 if (tzid == null) { 303 if ((lasttzid != null) || (lasttz == null)) { 304 lasttz = TimeZone.getDefault(); 305 tzchanged = true; 306 } 307 } else { 308 if ((lasttzid == null) || (!lasttzid.equals(tzid))) { 309 lasttz = getTimeZone(tzid); 310 if (lasttz == null) { 311 lasttzid = null; 312 throw new CalFacadeBadDateException(); 313 } 314 tzchanged = true; 315 } 299 316 } 300 301 dte.getParameters().add(new TzId(tzid)); 302 dte.setTimeZone(tz); 317 } else { 318 // tz supplied 319 if (tz != lasttz) { 320 /* Yes, that's a !=. I'm looking for it being the same object. 321 * If I were sure that equals were correct and fast I'd use 322 * that. 323 */ 324 tzchanged = true; 325 tzid = tz.getID(); 326 lasttz = tz; 327 } 303 328 } 304 329 305 dte.setValue(time); 306 dte.setUtc(true); 307 308 return dte.getValue(); 330 331 if (tzchanged) { 332 if (debug) { 333 trace("**********tzchanged"); 334 } 335 formatTd.setTimeZone(lasttz); 336 lasttzid = tzid; 337 } 338 339 cal.setTimeZone(utctz); 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(); 309 352 } catch (Throwable t) { 310 353 t.printStackTrace(); … … 323 366 * Private methods 324 367 * ==================================================================== */ 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 } 325 392 326 393 private TimezoneInfo lookup(String id) throws CalFacadeException { trunk/calendar3/webcommon/src/org/bedework/webcommon/BwSvciFilter.java
r2 r96 68 68 import org.apache.log4j.Logger; 69 69 70 /** This class must be installed as a filter for a UWCalweb application.70 /** This class must be installed as a filter for a Bedework web application. 71 71 * 72 72 * <p>We assume that any CalSvci object must remain open until after the jsp
