View Javadoc

1   /*
2    * $Id: RequestStatus.java [Apr 6, 2004]
3    *
4    * Copyright (c) 2004, Ben Fortuna
5    * All rights reserved.
6    *
7    * Redistribution and use in source and binary forms, with or without
8    * modification, are permitted provided that the following conditions
9    * are met:
10   *
11   * 	o Redistributions of source code must retain the above copyright
12   * notice, this list of conditions and the following disclaimer.
13   *
14   * 	o Redistributions in binary form must reproduce the above copyright
15   * notice, this list of conditions and the following disclaimer in the
16   * documentation and/or other materials provided with the distribution.
17   *
18   * 	o Neither the name of Ben Fortuna nor the names of any other contributors
19   * may be used to endorse or promote products derived from this software
20   * without specific prior written permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25   * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
26   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33   */
34  package net.fortuna.ical4j.model.property;
35  
36  import java.util.StringTokenizer;
37  
38  import net.fortuna.ical4j.model.Parameter;
39  import net.fortuna.ical4j.model.ParameterList;
40  import net.fortuna.ical4j.model.Property;
41  import net.fortuna.ical4j.model.ValidationException;
42  import net.fortuna.ical4j.util.ParameterValidator;
43  
44  /***
45   * Defines a REQUEST-STATUS iCalendar component property.
46   *
47   * @author benf
48   */
49  public class RequestStatus extends Property {
50  
51      private static final String PRELIM_SUCCESS = "1";
52  
53      private static final String SUCCESS = "2";
54  
55      private static final String CLIENT_ERROR = "3";
56  
57      private static final String SCHEDULING_ERROR = "4";
58  
59      private String statusCode;
60  
61      private String description;
62  
63      private String exData;
64  
65      /***
66       * @param aList
67       *            a list of parameters for this component
68       * @param aValue
69       *            a value string for this component
70       */
71      public RequestStatus(final ParameterList aList, final String aValue) {
72          super(REQUEST_STATUS, aList);
73  
74          StringTokenizer t = new StringTokenizer(aValue, ";");
75  
76          if (t.hasMoreTokens()) {
77              statusCode = t.nextToken();
78          }
79  
80          if (t.hasMoreTokens()) {
81              description = t.nextToken();
82          }
83  
84          if (t.hasMoreTokens()) {
85              exData = t.nextToken();
86          }
87      }
88  
89      /***
90       * @param aList
91       *            a list of parameters for this component
92       * @param aStatusCode
93       *            a string representation of a status code
94       * @param aDescription
95       *            a description
96       * @param data
97       *            a string representation of extension data
98       */
99      public RequestStatus(final ParameterList aList, final String aStatusCode,
100             final String aDescription, final String data) {
101         super(REQUEST_STATUS, aList);
102 
103         statusCode = aStatusCode;
104         description = aDescription;
105         exData = data;
106     }
107 
108     /***
109      * @see net.fortuna.ical4j.model.Property#validate()
110      */
111     public final void validate() throws ValidationException {
112 
113         /*
114          * ; the following is optional, ; but MUST NOT occur more than once
115          *
116          * (";" languageparm) /
117          */
118         ParameterValidator.getInstance().validateOneOrLess(Parameter.LANGUAGE,
119                 getParameters());
120 
121         /*
122          * ; the following is optional, ; and MAY occur more than once
123          *
124          * (";" xparam)
125          */
126     }
127 
128     /***
129      * @return Returns the description.
130      */
131     public final String getDescription() {
132         return description;
133     }
134 
135     /***
136      * @return Returns the exData.
137      */
138     public final String getExData() {
139         return exData;
140     }
141 
142     /***
143      * @return Returns the statusCode.
144      */
145     public final String getStatusCode() {
146         return statusCode;
147     }
148 
149     /*
150      * (non-Javadoc)
151      *
152      * @see net.fortuna.ical4j.model.Property#getValue()
153      */
154     public String getValue() {
155         StringBuffer b = new StringBuffer();
156 
157         if ((getStatusCode() != null)) {
158             b.append(getStatusCode());
159             b.append(';');
160         }
161 
162         if ((getDescription() != null)) {
163             b.append(getDescription());
164             b.append(';');
165         }
166 
167         if ((getExData() != null)) {
168             b.append(getExData());
169         }
170 
171         return b.toString();
172     }
173 }