コード例 #1
0
ファイル: CssUrlRewriter.java プロジェクト: jngo00/brjs
  public CssUrlRewriter(File cssBasePath, final CharSequence input)
      throws BundlerProcessingException {
    Matcher urlMatcher = URL_PATTERN.matcher(input);
    while (urlMatcher.find()) {
      String relativePath = urlMatcher.group(1);
      // this is used to ignore any spacing so can be read as a URI correctly.
      String withoutSpacesOrNewLines = relativePath.replaceAll("(\\s)", "");

      boolean parsableUrl = true;
      try {
        /* if it parses as a URI don't rewrite */
        URI uri = new URI(withoutSpacesOrNewLines);
        if (uri.isAbsolute()) {
          parsableUrl = false;
        }
      } catch (URISyntaxException ex) {
        throw new RuntimeException(
            "URI \"" + relativePath + "\" is invalid (" + ex.getReason() + ").", ex);
      }

      if (parsableUrl) {
        String parsedUrl = parseUrl(cssBasePath, relativePath);
        urlMatcher.appendReplacement(css, parsedUrl);
      }
    }
    urlMatcher.appendTail(css);
  }
コード例 #2
0
  /**
   * Valide le format de l'adresse du serveur et sépare le nom d'hôte ainsi que le port pour
   * utilisation future. Utilise la classe URI de Java pour séparer les deux sections plus
   * facilement.
   *
   * <p>Largement inspiré de cet exemple:
   * http://stackoverflow.com/questions/2345063/java-common-way-to-validate-
   * and-convert-hostport-to-inetsocketaddress
   *
   * @param adresse Adresse du serveur fournit par l'utilisateur.
   * @return Si l'adresse est au format exigé ou non.
   */
  public static boolean estValide(String adresse) {

    boolean valide = true;

    try {

      // En cas d'adresse vide
      if (adresse.equals("")) {
        throw new URISyntaxException("", "L'adresse ne peut pas être vide.");
      }

      URI uri = new URI("my://" + adresse);
      host = uri.getHost();
      port = uri.getPort();

      // Si le nom d'hôte est invalide
      if (uri.getHost() == null || uri.getHost() == "")
        throw new URISyntaxException(
            uri.toString(), "L'adresse doit contenir un hôte au format valide.");
      // Si le port est invalide
      else if (uri.getPort() == -1)
        throw new URISyntaxException(uri.toString(), "L'adresse doit contenir un port valide.");

    } catch (URISyntaxException ex) {

      valide = false;
      JOptionPane.showMessageDialog(null, ex.getReason(), "Serveur", JOptionPane.WARNING_MESSAGE);
    }

    return valide;
  }
コード例 #3
0
 public void testInvalidUriString() {
   try {
     new ConfigUriBeacon.Builder().uriString(TestData.malformedUrlString).build();
     Assert.fail("Should have failed");
   } catch (URISyntaxException e) {
     assertEquals("Not a valid URI", e.getReason());
   }
 }
コード例 #4
0
 public void testLongInvalidLongUrlCreateConfigUriBeacon() {
   try {
     ConfigUriBeacon.createConfigUriBeacon(TestData.longInvalidUrlAdbPacketBytes);
     Assert.fail("Should fail");
   } catch (URISyntaxException e) {
     assertEquals("Uri size is larger than 18 bytes", e.getReason());
   }
 }
コード例 #5
0
 public void testLongInvalidUrlByteArray() {
   try {
     new ConfigUriBeacon.Builder().uriString(TestData.longButInvalidUrlByteArray).build();
     Assert.fail("Should fail");
   } catch (URISyntaxException e) {
     assertEquals("Uri size is larger than 18 bytes", e.getReason());
   }
 }
コード例 #6
0
 public void testInvalidHighPeriod() {
   try {
     new ConfigUriBeacon.Builder()
         .uriString(TestData.emptyTestString)
         .advertisedTxPowerLevels(makeTxPowerLevelArray(TestData.validTxPowerLevels))
         .txPowerMode(TestData.validTxPowerMode)
         .beaconPeriod(ConfigUriBeacon.UINT16_MAX_VALUE)
         .build();
   } catch (URISyntaxException e) {
     assertEquals("Invalid broadcasting period", e.getReason());
   }
 }
