|
1 /** |
|
2 * Copyright (c) 2012, Ben Fortuna |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions |
|
7 * are met: |
|
8 * |
|
9 * o Redistributions of source code must retain the above copyright |
|
10 * notice, this list of conditions and the following disclaimer. |
|
11 * |
|
12 * o Redistributions in binary form must reproduce the above copyright |
|
13 * notice, this list of conditions and the following disclaimer in the |
|
14 * documentation and/or other materials provided with the distribution. |
|
15 * |
|
16 * o Neither the name of Ben Fortuna nor the names of any other contributors |
|
17 * may be used to endorse or promote products derived from this software |
|
18 * without specific prior written permission. |
|
19 * |
|
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
31 */ |
|
32 package net.fortuna.ical4j.model.property; |
|
33 |
|
34 import java.math.BigDecimal; |
|
35 |
|
36 import org.apache.commons.lang.StringUtils; |
|
37 |
|
38 import net.fortuna.ical4j.model.ParameterList; |
|
39 import net.fortuna.ical4j.model.Property; |
|
40 import net.fortuna.ical4j.model.PropertyFactoryImpl; |
|
41 import net.fortuna.ical4j.model.ValidationException; |
|
42 |
|
43 /** |
|
44 * $Id$ |
|
45 * |
|
46 * Created: [Apr 6, 2004] |
|
47 * |
|
48 * Defines a GEO iCalendar component property. |
|
49 * |
|
50 * <pre> |
|
51 * 4.8.1.6 Geographic Position |
|
52 * |
|
53 * Property Name: GEO |
|
54 * |
|
55 * Purpose: This property specifies information related to the global |
|
56 * position for the activity specified by a calendar component. |
|
57 * |
|
58 * Value Type: FLOAT. The value MUST be two SEMICOLON separated FLOAT |
|
59 * values. |
|
60 * |
|
61 * Property Parameters: Non-standard property parameters can be |
|
62 * specified on this property. |
|
63 * |
|
64 * Conformance: This property can be specified in "VEVENT" or "VTODO" |
|
65 * calendar components. |
|
66 * |
|
67 * Description: The property value specifies latitude and longitude, in |
|
68 * that order (i.e., "LAT LON" ordering). The longitude represents the |
|
69 * location east or west of the prime meridian as a positive or negative |
|
70 * real number, respectively. The longitude and latitude values MAY be |
|
71 * specified up to six decimal places, which will allow for accuracy to |
|
72 * within one meter of geographical position. Receiving applications |
|
73 * MUST accept values of this precision and MAY truncate values of |
|
74 * greater precision. |
|
75 * |
|
76 * Values for latitude and longitude shall be expressed as decimal |
|
77 * fractions of degrees. Whole degrees of latitude shall be represented |
|
78 * by a two-digit decimal number ranging from 0 through 90. Whole |
|
79 * degrees of longitude shall be represented by a decimal number ranging |
|
80 * from 0 through 180. When a decimal fraction of a degree is specified, |
|
81 * it shall be separated from the whole number of degrees by a decimal |
|
82 * point. |
|
83 * |
|
84 * Latitudes north of the equator shall be specified by a plus sign (+), |
|
85 * or by the absence of a minus sign (-), preceding the digits |
|
86 * designating degrees. Latitudes south of the Equator shall be |
|
87 * designated by a minus sign (-) preceding the digits designating |
|
88 * degrees. A point on the Equator shall be assigned to the Northern |
|
89 * Hemisphere. |
|
90 * |
|
91 * Longitudes east of the prime meridian shall be specified by a plus |
|
92 * sign (+), or by the absence of a minus sign (-), preceding the digits |
|
93 * designating degrees. Longitudes west of the meridian shall be |
|
94 * designated by minus sign (-) preceding the digits designating |
|
95 * degrees. A point on the prime meridian shall be assigned to the |
|
96 * Eastern Hemisphere. A point on the 180th meridian shall be assigned |
|
97 * to the Western Hemisphere. One exception to this last convention is |
|
98 * permitted. For the special condition of describing a band of latitude |
|
99 * around the earth, the East Bounding Coordinate data element shall be |
|
100 * assigned the value +180 (180) degrees. |
|
101 * |
|
102 * Any spatial address with a latitude of +90 (90) or -90 degrees will |
|
103 * specify the position at the North or South Pole, respectively. The |
|
104 * component for longitude may have any legal value. |
|
105 * |
|
106 * With the exception of the special condition described above, this |
|
107 * form is specified in Department of Commerce, 1986, Representation of |
|
108 * geographic point locations for information interchange (Federal |
|
109 * Information Processing Standard 70-1): Washington, Department of |
|
110 * Commerce, National Institute of Standards and Technology. |
|
111 * |
|
112 * The simple formula for converting degrees-minutes-seconds into |
|
113 * decimal degrees is: |
|
114 * |
|
115 * decimal = degrees + minutes/60 + seconds/3600. |
|
116 * |
|
117 * Format Definition: The property is defined by the following notation: |
|
118 * |
|
119 * geo = "GEO" geoparam ":" geovalue CRLF |
|
120 * |
|
121 * geoparam = *(";" xparam) |
|
122 * |
|
123 * geovalue = float ";" float |
|
124 * ;Latitude and Longitude components |
|
125 * |
|
126 * Example: The following is an example of this property: |
|
127 * |
|
128 * GEO:37.386013;-122.082932 |
|
129 * </pre> |
|
130 * |
|
131 * @author Ben Fortuna |
|
132 */ |
|
133 public class Geo extends Property { |
|
134 |
|
135 private static final long serialVersionUID = -902100715801867636L; |
|
136 |
|
137 private BigDecimal latitude; |
|
138 |
|
139 private BigDecimal longitude; |
|
140 |
|
141 /** |
|
142 * Default constructor. |
|
143 */ |
|
144 public Geo() { |
|
145 super(GEO, PropertyFactoryImpl.getInstance()); |
|
146 latitude = BigDecimal.valueOf(0); |
|
147 longitude = BigDecimal.valueOf(0); |
|
148 } |
|
149 |
|
150 /** |
|
151 * Creates a new instance by parsing the specified string representation. |
|
152 * @param value a geo value |
|
153 */ |
|
154 public Geo(final String value) { |
|
155 super(GEO, PropertyFactoryImpl.getInstance()); |
|
156 setValue(value); |
|
157 } |
|
158 |
|
159 /** |
|
160 * @param aList a list of parameters for this component |
|
161 * @param aValue a value string for this component |
|
162 */ |
|
163 public Geo(final ParameterList aList, final String aValue) { |
|
164 super(GEO, aList, PropertyFactoryImpl.getInstance()); |
|
165 setValue(aValue); |
|
166 } |
|
167 |
|
168 /** |
|
169 * @param latitude a latitudinal value |
|
170 * @param longitude a longitudinal value |
|
171 */ |
|
172 public Geo(final BigDecimal latitude, final BigDecimal longitude) { |
|
173 super(GEO, PropertyFactoryImpl.getInstance()); |
|
174 this.latitude = latitude; |
|
175 this.longitude = longitude; |
|
176 } |
|
177 |
|
178 /** |
|
179 * @param aList a list of parameters for this component |
|
180 * @param latitude a latitudinal value |
|
181 * @param longitude a longitudinal value |
|
182 */ |
|
183 public Geo(final ParameterList aList, final BigDecimal latitude, |
|
184 final BigDecimal longitude) { |
|
185 super(GEO, aList, PropertyFactoryImpl.getInstance()); |
|
186 this.latitude = latitude; |
|
187 this.longitude = longitude; |
|
188 } |
|
189 |
|
190 /** |
|
191 * @return Returns the latitude. |
|
192 */ |
|
193 public final BigDecimal getLatitude() { |
|
194 return latitude; |
|
195 } |
|
196 |
|
197 /** |
|
198 * @return Returns the longitude. |
|
199 */ |
|
200 public final BigDecimal getLongitude() { |
|
201 return longitude; |
|
202 } |
|
203 |
|
204 /** |
|
205 * {@inheritDoc} |
|
206 */ |
|
207 public final void setValue(final String aValue) { |
|
208 final String latitudeString = aValue.substring(0, aValue.indexOf(';')); |
|
209 if (StringUtils.isNotBlank(latitudeString)) { |
|
210 latitude = new BigDecimal(latitudeString); |
|
211 } |
|
212 else { |
|
213 latitude = BigDecimal.valueOf(0); |
|
214 } |
|
215 |
|
216 final String longitudeString = aValue.substring(aValue.indexOf(';') + 1); |
|
217 if (StringUtils.isNotBlank(longitudeString)) { |
|
218 longitude = new BigDecimal(longitudeString); |
|
219 } |
|
220 else { |
|
221 longitude = BigDecimal.valueOf(0); |
|
222 } |
|
223 } |
|
224 |
|
225 /** |
|
226 * {@inheritDoc} |
|
227 */ |
|
228 public final String getValue() { |
|
229 return String.valueOf(getLatitude()) + ";" |
|
230 + String.valueOf(getLongitude()); |
|
231 } |
|
232 |
|
233 /** |
|
234 * @param latitude The latitude to set. |
|
235 */ |
|
236 public final void setLatitude(final BigDecimal latitude) { |
|
237 this.latitude = latitude; |
|
238 } |
|
239 |
|
240 /** |
|
241 * @param longitude The longitude to set. |
|
242 */ |
|
243 public final void setLongitude(final BigDecimal longitude) { |
|
244 this.longitude = longitude; |
|
245 } |
|
246 |
|
247 /** |
|
248 * {@inheritDoc} |
|
249 */ |
|
250 public final void validate() throws ValidationException { |
|
251 // TODO: Auto-generated method stub |
|
252 } |
|
253 } |