Beispiel #1
0
 /** ** Scrambles String */
 public static String _ens64(String d) {
   if (!StringTools.isBlank(d)) {
     return Base64.encode(StringTools.getBytes(d), getBase64Alphabet(), Base64Pad);
   } else {
     return "";
   }
 }
Beispiel #2
0
 /**
  * ** Returns an I18N.Text instance used for lazy localization.<br>
  * ** (use in XML loaders to avoid expression matches when auto-updating
  * 'LocalStrings_XX.properties') ** @param pkg The package name ** @param key The localization key
  * ** @param dft The default localized text ** @param showError If true, a stacktrace will be
  * display if the key is invalid. ** @return An I18N.Text instance used for lazy localization
  */
 public static I18N.Text parseText(String pkg, String key, String dft, boolean showError) {
   if (dft == null) {
     Print.logStackTrace("Default value is null!");
     return new I18N.Text(pkg, key, "");
   } else if (!StringTools.isBlank(key)) {
     return new I18N.Text(pkg, key, dft);
   } else if (!StringTools.startsWithIgnoreCase(dft, I18N_KEY_STARTE)
       && !StringTools.startsWithIgnoreCase(dft, I18N_KEY_STARTC)) {
     if (showError) {
       Print.logStackTrace(
           "Invalid/missing key definition!\n"
               + "Package: "
               + pkg
               + "\n"
               + "Key    : "
               + key
               + "\n"
               + "Default: "
               + dft);
     }
     return new I18N.Text(pkg, null, dft);
   } else {
     int ks = I18N_KEY_STARTE.length();
     int ke = dft.indexOf(I18N_KEY_END, ks);
     if (ke < ks) {
       return new I18N.Text(pkg, null, dft); // ']' is missing, return string as-is
     }
     String k = dft.substring(ks, ke).trim();
     String v = dft.substring(ke + I18N_KEY_END.length()).trim();
     return new I18N.Text(pkg, k, v);
   }
 }
Beispiel #3
0
 /** ** Descrambles String */
 public static String _des64(String e) {
   if (!StringTools.isBlank(e)) {
     byte b[] = Base64.decode(e, getBase64Alphabet(), Base64Pad);
     return StringTools.toStringValue(b, ' ');
   } else {
     return "";
   }
 }
Beispiel #4
0
 /** ** Decodes an RTP encoded argument */
 public static RTProperties parseRTP(String rtpArg) {
   if (!StringTools.isBlank(rtpArg)) {
     String s = _des64(rtpArg);
     if (!StringTools.isBlank(s)) {
       return new RTProperties(s);
     }
   }
   return null;
 }
Beispiel #5
0
 /** ** Descrambles String */
 public static String _des64(String e) {
   if (!StringTools.isBlank(e)) {
     try {
       byte b[] = Base64.decode(e, getBase64Alphabet(), Base64Pad);
       return StringTools.toStringValue(b, ' ');
     } catch (Base64.Base64DecodeException bde) {
       Print.logError("Invalid Base64 characters", bde);
       return "";
     }
   } else {
     return "";
   }
 }
Beispiel #6
0
 /**
  * ** Adds an argument to the URI ** @param key The key name of the argument to add ** @param
  * value The value of the new key ** @param encode True if <code>value</code> shoudl be hex
  * encoded ** @param obfuscate True if <code>value</code> should be obfuscated ** @return This
  * URIArg, with the argument added
  */
 protected URIArg _addArg(String key, String value, boolean encode, boolean obfuscate) {
   if (!StringTools.isBlank(key)) {
     String val = encode ? this.encodeArg(value, obfuscate) : value;
     this.getKeyValList().add(new KeyVal(key, val));
   }
   return this;
 }
  public void addDataSet(Color color, String legend, Data data[]) throws Exception {

    /* init */
    this._initChart();

    /* dataset color/legend/markers */
    String hexColor = ColorTools.toHexString(color, false);
    this.addDatasetColor(hexColor);
    this.addDatasetLegend(legend);
    this.addShapeMarker("d," + hexColor + "," + this.dataSetCount + ",-1,7,1");

    /* data */
    StringBuffer xv = new StringBuffer();
    StringBuffer yv = new StringBuffer();
    for (int i = 0; i < data.length; i++) {
      GetScaledExtendedEncodedValue(yv, data[i].getTempC(), this.minTempC, this.maxTempC);
      GetScaledExtendedEncodedValue(xv, data[i].getTimestamp(), this.minDateTS, this.maxDateTS);
    }
    if (StringTools.isBlank(this.chd)) {
      this.chd = "e:";
    } else {
      this.chd += ",";
    }
    this.chd += xv.toString() + "," + yv.toString();

    /* count data set */
    this.dataSetCount++;
  }
