當前位置: 首頁>>代碼示例>>Java>>正文


Java UrlValidator.ALLOW_LOCAL_URLS屬性代碼示例

本文整理匯總了Java中org.apache.commons.validator.routines.UrlValidator.ALLOW_LOCAL_URLS屬性的典型用法代碼示例。如果您正苦於以下問題:Java UrlValidator.ALLOW_LOCAL_URLS屬性的具體用法?Java UrlValidator.ALLOW_LOCAL_URLS怎麽用?Java UrlValidator.ALLOW_LOCAL_URLS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.commons.validator.routines.UrlValidator的用法示例。


在下文中一共展示了UrlValidator.ALLOW_LOCAL_URLS屬性的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validateURL

public boolean validateURL(String urlToValidate) {
// return FormattedText.validateURL(urlToValidate); // KNL-1105
      if (StringUtils.isBlank(urlToValidate)) return false;

if ( ABOUT_BLANK.equals(urlToValidate) ) return true;

      // Check if the url is "Escapable" - run through the URL-URI-URL gauntlet
      String escapedURL = sanitizeHrefURL(urlToValidate);
      if ( escapedURL == null ) return false;

      // For a protocol-relative URL, we validate with protocol attached 
      // RFC 1808 Section 4
      if ((urlToValidate.startsWith("//")) && (urlToValidate.indexOf("://") == -1))
      {
          urlToValidate = PROTOCOL_PREFIX + urlToValidate;
      }

      // For a site-relative URL, we validate with host name and protocol attached 
      // SAK-13787 SAK-23752
      if ((urlToValidate.startsWith("/")) && (urlToValidate.indexOf("://") == -1))
      {
          urlToValidate = HOST_PREFIX + urlToValidate;
      }

      // Validate the url
      UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
      return urlValidator.isValid(urlToValidate);
  }
 
開發者ID:sakaiproject,項目名稱:sakai,代碼行數:28,代碼來源:PortletIFrame.java

示例2: validateURL

public boolean validateURL(String urlToValidate) {
      if (StringUtils.isBlank(urlToValidate)) return false;

if ( ABOUT_BLANK.equals(urlToValidate) ) return true;

      // Check if the url is "Escapable" - run through the URL-URI-URL gauntlet
      String escapedURL = sanitizeHrefURL(urlToValidate);
      if ( escapedURL == null ) return false;

      // For a protocol-relative URL, we validate with protocol attached 
      // RFC 1808 Section 4
      if ((urlToValidate.startsWith("//")) && (urlToValidate.indexOf("://") == -1))
      {
          urlToValidate = PROTOCOL_PREFIX + urlToValidate;
      }

      // For a site-relative URL, we validate with host name and protocol attached 
      // SAK-13787 SAK-23752
      if ((urlToValidate.startsWith("/")) && (urlToValidate.indexOf("://") == -1))
      {
          urlToValidate = HOST_PREFIX + urlToValidate;
      }

      // Validate the url
      UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
      return urlValidator.isValid(urlToValidate);
  }
 
開發者ID:sakaiproject,項目名稱:sakai,代碼行數:27,代碼來源:FormattedTextImpl.java

示例3: setEndpoint

/**
 * Sets the rpc endpoint to which this object will try to make requests.
 * @param endpoint The rpc endpoint.
 * @throws MalformedURLException When the URL string is not valid.
 */
void setEndpoint( String endpoint ) throws MalformedURLException{
			
	UrlValidator validator = new UrlValidator(new String[]{"http"},UrlValidator.ALLOW_LOCAL_URLS);
	if( validator.isValid(endpoint ))
		this.endpoint = new URL(endpoint);
	else
		throw new MalformedURLException();
	
}
 
開發者ID:ececilla,項目名稱:WorizonJsonRpc,代碼行數:14,代碼來源:HttpRequest.java

示例4: isValidUrl

@Contract("null, _ -> false")
public static boolean isValidUrl(@Nullable String url, String[] allowedSchemes) {
    if (StringUtil.isBlank(url)) {
        return false;
    }

    UrlValidator urlValidator = new UrlValidator(allowedSchemes, UrlValidator.ALLOW_LOCAL_URLS);
    return urlValidator.isValid(url);
}
 
開發者ID:Codeforces,項目名稱:codeforces-commons,代碼行數:9,代碼來源:UrlUtil.java

示例5: validate

