1   /*
2    * This file is part of Domingo
3    * an Open Source Java-API to Lotus Notes/Domino
4    * hosted at http://domingo.sourceforge.net
5    *
6    * Copyright (c) 2003-2007 Beck et al. projects GmbH München (http://www.bea.de)
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21   */
22  package de.bea.domingo.samples.groupware;
23  
24  import java.util.Calendar;
25  import java.util.Iterator;
26  
27  import de.bea.domingo.groupware.CalendarEntry;
28  import de.bea.domingo.groupware.CalendarInterface;
29  import de.bea.domingo.groupware.Email;
30  import de.bea.domingo.groupware.EmailDigest;
31  import de.bea.domingo.groupware.Groupware;
32  import de.bea.domingo.groupware.GroupwareException;
33  import de.bea.domingo.groupware.Mailbox;
34  import de.bea.domingo.monitor.ConsoleMonitor;
35  
36  
37  /***
38   * A simple example about how to use the groupware package of domingo.
39   *
40   * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
41   */
42  public class GroupwareSample {
43  
44      private static final int MAX_MAILS = 10;
45  
46      /***
47       * The main method.
48       *
49       * @param args arguments
50       */
51      public static void main(final String[] args) {
52          GroupwareSample sample = new GroupwareSample();
53          try {
54              sample.run();
55          } catch (GroupwareException e) {
56              e.printStackTrace();
57          }
58      }
59  
60      private void run() throws GroupwareException {
61  
62          //initialize the groupware package
63          ConsoleMonitor monitor = new ConsoleMonitor();
64          monitor.setLevel(ConsoleMonitor.DEBUG);
65          Groupware groupware = new Groupware("notes:///local!!mail/kriede2.nsf", monitor);
66          Mailbox mailbox = groupware.getMailbox();
67          CalendarInterface calendar = groupware.getCalendar();
68  
69          // Read the last ten mails from the inbox
70          Iterator inbox = mailbox.getInbox();
71          int i = 0;
72          while (inbox.hasNext() && i++ < MAX_MAILS) {
73              EmailDigest emailDigest = (EmailDigest) inbox.next();
74              System.out.println(emailDigest.toString());
75          }
76  
77          // create and send an email
78          Email email = new Email();
79          email.setSubject("Test");
80          email.setRecipient("kurt.riede@bea.de");
81          email.setBody("Hello world!");
82          mailbox.send(email);
83          System.out.println("Email sent");
84  
85          // create a new calendar entry
86          CalendarEntry entry = new CalendarEntry();
87          entry.setTitle("New Years Party");
88          entry.setStartDate(2006, Calendar.DECEMBER, 31);
89          entry.setStartTime(20, 0, 0);
90          entry.setEndDate(2007, Calendar.JANUARY, 1);
91          entry.setEndTime(5, 0, 0);
92          calendar.save(entry);
93          System.out.println("Appointment created");
94      }
95  }