示例#1
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;
 }
示例#2
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;
 }
示例#3
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, "");
   }
 }
示例#4
0
  /** ** Main entry point for testing/debugging ** @param argv Comand-line arguments */
  public static void main(String argv[]) {
    RTConfig.setCommandLineArgs(argv);

    /* decode URI argument strings */
    if (RTConfig.hasProperty(ARG_DECODE)) {
      String a = RTConfig.getString(ARG_DECODE, "");
      String s = URIArg.decodeArg(new StringBuffer(), a).toString();
      Print.sysPrintln("ASCII: " + s);
      System.exit(0);
    }

    /* encode Base64 strings */
    if (RTConfig.hasProperty(ARG_ENCODE)) {
      String s = RTConfig.getString(ARG_ENCODE, "");
      String a = URIArg.encodeArg(new StringBuffer(), s).toString();
      Print.sysPrintln("Args: " + a);
      System.exit(0);
    }

    /* RTP decode */
    if (RTConfig.hasProperty(ARG_RTPDEC)) {
      URIArg rtpUrl = new URIArg(RTConfig.getString(ARG_RTPDEC, ""));
      URIArg decUrl = rtpUrl.rtpDecode("rtp");
      Print.sysPrintln("URL: " + decUrl.toString());
      System.exit(0);
    }

    /* RTP encode */
    if (RTConfig.hasProperty(ARG_RTPENC)) {
      URIArg decUrl = new URIArg(RTConfig.getString(ARG_RTPENC, ""));
      URIArg rtpUrl = decUrl.rtpEncode("rtp");
      Print.sysPrintln("URL: " + rtpUrl.toString());
      System.exit(0);
    }

    /* no options */
    usage();
  }
示例#5
0
 /** ** Sets the 'port' */
 public boolean setPort(int _port) {
   String uri = this.getURI();
   if ((_port > 0) && URIArg.isAbsoluteURL(uri)) {
     try {
       URL oldURI = new URL(uri);
       String proto = oldURI.getProtocol();
       String host = oldURI.getHost();
       int port = _port;
       String file = oldURI.getFile();
       URL newURI = new URL(proto, host, port, file);
       this._setURI(newURI.toString());
       return true;
     } catch (MalformedURLException mue) {
       // error
     }
   }
   return false;
 }
示例#6
0
 /**
  * ** Hex-encodes a URL argument ** @param sb The StringBuffer where the hex encoded String
  * argument will be placed ** @param s The URL argument to encode ** @param obfuscateAll True to
  * force hex-encoding on all argument characters ** @return The StringBuffer where the hex-encoded
  * String will be placed
  */
 public static StringBuffer encodeArg(StringBuffer sb, String s, boolean obfuscateAll) {
   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 (obfuscateAll || URIArg.shouldEncodeArgChar(ch[i])) {
         // escape non-alphanumeric characters
         sb.append("%");
         sb.append(Integer.toHexString(0x100 + (ch[i] & 0xFF)).substring(1));
       } else {
         // letters and digits are ok as-is
         sb.append(ch[i]);
       }
     }
   }
   return sb;
 }
示例#7
0
 /**
  * ** Decodes the specified hex-encoded argument (not yet fully tested) ** @param s The String to
  * decode ** @return The decoded String
  */
 private String decodeArg(String s) {
   StringBuffer sb = URIArg.decodeArg(null, s);
   return sb.toString();
 }
示例#8
0
 /**
  * ** Hex-encodes a URL argument ** @param s The URL argument to encode ** @param obfuscateAll
  * True to force hex-encoding on all argument characters ** @return The hex-encoded String
  */
 private String encodeArg(String s, boolean obfuscateAll) {
   StringBuffer sb = URIArg.encodeArg(null, s, obfuscateAll);
   return sb.toString();
 }
示例#9
0
 /** ** Copy Constructor */
 public URIArg(URIArg uriArg) {
   this.setUniqueKeys(uriArg.hasUniqueKeys());
   this._setURI(uriArg.uri);
   this.setKeys(uriArg.keys); // deep copy
 }
示例#10
0
 /**
  * ** Obfuscates (hex-encodes) all characters in the String ** @param s The String to hex-encode
  * ** @return The hex-encoded String
  */
 public static String obfuscateArg(String s) {
   return URIArg.encodeArg(new StringBuffer(), s, true).toString();
 }