Beispiel #8
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, "");
   }
 }
Beispiel #9
0
 public String toString() {
   String locStr = RTConfig.getString(RTKey.SESSION_LOCALE, null);
   if (StringTools.isBlank(locStr)) {
     return this.getDefault();
   } else {
     Locale loc = I18N.getLocale(locStr);
     return this.toString(loc);
   }
 }
Beispiel #10
0
 /**
  * ** Gets the Java Locale instance based on the specified locale name ** @param loc The name of
  * the Locale ** @param dft The default Locale returned ** @return The Java Locale instance
  */
 public static Locale getLocale(String loc, Locale dft) {
   String locale = !StringTools.isBlank(loc) ? loc : RTConfig.getString(RTKey.LOCALE, "");
   if (StringTools.isBlank(locale)) {
     return dft;
   } else {
     int p = locale.indexOf("_");
     try {
       if (p < 0) {
         String language = locale;
         return new Locale(language);
       } else {
         String language = locale.substring(0, p);
         String country = locale.substring(p + 1);
         return new Locale(language, country);
       }
     } catch (Throwable th) {
       return dft;
     }
   }
 }
Beispiel #11
0
 /**
  * ** Create a new instance of the specified class name ** @param className The class name to
  * instantiate ** @return The new instance of the specified class name
  */
 public static Object newInstance(String className)
     throws NoSuchMethodException, ClassNotFoundException, InstantiationException,
         IllegalAccessException {
   if (!StringTools.isBlank(className)) {
     // try {
     return Class.forName(className).newInstance();
     // } catch (InvocationTargetException ite) {
     //    Throwable th = ite.getCause();
     //    if (th == null) { th = ite; }
     //    throw th;
     // }
   } else {
     throw new ClassNotFoundException("Class name is null/blank");
   }
 }
Beispiel #12
0
 /**
  * ** Decodes the specified hex-encoded argument (not yet fully tested) ** @param sb The
  * StringBuffer where the decoded String argument will be placed ** @param s The String to decode
  * ** @return The StringBuffer where the decoded String will be placed
  */
 public static StringBuffer decodeArg(StringBuffer sb, String s) {
   if (sb == null) {
     sb = new StringBuffer();
   }
   if (s != null) {
     char ch[] = new char[s.length()];
     s.getChars(0, s.length(), ch, 0);
     for (int i = 0; i < ch.length; i++) {
       if (ch[i] == '%') {
         if ((i + 2) < ch.length) {
           int ch1 = StringTools.hexIndex(ch[i + 1]);
           int ch2 = StringTools.hexIndex(ch[i + 2]);
           sb.append((char) (((ch1 << 4) | ch2) & 0xFF));
           i += 2;
         } else {
           i = ch.length - 1;
         }
       } else {
         sb.append(ch[i]);
       }
     }
   }
   return sb;
 }
Beispiel #13
0
 /** ** Sets the 'host' */
 public boolean setHost(String _host) {
   String uri = this.getURI();
   if (!StringTools.isBlank(_host) && URIArg.isAbsoluteURL(uri)) {
     try {
       URL oldURI = new URL(uri);
       String proto = oldURI.getProtocol();
       String host = _host;
       int port = oldURI.getPort();
       String file = oldURI.getFile();
       URL newURI = new URL(proto, host, port, file);
       this._setURI(newURI.toString());
       return true;
     } catch (MalformedURLException mue) {
       // error
     }
   }
   return false;
 }
Beispiel #14
0
 /**
  * ** Gets the Localized value for the specified key. The default String text is returned ** if
  * the specified key does not exist ** @param key The LocalStrings key ** @param dft The default
  * String text to return if the LocalStrings key does not exist ** @return The Localized String
  * text
  */
 public String getString(String key, String dft) {
   if (!StringTools.isBlank(key) && (this.resBundle != null)) {
     RTProperties cfgProps = RTConfig.getConfigFileProperties();
     if (!cfgProps.hasProperty(key) || cfgProps.getBoolean(key, true)) {
       try {
         String s = this.resBundle.getString(key);
         if (s != null) {
           return I18N.decodeNewLine(s);
         }
       } catch (Throwable th) {
         // Print.logException("",th);
         // MissingResourceException - if no object for the given key can be found
         // ClassCastException - if the object found for the given key is not a string
       }
     }
   }
   return I18N.decodeNewLine(dft);
 }