コード例 #7
0
 public void testSetHighInvalidPowerMode() {
   try {
     new ConfigUriBeacon.Builder()
         .uriString(TestData.emptyTestString)
         .beaconPeriod(TestData.validPeriod)
         .advertisedTxPowerLevels(makeTxPowerLevelArray(TestData.validTxPowerLevels))
         .txPowerMode((byte) (ConfigUriBeacon.POWER_MODE_HIGH + 1))
         .build();
     Assert.fail("Should fail");
   } catch (URISyntaxException e) {
     assertEquals("Unknown power mode", e.getReason());
   }
 }
コード例 #8
0
 public void testLongerTxPowerLevels() throws URISyntaxException {
   try {
     new ConfigUriBeacon.Builder()
         .uriString(TestData.emptyTestString)
         .advertisedTxPowerLevels(new byte[5])
         .txPowerMode(TestData.validTxPowerMode)
         .beaconPeriod(TestData.validPeriod)
         .build();
     Assert.fail("Should have failed");
   } catch (URISyntaxException e) {
     assertEquals("Invalid length for Tx Advertised Power Levels", e.getReason());
   }
 }
コード例 #9
0
 public void testHighTxPowerLevels() {
   try {
     new ConfigUriBeacon.Builder()
         .uriString(TestData.emptyTestString)
         .advertisedTxPowerLevels(
             makeTxPowerLevelArray((byte) (ConfigUriBeacon.TX_POWER_LEVEL_MAX_VALUE + 1)))
         .txPowerMode(TestData.validTxPowerMode)
         .beaconPeriod(TestData.validPeriod)
         .build();
     Assert.fail("Should have failed");
   } catch (URISyntaxException e) {
     assertEquals("Invalid TxPower Level", e.getReason());
   }
 }
コード例 #10
0
ファイル: UnparsedText.java プロジェクト: nuxleus/saxonica
  public static URI getAbsoluteURI(String href, String baseURI) throws XPathException {
    URI absoluteURI;
    try {
      absoluteURI = ResolveURI.makeAbsolute(href, baseURI);
    } catch (java.net.URISyntaxException err) {
      XPathException e = new XPathException(err.getReason() + ": " + err.getInput(), err);
      e.setErrorCode("XTDE1170");
      throw e;
    }

    if (absoluteURI.getFragment() != null) {
      XPathException e =
          new XPathException("URI for unparsed-text() must not contain a fragment identifier");
      e.setErrorCode("XTDE1170");
      throw e;
    }

    // The URL dereferencing classes throw all kinds of strange exceptions if given
    // ill-formed sequences of %hh escape characters. So we do a sanity check that the
    // escaping is well-formed according to UTF-8 rules

    EscapeURI.checkPercentEncoding(absoluteURI.toString());
    return absoluteURI;
  }
