@Override
    public void changing(LocationEvent event) {
      String url = event.location;

      if (url == null) return;

      URLParser parser = new URLParser(url);
      if (parser.isValidURI()) {
        // stop URL first.
        event.doit = false;

        // execute the action embedded in the IntroURL
        parser.runURL();
      }
    }
Example #2
0
 /**
  * Remove a list of parameters from a URL, automatically adds the original url to the alias list
  *
  * @param parameters Array of parameters to remove from URL
  */
 public void removeDestinationUrlParamters(String[] parameters) {
   String urlRemoved = URLParser.removeParameters(_destinationUrl, parameters);
   if (urlRemoved != null && urlRemoved.compareTo(_destinationUrl) != 0) {
     _aliases.add(_destinationUrl);
     _destinationUrl = urlRemoved;
   }
 }
  /**
   * parse the CallInfo String header
   *
   * @return SIPHeader (CallInfoList object)
   * @throws SIPParseException if the message does not respect the spec.
   */
  public SIPHeader parse() throws ParseException {

    if (debug) dbg_enter("CallInfoParser.parse");
    CallInfoList list = new CallInfoList();

    try {
      headerName(TokenTypes.CALL_INFO);

      while (lexer.lookAhead(0) != '\n') {
        CallInfo callInfo = new CallInfo();
        callInfo.setHeaderName(SIPHeaderNames.CALL_INFO);

        this.lexer.SPorHT();
        this.lexer.match('<');
        URLParser urlParser = new URLParser((Lexer) this.lexer);
        GenericURI uri = urlParser.uriReference(true);
        callInfo.setInfo(uri);
        this.lexer.match('>');
        this.lexer.SPorHT();

        super.parse(callInfo);
        list.add(callInfo);

        while (lexer.lookAhead(0) == ',') {
          this.lexer.match(',');
          this.lexer.SPorHT();

          callInfo = new CallInfo();

          this.lexer.SPorHT();
          this.lexer.match('<');
          urlParser = new URLParser((Lexer) this.lexer);
          uri = urlParser.uriReference(true);
          callInfo.setInfo(uri);
          this.lexer.match('>');
          this.lexer.SPorHT();

          super.parse(callInfo);
          list.add(callInfo);
        }
      }

      return list;
    } finally {
      if (debug) dbg_leave("CallInfoParser.parse");
    }
  }
  /**
   * parse the AlertInfo String header
   *
   * @return SIPHeader (AlertInfoList object)
   * @throws SIPParseException if the message does not respect the spec.
   */
  public SIPHeader parse() throws ParseException {

    if (debug) dbg_enter("AlertInfoParser.parse");
    AlertInfoList list = new AlertInfoList();

    try {
      headerName(TokenTypes.ALERT_INFO);

      while (lexer.lookAhead(0) != '\n') {
        AlertInfo alertInfo = new AlertInfo();
        alertInfo.setHeaderName(SIPHeaderNames.ALERT_INFO);
        URLParser urlParser;
        GenericURI uri;

        do {
          this.lexer.SPorHT();
          if (this.lexer.lookAhead(0) == '<') {
            this.lexer.match('<');
            urlParser = new URLParser((Lexer) this.lexer);
            uri = urlParser.uriReference(true);
            alertInfo.setAlertInfo(uri);
            this.lexer.match('>');
          } else {
            /* This is non standard for Polycom support.
             * I know it is bad grammar but please do not remove. mranga
             */
            String alertInfoStr = this.lexer.byteStringNoSemicolon();
            alertInfo.setAlertInfo(alertInfoStr);
          }

          this.lexer.SPorHT();

          super.parse(alertInfo);
          list.add(alertInfo);

          if (lexer.lookAhead(0) == ',') {
            this.lexer.match(',');
          } else break;
        } while (true);
      }
      return list;
    } finally {
      if (debug) dbg_leave("AlertInfoParser.parse");
    }
  }
 /**
  * Test of toAbsolute method, of class URLParser.
  *
  * @throws java.lang.Exception
  */
 @Test
 public void testToAbsolute_String_String() throws Exception {
   logger.info("toAbsolute");
   String base =
       "http://*****:*****@www.example.com:8080/to/path/document?arg1=val1&arg2=val2#part";
   String relative = "../path2/doc2?a=1&b=2#part2";
   String expResult = "http://*****:*****@www.example.com:8080/to/path2/doc2?a=1&b=2#part2";
   String result = URLParser.toAbsolute(base, relative);
   assertEquals(expResult, result);
 }
  /** Test of splitDomain method, of class URLParser. */
  @Test
  public void testSplitDomain1() {
    logger.info("splitDomain1");
    String domain = "www.cars.example.co.uk";
    Map<URLParser.DomainParts, String> expResult = new HashMap<>();
    expResult.put(URLParser.DomainParts.TLD, "co.uk");
    expResult.put(URLParser.DomainParts.DOMAINNAME, "example");
    expResult.put(URLParser.DomainParts.SUBDOMAIN, "www.cars");

    Map<URLParser.DomainParts, String> result = URLParser.splitDomain(domain);
    assertEquals(expResult, result);
  }
  public JDBCKettleMetaData(ConnectionJDBC3 connectionJDBC3, String url) {
    this.connectionJDBC3 = connectionJDBC3;
    this.url = url;
    String kettleurl =
        url.substring(url.indexOf(KettleDriver.driverPrefix) + KettleDriver.driverPrefix.length());
    URLParser p = new URLParser();
    p.parse(kettleurl);
    helper = new KettleHelper();
    String fileUrl = p.getKettleUrl();
    if (fileUrl.indexOf("file://") != -1) {
      fileUrl = fileUrl.substring(fileUrl.indexOf("file://") + 7);
    } else if (fileUrl.indexOf("file:///") != -1) {
      fileUrl = fileUrl.substring(fileUrl.indexOf("file://") + 8);
    }
    File f = new File(fileUrl);

    if (f.isDirectory()) {
      stepsMap = helper.visitDirectory(f);
      isDir = true;
    } else {
      stepsMap = helper.getSteps(f);
    }
  }
  /**
   * Test of joinURL method, of class URLParser.
   *
   * @throws java.lang.Exception
   */
  @Test
  public void testJoinURL() throws Exception {
    logger.info("joinURL");
    Map<URLParser.URLParts, String> urlParts = new HashMap<>();
    urlParts.put(URLParser.URLParts.PROTOCOL, "http");
    urlParts.put(URLParser.URLParts.PATH, "/to/path/document");
    urlParts.put(URLParser.URLParts.HOST, "www.example.com");
    urlParts.put(URLParser.URLParts.PORT, "8080");
    urlParts.put(URLParser.URLParts.USERINFO, "user:password");
    urlParts.put(URLParser.URLParts.FILENAME, "/to/path/document?arg1=val1&arg2=val2");
    urlParts.put(URLParser.URLParts.QUERY, "arg1=val1&arg2=val2");
    urlParts.put(URLParser.URLParts.AUTHORITY, "user:[email protected]:8080");
    urlParts.put(URLParser.URLParts.REF, "part");

    String expResult =
        "http://*****:*****@www.example.com:8080/to/path/document?arg1=val1&arg2=val2#part";
    String result = URLParser.joinURL(urlParts);
    assertEquals(expResult, result);
  }
 private void checkCanonicalization(String in, String want) throws URISyntaxException {
   HandyURL h = URLParser.parse(in);
   canon.canonicalize(h);
   String got = h.getURLString();
   assertEquals(want, got);
 }