protected void validate(String user, String password, INodeEntry entry) throws SaltStepValidationException {
    checkNotEmpty(SALT_API_END_POINT_OPTION_NAME, saltEndpoint, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING,
            entry);
    checkNotEmpty(SALT_API_FUNCTION_OPTION_NAME, function, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry);
    checkNotEmpty(SALT_API_EAUTH_OPTION_NAME, eAuth, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry);
    checkNotEmpty(SALT_USER_OPTION_NAME, user, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry);
    checkNotEmpty(SALT_PASSWORD_OPTION_NAME, password, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry);

    UrlValidator urlValidator = new UrlValidator(endPointSchemes, UrlValidator.ALLOW_LOCAL_URLS);
    if (!urlValidator.isValid(saltEndpoint)) {
        throw new SaltStepValidationException(SALT_API_END_POINT_OPTION_NAME, String.format(
                "%s is not a valid endpoint.", saltEndpoint), SaltApiNodeStepFailureReason.ARGUMENTS_INVALID,
                entry.getNodename());
    }
}
 
開發者ID:rundeck-plugins,項目名稱:salt-step,代碼行數:15,代碼來源:SaltApiNodeStepPlugin.java

示例6: parseStringToURI

public static URI parseStringToURI(String uri) {
    String[] schemes = {"http","https"};
    UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS);
    if(urlValidator.isValid(uri)){
        try {
            return new URI(uri);
        } catch (URISyntaxException e) {
            return null;
        }
    }
    return null;
}
 
開發者ID:micromata,項目名稱:JiraRestClient,代碼行數:12,代碼來源:URIHelper.java

示例7: isValidUrl

private boolean isValidUrl(String url) {
    String[] schemes = {"http", "https"};
    long options = UrlValidator.ALLOW_LOCAL_URLS;
    UrlValidator urlValidator = new UrlValidator(schemes, options);
    return urlValidator.isValid(url);
}
 
開發者ID:weweave,項目名稱:tubewarder,代碼行數:6,代碼來源:WebserviceOutputHandler.java

示例8: QueueURLValidator

public QueueURLValidator() {
    this(new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES + UrlValidator.ALLOW_LOCAL_URLS));
}
 
開發者ID:motech,項目名稱:motech,代碼行數:3,代碼來源:QueueURLValidator.java

示例9: loadRequiredProperties

/**
 * @return {@code true} if required properties are loaded
 */
private boolean loadRequiredProperties() {
    if (logger.isDebugEnabled()) {
        logger.debug("Loading properties...");
    }
    // Load properties
    String stratosURL = null;
    String username = null;
    String password = null;

    stratosURL = System.getenv(CliConstants.STRATOS_URL_ENV_PROPERTY);
    username = System.getenv(CliConstants.STRATOS_USERNAME_ENV_PROPERTY);
    password = System.getenv(CliConstants.STRATOS_PASSWORD_ENV_PROPERTY);

    if (StringUtils.isBlank(stratosURL)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Required configuration not found.");
        }
        // Stratos Controller details are not set.
        System.out.format("Could not find required \"%s\" variable in your environment.%n",
                CliConstants.STRATOS_URL_ENV_PROPERTY);
        return false;
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Required configuration found. Validating {}", stratosURL);
    }

    int slashCount = StringUtils.countMatches(stratosURL, "/");
    int colonCount = StringUtils.countMatches(stratosURL, ":");

    UrlValidator urlValidator = new UrlValidator(new String[]{"https"}, UrlValidator.ALLOW_LOCAL_URLS);

    // port must be provided, so colonCount must be 2
    // context path must not be provided, so slashCount must not be >3

    if (!urlValidator.isValid(stratosURL) || colonCount != 2 || slashCount > 3) {
        if (logger.isDebugEnabled()) {
            logger.debug("Stratos Controller URL {} is not valid", stratosURL);
        }
        System.out.format(
                "The \"%s\" variable in your environment is not a valid URL. You have provided \"%s\".%n"
                        + "Please provide the Stratos Controller URL as follows%nhttps://<host>:<port>%n",
                CliConstants.STRATOS_URL_ENV_PROPERTY, stratosURL);
        return false;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Stratos Controller URL {} is valid.", stratosURL);
        logger.debug("Adding the values to context.");
    }
    context.put(CliConstants.STRATOS_URL_ENV_PROPERTY, stratosURL);
    context.put(CliConstants.STRATOS_USERNAME_ENV_PROPERTY, username);
    context.put(CliConstants.STRATOS_PASSWORD_ENV_PROPERTY, password);
    return true;
}
 
