⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 event.java

📁 The program is used for the calculations of the day , week , month on the calendar .
💻 JAVA
字号:
package us.k5n.ical;import java.util.Vector;/**  * iCal Event class that corresponds to the VEVENT iCalendar  * object.  * @version $Id$  * @author Craig Knudsen, craig@k5n.us  */public class Event  implements Constants{  // TODO: handle multiple instances of summary/description since  // there can be more than one if LANGUAGE attribute is specified  /** Unique Id */  public Uid uid = null;  /** Sequence number (0 is first version) */  public Sequence sequence = null;  /** Brief summary */  public Summary summary = null;  /** Full description */  public Description description = null;  /** List of categories (comma-separated) */  public Categories categories = null;  /** Primary start date */  public Date startDate = null;  /** End date */  public Date endDate = null; // may be derived from duration if not specified  /** Time created */  public Date dtstamp = null;  /** Time last modified */  public Date lastModified = null;  /** Event duration (in seconds) */  public Duration duration;  /** Contact for the event */  //public Individual contact;  /** Participants for the event (Vector of Attendee) */  public Vector attendees = null;  /** Recurrence rule (RRULE) */  public Rrule rrule = null;  // TODO: multiple summaries, descriptions with different LANGUAGE values  // TODO: alarms/triggers  // TODO: RDATE - recurrance dates  // TODO: EXDATE - exception dates  // TODO: EXRULE - exception rule  // TODO: URL  // TODO: RELATED-TO  /**    * Create an Event object based on the specified iCal data    * @param parser	The IcalParser object    * @param initialLine	The starting line number    * @Param textLines	Vector of iCal text lines    */  public Event ( IcalParser parser, int initialLine, Vector textLines )  {    for ( int i = 0; i < textLines.size(); i++ ) {      String line = (String) textLines.elementAt ( i );      try {        parseLine ( line, parser.getParseMethod() );      } catch ( BogusDataException bde ) {        parser.reportParseError ( new ParseError ( initialLine + i,          bde.error, line ) );      } catch ( ParseException pe ) {        parser.reportParseError ( new ParseError ( initialLine + i,          pe.error, line ) );      }    }    // must have UID    if ( uid == null )      uid = new Uid ();    // create a sequence if not specified    if ( sequence == null )      sequence = new Sequence ( 0 );  }  /**    * Create an event that is timeless (no duration)    * @param summary	Brief summary of event    * @param description	Full description of the event    * @param startDate		The date of the event in ISO 8601 format    *				(19991231, 199912310T115900, etc.)    */  public Event ( String summary, String description,    Date startDate )  {    this ( summary, description, startDate, 0 );  }  /**    * Create an event with the specified duration    * @param summary	Brief summary of event    * @param description	Full description of the event    * @param startDate		The date of the event in ISO 8601 format    *				(19991231, 199912310T115900, etc.)    * @param duration		The event duration in seconds    */  public Event ( String summary, String description,    Date startDate, int duration )  {    uid = new Uid (); // Generate unique Id    this.summary = new Summary ();    this.summary.value = summary;    this.description = new Description ();    this.description.value = description;    this.duration = new Duration ( duration );    // TODO: calculate endDate from duration  }  /**    * Was enough information parsed for this Event to be valid?    */  public boolean isValid ()  {    // Must have at least a start date and a summary    //return ( startDate != null && summary != null );    return true;  }  /**    * Parse a line of iCal test.    * @param line       The line of text    * @param parseMethod	PARSE_STRICT or PARSE_LOOSE    */  public void parseLine ( String icalStr, int parseMethod )    throws ParseException, BogusDataException  {    String up = icalStr.toUpperCase();    if ( up.equals ( "BEGIN:VEVENT" ) || up.equals ( "END:VEVENT" ) ) {      // ignore    } else if ( up.trim().length() == 0 ) {      // ignore empty lines    } else if ( up.startsWith ( "DESCRIPTION" ) ) {      description = new Description ( icalStr );    } else if ( up.startsWith ( "SUMMARY" ) ) {      summary = new Summary ( icalStr );    } else if ( up.startsWith ( "DTSTART" ) ) {      startDate = new Date ( icalStr );    } else if ( up.startsWith ( "DTEND" ) ) {      endDate = new Date ( icalStr );    } else if ( up.startsWith ( "DTSTAMP" ) ) {      dtstamp = new Date ( icalStr );    } else if ( up.startsWith ( "LAST-MODIFIED" ) ) {      lastModified = new Date ( icalStr );    } else if ( up.startsWith ( "CATEGORIES" ) ) {      categories = new Categories ( icalStr );    } else if ( up.startsWith ( "UID" ) ) {      uid = new Uid ( icalStr );    } else if ( up.startsWith ( "SEQUENCE" ) ) {      sequence = new Sequence ( icalStr );    } else if ( up.startsWith ( "RRULE" ) ) {      rrule = new Rrule ( icalStr, parseMethod );    } else {System.out.println ( "Ignoring: " + icalStr );    }  }  /**    * Get the event summary    */  public Summary getSummary ()  {    return getSummary ( "EN" );  }  /**    * Get the event summary for the specified language.    * If not available, then the primary summary will be returned.    * @param langage	The language ("EN", "FR", etc.)    */  public Summary getSummary ( String language )  {    // TODO: handle language param    return summary;  }    /**    * Convert this Event into iCal text    */  public String toIcal ()  {    StringBuffer ret = new StringBuffer ( 128 );    ret.append ( "BEGIN:VEVENT" );    ret.append ( CRLF );    if ( uid != null )      ret.append ( uid.toIcal () );    if ( sequence != null )      ret.append ( sequence.toIcal () );    if ( summary != null )      ret.append ( summary.toIcal () );    if ( description != null )      ret.append ( description.toIcal () );    if ( startDate != null )      ret.append ( startDate.toIcal () );    if ( endDate != null )      ret.append ( endDate.toIcal () );    if ( dtstamp != null )      ret.append ( dtstamp.toIcal () );    if ( lastModified != null )      ret.append ( lastModified.toIcal () );     ret.append ( "END:VEVENT" );    ret.append ( CRLF );    return ret.toString ();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -