001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/calendar/tags/sakai_2-4-1/calendar-impl/impl/src/java/org/sakaiproject/calendar/impl/WeeklyRecurrenceRule.java $
003: * $Id: WeeklyRecurrenceRule.java 8050 2006-04-20 17:39:55Z ggolden@umich.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.calendar.impl;
021:
022: import java.util.GregorianCalendar;
023: import java.util.Stack;
024:
025: import org.sakaiproject.time.api.Time;
026: import org.w3c.dom.Document;
027: import org.w3c.dom.Element;
028:
029: /**
030: * <p>WeeklyRecurrenceRule is a time range generating rule that is based on a weekly recurrence.</p>
031: * <p>The recurrences happen on the same day-of-week, at the same time as the prototype.</p>
032: * <p>TODO: support changing the day-of-week of recurrences -ggolden</p>
033: */
034: public class WeeklyRecurrenceRule extends RecurrenceRuleBase {
035: /** The unique type / short frequency description. */
036: protected final static String FREQ = "week";
037:
038: /**
039: * Construct.
040: */
041: public WeeklyRecurrenceRule() {
042: super ();
043: } // WeeklyRecurrenceRule
044:
045: /**
046: * Construct with no limits.
047: * @param interval Every this many number of weeks: 1 would be weekly.
048: */
049: public WeeklyRecurrenceRule(int interval) {
050: super (interval);
051: } // WeeklyRecurrenceRule
052:
053: /**
054: * Construct with count limit.
055: * @param interval Every this many number of weeks: 1 would be weekly.
056: * @param count For this many occurrences - if 0, does not limit.
057: */
058: public WeeklyRecurrenceRule(int interval, int count) {
059: super (interval, count);
060: } // WeeklyRecurrenceRule
061:
062: /**
063: * Construct with time limit.
064: * @param interval Every this many number of weeks: 1 would be weekly.
065: * @param until No time ranges past this time are generated - if null, does not limit.
066: */
067: public WeeklyRecurrenceRule(int interval, Time until) {
068: super (interval, until);
069: } // WeeklyRecurrenceRule
070:
071: /**
072: * Serialize the resource into XML, adding an element to the doc under the top of the stack element.
073: * @param doc The DOM doc to contain the XML (or null for a string return).
074: * @param stack The DOM elements, the top of which is the containing element of the new "resource" element.
075: * @return The newly added element.
076: */
077: public Element toXml(Document doc, Stack stack) {
078: // add the "rule" element to the stack'ed element
079: Element rule = doc.createElement("rule");
080: ((Element) stack.peek()).appendChild(rule);
081:
082: // set the class name - old style for CHEF 1.2.10 compatibility
083: rule.setAttribute("class",
084: "org.chefproject.osid.calendar.WeeklyRecurrenceRule");
085:
086: // set the rule class name w/o package, for modern usage
087: rule.setAttribute("name", "WeeklyRecurrenceRule");
088:
089: // Do the base class part.
090: setBaseClassXML(rule);
091:
092: return rule;
093:
094: } // toXml
095:
096: /* (non-Javadoc)
097: * @see org.chefproject.service.calendar.RecurrenceRuleBase#getRecurrenceType()
098: */
099: protected int getRecurrenceType() {
100: return GregorianCalendar.WEEK_OF_MONTH;
101: }
102:
103: /**
104: * {@inheritDoc}
105: */
106: public String getFrequencyDescription() {
107: return FREQ;
108: }
109:
110: } // WeeklyRecurrenceRule
|