Exemplo n.º 1
0
 /**
  * ** Returns true if the specified character is a valid character to use in ** an ID ** @param ch
  * The character ** @return True if the specified character is a valid character to use in ** an
  * ID
  */
 public static boolean isValidIDChar(char ch) {
   // At a minimum, avoid the following special chars:
   //   $   - substitution character
   //   {}  - have had problems using this character in MySQL
   //   %   - MySQL wildcard character
   //   *   - generic wildcard character
   //   \   - escape character
   //   ?   - just don't use it
   //   ,   - will get confused as a field separator
   //   |   - will get confused as a field separator
   //   /   - will get confused as a field separator
   //   =   - will get confused as a key=value separator
   //   "'` - quotation characters
   //   #   - possible beginning of comment
   //   ~   - just don't use it
   //   ?   - just don't use it
   //   ^   - just don't use it
   // Pending possibles:
   //   !   - Looks like '|'?
   //   -   - ?
   //   +   - ?
   // @abc,#abc,_abc,.abc,&abc
   if (Character.isLetterOrDigit(ch)) {
     return true;
   } else if ((ch == '.') || (ch == '_')) {
     // definately accept these
     return true;
   } else if ((ch == '@') || (ch == '&') || (ch == '-')) {
     // we'll consider these
     return true;
   } else {
     return false;
   }
 }
Exemplo n.º 2
0
 /* return string representation of fault code */
 public static String GetFaultString(long fault) {
   if (fault > 0L) {
     StringBuffer sb = new StringBuffer();
     if ((fault & TYPE_MASK) == TYPE_J1708) {
       // SID: "128/s123/1"
       // PID: "128/123/1"
       boolean active = DTOBDFault.DecodeActive(fault);
       int mid = DTOBDFault.DecodeSystem(fault);
       int fmi = DTOBDFault.DecodeFMI(fault);
       if (!active) {
         sb.append("[");
       }
       sb.append(mid); // MID
       sb.append("/");
       if (DTOBDFault.IsJ1708_SID(fault)) {
         int sid = DTOBDFault.DecodePidSid(fault);
         sb.append("s").append(sid); // SID "128/s123/1"
       } else {
         int pid = DTOBDFault.DecodePidSid(fault);
         sb.append(pid); // PID "128/123/1"
       }
       sb.append("/");
       sb.append(fmi); // FMI
       if (!active) {
         sb.append("]");
       }
       return sb.toString();
     } else if ((fault & TYPE_MASK) == TYPE_J1939) {
       // SPN: "128/1"
       boolean active = DTOBDFault.DecodeActive(fault);
       int spn = DTOBDFault.DecodeSystem(fault);
       int fmi = DTOBDFault.DecodeFMI(fault);
       sb.append(spn); // SPN
       sb.append("/");
       sb.append(fmi); // FMI
       return sb.toString();
     } else if ((fault & TYPE_MASK) == TYPE_OBDII) {
       // DTC: "P0071" [was "024C"]
       boolean active = DTOBDFault.DecodeActive(fault);
       int sysChar = DTOBDFault.DecodeSystem(fault); // System: powertrain
       int subSys = DTOBDFault.DecodeSPID(fault); // Mfg/Subsystem/Problem
       if (Character.isLetter((char) sysChar)) {
         sb.append((char) sysChar);
       } else {
         sb.append("U");
       }
       if ((subSys & 0x8000) != 0) {
         sb.append("1");
       } else {
         sb.append("0");
       }
       String subSysStr = String.valueOf(1000 + ((subSys & 0xFFF) % 1000));
       sb.append(subSysStr.substring(1));
       return sb.toString();
     } else {
       // unrecognized
     }
   }
   return "";
 }
Exemplo n.º 3
0
 public Field(String s) {
   String f[] = StringTools.parseString(s, FIELD_VALUE_SEPARATOR);
   if ((f.length > 0) && (f[0].length() > 0) && Character.isLetter(f[0].charAt(0))) {
     this.isHiRes = (f.length > 0) ? f[0].equalsIgnoreCase("H") : false;
     this.type = (f.length > 1) ? StringTools.parseInt(f[1], -1) : -1;
   } else {
     this.type = (f.length > 0) ? StringTools.parseInt(f[0], -1) : -1;
     this.isHiRes = (f.length > 1) ? f[1].equalsIgnoreCase("H") : false;
   }
   this.index = (f.length > 2) ? StringTools.parseInt(f[2], 0) : 0;
   this.length = (f.length > 3) ? StringTools.parseInt(f[3], 0) : 0;
   this.isValid = (f.length == 4) && (this.type >= 0) && (this.index >= 0) && (this.length > 0);
 }
Exemplo n.º 4
0
 /**
  * ** Filters an ID String, convertering all letters to lowercase and ** removing invalid
  * characters ** @param text The ID String to filter ** @return The filtered ID String
  */
 public static String FilterID(String text) {
   // ie. "sky.12", "acme@123"
   if (text != null) {
     StringBuffer sb = new StringBuffer();
     for (int i = 0; i < text.length(); i++) {
       char ch = Character.toLowerCase(text.charAt(i));
       if (DBRecordKey.isValidIDChar(ch)) {
         sb.append(ch);
       }
     }
     return sb.toString();
   } else {
     return "";
   }
 }
Exemplo n.º 5
0
 private static String FilterID(String id) {
   if (id == null) {
     return null;
   } else {
     StringBuffer newID = new StringBuffer();
     int st = 0;
     for (int i = 0; i < id.length(); i++) {
       char ch = Character.toLowerCase(id.charAt(i));
       if (Character.isLetterOrDigit(ch)) {
         newID.append(ch);
         st = 1;
       } else if (st == 1) {
         newID.append("_");
         st = 0;
       } else {
         // ignore char
       }
     }
     while ((newID.length() > 0) && (newID.charAt(newID.length() - 1) == '_')) {
       newID.setLength(newID.length() - 1);
     }
     return newID.toString();
   }
 }