michael@0: /** michael@0: * Copyright (c) 2012, Ben Fortuna michael@0: * All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * michael@0: * o Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * michael@0: * o Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * michael@0: * o Neither the name of Ben Fortuna nor the names of any other contributors michael@0: * may be used to endorse or promote products derived from this software michael@0: * without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR michael@0: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, michael@0: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR michael@0: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF michael@0: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING michael@0: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS michael@0: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: package net.fortuna.ical4j.model.property; michael@0: michael@0: import java.math.BigDecimal; michael@0: michael@0: import org.apache.commons.lang.StringUtils; michael@0: michael@0: import net.fortuna.ical4j.model.ParameterList; michael@0: import net.fortuna.ical4j.model.Property; michael@0: import net.fortuna.ical4j.model.PropertyFactoryImpl; michael@0: import net.fortuna.ical4j.model.ValidationException; michael@0: michael@0: /** michael@0: * $Id$ michael@0: * michael@0: * Created: [Apr 6, 2004] michael@0: * michael@0: * Defines a GEO iCalendar component property. michael@0: * michael@0: *
michael@0:  *      4.8.1.6 Geographic Position
michael@0:  *      
michael@0:  *         Property Name: GEO
michael@0:  *      
michael@0:  *         Purpose: This property specifies information related to the global
michael@0:  *         position for the activity specified by a calendar component.
michael@0:  *      
michael@0:  *         Value Type: FLOAT. The value MUST be two SEMICOLON separated FLOAT
michael@0:  *         values.
michael@0:  *      
michael@0:  *         Property Parameters: Non-standard property parameters can be
michael@0:  *         specified on this property.
michael@0:  *      
michael@0:  *         Conformance: This property can be specified in  "VEVENT" or "VTODO"
michael@0:  *         calendar components.
michael@0:  *      
michael@0:  *         Description: The property value specifies latitude and longitude, in
michael@0:  *         that order (i.e., "LAT LON" ordering). The longitude represents the
michael@0:  *         location east or west of the prime meridian as a positive or negative
michael@0:  *         real number, respectively. The longitude and latitude values MAY be
michael@0:  *         specified up to six decimal places, which will allow for accuracy to
michael@0:  *         within one meter of geographical position. Receiving applications
michael@0:  *         MUST accept values of this precision and MAY truncate values of
michael@0:  *         greater precision.
michael@0:  *      
michael@0:  *         Values for latitude and longitude shall be expressed as decimal
michael@0:  *         fractions of degrees. Whole degrees of latitude shall be represented
michael@0:  *         by a two-digit decimal number ranging from 0 through 90. Whole
michael@0:  *         degrees of longitude shall be represented by a decimal number ranging
michael@0:  *         from 0 through 180. When a decimal fraction of a degree is specified,
michael@0:  *         it shall be separated from the whole number of degrees by a decimal
michael@0:  *         point.
michael@0:  *      
michael@0:  *         Latitudes north of the equator shall be specified by a plus sign (+),
michael@0:  *         or by the absence of a minus sign (-), preceding the digits
michael@0:  *         designating degrees. Latitudes south of the Equator shall be
michael@0:  *         designated by a minus sign (-) preceding the digits designating
michael@0:  *         degrees. A point on the Equator shall be assigned to the Northern
michael@0:  *         Hemisphere.
michael@0:  *      
michael@0:  *         Longitudes east of the prime meridian shall be specified by a plus
michael@0:  *         sign (+), or by the absence of a minus sign (-), preceding the digits
michael@0:  *         designating degrees. Longitudes west of the meridian shall be
michael@0:  *         designated by minus sign (-) preceding the digits designating
michael@0:  *         degrees. A point on the prime meridian shall be assigned to the
michael@0:  *         Eastern Hemisphere. A point on the 180th meridian shall be assigned
michael@0:  *         to the Western Hemisphere. One exception to this last convention is
michael@0:  *         permitted. For the special condition of describing a band of latitude
michael@0:  *         around the earth, the East Bounding Coordinate data element shall be
michael@0:  *         assigned the value +180 (180) degrees.
michael@0:  *      
michael@0:  *         Any spatial address with a latitude of +90 (90) or -90 degrees will
michael@0:  *         specify the position at the North or South Pole, respectively. The
michael@0:  *         component for longitude may have any legal value.
michael@0:  *      
michael@0:  *         With the exception of the special condition described above, this
michael@0:  *         form is specified in Department of Commerce, 1986, Representation of
michael@0:  *         geographic point locations for information interchange (Federal
michael@0:  *         Information Processing Standard 70-1):  Washington,  Department of
michael@0:  *         Commerce, National Institute of Standards and Technology.
michael@0:  *      
michael@0:  *         The simple formula for converting degrees-minutes-seconds into
michael@0:  *         decimal degrees is:
michael@0:  *      
michael@0:  *           decimal = degrees + minutes/60 + seconds/3600.
michael@0:  *      
michael@0:  *         Format Definition: The property is defined by the following notation:
michael@0:  *      
michael@0:  *           geo        = "GEO" geoparam ":" geovalue CRLF
michael@0:  *      
michael@0:  *           geoparam   = *(";" xparam)
michael@0:  *      
michael@0:  *           geovalue   = float ";" float
michael@0:  *           ;Latitude and Longitude components
michael@0:  *      
michael@0:  *         Example: The following is an example of this property:
michael@0:  *      
michael@0:  *           GEO:37.386013;-122.082932
michael@0:  * 
michael@0: * michael@0: * @author Ben Fortuna michael@0: */ michael@0: public class Geo extends Property { michael@0: michael@0: private static final long serialVersionUID = -902100715801867636L; michael@0: michael@0: private BigDecimal latitude; michael@0: michael@0: private BigDecimal longitude; michael@0: michael@0: /** michael@0: * Default constructor. michael@0: */ michael@0: public Geo() { michael@0: super(GEO, PropertyFactoryImpl.getInstance()); michael@0: latitude = BigDecimal.valueOf(0); michael@0: longitude = BigDecimal.valueOf(0); michael@0: } michael@0: michael@0: /** michael@0: * Creates a new instance by parsing the specified string representation. michael@0: * @param value a geo value michael@0: */ michael@0: public Geo(final String value) { michael@0: super(GEO, PropertyFactoryImpl.getInstance()); michael@0: setValue(value); michael@0: } michael@0: michael@0: /** michael@0: * @param aList a list of parameters for this component michael@0: * @param aValue a value string for this component michael@0: */ michael@0: public Geo(final ParameterList aList, final String aValue) { michael@0: super(GEO, aList, PropertyFactoryImpl.getInstance()); michael@0: setValue(aValue); michael@0: } michael@0: michael@0: /** michael@0: * @param latitude a latitudinal value michael@0: * @param longitude a longitudinal value michael@0: */ michael@0: public Geo(final BigDecimal latitude, final BigDecimal longitude) { michael@0: super(GEO, PropertyFactoryImpl.getInstance()); michael@0: this.latitude = latitude; michael@0: this.longitude = longitude; michael@0: } michael@0: michael@0: /** michael@0: * @param aList a list of parameters for this component michael@0: * @param latitude a latitudinal value michael@0: * @param longitude a longitudinal value michael@0: */ michael@0: public Geo(final ParameterList aList, final BigDecimal latitude, michael@0: final BigDecimal longitude) { michael@0: super(GEO, aList, PropertyFactoryImpl.getInstance()); michael@0: this.latitude = latitude; michael@0: this.longitude = longitude; michael@0: } michael@0: michael@0: /** michael@0: * @return Returns the latitude. michael@0: */ michael@0: public final BigDecimal getLatitude() { michael@0: return latitude; michael@0: } michael@0: michael@0: /** michael@0: * @return Returns the longitude. michael@0: */ michael@0: public final BigDecimal getLongitude() { michael@0: return longitude; michael@0: } michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: public final void setValue(final String aValue) { michael@0: final String latitudeString = aValue.substring(0, aValue.indexOf(';')); michael@0: if (StringUtils.isNotBlank(latitudeString)) { michael@0: latitude = new BigDecimal(latitudeString); michael@0: } michael@0: else { michael@0: latitude = BigDecimal.valueOf(0); michael@0: } michael@0: michael@0: final String longitudeString = aValue.substring(aValue.indexOf(';') + 1); michael@0: if (StringUtils.isNotBlank(longitudeString)) { michael@0: longitude = new BigDecimal(longitudeString); michael@0: } michael@0: else { michael@0: longitude = BigDecimal.valueOf(0); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: public final String getValue() { michael@0: return String.valueOf(getLatitude()) + ";" michael@0: + String.valueOf(getLongitude()); michael@0: } michael@0: michael@0: /** michael@0: * @param latitude The latitude to set. michael@0: */ michael@0: public final void setLatitude(final BigDecimal latitude) { michael@0: this.latitude = latitude; michael@0: } michael@0: michael@0: /** michael@0: * @param longitude The longitude to set. michael@0: */ michael@0: public final void setLongitude(final BigDecimal longitude) { michael@0: this.longitude = longitude; michael@0: } michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: public final void validate() throws ValidationException { michael@0: // TODO: Auto-generated method stub michael@0: } michael@0: }