Example #1
0
 /**
  * ** Gets args as RTProperties instance ** @return A new RTProperties instance with this URIArg's
  * key value pairs
  */
 public RTProperties getArgProperties() {
   RTProperties rtp = new RTProperties();
   for (Iterator i = this.getKeyValList().iterator(); i.hasNext(); ) {
     KeyVal kv = (KeyVal) i.next();
     rtp.setString(kv.getKey(), this.decodeArg(kv.getValue()));
   }
   return rtp;
 }
Example #2
0
 /**
  * ** Returns a new URIArg with this URIArg's arguments encoded into a ** single RTProperties
  * added with a specified key [CHECK] ** @param rtpKey The key to add the encoded args at
  * ** @param exclKeys keys to exclude from encoding ** @return A new URIArg with non excluded
  * arguments encoded
  */
 public URIArg rtpEncode(String rtpKey, String... exclKeys) {
   URIArg rtpUrl = new URIArg(this.getURI());
   RTProperties rtp = new RTProperties();
   for (KeyVal kv : this.getKeyValList()) {
     String kn = kv.getKey();
     if (ListTools.contains(exclKeys, kn)) {
       rtpUrl.addArg(kv);
     } else {
       rtp.setString(kn, kv.getValue());
     }
   }
   rtpUrl.addArg(rtpKey, rtp);
   return rtpUrl;
 }
Example #3
0
 /**
  * ** Returns a new URIArg with this URIArg's arguments decoded from a ** single RTProperties
  * added a specified key [CHECK] ** @param rtpKey The key of the RTProperties to decode the
  * encoded args from ** @return A new URIArg with non excluded arguments encoded
  */
 public URIArg rtpDecode(String rtpKey) {
   URIArg cpyUrl = new URIArg(this.getURI());
   for (KeyVal kv : this.getKeyValList()) {
     String kn = kv.getKey();
     if (!kn.equals(rtpKey)) {
       cpyUrl.addArg(kv);
     } else {
       RTProperties rtp = URIArg.parseRTP(kv.getValue());
       for (Object rpk : rtp.getPropertyKeys()) {
         String rk = rpk.toString();
         String rv = rtp.getString(rk, "");
         cpyUrl.addArg(rk, rv);
       }
     }
   }
   return cpyUrl;
 }
Example #4
0
 /**
  * ** Adds an argument to the URI ** @param key The key name of the argument to add ** @param rtp
  * The RTP encoded values of the new key ** @return This URIArg, with the argument added
  */
 public URIArg addArg(String key, RTProperties rtp) {
   String r = (rtp != null) ? rtp.toString() : null;
   if (!StringTools.isBlank(r)) {
     return this._addArg(key, URIArg.encodeRTP(rtp), false /*encode*/, false /*obfuscate*/);
   } else {
     return this.addArg(key, "");
   }
 }
Example #5
0
 /* return fault header */
 public static String GetFaultHeader(RTProperties fault) {
   if (fault != null) {
     String type = fault.getString(PROP_TYPE, "");
     if (type.equalsIgnoreCase(NAME_J1708)) {
       if (fault.hasProperty(PROP_SID)) {
         return NAME_MID + "/" + NAME_SID + "/" + NAME_FMI;
       } else {
         return NAME_MID + "/" + NAME_PID + "/" + NAME_FMI;
       }
     } else if (type.equalsIgnoreCase(NAME_J1939)) {
       return NAME_SPN + "/" + NAME_FMI;
     } else if (type.equalsIgnoreCase(NAME_OBDII)) {
       return NAME_DTC;
     } else {
       return "";
     }
   }
   return "";
 }