コード例 #11
0
  /** Check the user input and set messages in case of invalid input. */
  protected void checkPage() {
    if (isURISelected()) {
      assert uri != null;
      if (uriText.getText().length() == 0) {
        selectionIncomplete(null);
        return;
      } else if (uriText.getText().endsWith(" ")) { // $NON-NLS-1$
        selectionIncomplete(UIText.RepositorySelectionPage_UriMustNotHaveTrailingSpacesMessage);
        return;
      }

      try {
        final URIish finalURI = new URIish(uriText.getText().trim());
        String proto = finalURI.getScheme();
        if (proto == null && scheme.getSelectionIndex() >= 0)
          proto = scheme.getItem(scheme.getSelectionIndex());

        if (uri.getPath() == null) {
          selectionIncomplete(
              NLS.bind(
                  UIText.RepositorySelectionPage_fieldRequired,
                  unamp(UIText.RepositorySelectionPage_promptPath),
                  proto));
          return;
        }

        if (Protocol.FILE.handles(finalURI)) {
          String badField = null;
          if (uri.getHost() != null) badField = UIText.RepositorySelectionPage_promptHost;
          else if (uri.getUser() != null) badField = UIText.RepositorySelectionPage_promptUser;
          else if (uri.getPass() != null) badField = UIText.RepositorySelectionPage_promptPassword;
          if (badField != null) {
            selectionIncomplete(
                NLS.bind(UIText.RepositorySelectionPage_fieldNotSupported, unamp(badField), proto));
            return;
          }

          final File d = FS.DETECTED.resolve(new File("."), uri.getPath()); // $NON-NLS-1$
          if (!d.exists()) {
            selectionIncomplete(
                NLS.bind(UIText.RepositorySelectionPage_fileNotFound, d.getAbsolutePath()));
            return;
          }

          selectionComplete(finalURI, null);
          return;
        }

        if (uri.getHost() == null) {
          selectionIncomplete(
              NLS.bind(
                  UIText.RepositorySelectionPage_fieldRequired,
                  unamp(UIText.RepositorySelectionPage_promptHost),
                  proto));
          return;
        }

        if (Protocol.GIT.handles(finalURI)) {
          String badField = null;
          if (uri.getUser() != null) badField = UIText.RepositorySelectionPage_promptUser;
          else if (uri.getPass() != null) badField = UIText.RepositorySelectionPage_promptPassword;
          if (badField != null) {
            selectionIncomplete(
                NLS.bind(UIText.RepositorySelectionPage_fieldNotSupported, unamp(badField), proto));
            return;
          }
        }

        if (Protocol.HTTP.handles(finalURI) || Protocol.HTTPS.handles(finalURI)) {
          UserPasswordCredentials credentials = getSecureStoreCredentials(finalURI);
          if (credentials != null) {
            String u = credentials.getUser();
            String p = credentials.getPassword();
            String uriUser = finalURI.getUser();
            if (uriUser == null) {
              if (setSafeUser(u) || setSafePassword(p)) setStoreInSecureStore(true);
            } else if (uriUser.length() != 0 && uriUser.equals(u)) {
              if (setSafePassword(p)) setStoreInSecureStore(true);
            }
          }
        }

        selectionComplete(finalURI, null);
        return;
      } catch (URISyntaxException e) {
        selectionIncomplete(e.getReason());
        return;
      } catch (Exception e) {
        Activator.logError(
            NLS.bind(UIText.RepositorySelectionPage_errorValidating, getClass().getName()), e);
        selectionIncomplete(UIText.RepositorySelectionPage_internalError);
        return;
      }
    } else {
      assert remoteButton.getSelection();
      selectionComplete(null, remoteConfig);
      return;
    }
  }
コード例 #12
0
  // handles ingress intel url intents, search intents, geo intents and javascript file intents
  private void handleIntent(final Intent intent, final boolean onCreate) {
    final String action = intent.getAction();
    if (Intent.ACTION_VIEW.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
      final Uri uri = intent.getData();
      Log.d("intent received url: " + uri.toString());

      if (uri.getScheme().equals("http") || uri.getScheme().equals("https")) {
        if (uri.getHost() != null
            && (uri.getHost().equals("ingress.com") || uri.getHost().endsWith(".ingress.com"))) {
          Log.d("loading url...");
          loadUrl(uri.toString());
          return;
        }
      }

      if (uri.getScheme().equals("geo")) {
        try {
          handleGeoUri(uri);
          return;
        } catch (final URISyntaxException e) {
          Log.w(e);
          new AlertDialog.Builder(this)
              .setTitle(R.string.intent_error)
              .setMessage(e.getReason())
              .setNeutralButton(
                  android.R.string.ok,
                  new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                      dialog.dismiss();
                    }
                  })
              .create()
              .show();
        }
      }

      // intent MIME type and uri path may be null
      final String type = intent.getType() == null ? "" : intent.getType();
      final String path = uri.getPath() == null ? "" : uri.getPath();
      if (path.endsWith(".user.js") || type.contains("javascript")) {
        final Intent prefIntent = new Intent(this, PluginPreferenceActivity.class);
        prefIntent.setDataAndType(uri, intent.getType());
        startActivity(prefIntent);
      }
    }

    if (Intent.ACTION_SEARCH.equals(action)) {
      String query = intent.getStringExtra(SearchManager.QUERY);
      query = query.replace("'", "''");
      final SearchView searchView = (SearchView) mSearchMenuItem.getActionView();
      searchView.setQuery(query, false);
      searchView.clearFocus();

      switchToPane(Pane.MAP);
      mIitcWebView.loadUrl("javascript:search('" + query + "');");
      return;
    }

    if (onCreate) {
      loadUrl(mIntelUrl);
    }
  }