Beispiel #15
0
 /** ** Sets the URI from a string */
 public void setURI(String uri) {
   int p = (uri != null) ? uri.indexOf("?") : -1;
   if (p >= 0) {
     this._setURI(uri.substring(0, p));
     String a[] = StringTools.parseString(uri.substring(p + 1), "&");
     for (int i = 0; i < a.length; i++) {
       String key = "", val = "";
       int e = a[i].indexOf("=");
       if (e >= 0) {
         key = a[i].substring(0, e);
         val = a[i].substring(e + 1);
       } else {
         key = a[i];
         val = "";
       }
       this._addArg(key, val, false /*encode*/, false /*obfuscate*/); // assume already encoded
     }
   } else {
     this._setURI(uri);
   }
 }
 public String getTimeFormat() {
   return StringTools.isBlank(this.timeFormat) ? this.timeFormat : "HH:mm:ss";
 }
Beispiel #17
0
 public boolean hasKey() {
   return !StringTools.isBlank(this.getKey());
 }
Beispiel #18
0
 public boolean hasPackage() {
   return !StringTools.isBlank(this.getPackage());
 }
Beispiel #19
0
 /**
  * ** Converts "\\n" patterns into literal newlines (\n) ** @param s The StringBuffer to convert
  * "\\n" to "\n" ** @return The decoded StringBuffer
  */
 protected static StringBuffer decodeNewLine(StringBuffer s) {
   return StringTools.replace(s, "\\n", "\n");
 }
Beispiel #20
0
 /**
  * ** Adds a file extension to the end of this URI, ".xml" etc. The ** extension will be added to
  * the URI if doesn't already end with it ** @param ext The extension to add
  */
 public void addExtension(String ext) {
   if (!StringTools.isBlank(ext) && !this.uri.endsWith(ext)) {
     this.uri += ext;
   }
 }
  protected void _initChart() throws Exception {

    /* already initialized? */
    if (this.didInitChart) {
      return;
    }

    /* axis tick counts */
    int yTickCnt = this.getTemperatureTickCount();
    int xTickCnt = this.getDateTickCount();

    /* horizontal grid */
    this.setGrid(0, yTickCnt);

    /* Y-axis labels */
    StringBuffer ya = new StringBuffer();
    double deltaC = this.maxTempC - this.minTempC;
    for (int y = 0; y <= yTickCnt; y++) {
      double C = this.minTempC + (deltaC * ((double) y / (double) yTickCnt));
      double v = (this.dispUnits == TEMP_C) ? C : C2F(C);
      ya.append("|").append(StringTools.format(v, "0.0"));
    }
    if ((this.maxTempC > 0.0) && (this.minTempC < 0.0)) {
      double sep = Math.abs(this.minTempC) / (this.maxTempC - this.minTempC);
      this.addShapeMarker(
          "r,AA4444,0,"
              + StringTools.format(sep, "0.000")
              + ","
              + StringTools.format(sep + 0.002, "0.000"));
    }

    /* X-axis labels */
    StringBuffer xat = new StringBuffer();
    StringBuffer xad = new StringBuffer();
    double deltaTS = (double) (this.maxDateTS - this.minDateTS);
    long lastDN = 0L;
    for (int x = 0; x <= xTickCnt; x++) {
      long ts = this.minDateTS + Math.round(deltaTS * ((double) x / (double) xTickCnt));
      DateTime dt = new DateTime(ts, this.timeZone);
      long dn = DateTime.getDayNumberFromDate(dt);
      xat.append("|").append(dt.format(this.getTimeFormat()));
      xad.append("|").append(dt.format(this.getDateFormat()));
      if (dn != lastDN) {
        long ds = dt.getDayStart();
        if (ds > this.minDateTS) {
          double sep = (double) (ds - this.minDateTS) / deltaTS;
          this.addShapeMarker(
              "R,444444,0,"
                  + StringTools.format(sep, "0.000")
                  + ","
                  + StringTools.format(sep + 0.001, "0.000"));
        }
        lastDN = dn;
      }
    }

    /* axis labels */
    this.setAxisLabels(
        "y,x,x", "0:" + ya.toString() + "|1:" + xad.toString() + "|2:" + xat.toString());

    /* did init */
    this.didInitChart = true;
  }
 public String getDateFormat() {
   return StringTools.isBlank(this.dateFormat) ? this.dateFormat : "MM/dd";
 }