Example #6
0
 /* encode "type=<type> ..." into long value */
 public static long EncodeFault(RTProperties rtp) {
   String type = rtp.getString(PROP_TYPE, null);
   if (type.equalsIgnoreCase(NAME_J1708)) {
     int mid = rtp.getInt(PROP_MID, 0);
     int sid = rtp.getInt(PROP_SID, -1);
     int pid = rtp.getInt(PROP_PID, -1);
     int pidSid = (sid >= 0) ? sid : pid;
     int fmi = rtp.getInt(PROP_FMI, 0);
     int count = rtp.getInt(PROP_COUNT, 0);
     boolean active = rtp.getBoolean(PROP_ACTIVE, true);
     return EncodeFault_J1708(mid, (sid >= 0), pidSid, fmi, count, active);
   } else if (type.equalsIgnoreCase(NAME_J1939)) {
     int spn = rtp.getInt(PROP_SPN, 0);
     int fmi = rtp.getInt(PROP_FMI, 0);
     int count = rtp.getInt(PROP_COUNT, 0);
     boolean active = rtp.getBoolean(PROP_ACTIVE, true);
     return EncodeFault_J1939(spn, fmi, count);
   } else if (type.equalsIgnoreCase(NAME_OBDII)) {
     String dtc = rtp.getString(PROP_DTC, ""); // "P0071"
     return EncodeFault_OBDII(dtc);
   } else {
     return 0L;
   }
 }
Example #7
0
 /** ** RTP encodes an argument */
 public static String encodeRTP(RTProperties rtp) {
   if (rtp != null) {
     return _ens64(rtp.toString());
   }
   return null;
 }
Example #8
0
 public static boolean IsOBDII(RTProperties rtpFault) {
   return ((rtpFault != null) && rtpFault.getString(PROP_TYPE, "").equalsIgnoreCase(NAME_OBDII));
 }
Example #9
0
 public static boolean IsJ1708_PID(RTProperties rtpFault) {
   return DTOBDFault.IsJ1708(rtpFault) && rtpFault.hasProperty(PROP_PID);
 }
Example #10
0
 /* return string representation of fault code */
 public static String GetFaultString(RTProperties fault) {
   if (fault != null) {
     StringBuffer sb = new StringBuffer();
     String type = fault.getString(PROP_TYPE, "");
     if (type.equalsIgnoreCase(NAME_J1708)) {
       // J1708: type=j1708 mil=1 mid=123 pid=123 fmi=1 count=1 active=false
       // SID: "128/s123/1"
       // PID: "128/123/1"
       boolean active = fault.getBoolean(PROP_ACTIVE, true);
       int mid = fault.getInt(PROP_MID, 0);
       int fmi = fault.getInt(PROP_FMI, 0);
       if (!active) {
         sb.append("[");
       }
       sb.append(mid); // MID
       sb.append("/");
       if (fault.hasProperty(PROP_SID)) {
         int sid = fault.getInt(PROP_SID, 0);
         sb.append("s").append(sid); // SID "128/s123/1"
       } else {
         int pid = fault.getInt(PROP_PID, 0);
         sb.append(pid); // PID "128/123/1"
       }
       sb.append("/");
       sb.append(fmi); // FMI
       if (!active) {
         sb.append("]");
       }
       return sb.toString();
     } else if (type.equalsIgnoreCase(NAME_J1939)) {
       // J1939: type=i1939 mil=1 spn=1234 fmi=12 count=1 active=false
       // SPN: "128/1"
       boolean active = fault.getBoolean(PROP_ACTIVE, true);
       int spn = fault.getInt(PROP_SPN, 0);
       int fmi = fault.getInt(PROP_FMI, 0);
       if (!active) {
         sb.append("[");
       }
       sb.append(spn); // SPN
       sb.append("/");
       sb.append(fmi); // FMI
       if (!active) {
         sb.append("]");
       }
       return sb.toString();
     } else if (type.equalsIgnoreCase(NAME_OBDII)) {
       // OBDII: type=obdii mil=1 dtc=P0071
       // DTC: "P0071" [was "024C"]
       boolean active = fault.getBoolean(PROP_ACTIVE, true);
       String dtcStr = fault.getString(PROP_DTC, ""); // ie "P0123,P0321,P1234"
       if (!StringTools.isBlank(dtcStr)) {
         if (!active) {
           sb.append("[");
         }
         sb.append(dtcStr);
         if (!active) {
           sb.append("]");
         }
       }
       return sb.toString();
     } else {
       // unrecognized
     }
   }
   return "";
 }