/* validate the syntax of the specified list of multiple email addresses */ public static boolean validateAddresses(String addrs, boolean acceptSMS) { if (StringTools.isBlank(addrs)) { // blank is ok in this case return true; } else if (acceptSMS) { // allow "sms:123456789" format String addrArry[] = StringTools.parseStringArray(addrs, ','); if (addrArry.length == 0) { return false; } for (int i = 0; i < addrArry.length; i++) { String em = addrArry[i].trim(); if (StringTools.isBlank(em)) { // individual addresses not allowed return false; } else if (SMSOutboundGateway.StartsWithSMS(em)) { // TODO: for now, accept as-is } else if (!validateAddress(em)) { return false; } } return true; } else { // true email addresses only try { return SendMail.validateAddresses(addrs); } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException // this will fail if JavaMail support for SendMail is not available. Print.logError("*** SendMail error: " + t); return false; } } }
/* return the DBSelect statement for the specified account/group */ protected static DBSelect _getUserListSelect(String acctId, String groupId) { /* empty/null account */ if (StringTools.isBlank(acctId)) { return null; } /* empty/null user */ if (StringTools.isBlank(groupId)) { return null; } /* get select */ // DBSelect: SELECT * FROM GroupList WHERE ((accountID='acct') and (groupID='group')) ORDER BY // userID DBSelect<GroupList> dsel = new DBSelect<GroupList>(GroupList.getFactory()); dsel.setSelectedFields(GroupList.FLD_userID); DBWhere dwh = dsel.createDBWhere(); dsel.setWhere( dwh.WHERE_( dwh.AND( dwh.EQ(GroupList.FLD_accountID, acctId), dwh.EQ(GroupList.FLD_groupID, groupId)))); dsel.setOrderByFields(GroupList.FLD_userID); return dsel; }
/* return status codes for account/device */ public static int[] getStatusCodes(String accountID, String deviceID) throws DBException { /* account-id specified? */ if (StringTools.isBlank(accountID)) { return new int[0]; } /* device-id specified? */ if (StringTools.isBlank(deviceID)) { deviceID = ALL_DEVICES; } /* select */ // DBSelect: SELECT statucCode FROM StatusCode WHERE (accountID='acct') AND (deviceID='*') ORDER // BY statucCode DBSelect<StatusCode> dsel = new DBSelect<StatusCode>(StatusCode.getFactory()); dsel.setSelectedFields(StatusCode.FLD_statusCode); DBWhere dwh = dsel.createDBWhere(); dsel.setWhere( dwh.WHERE_( dwh.AND( dwh.EQ(StatusCode.FLD_accountID, accountID), dwh.EQ(StatusCode.FLD_deviceID, deviceID)))); dsel.setOrderByFields(StatusCode.FLD_statusCode); /* get list */ java.util.List<Integer> codeList = new Vector<Integer>(); Statement stmt = null; ResultSet rs = null; try { stmt = DBConnection.getDefaultConnection().execute(dsel.toString()); rs = stmt.getResultSet(); while (rs.next()) { int code = rs.getInt(StatusCode.FLD_statusCode); codeList.add(new Integer(code)); } } catch (SQLException sqe) { throw new DBException("Getting StatusCode List", sqe); } finally { if (rs != null) { try { rs.close(); } catch (Throwable t) { } } if (stmt != null) { try { stmt.close(); } catch (Throwable t) { } } } /* return array of status codes */ int codeListInt[] = new int[codeList.size()]; for (int i = 0; i < codeListInt.length; i++) { codeListInt[i] = codeList.get(i).intValue(); } return codeListInt; }
public static String XmlFilter(boolean isSoapReq, String value) { if ((value == null) || value.equals("")) { // do not use StringTools.isBlank (spaces are significant) return ""; } else if (StringTools.isAlphaNumeric(value, XML_CHARS)) { return value; // return all significant spaces } else { String v = StringTools.replace(value, "\n", "\\n"); return XMLTools.CDATA(isSoapReq, v); } }
/* return StatusCode */ public static StatusCode findStatusCode(String accountID, String deviceID, int statusCode) { /* check account status codes */ if (!StringTools.isBlank(accountID)) { // first, try account/device if (!StringTools.isBlank(deviceID)) { try { StatusCode.Key codeKey = new StatusCode.Key(accountID, deviceID, statusCode); if (codeKey.exists()) { // may throw DBException StatusCode code = codeKey.getDBRecord(true); if (code != null) { // should not be null return code; } } } catch (DBException dbe) { // ignore error } } // next, try just the account try { StatusCode.Key codeKey = new StatusCode.Key(accountID, statusCode); if (codeKey.exists()) { // may throw DBException StatusCode code = codeKey.getDBRecord(true); if (code != null) { // should not be null return code; } } } catch (DBException dbe) { // ignore error } } /* check global status codes */ String sysAdmin = AccountRecord.getSystemAdminAccountID(); if (!StringTools.isBlank(sysAdmin)) { try { StatusCode.Key codeKey = new StatusCode.Key(sysAdmin, statusCode); if (codeKey.exists()) { // may throw DBException StatusCode code = codeKey.getDBRecord(true); if (code != null) { // should not be null return code; } } } catch (DBException dbe) { // ignore error } } /* icon selector not found */ return null; }
/* return list of all Devices within the specified DeviceGroup (NOT SCALABLE BEYOND A FEW HUNDRED GROUPS) */ public static java.util.List<String> getUsersForGroup(String acctId, String groupId) throws DBException { /* valid account/groupId? */ if (StringTools.isBlank(acctId)) { return null; } else if (StringTools.isBlank(groupId)) { return null; } /* get db selector */ DBSelect dsel = GroupList._getUserListSelect(acctId, groupId); if (dsel == null) { return null; } /* read users for group */ java.util.List<String> usrList = new Vector<String>(); DBConnection dbc = null; Statement stmt = null; ResultSet rs = null; try { dbc = DBConnection.getDefaultConnection(); stmt = dbc.execute(dsel.toString()); rs = stmt.getResultSet(); while (rs.next()) { String usrId = rs.getString(GroupList.FLD_userID); usrList.add(usrId); } } catch (SQLException sqe) { throw new DBException("Get Group GroupeList", sqe); } finally { if (rs != null) { try { rs.close(); } catch (Throwable t) { } } if (stmt != null) { try { stmt.close(); } catch (Throwable t) { } } DBConnection.release(dbc); } /* return list */ return usrList; }
public String toString() { StringBuffer sb = new StringBuffer(); /* standard event fields */ int sc = this.getStatusCode(); sb.append("Event values:\n"); sb.append(" DeviceID : " + this.getAccountID() + "/" + this.getDeviceID() + "\n"); sb.append(" UniqueID : " + this.getUniqueID() + "\n"); sb.append( " Fixtime : " + this.getTimestamp() + " [" + new DateTime(this.getTimestamp()) + "]\n"); sb.append( " StatusCode: [" + StatusCodes.GetHex(sc) + "] " + StatusCodes.GetDescription(sc, null)); sb.append(" GPS : " + this.getGeoPoint() + " [age " + this.getGpsAge() + " sec]\n"); sb.append( " SpeedKPH : " + StringTools.format(this.getSpeedKPH(), "0.0") + " [" + this.getHeading() + "]\n"); /* remaining event fields (not already displayed) */ OrderedSet<?> fldn = new OrderedSet<Object>(this.fieldValues.getPropertyKeys()); fldn.remove(EventData.FLD_timestamp); fldn.remove(EventData.FLD_statusCode); fldn.remove(EventData.FLD_latitude); fldn.remove(EventData.FLD_longitude); fldn.remove(EventData.FLD_gpsAge); fldn.remove(EventData.FLD_speedKPH); fldn.remove(EventData.FLD_heading); for (Object k : fldn) { Object v = this.fieldValues.getProperty(k, "?"); sb.append(" "); sb.append(StringTools.leftAlign(k.toString(), 10)).append(": "); sb.append(v.toString()).append("\n"); } /* alternate fields */ if (this.otherValues != null) { for (String k : this.otherValues.keySet()) { String v = StringTools.trim(this.otherValues.get(k)); sb.append(" "); sb.append(StringTools.leftAlign(k, 10)).append(": "); sb.append(v).append("\n"); } } /* return string */ return sb.toString(); }
/* set Role access level */ public static boolean deleteAccessLevel(Role role, String aclId) throws DBException { /* role specified? */ if (role == null) { return false; // quietly ignore } String acctId = role.getAccountID(); String roleId = role.getRoleID(); /* acl-id specified? */ if (StringTools.isBlank(aclId)) { return false; // quietly ignore } /* already deleted? */ boolean aclExists = RoleAcl.exists(acctId, roleId, aclId); if (!aclExists) { return false; } /* delete */ RoleAcl.Key aclKey = new RoleAcl.Key(acctId, roleId, aclId); aclKey.delete(true); // also delete dependencies return true; }
public void setGeozoneID(String gzid) { if (!StringTools.isBlank(gzid)) { this.fieldValues.setString(EventData.FLD_geozoneID, gzid); } else { this.fieldValues.removeProperty(EventData.FLD_geozoneID); } }
public GoogleSig getSignature() { if (!this.signature_init) { this.signature_init = true; String key = this.getAuthorization(); if (!StringTools.isBlank(key) && key.startsWith(CLIENT_ID_PREFIX)) { String sigKey = this.getProperties().getString(PROP_signatureKey, ""); if (!StringTools.isBlank(sigKey)) { Print.logWarn("Setting SignatureKey: " + sigKey); this.signature = new GoogleSig(sigKey); } else { Print.logWarn("No signatureKey ..."); } } } return this.signature; }
/* set Role access level */ public static void setAccessLevel(Role role, String aclId, AccessLevel level) throws DBException { /* role specified? */ if (role == null) { throw new DBException("Role not specified."); } String acctId = role.getAccountID(); String roleId = role.getRoleID(); /* acl-id specified? */ if (StringTools.isBlank(aclId)) { throw new DBException("Acl-ID not specified."); } /* get/create role */ RoleAcl roleAcl = null; RoleAcl.Key aclKey = new RoleAcl.Key(acctId, roleId, aclId); if (aclKey.exists()) { // may throw DBException roleAcl = RoleAcl.getRoleAcl(role, aclId); // may throw DBException } else { roleAcl = aclKey.getDBRecord(); roleAcl.setRole(role); } /* set access level */ int levelInt = (level != null) ? level.getIntValue() : AccessLevel.NONE.getIntValue(); roleAcl.setAccessLevel(levelInt); /* save */ roleAcl.save(); // may throw DBException }
/* get/create device list entry */ public static GroupList getGroupList(User user, String groupID, boolean createOK) throws DBException { // does not return null, if 'createOK' is true /* User specified? */ if (user == null) { throw new DBException("User not specified."); } String accountID = user.getAccountID(); String userID = user.getUserID(); /* group exists? */ if (StringTools.isBlank(groupID)) { throw new DBException("DeviceGroup ID not specified."); } else if (!DeviceGroup.exists(accountID, groupID)) { throw new DBException("DeviceGroup does not exist: " + accountID + "/" + groupID); } /* create/save record */ GroupList.Key grpListKey = new GroupList.Key(accountID, userID, groupID); if (grpListKey.exists()) { // may throw DBException // already exists GroupList listItem = grpListKey.getDBRecord(true); listItem.setUser(user); return listItem; } else if (createOK) { GroupList listItem = grpListKey.getDBRecord(); listItem.setCreationDefaultValues(); listItem.setUser(user); return listItem; } else { // record doesn't exist, and caller doesn't want us to create it return null; } }
public void setFieldValue(String fldName, Object fldVal) { if (!StringTools.isBlank(fldName) && (fldVal != null)) { if (USE_ALTERNATE_FIELD_MAP) { this.getAlternateFieldMap().put(fldName, fldVal); } else { this.fieldValues.setProperty(fldName, fldVal); } } }
/* Return specified StatusCode, create if specified */ private static StatusCode _getStatusCode( String accountID, Account account, String deviceID, int code, boolean createOK) throws DBException { // does not return null if 'createOK' is true /* account-id specified? */ if (StringTools.isBlank(accountID)) { if (account == null) { throw new DBException("Account not specified."); } else { accountID = account.getAccountID(); } } else if ((account != null) && !account.getAccountID().equals(accountID)) { throw new DBException("Account does not match specified AccountID."); } /* device-id specified? */ if (StringTools.isBlank(deviceID)) { // throw new DBException("Device-ID not specified."); deviceID = ALL_DEVICES; } /* get/create entity */ StatusCode.Key scKey = new StatusCode.Key(accountID, deviceID, code); if (scKey.exists()) { // may throw DBException StatusCode sc = scKey.getDBRecord(true); if (account != null) { sc.setAccount(account); } return sc; } else if (createOK) { StatusCode sc = scKey.getDBRecord(); if (account != null) { sc.setAccount(account); } sc.setCreationDefaultValues(); return sc; // not yet saved! } else { // record doesn't exist, and caller doesn't want us to create it return null; } }
/* write JS to stream */ public void writeJavaScript(PrintWriter out, RequestProperties reqState) throws IOException { /* prefetch map "Loading" image */ if (this.getProperties().getBoolean(PROP_MAP_LOADING, false)) { String mapLoadingImageURI = this.getProperties().getString(PROP_MAP_LOADING_IMAGE, null); if (!StringTools.isBlank(mapLoadingImageURI)) { out.write("<link rel=\"prefetch\" href=\"" + mapLoadingImageURI + "\">\n"); } } /* JSMap variables */ JavaScriptTools.writeStartJavaScript(out); this.writeJSVariables(out, reqState); JavaScriptTools.writeEndJavaScript(out); /* Subclass JavaScript includes */ // links to MapProvider support are written by the subclass here this.writeJSIncludes(out, reqState); /* JSMap Custom included JavaScript */ String jsMapURLs[] = StringTools.parseStringArray(this.getProperties().getString(PROP_javascript_src, ""), '\n'); this.writeJSIncludes(out, reqState, jsMapURLs); /* JSMap Custom inline JavaScript */ String jsMapInline = StringTools.trim(this.getProperties().getString(PROP_javascript_inline, null)); if (!StringTools.isBlank(jsMapInline)) { JavaScriptTools.writeStartJavaScript(out); out.write("// --- Inline Javascript [" + this.getName() + "]\n"); out.write(jsMapInline); out.write("\n"); JavaScriptTools.writeEndJavaScript(out); } /* event CSV parsing code */ JavaScriptTools.writeStartJavaScript(out); out.write(EventUtil.getInstance().getParseMapEventJS(reqState.isFleet(), reqState.getLocale())); JavaScriptTools.writeEndJavaScript(out); }
/* validate the syntax of the specified single email address */ public static boolean validateAddress(String addr) { if (StringTools.isBlank(addr)) { // blanks not alowed here return false; // fail quickly } else { try { return SendMail.validateAddress(addr); } catch (Throwable t) { // NoClassDefFoundException, ClassNotFoundException // this will fail if JavaMail support for SendMail is not available. Print.logWarn("SendMail error: " + t); return false; } } }
/* write mapping support JS to stream */ public static void writePushpinArray(PrintWriter out, RequestProperties reqState) throws IOException { MapProvider mapProv = reqState.getMapProvider(); out.write("// Icon URLs\n"); out.write("var jsvPushpinIcon = new Array(\n"); OrderedMap<String, PushpinIcon> iconMap = mapProv.getPushpinIconMap(reqState); for (Iterator<String> k = iconMap.keyIterator(); k.hasNext(); ) { String key = k.next(); PushpinIcon ppi = iconMap.get(key); String I = ppi.getIconURL(); boolean iE = ppi.getIconEval(); int iW = ppi.getIconWidth(); int iH = ppi.getIconHeight(); int iX = ppi.getIconHotspotX(); int iY = ppi.getIconHotspotY(); String S = ppi.getShadowURL(); int sW = ppi.getShadowWidth(); int sH = ppi.getShadowHeight(); String B = ppi.getBackgroundURL(); int bW = ppi.getBackgroundWidth(); int bH = ppi.getBackgroundHeight(); int bX = ppi.getBackgroundOffsetX(); int bY = ppi.getBackgroundOffsetY(); out.write(" {"); out.write(" key:\"" + key + "\","); if (iE) { out.write(" iconEval:\"" + I + "\","); } else { out.write(" iconURL:\"" + I + "\","); } out.write(" iconSize:[" + iW + "," + iH + "],"); out.write(" iconOffset:[" + iX + "," + iY + "],"); out.write(" iconHotspot:[" + iX + "," + iY + "],"); out.write(" shadowURL:\"" + S + "\","); out.write(" shadowSize:[" + sW + "," + sH + "]"); if (!StringTools.isBlank(B)) { out.write(","); out.write(" bgURL:\"" + B + "\","); out.write(" bgSize:[" + bW + "," + bH + "],"); out.write(" bgOffset:[" + bX + "," + bY + "]"); } out.write(" }"); if (k.hasNext()) { out.write(","); } out.write("\n"); } out.write(" );\n"); }
/* Return status code description (used by RuleInfo, RequestProperties) */ public static String getDescription( String accountID, int statusCode, BasicPrivateLabel pl, String dftDesc) { /* custom code (record) */ StatusCode code = StatusCode.findStatusCode(accountID, null, statusCode); if (code != null) { return code.getDescription(); } /* default */ if (!StringTools.isBlank(dftDesc)) { return dftDesc; } else { return StatusCodes.GetDescription(statusCode, pl); } }
/* Return status code description */ public static String getDescription( Device device, int statusCode, BasicPrivateLabel bpl, String dftDesc) { /* device code */ if (device != null) { StatusCode code = device.getStatusCode(statusCode); if (code != null) { return code.getDescription(); } } /* default */ if (!StringTools.isBlank(dftDesc)) { return dftDesc; } else { return StatusCodes.GetDescription(statusCode, bpl); } }
/* return Role access level */ public static AccessLevel getAccessLevel(Role role, String aclId, AccessLevel dftAccess) { if (role == null) { return dftAccess; } else if (StringTools.isBlank(aclId)) { return dftAccess; } else { try { RoleAcl roleAcl = RoleAcl.getRoleAcl(role, aclId); // may throw DBException if (roleAcl != null) { return RoleAcl.getAccessLevel(roleAcl); } else { return dftAccess; } } catch (DBException dbe) { // error occurred return AccessLevel.NONE; } } }
protected Device loadDevice(String acctID, String devID) { if (StringTools.isBlank(acctID)) { return this.loadDevice(devID); // load ad ModemID } else { try { Account account = Account.getAccount(acctID); if (account == null) { Print.logError("Account-ID not found: " + acctID); return null; } else { Device dev = Transport.loadDeviceByTransportID(account, devID); return dev; } } catch (DBException dbe) { Print.logError("Error getting Device: " + acctID + "/" + devID + " [" + dbe + "]"); return null; } } }
/* Return specified role ACL, create if specified */ public static RoleAcl getRoleAcl(Role role, String aclId, boolean create) throws DBException { // does not return null /* role specified? */ if (role == null) { throw new DBNotFoundException("Role not specified."); } String acctId = role.getAccountID(); String roleId = role.getRoleID(); /* acl-id specified? */ if (StringTools.isBlank(aclId)) { throw new DBNotFoundException("Acl-ID not specified."); } /* get/create role */ RoleAcl roleAcl = null; RoleAcl.Key aclKey = new RoleAcl.Key(acctId, roleId, aclId); if (!aclKey.exists()) { // may throw DBException if (create) { roleAcl = aclKey.getDBRecord(); roleAcl.setRole(role); roleAcl.setCreationDefaultValues(); return roleAcl; // not yet saved! } else { throw new DBNotFoundException("Acl-ID does not exists '" + aclKey + "'"); } } else if (create) { // we've been asked to create the Acl, and it already exists throw new DBAlreadyExistsException("Acl-ID already exists '" + aclKey + "'"); } else { roleAcl = RoleAcl.getRoleAcl(role, aclId); // may throw DBException if (roleAcl == null) { throw new DBException("Unable to read existing Role-ID '" + aclKey + "'"); } return roleAcl; } }
/* create a new StatusCode */ public static StatusCode createNewStatusCode(Account account, String deviceID, int code) throws DBException { /* invalid account */ if (account == null) { throw new DBException("Invalid/Null Account specified"); } /* invalid code */ if ((code < 0) || (code > 0xFFFF)) { throw new DBException("Invalid StatusCode specified"); } /* default to 'ALL' devices */ if (StringTools.isBlank(deviceID)) { deviceID = ALL_DEVICES; } /* create status code */ StatusCode sc = StatusCode.getStatusCode(account, deviceID, code, true); // does not return null sc.save(); return sc; }
/* encode GeoPoint into nearest address URI */ protected String getGeoPointGeocodeURL(String address, String country) { StringBuffer sb = new StringBuffer(); GoogleSig sig = this.getSignature(); /* country */ if (StringTools.isBlank(country)) { country = this.getProperties().getString(PROP_countryCodeBias, DEFAULT_COUNTRY); } /* predefined URL */ String gcURL = this.getProperties().getString(PROP_geocodeURL, null); if (!StringTools.isBlank(gcURL)) { sb.append(gcURL); sb.append("&q=").append(URIArg.encodeArg(address)); if (!StringTools.isBlank(country)) { // country code bias: http://en.wikipedia.org/wiki/CcTLD sb.append("&gl=").append(country); } return sb.toString(); } /* assemble URL */ sb.append(this.getGeoPointGeocodeURI()); sb.append("output=xml"); sb.append("&oe=utf8"); /* address/country */ sb.append("&q=").append(URIArg.encodeArg(address)); if (!StringTools.isBlank(country)) { sb.append("&gl=").append(country); } /* sensor */ String sensor = this.getProperties().getString(PROP_sensor, null); if (!StringTools.isBlank(sensor)) { sb.append("&sensor=").append(sensor); } /* channel */ String channel = this.getProperties().getString(PROP_channel, null); if (!StringTools.isBlank(channel)) { sb.append("&channel=").append(channel); } /* key */ String auth = this.getAuthorization(); if (StringTools.isBlank(auth) || auth.startsWith("*")) { // invalid key } else if (auth.startsWith(CLIENT_ID_PREFIX)) { sb.append("&client=").append(auth); } else { sb.append("&key=").append(auth); } /* return url */ String defURL = sb.toString(); if (sig == null) { return defURL; } else { String urlStr = sig.signURL(defURL); return (urlStr != null) ? urlStr : defURL; } }
private void setGroupID(String v) { this.setFieldValue(FLD_groupID, StringTools.trim(v)); }
public String getGroupID() { String v = (String) this.getFieldValue(FLD_groupID); return StringTools.trim(v); }
/* return reverse-geocode using nearest address */ public ReverseGeocode getAddressReverseGeocode(GeoPoint gp, String localeStr, boolean cache) { /* check for failover mode */ if (this.isReverseGeocodeFailoverMode()) { ReverseGeocodeProvider frgp = this.getFailoverReverseGeocodeProvider(); return frgp.getReverseGeocode(gp, localeStr, cache); } /* URL */ String url = this.getAddressReverseGeocodeURL(gp, localeStr); Print.logDebug("Google RG URL: " + url); // byte xmlBytes[] = HTMLTools.readPage(url); /* create XML document */ Document xmlDoc = GetXMLDocument(url, this.getReverseGeocodeTimeout()); if (xmlDoc == null) { return null; } /* vars */ String errCode = null; String address = null; /* parse "xml" */ Element kml = xmlDoc.getDocumentElement(); if (kml.getTagName().equalsIgnoreCase(TAG_kml)) { NodeList ResponseList = XMLTools.getChildElements(kml, TAG_Response); for (int g = 0; (g < ResponseList.getLength()); g++) { Element response = (Element) ResponseList.item(g); NodeList responseNodes = response.getChildNodes(); for (int n = 0; n < responseNodes.getLength(); n++) { Node responseNode = responseNodes.item(n); if (!(responseNode instanceof Element)) { continue; } Element responseElem = (Element) responseNode; String responseNodeName = responseElem.getNodeName(); if (responseNodeName.equalsIgnoreCase(TAG_name)) { // <name>40.479581,-117.773438</name> } else if (responseNodeName.equalsIgnoreCase(TAG_Status)) { // <Status> ... </Status> NodeList statusNodes = responseElem.getChildNodes(); for (int st = 0; st < statusNodes.getLength(); st++) { Node statusNode = statusNodes.item(st); if (!(statusNode instanceof Element)) { continue; } Element statusElem = (Element) statusNode; String statusNodeName = statusElem.getNodeName(); if (statusNodeName.equalsIgnoreCase(TAG_code)) { errCode = StringTools.trim(GoogleGeocodeV2.GetNodeText(statusElem)); // expect "200" break; // we only care about the 'code' } } } else if (responseNodeName.equalsIgnoreCase(TAG_Placemark)) { // <Placemark> ... </Placemark> String id = responseElem.getAttribute(ATTR_id); if ((id != null) && id.equals("p1")) { NodeList placemarkNodes = responseElem.getChildNodes(); for (int pm = 0; pm < placemarkNodes.getLength(); pm++) { Node placemarkNode = placemarkNodes.item(pm); if (!(placemarkNode instanceof Element)) { continue; } Element placemarkElem = (Element) placemarkNode; String placemarkNodeName = placemarkElem.getNodeName(); if (placemarkNodeName.equalsIgnoreCase(TAG_address)) { address = GoogleGeocodeV2.GetNodeText(placemarkElem); break; // we only care about the 'address' } } } else { // Print.logInfo("Skipping Placemark ID = %s", id); } } } } } /* create address */ if (FAILOVER_DEBUG) { errCode = "620"; } else if (!StringTools.isBlank(address)) { // address found ReverseGeocode rg = new ReverseGeocode(); rg.setFullAddress(address); return rg; } /* check for Google reverse-geocode limit exceeded */ if ((errCode != null) && errCode.equals("620")) { Print.logError("!!!! Google Reverse-Geocode Limit Exceeded [Error 620] !!!!"); if (this.hasFailoverReverseGeocodeProvider()) { this.startReverseGeocodeFailoverMode(); ReverseGeocodeProvider frgp = this.getFailoverReverseGeocodeProvider(); Print.logWarn("Failing over to '" + frgp.getName() + "'"); return frgp.getReverseGeocode(gp, localeStr, cache); } } /* no reverse-geocode available */ return null; }
// http://code.google.com/apis/maps/documentation/geocoding/index.html public GeoPoint getGeocode(String address, String country) { /* URL */ String url = this.getGeoPointGeocodeURL(address, country); Print.logDebug("Google GC URL: " + url); /* create XML document */ Document xmlDoc = GetXMLDocument(url, this.getGeocodeTimeout()); if (xmlDoc == null) { return null; } /* vars */ String errCode = null; GeoPoint geoPoint = null; /* parse "xml" */ Element kml = xmlDoc.getDocumentElement(); if (kml.getTagName().equalsIgnoreCase(TAG_kml)) { NodeList ResponseList = XMLTools.getChildElements(kml, TAG_Response); for (int g = 0; (g < ResponseList.getLength()); g++) { Element response = (Element) ResponseList.item(g); NodeList responseNodes = response.getChildNodes(); for (int n = 0; n < responseNodes.getLength(); n++) { Node responseNode = responseNodes.item(n); if (!(responseNode instanceof Element)) { continue; } Element responseElem = (Element) responseNode; String responseNodeName = responseElem.getNodeName(); if (responseNodeName.equalsIgnoreCase(TAG_name)) { // <name>1600 Amphitheatre Parkway, Mountain View, CA</name> } else if (responseNodeName.equalsIgnoreCase(TAG_Status)) { // <Status> ... </Status> NodeList statusNodes = responseElem.getChildNodes(); for (int st = 0; st < statusNodes.getLength(); st++) { Node statusNode = statusNodes.item(st); if (!(statusNode instanceof Element)) { continue; } Element statusElem = (Element) statusNode; String statusNodeName = statusElem.getNodeName(); if (statusNodeName.equalsIgnoreCase(TAG_code)) { errCode = StringTools.trim(GoogleGeocodeV2.GetNodeText(statusElem)); // expect "200" break; // we only care about the 'code' } } } else if (responseNodeName.equalsIgnoreCase(TAG_Placemark)) { // <Placemark> ... </Placemark> String id = responseElem.getAttribute(ATTR_id); if ((id != null) && id.equals("p1")) { NodeList placemarkNodes = responseElem.getChildNodes(); for (int pm = 0; (geoPoint == null) && (pm < placemarkNodes.getLength()); pm++) { Node placemarkNode = placemarkNodes.item(pm); if (!(placemarkNode instanceof Element)) { continue; } Element placemarkElem = (Element) placemarkNode; String placemarkNodeName = placemarkElem.getNodeName(); if (placemarkNodeName.equalsIgnoreCase(TAG_Point)) { NodeList pointNodes = placemarkElem.getChildNodes(); for (int ptn = 0; (geoPoint == null) && (ptn < pointNodes.getLength()); ptn++) { Node pointNode = pointNodes.item(ptn); if (!(pointNode instanceof Element)) { continue; } Element pointElem = (Element) pointNode; String pointNodeName = pointElem.getNodeName(); if (pointNodeName.equalsIgnoreCase(TAG_coordinates)) { String ll[] = StringTools.split(GoogleGeocodeV2.GetNodeText(pointElem), ','); if (ll.length >= 2) { double lon = StringTools.parseDouble(ll[0], 0.0); // longitude is first double lat = StringTools.parseDouble(ll[1], 0.0); if (GeoPoint.isValid(lat, lon)) { geoPoint = new GeoPoint(lat, lon); break; // we only care about the 'GeoPoint' } } } } } } } else { // Print.logInfo("Skipping Placemark ID = %s", id); } } } } } /* create address */ if (geoPoint != null) { // GeoPoint found return geoPoint; } /* check for Google reverse-geocode limit exceeded */ if ((errCode != null) && errCode.equals("620")) { Print.logError("!!!! Google Reverse-Geocode Limit Exceeded [Error 620] !!!!"); } /* no reverse-geocode available */ return null; }
/* write mapping support JS to stream */ protected void writeJSVariables(PrintWriter out, RequestProperties reqState) throws IOException { // This var initilizations must not use any functions defined in 'jsmap.js' PrivateLabel privLabel = reqState.getPrivateLabel(); I18N i18n = privLabel.getI18N(JSMap.class); Locale locale = reqState.getLocale(); GeoPoint dftCenter = this.getDefaultCenter(null); boolean isFleet = reqState.isFleet(); Account account = reqState.getCurrentAccount(); long maxPushpins = this.getMaxPushpins(reqState); out.write("// --- Map support Javascript [" + this.getName() + "]\n"); JavaScriptTools.writeJSVar(out, "MAP_PROVIDER_NAME", this.getName()); /* properties */ boolean wrotePropHeader = false; RTProperties rtp = this.getProperties(); for (Iterator<?> i = rtp.keyIterator(); i.hasNext(); ) { Object key = i.next(); if (!this._skipPropKey(key)) { if (!wrotePropHeader) { // out.write("\n"); out.write("// Defined properties\n"); wrotePropHeader = true; } String val[] = StringTools.parseStringArray(rtp.getProperty(key, "").toString(), '\n'); String propVar = "PROP_" + key.toString().replace('.', '_').replace('-', '_'); if (val.length == 1) { if (StringTools.isDouble(val[0], true) || StringTools.isLong(val[0], true) || StringTools.isBoolean(val[0], true)) { JavaScriptTools.writeJSVar(out, propVar, val[0], false); } else { JavaScriptTools.writeJSVar(out, propVar, val[0]); } } else if (val.length > 1) { JavaScriptTools.writeJSVar(out, propVar, StringTools.join(val, "\\n")); } } } /* speed units */ Account.SpeedUnits speedUnits = reqState.getSpeedUnits(); boolean speedIsKph = speedUnits.equals(Account.SpeedUnits.KPH); double altUnitsMult = speedIsKph ? 1.0 : GeoPoint.FEET_PER_METER; String altUnitsName = speedIsKph ? i18n.getString("JSMap.altitude.meters", "Meters") : i18n.getString("JSMap.altitude.feet", "Feet"); /* constants (these do not change during the user session) */ out.write("// Element IDs\n"); JavaScriptTools.writeJSVar(out, "MAP_ID", this.getMapID()); JavaScriptTools.writeJSVar(out, "ID_DETAIL_TABLE", ID_DETAIL_TABLE); JavaScriptTools.writeJSVar(out, "ID_DETAIL_CONTROL", ID_DETAIL_CONTROL); JavaScriptTools.writeJSVar(out, "ID_LAT_LON_DISPLAY", ID_LAT_LON_DISPLAY); JavaScriptTools.writeJSVar(out, "ID_DISTANCE_DISPLAY", ID_DISTANCE_DISPLAY); JavaScriptTools.writeJSVar(out, "ID_LATEST_EVENT_DATE", ID_LATEST_EVENT_DATE); JavaScriptTools.writeJSVar(out, "ID_LATEST_EVENT_TIME", ID_LATEST_EVENT_TIME); JavaScriptTools.writeJSVar(out, "ID_LATEST_EVENT_TMZ", ID_LATEST_EVENT_TMZ); JavaScriptTools.writeJSVar(out, "ID_LATEST_BATTERY", ID_LATEST_BATTERY); JavaScriptTools.writeJSVar(out, "ID_MESSAGE_TEXT", ID_MESSAGE_TEXT); out.write("// Geozone IDs\n"); JavaScriptTools.writeJSVar(out, "ID_ZONE_LATITUDE_", ID_ZONE_LATITUDE_); JavaScriptTools.writeJSVar(out, "ID_ZONE_LONGITUDE_", ID_ZONE_LONGITUDE_); JavaScriptTools.writeJSVar(out, "ID_ZONE_RADIUS_M", ID_ZONE_RADIUS_M); out.write("// Session constants\n"); JavaScriptTools.writeJSVar(out, "PUSHPINS_SHOW", rtp.getBoolean(PROP_map_pushpins, true)); JavaScriptTools.writeJSVar(out, "MAX_PUSH_PINS", maxPushpins); JavaScriptTools.writeJSVar(out, "MAX_CREATION_AGE_SEC", rtp.getInt(PROP_map_maxCreationAge, 0)); JavaScriptTools.writeJSVar(out, "MAP_WIDTH", this.getDimension().getWidth()); JavaScriptTools.writeJSVar(out, "MAP_HEIGHT", this.getDimension().getHeight()); JavaScriptTools.writeJSVar(out, "IS_FLEET", isFleet); JavaScriptTools.writeJSVar( out, "SHOW_SAT_COUNT", rtp.getBoolean(PROP_detail_showSatCount, false)); JavaScriptTools.writeJSVar(out, "SHOW_SPEED", rtp.getBoolean(PROP_info_showSpeed, true)); JavaScriptTools.writeJSVar( out, "COMBINE_SPEED_HEAD", rtp.getBoolean(PROP_combineSpeedHeading, true)); JavaScriptTools.writeJSVar(out, "SHOW_ALTITUDE", rtp.getBoolean(PROP_info_showAltitude, false)); JavaScriptTools.writeJSVar(out, "SHOW_ADDR", reqState.getShowAddress()); JavaScriptTools.writeJSVar( out, "INCL_BLANK_ADDR", rtp.getBoolean(PROP_info_inclBlankAddress, true)); JavaScriptTools.writeJSVar( out, "SHOW_OPT_FIELDS", rtp.getBoolean(PROP_info_showOptionalFields, true)); JavaScriptTools.writeJSVar( out, "INCL_BLANK_OPT_FIELDS", rtp.getBoolean(PROP_info_inclBlankOptFields, true)); JavaScriptTools.writeJSVar( out, "LATLON_FORMAT", Account.getLatLonFormat(account).getIntValue()); JavaScriptTools.writeJSVar( out, "DISTANCE_KM_MULT", reqState.getDistanceUnits().getMultiplier()); JavaScriptTools.writeJSVar(out, "SPEED_KPH_MULT", speedUnits.getMultiplier()); JavaScriptTools.writeJSVar(out, "SPEED_UNITS", speedUnits.toString(locale)); JavaScriptTools.writeJSVar(out, "ALTITUDE_METERS_MULT", altUnitsMult); JavaScriptTools.writeJSVar(out, "ALTITUDE_UNITS", altUnitsName); JavaScriptTools.writeJSVar(out, "TIME_ZONE", reqState.getTimeZoneString(null)); // long JavaScriptTools.writeJSVar( out, "DEFAULT_CENTER", "{ lat:" + dftCenter.getLatitude() + ", lon:" + dftCenter.getLongitude() + " }", false); JavaScriptTools.writeJSVar(out, "DEFAULT_ZOOM", this.getDefaultZoom(JSMap.DEFAULT_ZOOM, false)); JavaScriptTools.writeJSVar(out, "PUSHPIN_ZOOM", this.getDefaultZoom(JSMap.PUSHPIN_ZOOM, true)); JavaScriptTools.writeJSVar(out, "MAP_AUTHORIZATION", this.getAuthorization()); JavaScriptTools.writeJSVar( out, "SCROLL_WHEEL_ZOOM", rtp.getBoolean(PROP_scrollWheelZoom, false)); JavaScriptTools.writeJSVar(out, "DEFAULT_VIEW", rtp.getString(PROP_map_view, "").toLowerCase()); JavaScriptTools.writeJSVar(out, "ROUTE_LINE_SHOW", rtp.getBoolean(PROP_map_routeLine, true)); JavaScriptTools.writeJSVar( out, "ROUTE_LINE_COLOR", rtp.getString(PROP_map_routeLine_color, "#FF2222")); JavaScriptTools.writeJSVar( out, "ROUTE_LINE_ARROWS", rtp.getBoolean(PROP_map_routeLine_arrows, false)); JavaScriptTools.writeJSVar( out, "ROUTE_SNAP_TO_ROAD", rtp.getBoolean(PROP_map_routeLine_snapToRoad, false)); // Google V2 only JavaScriptTools.writeJSVar(out, "REPLAY_INTERVAL", this.getReplayInterval()); JavaScriptTools.writeJSVar(out, "REPLAY_SINGLE", this.getReplaySinglePushpin()); /* address title */ String adrTitles[] = reqState.getAddressTitles(); String adrTitle = ListTools.itemAt(adrTitles, 0, null); /* device title */ String devTitles[] = reqState.getDeviceTitles(); String devTitle = ListTools.itemAt(devTitles, 0, null); /* labels */ out.write("// Localized Text/Labels\n"); JavaScriptTools.writeJSVar( out, "HEADING", "new Array(" + "\"" + GeoPoint.CompassHeading.N.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.NE.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.E.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.SE.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.S.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.SW.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.W.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.NW.toString(locale) + "\")", false); JavaScriptTools.writeJSVar(out, "TEXT_INFO_DATE", i18n.getString("JSMap.info.date", "Date")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_GPS", i18n.getString("JSMap.info.gps", "GPS")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_SATS", i18n.getString("JSMap.info.sats", "#Sats")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_SPEED", i18n.getString("JSMap.info.speed", "Speed")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_HEADING", GeoPoint.GetHeadingTitle(locale)); JavaScriptTools.writeJSVar( out, "TEXT_INFO_ALTITUDE", i18n.getString("JSMap.info.altitude", "Altitude")); JavaScriptTools.writeJSVar( out, "TEXT_INFO_STOP_TIME", i18n.getString("JSMap.info.stopTime", "Stop Time")); JavaScriptTools.writeJSVar( out, "TEXT_INFO_ADDR", !StringTools.isBlank(adrTitle) ? adrTitle : i18n.getString("JSMap.info.address", "Address")); JavaScriptTools.writeJSVar( out, "TEXT_DEVICE", !StringTools.isBlank(devTitle) ? devTitle : i18n.getString("JSMap.device", "Device")); JavaScriptTools.writeJSVar(out, "TEXT_DATE", i18n.getString("JSMap.dateTime", "Date/Time")); JavaScriptTools.writeJSVar(out, "TEXT_CODE", i18n.getString("JSMap.code", "Status")); JavaScriptTools.writeJSVar(out, "TEXT_LATLON", i18n.getString("JSMap.latLon", "Lat/Lon")); JavaScriptTools.writeJSVar(out, "TEXT_SATCOUNT", i18n.getString("JSMap.satCount", "#Sats")); JavaScriptTools.writeJSVar( out, "TEXT_ADDR", !StringTools.isBlank(adrTitle) ? adrTitle : i18n.getString("JSMap.address", "Address")); JavaScriptTools.writeJSVar(out, "TEXT_SPEED", reqState.getSpeedUnits().toString(locale)); JavaScriptTools.writeJSVar(out, "TEXT_HEADING", i18n.getString("JSMap.heading", "Heading")); JavaScriptTools.writeJSVar(out, "TEXT_DISTANCE", reqState.getDistanceUnits().toString(locale)); JavaScriptTools.writeJSVar( out, "TEXT_TIMEOUT", i18n.getString("JSMap.sessionTimeout", "Your session has timed-out.\nPlease login ...")); JavaScriptTools.writeJSVar( out, "TEXT_PING_OK", i18n.getString( "JSMap.pingDevice.ok", "A command request has been sent.\nThe {0} should respond shortly ...", devTitles)); JavaScriptTools.writeJSVar( out, "TEXT_PING_ERROR", i18n.getString( "JSMap.pingDevice.err", "The command request failed.\nThe {0} may not support this feature ...", devTitles)); JavaScriptTools.writeJSVar( out, "TEXT_MAXPUSHPINS_ALERT", i18n.getString( "JSMap.maxPushpins.err", "The maximum number of allowed pushpins has been exceeded.\n" + " [max={0}] Not all pushpins may be displayed on this map.\n" + "Adjust the 'From' time to see remaining pushpins", String.valueOf(maxPushpins))); JavaScriptTools.writeJSVar( out, "TEXT_MAXPUSHPINS_MSG", i18n.getString( "JSMap.maxPushpins.msg", "Only partial data displayed. The maximum allowed pushpins has been reached.<BR>" + "Adjust the Date/Time range accordingly to view the remaining pushpins.")); JavaScriptTools.writeJSVar( out, "TEXT_UNAVAILABLE", i18n.getString("JSMap.unavailable", "unavailable")); JavaScriptTools.writeJSVar( out, "TEXT_showLocationDetails", i18n.getString("JSMap.showLocationDetails", "Show Location Details")); JavaScriptTools.writeJSVar( out, "TEXT_hideLocationDetails", i18n.getString("JSMap.hideLocationDetails", "Hide Location Details")); /* map "Loading ..." */ JavaScriptTools.writeJSVar( out, "TEXT_LOADING_MAP_POINTS", (rtp.getBoolean(PROP_MAP_LOADING, false) ? i18n.getString("JSMap.loadingMapPoints", "Loading Map Points ...") : null)); JavaScriptTools.writeJSVar( out, "MAP_LOADING_IMAGE_URI", rtp.getString(PROP_MAP_LOADING_IMAGE, null)); /* icons/shadows */ JSMap.writePushpinArray(out, reqState); /* constants (these do not change during the user session) */ out.write("// Geozone support constants\n"); JavaScriptTools.writeJSVar(out, "jsvGeozoneMode", false); JavaScriptTools.writeJSVar(out, "MAX_ZONE_RADIUS_M", Geozone.MAX_RADIUS_METERS); JavaScriptTools.writeJSVar(out, "MIN_ZONE_RADIUS_M", Geozone.MIN_RADIUS_METERS); JavaScriptTools.writeJSVar( out, "DETAIL_REPORT", this.isFeatureSupported(FEATURE_DETAIL_REPORT)); JavaScriptTools.writeJSVar( out, "DETAIL_INFO_BOX", this.isFeatureSupported(FEATURE_DETAIL_INFO_BOX)); JavaScriptTools.writeJSVar(out, "TEXT_METERS", GeoPoint.DistanceUnits.METERS.toString(locale)); /* variables */ out.write("// TrackMap Vars\n"); JavaScriptTools.writeJSVar(out, "jsvPoiPins", null); JavaScriptTools.writeJSVar(out, "jsvDataSets", null); JavaScriptTools.writeJSVar(out, "jsvDetailPoints", null); JavaScriptTools.writeJSVar(out, "jsvDetailVisible", false); JavaScriptTools.writeJSVar( out, "jsvDetailAscending", privLabel.getBooleanProperty(PrivateLabel.PROP_TrackMap_detailAscending, true)); JavaScriptTools.writeJSVar( out, "jsvDetailCenterPushpin", privLabel.getBooleanProperty(PrivateLabel.PROP_TrackMap_detailCenterPushpin, false)); /* last update time */ TimeZone tmz = reqState.getTimeZone(); String dateFmt = (account != null) ? account.getDateFormat() : BasicPrivateLabel.getDefaultDateFormat(); String timeFmt = (account != null) ? account.getTimeFormat() : BasicPrivateLabel.getDefaultTimeFormat(); DateTime today = new DateTime(tmz); JavaScriptTools.writeJSVar(out, "jsvTodayEpoch", today.getTimeSec()); JavaScriptTools.writeJSVar( out, "jsvTodayYMD", "{ YYYY:" + today.getYear(tmz) + ", MM:" + today.getMonth1(tmz) + ", DD:" + today.getDayOfMonth(tmz) + " }", false); JavaScriptTools.writeJSVar(out, "jsvTodayDateFmt", today.format(dateFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvTodayTimeFmt", today.format(timeFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvTodayTmzFmt", today.format("z", tmz)); /* last event time */ out.write("// Last event time\n"); DateTime lastEventTime = reqState.getLastEventTime(); if (lastEventTime != null) { JavaScriptTools.writeJSVar(out, "jsvLastEventEpoch", lastEventTime.getTimeSec()); JavaScriptTools.writeJSVar( out, "jsvLastEventYMD", "{ YYYY:" + lastEventTime.getYear(tmz) + ", MM:" + lastEventTime.getMonth1(tmz) + ", DD:" + lastEventTime.getDayOfMonth(tmz) + " }", false); JavaScriptTools.writeJSVar(out, "jsvLastEventDateFmt", lastEventTime.format(dateFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvLastEventTimeFmt", lastEventTime.format(timeFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvLastEventTmzFmt", lastEventTime.format("z", tmz)); JavaScriptTools.writeJSVar(out, "jsvLastBatteryLevel", 0L); JavaScriptTools.writeJSVar(out, "jsvLastSignalStrength", 0L); } else { JavaScriptTools.writeJSVar(out, "jsvLastEventEpoch", 0L); JavaScriptTools.writeJSVar(out, "jsvLastEventYMD", null); JavaScriptTools.writeJSVar(out, "jsvLastEventDateFmt", null); JavaScriptTools.writeJSVar(out, "jsvLastEventTimeFmt", null); JavaScriptTools.writeJSVar(out, "jsvLastEventTmzFmt", null); JavaScriptTools.writeJSVar(out, "jsvLastBatteryLevel", 0.0); JavaScriptTools.writeJSVar(out, "jsvLastSignalStrength", 0.0); } /* map pointers */ out.write("// Map vars\n"); JavaScriptTools.writeJSVar(out, "jsmapElem", null); JavaScriptTools.writeJSVar(out, "jsmap", null); }
public boolean insertEventData() { /* valid device? */ if (this.device == null) { return false; } /* debug message */ if (RTConfig.isDebugMode()) { Print.logDebug("Inserting EventData ...\n" + this.toString()); } /* EventData key */ String acctID = this.device.getAccountID(); String devID = this.device.getDeviceID(); long fixtime = this.getTimestamp(); int statusCode = this.getStatusCode(); EventData.Key evKey = new EventData.Key(acctID, devID, fixtime, statusCode); EventData evdb = evKey.getDBRecord(); /* set EventData field values */ if (USE_EVENTDATA_SETVALUE) { for (Object fldn : this.fieldValues.getPropertyKeys()) { if (fldn.equals(EventData.FLD_timestamp)) { continue; // already set above } else if (fldn.equals(EventData.FLD_statusCode)) { continue; // already set above } Object fldv = this.fieldValues.getProperty(fldn, null); if (fldv != null) { evdb.setValue((String) fldn, fldv); // attempts to use "setter" methods } } } else { if (this.hasLatitude()) { evdb.setLatitude(this.getLatitude()); } if (this.hasLongitude()) { evdb.setLongitude(this.getLongitude()); } if (this.hasGpsAge()) { evdb.setGpsAge(this.getGpsAge()); } if (this.hasHDOP()) { evdb.setHDOP(this.getHDOP()); } if (this.hasSatelliteCount()) { evdb.setSatelliteCount(this.getSatelliteCount()); } if (this.hasSpeedKPH()) { evdb.setSpeedKPH(this.getSpeedKPH()); } if (this.hasHeading()) { evdb.setHeading(this.getHeading()); } if (this.hasAltitude()) { evdb.setAltitude(this.getAltitude()); } if (this.hasInputMask()) { evdb.setInputMask(this.getInputMask()); } if (this.hasBatteryLevel()) { evdb.setBatteryLevel(this.getBatteryLevel()); } if (this.hasSignalStrength()) { evdb.setSignalStrength(this.getSignalStrength()); } if (this.hasOdometerKM()) { evdb.setOdometerKM(this.getOdometerKM()); } if (this.hasEngineHours()) { evdb.setEngineHours(this.getEngineHours()); } if (this.hasPtoHours()) { evdb.setPtoHours(this.getPtoHours()); } if (this.hasFuelTotal()) { evdb.setFuelTotal(this.getFuelTotal()); } if (this.hasGeozoneID()) { evdb.setGeozoneID(this.getGeozoneID()); } } /* other fields (if available) */ if (this.otherValues != null) { for (String fldn : this.otherValues.keySet()) { if (fldn.equals(EventData.FLD_timestamp)) { continue; } else if (fldn.equals(EventData.FLD_statusCode)) { continue; } Object fldv = this.otherValues.get(fldn); if (fldv != null) { evdb.setValue(fldn, fldv); // attempts to use "setter" methods } } } /* insert event */ // this will display an error if it was unable to store the event Print.logInfo( "Event : [0x" + StringTools.toHexString(statusCode, 16) + "] " + StatusCodes.GetDescription(statusCode, null)); this.device.insertEventData( evdb); // FLD_lastValidLatitude,FLD_lastValidLongitude,FLD_lastGPSTimestamp,FLD_lastOdometerKM this.eventTotalCount++; return true; }