1 9 10 package org.jical; 11 12 18 19 import java.text.SimpleDateFormat ; 20 import java.util.Calendar ; 21 import java.util.Date ; 22 23 32 33 public class RepeatRules { 34 35 private String id; 36 37 48 49 public String getId() 50 { 51 return this.id; 52 } 53 54 public void setId(String id) 55 { 56 this.id = id; 57 } 58 59 private String uid; 60 61 71 72 public String getUid() 73 { 74 return uid; 75 } 76 77 public void setUid(String uid) 78 { 79 this.uid = uid; 80 } 81 82 int interval = 0; 83 84 94 95 public int getInterval() 96 { 97 return interval; 98 } 99 100 public void setInterval(int interval) 101 { 102 this.interval = interval; 103 } 104 105 int dateRepeatUnit = Calendar.DATE; 106 107 117 118 public int getDateRepeatUnit() 119 { 120 return dateRepeatUnit; 121 } 122 123 public void setDateRepeatUnit(int dateRepeatUnit) 124 { 125 this.dateRepeatUnit = dateRepeatUnit; 126 } 127 128 String frequency = null; 129 130 140 141 public String getFrequency() 142 { 143 return frequency; 144 } 145 146 public void setFrequency(String frequency) 147 { 148 this.frequency = frequency; 149 } 150 151 String repeatUntil = null; 152 153 163 164 public String getRepeatUntil() 165 { 166 return repeatUntil; 167 } 168 169 public void setRepeatUntil(String repeatUntil) 170 { 171 this.repeatUntil = repeatUntil; 172 } 173 174 String repeatByDay = null; 175 176 186 187 public String getRepeatByDay() 188 { 189 return repeatByDay; 190 } 191 192 public void setRepeatByDay(String repeatByDay) 193 { 194 this.repeatByDay = repeatByDay; 195 } 196 197 String repeatByMonth = null; 198 199 209 210 public String getRepeatByMonth() 211 { 212 return repeatByMonth; 213 } 214 215 public void setRepeatByMonth(String repeatByMonth) 216 { 217 this.repeatByMonth = repeatByMonth; 218 } 219 220 String repeatBySecond = null; 221 222 232 233 public String getRepeatBySecond() 234 { 235 return repeatBySecond; 236 } 237 238 public void setRepeatBySecond(String repeatBySecond) 239 { 240 this.repeatBySecond = repeatBySecond; 241 } 242 243 String repeatByMinute = null; 244 245 255 256 public String getRepeatByMinute() 257 { 258 return repeatByMinute; 259 } 260 261 public void setRepeatByMinute(String repeatByMinute) 262 { 263 this.repeatByMinute = repeatByMinute; 264 } 265 266 String repeatByHour = null; 267 268 278 279 public String getRepeatByHour() 280 { 281 return repeatByHour; 282 } 283 284 public void setRepeatByHour(String repeatByHour) 285 { 286 this.repeatByHour = repeatByHour; 287 } 288 289 String repeatByMonthDay = null; 290 291 301 302 public String getRepeatByMonthDay() 303 { 304 return repeatByMonthDay; 305 } 306 307 public void setRepeatByMonthDay(String repeatByMonthDay) 308 { 309 this.repeatByMonthDay = repeatByMonthDay; 310 } 311 312 String repeatByYearDay = null; 313 314 324 325 public String getRepeatByYearDay() 326 { 327 return repeatByYearDay; 328 } 329 330 public void setRepeatByYearDay(String repeatByYearDay) 331 { 332 this.repeatByYearDay = repeatByYearDay; 333 } 334 335 String repeatByWeekNo = null; 336 337 347 348 public String getRepeatByWeekNo() 349 { 350 return repeatByWeekNo; 351 } 352 353 public void setRepeatByWeekNo(String repeatByWeekNo) 354 { 355 this.repeatByWeekNo = repeatByWeekNo; 356 } 357 358 Integer repeatBySetPos = null; 360 361 371 372 public Integer getRepeatBySetPos() 373 { 374 return repeatBySetPos; 375 } 376 377 public void setRepeatBySetPos(Integer repeatBySetPos) 378 { 379 this.repeatBySetPos = repeatBySetPos; 380 } 381 382 int repeatUntilCount = 99999999; 383 384 394 395 public int getRepeatUntilCount() 396 { 397 return repeatUntilCount; 398 } 399 400 public void setRepeatUntilCount(int repeatUntilCount) 401 { 402 this.repeatUntilCount = repeatUntilCount; 403 } 404 405 Date repeatUntilDate = null; 406 407 417 418 public Date getRepeatUntilDate() 419 { 420 return repeatUntilDate; 421 } 422 423 public void setRepeatUntilDate(Date repeatUntilDate) 424 { 425 this.repeatUntilDate = repeatUntilDate; 426 } 427 428 429 private SimpleDateFormat dateFormatter = new SimpleDateFormat ("yyyyMMddHHmmss"); 430 431 public RepeatRules() { 432 } 433 434 public void parseRepeatRules (String rRule) 435 { 436 int startPoint = -1; 437 int ii = 0; 438 while (rRule != null && ii < 10) 439 { 440 ii++; 441 String thisRule = null; 442 startPoint = rRule.indexOf(";"); 443 if (startPoint != -1) 444 { 445 thisRule = rRule.substring(0,startPoint); 446 rRule = rRule.substring(startPoint + 1); 447 } 448 else 449 { 450 thisRule = rRule; 451 rRule = null; 452 } 453 if (thisRule.startsWith("X-EVOLUTION-ENDDATE=")) 456 { 457 startPoint = thisRule.indexOf(":"); 458 String newRule = thisRule.substring(0,startPoint); 459 String evoEndDate = newRule.substring(20); 460 thisRule = thisRule.substring(startPoint +1); 461 } 462 463 if (thisRule.startsWith("FREQ=")) 464 { 465 frequency = thisRule.substring(5); 466 } 467 else if (thisRule.startsWith("INTERVAL=")) 468 { 469 try{ 470 Long Lint = (new Long (thisRule.substring(9))); 471 interval = Lint.intValue(); 472 } 473 catch (Exception e){ 474 System.err.println("INTERVAL Parse Error on " + thisRule + e); 475 } 476 } 477 else if (thisRule.startsWith("UNTIL=")) 478 { 479 repeatUntil = thisRule; 480 if (repeatUntil != null) { 481 repeatUntil = repeatUntil.substring(6); 482 if (repeatUntil.length() == 8) { 485 repeatUntil = repeatUntil + "235959"; 486 } 487 try 488 { 489 if (repeatUntil.charAt(8) == 'T') 490 { 491 repeatUntil = repeatUntil.substring(0,8) + repeatUntil.substring(9); 492 } 493 497 if ((dateRepeatUnit != Calendar.HOUR) && 498 (dateRepeatUnit != Calendar.MINUTE) && 499 (dateRepeatUnit != Calendar.SECOND)) 500 { 501 if (repeatUntil.substring(8).equals("000000")) { 502 repeatUntil = repeatUntil.substring(0,8) + "235959"; 503 } 504 } 505 repeatUntilDate = dateFormatter.parse(repeatUntil); 506 } 507 catch (Exception e) 508 { 509 System.err.println("Exception getting RepeatUntilDate" +e); 510 System.err.println("Exception for date string" +thisRule); 511 repeatUntilDate = null; 512 } 513 } 514 } 515 else if (thisRule.startsWith("BYDAY=")) 516 { 517 repeatByDay = thisRule.substring(6); 519 } 520 else if (thisRule.startsWith("BYMONTH=")) 521 { 522 repeatByMonth = thisRule.substring(8); 525 } 526 else if (thisRule.startsWith("BYSECOND=")) 527 { 528 repeatBySecond = thisRule.substring(9); 531 } 532 else if (thisRule.startsWith("BYMINUTE=")) 533 { 534 repeatByMinute = thisRule.substring(9); 537 } 538 else if (thisRule.startsWith("BYHOUR=")) 539 { 540 repeatByHour = thisRule.substring(7); 543 } 544 else if (thisRule.startsWith("BYMONTHDAY=")) 545 { 546 repeatByMonthDay = thisRule.substring(11); 549 } 550 else if (thisRule.startsWith("BYYEARDAY=")) 551 { 552 repeatByYearDay = thisRule.substring(10); 555 } 556 else if (thisRule.startsWith("BYWEEKNO=")) 557 { 558 repeatByWeekNo = thisRule.substring(9); 561 } 562 572 else if (thisRule.startsWith("BYSETPOS=")) 573 { 574 repeatBySetPos = new Integer (thisRule.substring(9)); 577 } 578 else if (thisRule.startsWith("COUNT=")) 579 { 580 try{ 582 repeatUntilCount = Integer.parseInt(thisRule.substring(6)); 585 586 } 587 catch(Exception e){ 588 System.err.println("BYSETPOS= Parse Error on " + thisRule + e); 589 } 590 } 591 } 592 593 if (frequency.equalsIgnoreCase("YEARLY")) 595 { 596 dateRepeatUnit = Calendar.YEAR; 597 } else if (frequency.equalsIgnoreCase("MONTHLY")) 598 { 599 dateRepeatUnit = Calendar.MONTH; 600 } else if (frequency.equalsIgnoreCase("WEEKLY")) 601 { 602 dateRepeatUnit = Calendar.DAY_OF_WEEK; 603 } else if (frequency.equalsIgnoreCase("DAILY")) 604 { 605 dateRepeatUnit = Calendar.DATE; 606 } else if (frequency.equalsIgnoreCase("HOURLY")) 607 { 608 dateRepeatUnit = Calendar.HOUR; 609 } else if (frequency.equalsIgnoreCase("MINUTELY")) 610 { 611 dateRepeatUnit = Calendar.MINUTE; 612 } else if (frequency.equalsIgnoreCase("SECONDLY")) 613 { 614 dateRepeatUnit = Calendar.SECOND; 615 } 616 else { 617 System.err.println("RepeatRules =- No Matching rule for frequency " +frequency); 618 } 619 } 620 621 } 622 | Popular Tags |