1 package tim.prune.drew.jpeg;
3 import java.util.ArrayList;
7 * Class to hold the GPS data extracted from a Jpeg including position and time
8 * All contents are in Rational format
12 private boolean _exifDataPresent = false;
13 private char _latitudeRef = '\0';
14 private char _longitudeRef = '\0';
15 private byte _altitudeRef = 0;
16 private Rational[] _latitude = null;
17 private Rational[] _longitude = null;
18 private Rational _altitude = null;
19 private Rational[] _gpsTimestamp = null;
20 private Rational[] _gpsDatestamp = null;
21 private String _originalTimestamp = null;
22 private byte[] _thumbnail = null;
23 private ArrayList _errors = null;
27 * Set the exif data present flag
29 public void setExifDataPresent()
31 _exifDataPresent = true;
34 * @return true if exif data found
36 public boolean getExifDataPresent()
38 return _exifDataPresent;
42 * Set the latitude reference (N/S)
43 * @param inChar character representing reference
45 public void setLatitudeRef(char inChar)
47 _latitudeRef = inChar;
51 * Set the latitude reference (N/S)
52 * @param inString string containing reference
54 public void setLatitudeRef(String inString)
56 if (inString != null && inString.length() == 1)
57 setLatitudeRef(inString.charAt(0));
62 * @param inValues array of three Rationals for deg-min-sec
64 public void setLatitude(Rational[] inValues)
66 if (inValues != null && inValues.length == 3)
71 * Set the longitude reference (E/W)
72 * @param inChar character representing reference
74 public void setLongitudeRef(char inChar)
76 _longitudeRef = inChar;
80 * Set the longitude reference (E/W)
81 * @param inString string containing reference
83 public void setLongitudeRef(String inString)
85 if (inString != null && inString.length() == 1)
86 setLongitudeRef(inString.charAt(0));
91 * @param inValues array of three Rationals for deg-min-sec
93 public void setLongitude(Rational[] inValues)
95 if (inValues != null && inValues.length == 3)
96 _longitude = inValues;
100 * Set the altitude reference (sea level / not)
101 * @param inByte byte representing reference
103 public void setAltitudeRef(byte inByte)
105 _altitudeRef = inByte;
110 * @param inRational Rational number representing altitude
112 public void setAltitude(Rational inRational)
114 _altitude = inRational;
118 * Set the Gps timestamp
119 * @param inValues array of Rationals holding timestamp
121 public void setGpsTimestamp(Rational[] inValues)
123 _gpsTimestamp = inValues;
127 * Set the Gps datestamp
128 * @param inValues array of Rationals holding datestamp
130 public void setGpsDatestamp(Rational[] inValues)
132 _gpsDatestamp = inValues;
136 * Set the original timestamp
137 * @param inStamp original timestamp of photo
139 public void setOriginalTimestamp(String inStamp)
141 _originalTimestamp = inStamp;
144 /** @return latitude ref as char */
145 public char getLatitudeRef() { return _latitudeRef; }
146 /** @return latitude as array of 3 Rationals */
147 public Rational[] getLatitude() { return _latitude; }
148 /** @return longitude ref as char */
149 public char getLongitudeRef() { return _longitudeRef; }
150 /** @return longitude as array of 3 Rationals */
151 public Rational[] getLongitude() { return _longitude; }
152 /** @return altitude ref as byte (should be 0) */
153 public byte getAltitudeRef() { return _altitudeRef; }
154 /** @return altitude as Rational */
155 public Rational getAltitude() { return _altitude; }
156 /** @return Gps timestamp as array of 3 Rationals */
157 public Rational[] getGpsTimestamp() { return _gpsTimestamp; }
158 /** @return Gps datestamp as array of 3 Rationals */
159 public Rational[] getGpsDatestamp() { return _gpsDatestamp; }
160 /** @return original timestamp as string */
161 public String getOriginalTimestamp() { return _originalTimestamp; }
165 * @param inBytes byte array containing thumbnail
167 public void setThumbnailImage(byte[] inBytes) {
168 _thumbnail = inBytes;
170 /** @return thumbnail as byte array */
171 public byte[] getThumbnailImage() {
176 * @return true if data looks valid, ie has at least lat and long
177 * (altitude and timestamp optional).
179 public boolean isValid()
181 return (_latitudeRef == 'N' || _latitudeRef == 'n' || _latitudeRef == 'S' || _latitudeRef == 's')
183 && (_longitudeRef == 'E' || _longitudeRef == 'e' || _longitudeRef == 'W' || _longitudeRef == 'w')
184 && _longitude != null;
188 * Add the given error message to the list of errors
189 * @param inError String containing error message
191 public void addError(String inError)
193 if (_errors == null) _errors = new ArrayList();
194 _errors.add(inError);
198 * @return the number of errors, if any
200 public int getNumErrors()
202 if (_errors == null) return 0;
203 return _errors.size();
207 * @return true if errors occurred
209 public boolean hasErrors()
211 return getNumErrors() > 0;
215 * @return all errors as a list
217 public List getErrors()