示例#11
0
 /**
  * ** Hex-encodes a URL argument (if required) ** @param sb The StringBuffer where the hex encoded
  * String argument will be placed ** @param s The URL argument to encode (if required) ** @return
  * The StringBuffer where the hex-encoded String will be placed
  */
 public static StringBuffer encodeArg(StringBuffer sb, String s) {
   return URIArg.encodeArg(sb, s, false);
 }
示例#12
0
 /**
  * ** Hex-encodes a URL argument (if required) ** @param s The URL argument to encode (if
  * required) ** @return The hex encoded argument
  */
 public static String encodeArg(String s) {
   return URIArg.encodeArg(null, s, false).toString();
 }
示例#13
0
  /* 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;
    }
  }
示例#14
0
  private int _writeXML(PrintWriter out, int level, ReportData rd, boolean urlOnly)
      throws ReportException {
    boolean isSoapRequest = rd.isSoapRequest();
    RequestProperties reqState = rd.getRequestProperties();
    PrivateLabel privLabel = rd.getPrivateLabel();
    I18N i18n = privLabel.getI18N(ReportTable.class);
    String PFX1 = XMLTools.PREFIX(isSoapRequest, level * ReportTable.INDENT);
    String PFX2 = XMLTools.PREFIX(isSoapRequest, (level + 1) * ReportTable.INDENT);

    /* begin */
    out.print(PFX1);
    out.print(
        XMLTools.startTAG(
            isSoapRequest,
            "Report", // TAG_Report
            XMLTools.ATTR("name", rd.getReportName())
                + // ATTR_name
                XMLTools.ATTR("type", rd.getReportType()), // ATTR_type
            false,
            true));

    /* constraints */
    ReportConstraints rc = rd.getReportConstraints();
    String dtFmt = DateTime.DEFAULT_DATE_FORMAT + "," + DateTime.DEFAULT_TIME_FORMAT;
    TimeZone tzone = rd.getTimeZone();
    String tzStr = rd.getTimeZoneString();
    long tmBeg = rc.getTimeStart();
    long tmEnd = rc.getTimeEnd();
    DateTime dtStr = new DateTime(tmBeg, tzone);
    DateTime dtEnd = new DateTime(tmEnd, tzone);

    /* Account */
    out.print(PFX2);
    out.print(XMLTools.startTAG(isSoapRequest, "Account", "", false, false)); // TAG_Account
    out.print(XmlFilter(isSoapRequest, rd.getAccountID()));
    out.print(XMLTools.endTAG(isSoapRequest, "Account", true)); // TAG_Account

    /* TimeFrom */
    out.print(PFX2);
    out.print(
        XMLTools.startTAG(
            isSoapRequest,
            "TimeFrom", // TAG_TimeFrom
            XMLTools.ATTR("timestamp", String.valueOf(tmBeg))
                + // ATTR_timestamp
                XMLTools.ATTR("timezone", tzStr), // ATTR_timezone
            false,
            false));
    out.print((tmBeg > 0L) ? XmlFilter(isSoapRequest, dtStr.format(dtFmt)) : "");
    out.print(XMLTools.endTAG(isSoapRequest, "TimeFrom", true)); // TAG_TimeFrom

    /* TimeTo */
    out.print(PFX2);
    out.print(
        XMLTools.startTAG(
            isSoapRequest,
            "TimeTo", // TAG_TimeTo
            XMLTools.ATTR("timestamp", String.valueOf(tmEnd))
                + // ATTR_timestamp
                XMLTools.ATTR("timezone", tzStr), // ATTR_timezone
            false,
            false));
    out.print((tmEnd > 0L) ? XmlFilter(isSoapRequest, dtEnd.format(dtFmt)) : "");
    out.print(XMLTools.endTAG(isSoapRequest, "TimeTo", true)); // TAG_TimeTo

    /* ValidGPSRequired */
    out.print(PFX2);
    out.print(
        XMLTools.startTAG(
            isSoapRequest, "ValidGPSRequired", "", false, false)); // TAG_ValidGPSRequired
    out.print(XmlFilter(isSoapRequest, rc.getValidGPSRequired()));
    out.print(XMLTools.endTAG(isSoapRequest, "ValidGPSRequired", true)); // TAG_ValidGPSRequired

    /* SelectionLimit */
    out.print(PFX2);
    out.print(
        XMLTools.startTAG(
            isSoapRequest,
            "SelectionLimit", // TAG_SelectionLimit
            XMLTools.ATTR("type", rc.getSelectionLimitType()),
            false,
            false));
    out.print(XmlFilter(isSoapRequest, rc.getSelectionLimit()));
    out.print(XMLTools.endTAG(isSoapRequest, "SelectionLimit", true)); // TAG_SelectionLimit

    /* Ascending */
    out.print(PFX2);
    out.print(XMLTools.startTAG(isSoapRequest, "Ascending", "", false, false)); // TAG_Ascending
    out.print(XmlFilter(isSoapRequest, rc.getOrderAscending()));
    out.print(XMLTools.endTAG(isSoapRequest, "Ascending", true)); // TAG_Ascending

    /* ReportLimit */
    out.print(PFX2);
    out.print(XMLTools.startTAG(isSoapRequest, "ReportLimit", "", false, false)); // TAG_ReportLimit
    out.print(XmlFilter(isSoapRequest, rc.getReportLimit()));
    out.print(XMLTools.endTAG(isSoapRequest, "ReportLimit", true)); // TAG_ReportLimit

    /* Where */
    if (rc.hasWhere()) {
      out.print(PFX2);
      out.print(XMLTools.startTAG(isSoapRequest, "Where", "", false, false)); // TAG_Where
      out.print(XmlFilter(isSoapRequest, rc.getWhere()));
      out.print(XMLTools.endTAG(isSoapRequest, "Where", true)); // TAG_Where
    }

    /* RuleSelector */
    if (rc.hasRuleSelector()) {
      out.print(PFX2);
      out.print(
          XMLTools.startTAG(isSoapRequest, "RuleSelector", "", false, false)); // TAG_RuleSelector
      out.print(XmlFilter(isSoapRequest, rc.getRuleSelector()));
      out.print(XMLTools.endTAG(isSoapRequest, "RuleSelector", true)); // TAG_RuleSelector
    }

    /* Title */
    out.print(PFX2);
    out.print(XMLTools.startTAG(isSoapRequest, "Title", "", false, false)); // TAG_Title
    out.print(XmlFilter(isSoapRequest, rd.getReportTitle()));
    out.print(XMLTools.endTAG(isSoapRequest, "Title", true)); // TAG_Title

    /* Subtitle */
    out.print(PFX2);
    out.print(XMLTools.startTAG(isSoapRequest, "Subtitle", "", false, false)); // TAG_Subtitle
    out.print(XmlFilter(isSoapRequest, rd.getReportSubtitle()));
    out.print(XMLTools.endTAG(isSoapRequest, "Subtitle", true)); // TAG_Subtitle

    /* URL */
    if (urlOnly) {
      // Web-URL only
      HttpServletRequest request = reqState.getHttpServletRequest();
      ReportDeviceList devList = rd.getReportDeviceList();
      String deviceID = devList.isDeviceGroup() ? null : devList.getFirstDeviceID();
      String groupID = devList.isDeviceGroup() ? devList.getDeviceGroupID() : null;
      String baseURL =
          privLabel.hasDefaultBaseURL()
              ? privLabel.getDefaultBaseURL()
              : ((request != null) ? request.getRequestURL().toString() : "");
      URIArg rptURL =
          ReportURL.createReportURL(
              baseURL,
              false,
              rd.getAccountID(),
              rd.getUserID(),
              "",
              deviceID,
              groupID,
              rc.getTimeStart(),
              rc.getTimeEnd(),
              rd.getTimeZoneString(),
              rd.getReportName(),
              rc.getReportLimit(),
              rc.getSelectionLimitType().toString(),
              ReportPresentation.FORMAT_HTML);
      out.print(PFX2);
      out.print(XMLTools.startTAG(isSoapRequest, "URL", "", false, false)); // TAG_URL
      out.print(XmlFilter(isSoapRequest, rptURL.toString()));
      out.print(XMLTools.endTAG(isSoapRequest, "URL", true)); // TAG_URL
    } else {
      // Report header/body
      this.rptHeader.writeXML(out, level + 1, rd);
      this.rptBody.writeXML(out, level + 1, rd);
    }

    /* Partial */
    out.print(PFX2);
    out.print(XMLTools.startTAG(isSoapRequest, "Partial", "", false, false)); // TAG_Partial
    out.print(XmlFilter(isSoapRequest, this.rptBody.isPartial()));
    out.print(XMLTools.endTAG(isSoapRequest, "Partial", true)); // TAG_Partial

    /* end of report */
    out.print(PFX1);
    out.print(XMLTools.endTAG(isSoapRequest, "Report", true)); // TAG_Report
    return this.rptBody.getRecordCount();
  }