本文整理汇总了Java中org.apache.commons.validator.routines.UrlValidator.isValid方法的典型用法代码示例。如果您正苦于以下问题:Java UrlValidator.isValid方法的具体用法?Java UrlValidator.isValid怎么用?Java UrlValidator.isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.validator.routines.UrlValidator
的用法示例。
在下文中一共展示了UrlValidator.isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
/**
* Validates a given JSON Object against the default profile schema.
* @param jsonObjectToValidate
* @throws IOException
* @throws DataPackageException
* @throws ValidationException
*/
public void validate(JSONObject jsonObjectToValidate) throws IOException, DataPackageException, ValidationException{
// If a profile value is provided.
if(jsonObjectToValidate.has(Package.JSON_KEY_PROFILE)){
String profile = jsonObjectToValidate.getString(Package.JSON_KEY_PROFILE);
String[] schemes = {"http", "https"};
UrlValidator urlValidator = new UrlValidator(schemes);
if (urlValidator.isValid(profile)) {
this.validate(jsonObjectToValidate, new URL(profile));
}else{
this.validate(jsonObjectToValidate, profile);
}
}else{
// If no profile value is provided, use default value.
this.validate(jsonObjectToValidate, Profile.PROFILE_DEFAULT);
}
}
示例2: fillTextFieldWithClipboard
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
private void fillTextFieldWithClipboard() {
String data = "<empty clipboard>";
try {
data = (String) Toolkit.getDefaultToolkit().getSystemClipboard().getData(DataFlavor.stringFlavor);
URL url = new URL(data);
UrlValidator urlValidator = new UrlValidator();
if (urlValidator.isValid(data)) {
textField.setText(url.toString());
setTextFieldFont(textField.getFont(), TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
textField.setCaretPosition(textField.getText().length());
textField.selectAll();
log.debug("Got URL from clipboard: " + url);
}
} catch (UnsupportedFlavorException | IllegalStateException | HeadlessException | IOException e) {
textField.setText("");
log.warn("Can not read URL from clipboard: [" + data + "]", e);
}
}
示例3: onOK
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
private void onOK() {
try {
URL url = new URL(textField.getText());
UrlValidator urlValidator = new UrlValidator();
if (urlValidator.isValid(textField.getText())) {
UrlsProceed.createWebloc(path, url);
dispose();
} else {
throw new MalformedURLException();
}
} catch (MalformedURLException e) {
log.warn("Can not parse URL: [" + textField.getText() + "]", e);
String message = incorrectUrlMessage + ": [";
String incorrectUrl = textField.getText()
.substring(0, Math.min(textField.getText().length(), 10));
//Fixes EditDialog long url message showing issue
message += textField.getText().length() > incorrectUrl.length() ? incorrectUrl + "...]" : incorrectUrl + "]";
UserUtils.showWarningMessageToUser(this, errorTitle,
message);
}
}
示例4: getAlignedReadCount
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
public static long getAlignedReadCount(String bam) throws IOException{
/* ------------------------------------------------------ */
/* This chunk prepares SamReader from local bam or URL bam */
UrlValidator urlValidator = new UrlValidator();
SamReaderFactory srf=SamReaderFactory.make();
srf.validationStringency(ValidationStringency.SILENT);
SamReader samReader;
if(urlValidator.isValid(bam)){
samReader = SamReaderFactory.makeDefault().open(
SamInputResource.of(new URL(bam)).index(new URL(bam + ".bai"))
);
} else {
samReader= srf.open(new File(bam));
}
/* ------------------------------------------------------ */
List<SAMSequenceRecord> sequences = samReader.getFileHeader().getSequenceDictionary().getSequences();
long alnCount= 0;
for(SAMSequenceRecord x : sequences){
alnCount += samReader.indexing().getIndex().getMetaData(x.getSequenceIndex()).getAlignedRecordCount();
}
samReader.close();
return alnCount;
}
示例5: bamHasIndex
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
public static boolean bamHasIndex(String bam) throws IOException{
/* ------------------------------------------------------ */
/* This chunk prepares SamReader from local bam or URL bam */
UrlValidator urlValidator = new UrlValidator();
SamReaderFactory srf=SamReaderFactory.make();
srf.validationStringency(ValidationStringency.SILENT);
SamReader samReader;
if(urlValidator.isValid(bam)){
samReader = SamReaderFactory.makeDefault().open(
SamInputResource.of(new URL(bam)).index(new URL(bam + ".bai"))
);
} else {
samReader= srf.open(new File(bam));
}
/* ------------------------------------------------------ */
// SamReaderFactory srf=SamReaderFactory.make();
// srf.validationStringency(ValidationStringency.SILENT);
// SamReader samReader = srf.open(new File(bam));
boolean hasIndex= samReader.hasIndex();
samReader.close();
return hasIndex;
}
示例6: removeExternalAnchors
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
private String removeExternalAnchors(String text) {
Pattern eanchorPattern = Pattern.compile("\\[.*?\\]");
Matcher eanchorMatcher = eanchorPattern.matcher(text);
while (eanchorMatcher.find()) {
String anchor = eanchorMatcher.group();
String manchor = anchor.replaceAll("\\[", "");
manchor = manchor.replaceAll("\\]", "");
String[] manchorParts = manchor.split("\\s");
UrlValidator validator = new UrlValidator();
if (validator.isValid(manchorParts[0])) {
text = text.replace(anchor, manchor);
}
}
return text;
}
示例7: onboardVNFD
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
public VirtualNetworkFunctionDescriptor onboardVNFD(byte[] bytes, String projectId)
throws NotFoundException, PluginException, VimException, IOException, IncompatibleVNFPackage,
org.openbaton.tosca.exceptions.NotFoundException, BadRequestException,
AlreadyExistingException, BadFormatException, InterruptedException,
EntityUnreachableException, ExecutionException {
InputStream input = new ByteArrayInputStream(bytes);
readFiles(input);
VNFDTemplate vnfdt = Utils.bytesToVNFDTemplate(this.template);
VirtualNetworkFunctionDescriptor vnfd = toscaParser.parseVNFDTemplate(vnfdt);
String scriptsLink = null;
UrlValidator urlValidator = new UrlValidator();
if (urlValidator.isValid(vnfd.getVnfPackageLocation())) {
scriptsLink = vnfd.getVnfPackageLocation();
}
saveVNFD(vnfd, projectId, scripts, scriptsLink);
input.close();
this.template.close();
this.metadata.close();
return vnfd;
}
示例8: checkIntegrityVNFPackage
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
private void checkIntegrityVNFPackage(
VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor) {
if (virtualNetworkFunctionDescriptor.getVnfPackageLocation() != null) {
UrlValidator urlValidator = new UrlValidator();
if (urlValidator.isValid(
virtualNetworkFunctionDescriptor.getVnfPackageLocation())) { // this is a script link
VNFPackage vnfPackage = new VNFPackage();
vnfPackage.setScriptsLink(virtualNetworkFunctionDescriptor.getVnfPackageLocation());
vnfPackage.setName(virtualNetworkFunctionDescriptor.getName());
vnfPackage.setProjectId(virtualNetworkFunctionDescriptor.getProjectId());
if (vnfPackage.getId() == null) vnfPackage = vnfPackageRepository.save(vnfPackage);
virtualNetworkFunctionDescriptor.setVnfPackageLocation(vnfPackage.getId());
}
} else {
log.warn("vnfPackageLocation is null. Are you sure?");
}
}
示例9: validateURL
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
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);
}
示例10: isValidHostUrl
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
/**
* Method checks given URL is a valid representation for a host URL
*
* @param url host URL to check the validity
* @return <code>true</code> if valid, else <code>false</code>
*/
public static boolean isValidHostUrl(String url) {
if (url.contains(AppFactoryExtensionConstants.COLON_SEPARATOR) && !url.startsWith(AppFactoryExtensionConstants.COLON_SEPARATOR)) {
if (url.startsWith(AppFactoryExtensionConstants.URL_PREFIX_HTTP) ||
url.startsWith(AppFactoryExtensionConstants.URL_PREFIX_HTTPS) ||
url.startsWith(AppFactoryExtensionConstants.URL_PREFIX_FTP)) {
UrlValidator urlValidator = new UrlValidator(8L);
return urlValidator.isValid(url);
} else {
return false;
}
} else {
return false;
}
}
示例11: checkSiteUrl
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
/**
*
* @param userSubscriptionCommand
* @param errors
* @return
*/
private boolean checkSiteUrl(CreateUserCommand userSubscriptionCommand, Errors errors) {
if (!checkSiteUrl) {
return true;
}
if (userSubscriptionCommand.getSiteUrl() == null ||
userSubscriptionCommand.getSiteUrl().trim().isEmpty()) {
errors.rejectValue(SITE_URL_KEY, MISSING_URL_KEY);
return false;
} else {
String url = userSubscriptionCommand.getSiteUrl().trim();
String[] schemes = {"http","https"};
UrlValidator urlValidator = new UrlValidator (schemes, UrlValidator.ALLOW_2_SLASHES);
if (!urlValidator.isValid(url)) {
errors.rejectValue(SITE_URL_KEY, INVALID_URL_KEY);
return false;
}
}
return true;
}
示例12: doCheckUrl
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
public FormValidation doCheckUrl(@QueryParameter final String value) throws IOException, ServletException {
if (StringUtils.isEmpty(value)) {
return FormValidation.error("API URL must not be empty");
}
final UrlValidator validator = new UrlValidator(URL_SCHEMES);
if (!validator.isValid(value)) {
return FormValidation.error(
"API URL must have valid scheme (%s).",
StringUtils.join(URL_SCHEMES, ", "));
}
return FormValidation.ok();
}
示例13: getUrl
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
public static String getUrl(String url) {
// Test to see if it's a valid URL.
UrlValidator defaultValidator = new UrlValidator(ALLOW_LOCAL_URLS);
if (!defaultValidator.isValid(url)) {
LOG.error("The url [" + url + "] isn't a valid URL.");
System.exit(1);
}
return url;
}
示例14: expandPredicateKey
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
public String expandPredicateKey(String predicateKey) throws OData2SparqlException {
UrlValidator urlValidator = new UrlValidator();
String entityKey = predicateKey.substring(1, predicateKey.length() - 1);
String decodedEntityKey = SparqlEntity.URLDecodeEntityKey(entityKey);
String expandedEntityKey = expandPrefix(decodedEntityKey);
if (urlValidator.isValid(expandedEntityKey)) {
return expandedEntityKey;
} else {
throw new OData2SparqlException("Invalid key: " + predicateKey, null);
}
}
示例15: prepareEntityLinksSparql
import org.apache.commons.validator.routines.UrlValidator; //导入方法依赖的package包/类
public SparqlStatement prepareEntityLinksSparql( ) throws EdmException, ODataApplicationException, OData2SparqlException {
List<UriResource> resourceParts = uriInfo.getUriResourceParts();
UriResource lastResourcePart = resourceParts.get(resourceParts.size() - 1);
int minSize = 1;
if (lastResourcePart.getSegmentValue().equals("$ref")) { // which it should do
minSize++;
}
UriResourceNavigation uriNavigation = (UriResourceNavigation) resourceParts.get(resourceParts.size() - minSize);
EdmNavigationProperty edmNavigationProperty = uriNavigation.getProperty();
UrlValidator urlValidator = new UrlValidator();
String expandedKey = rdfModel.getRdfPrefixes().expandPredicateKey( ((UriResourceEntitySet) resourceParts.get(0)).getKeyPredicates().get(0).getText());
String key = rdfEntityType.entityTypeName;
if (urlValidator.isValid(expandedKey)) {
} else {
throw new EdmException("Invalid key: " + ((UriResourceEntitySet) resourceParts.get(0)).getKeyPredicates().get(0).getText(), null);
}
RdfAssociation rdfProperty = rdfEntityType.findNavigationProperty(edmNavigationProperty.getName());
String expandedProperty = rdfProperty.getAssociationIRI();
StringBuilder sparql = new StringBuilder(
// "CONSTRUCT {?" + key + "_s <" + expandedProperty + "> ?" + key + "_o . ?"+ key +"_o <http://targetEntity> true . }\n");
"CONSTRUCT { ?" + key + "_o <http://targetEntity> true . }\n");
if (rdfProperty.IsInverse()) {
String expandedInverseProperty = rdfProperty.getInversePropertyOfURI().toString();
sparql.append(
"WHERE {?" + key + "_o ?" + key + "_p ?" + key + "_s . \nVALUES(?" + key + "_s ?" + key + "_p){(");
sparql.append("<" + expandedKey + "> ");
sparql.append("<" + expandedInverseProperty + ">)}\n}");
} else {
sparql.append(
"WHERE {?" + key + "_s ?" + key + "_p ?" + key + "_o .\n VALUES(?" + key + "_s ?" + key + "_p){(");
sparql.append("<" + expandedKey + "> ");
sparql.append("<" + expandedProperty + ">)}\n}");
}
return new SparqlStatement(sparql.toString());
}