開發者ID:apache,項目名稱:stratos,代碼行數:57,代碼來源:StratosApplication.java

示例10: VerificationServiceImpl

/**
 * @throws DrugMatchConfigurationException
 * @throws KeyManagementException
 * @throws NoSuchAlgorithmException
 * @throws IOException
 */
public VerificationServiceImpl() throws DrugMatchConfigurationException, KeyManagementException, NoSuchAlgorithmException, IOException {
	String serviceUrl = DrugMatchProperties.getVerificationService();
	if (serviceUrl == null) {
		throw new DrugMatchConfigurationException("Unable to proceed, cause: '" + DrugMatchProperties.VERIFICATION_SERVICE + "' isn't set!");
	}
	UrlValidator urlValidator = new UrlValidator(new String[] {"http", "https"}, UrlValidator.ALLOW_LOCAL_URLS);
	if (!urlValidator.isValid(serviceUrl.toLowerCase(Locale.ENGLISH))) {
		throw new DrugMatchConfigurationException("Unable to proceed, cause: '" + DrugMatchProperties.VERIFICATION_SERVICE + "' isn't a valid HTTP/HTTPS URL!");
	}
	String login = DrugMatchProperties.getVerificationLogin();
	if (login == null) {
		throw new DrugMatchConfigurationException("Unable to proceed, cause: '" + DrugMatchProperties.VERIFICATION_LOGIN + "' isn't set!");
	}
	String password = DrugMatchProperties.getVerificationPassword();
	if (password == null) {
		throw new DrugMatchConfigurationException("Unable to proceed, cause: '" + DrugMatchProperties.VERIFICATION_PASSWORD + "' isn't set!");
	}
	URL url = new URL(serviceUrl);
	int port;
	if (url.getPort() > 0) {
		port = url.getPort();
	} else {
		port = ("https".equals(url.getProtocol().toLowerCase(Locale.ENGLISH))) ? 443 : 80;
	}
	this.credentialsProvider = new BasicCredentialsProvider();
	this.credentialsProvider.setCredentials(
			new AuthScope(url.getHost(), port),
			new UsernamePasswordCredentials(login, password));
	// test if CA root is present in JRE, otherwise invoke SSL workaround
	try (CloseableHttpClient httpclient = HttpClients.createDefault();) {
		HttpGet httpget = new HttpGet(url.getProtocol() + "://" + url.getHost() + ":" + port);
		log.debug("Executing request: {}", httpget.getRequestLine());
		try (CloseableHttpResponse response = httpclient.execute(httpget);) {
			log.debug("Executed request: {} status: {}", httpget.getRequestLine(), response.getStatusLine());
			EntityUtils.consume(response.getEntity());
		} catch (SSLHandshakeException e) {
			if ("sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target".equals(e.getMessage())) {
				log.debug("Unable to establish certificate trust chain, most likely cause: root certificate unavailable from JRE keystore. Proceeding with disabled TrustManager.");
				this.customSslSocketFactory = new SSLConnectionSocketFactory(initializeCerts());
			} else {
				throw e;
			}
		}
	}
}
 
開發者ID:IHTSDO,項目名稱:drugMatch,代碼行數:51,代碼來源:VerificationServiceImpl.java

示例11: validateUrlParameter

/**
 * Helper function to validate the url passed to it.
 *
 * @param url          The url that needs to be validated.
 * @param sdkErrorCode The error message that needs to be thrown.
 * @throws ApiException
 */
public static void validateUrlParameter(String url, SdkErrorCodes sdkErrorCode) throws ApiException {
 UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
 if(!urlValidator.isValid(url))
   throw new ApiException(sdkErrorCode);
}
 
開發者ID:adobe-sign,項目名稱:AdobeSignJavaSdk,代碼行數:12,代碼來源:ApiValidatorHelper.java

示例12: isURLValid

/**
 * Check if URI is a valid URL.
 *
 * @param uriString
 * @return
 */
protected static Boolean isURLValid(String uriString) {
    String[] schemes = {"http", "https"};
    UrlValidator urlValidator = new UrlValidator(schemes,UrlValidator.ALLOW_LOCAL_URLS);
    return urlValidator.isValid(uriString);
}
 
開發者ID:fusepoolP3,項目名稱:p3-dictionary-matcher-transformer,代碼行數:11,代碼來源:Utils.java


注:本文中的org.apache.commons.validator.routines.UrlValidator.ALLOW_LOCAL_URLS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。