当前位置: 首页>>代码示例>>Java>>正文


Java UrlValidator类代码示例

本文整理汇总了Java中org.apache.commons.validator.routines.UrlValidator的典型用法代码示例。如果您正苦于以下问题:Java UrlValidator类的具体用法?Java UrlValidator怎么用?Java UrlValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UrlValidator类属于org.apache.commons.validator.routines包,在下文中一共展示了UrlValidator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendSlackImageResponse

import org.apache.commons.validator.routines.UrlValidator; //导入依赖的package包/类
private void sendSlackImageResponse(ObjectNode json, String s3Key) {
	try {
		ObjectMapper mapper = new ObjectMapper();
		ObjectNode message = mapper.createObjectNode();
		ArrayNode attachments = mapper.createArrayNode();
		ObjectNode attachment = mapper.createObjectNode();

		String emoji = json.get("text").asText();

		if (UrlValidator.getInstance().isValid(emoji)) {
			attachment.put("title_link", emoji);
			emoji = StringUtils.substringAfterLast(emoji, "/");
		}

		String username = json.get("user_name").asText();
		String responseUrl = json.get("response_url").asText();
		String slackChannelId = json.get("channel_id").asText();
		String imageUrl = String.format("https://s3.amazonaws.com/%s/%s", PROPERTIES.getProperty(S3_BUCKET_NAME), s3Key);

		message.put("response_type", "in_channel");
		message.put("channel_id", slackChannelId);
		attachment.put("title", resolveMessage("slackImageResponse", emoji, username));
		attachment.put("fallback", resolveMessage("approximated", emoji));
		attachment.put("image_url", imageUrl);
		attachments.add(attachment);
		message.set("attachments", attachments);

		HttpClient client = HttpClientBuilder.create().build();
		HttpPost slackResponseReq = new HttpPost(responseUrl);
		slackResponseReq.setEntity(new StringEntity(mapper.writeValueAsString(message), ContentType.APPLICATION_JSON));
		HttpResponse slackResponse = client.execute(slackResponseReq);
		int status = slackResponse.getStatusLine().getStatusCode();
		LOG.info("Got {} status from Slack API after sending approximation to response url.", status);
	} catch (UnsupportedOperationException | IOException e) {
		LOG.error("Exception occured when sending Slack response", e);
	}
}
 
开发者ID:villeau,项目名称:pprxmtr,代码行数:38,代码来源:Handler.java

示例2: determineLogoutUrl

import org.apache.commons.validator.routines.UrlValidator; //导入依赖的package包/类
@Override
public URL determineLogoutUrl(final RegisteredService registeredService, final WebApplicationService singleLogoutService) {
    try {
        final URL serviceLogoutUrl = registeredService.getLogoutUrl();
        if (serviceLogoutUrl != null) {
            LOGGER.debug("Logout request will be sent to [{}] for service [{}]", serviceLogoutUrl, singleLogoutService);
            return serviceLogoutUrl;
        }
        if (UrlValidator.getInstance().isValid(singleLogoutService.getOriginalUrl())) {
            return new URL(singleLogoutService.getOriginalUrl());
        }
        return null;
    } catch (final Exception e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:DefaultSingleLogoutServiceLogoutUrlBuilder.java

示例3: 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);
    }   
}
 
开发者ID:frictionlessdata,项目名称:datapackage-java,代码行数:28,代码来源:Validator.java

示例4: loadWebSite

import org.apache.commons.validator.routines.UrlValidator; //导入依赖的package包/类
/**
 * Loads the given website , either directly if the url is a valid WebSite Url or using a SearchEngine like Google
 * 
 * @param webSite
 */
public void loadWebSite(String webSite) {
	
	//Check null or empty
	//		if (webSite == null || webSite.isEmpty())
	//			return;
	
	//Search if it is a valid WebSite url
	String load = !new UrlValidator().isValid(webSite) ? null : webSite;
	
	//Load
	try {
		webEngine.load(
				load != null ? load : getSelectedEngineHomeUrl() + URLEncoder.encode(searchBar.getText(), "UTF-8"));
	} catch (UnsupportedEncodingException ex) {
		ex.printStackTrace();
	}
	
}
 
开发者ID:goxr3plus,项目名称:JavaFX-Web-Browser,代码行数:24,代码来源:WebBrowserTabController.java

示例5: validate

import org.apache.commons.validator.routines.UrlValidator; //导入依赖的package包/类
/**
 * Validates the input
 * @param object the user to validate
 * @param errors the errors
 */
public void validate(Object object, Errors errors) {

    UserDTO user = (UserDTO) object;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "googleId", "field.required",
            "googleId must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fullName", "field.required",
            "User Full Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenName", "field.required",
            "User Given Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "familyName", "field.required",
            "User Family Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageURL", "field.required",
            "User Image URL must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "field.required",
            "User Email must not be empty");
    ValidationUtils.rejectIfEmpty(errors, "role", "field.required",
            "User Role must not be empty.");

    // doing specific input validaiton, so we need to make sure all of the fields are there
    if(!errors.hasErrors()) {
        if(user.getRole() < 0 || user.getRole() > 1) {
            errors.rejectValue("role", "field.invalid", "User Role must be 0 or 1");
        }

        if(!EmailValidator.getInstance().isValid(user.getEmail())) {
            errors.rejectValue("email", "field.invalid", "User Email must be a valid email address.");
        }

        if(!UrlValidator.getInstance().isValid(user.getImageURL())) {
            errors.rejectValue("imageURL", "field.invalid", "User Image URl must be a valid web address.");
        }
    }



}
 
开发者ID:jackcmeyer,项目名称:SmartSync,代码行数:43,代码来源:UserValidator.java

示例6: validate

import org.apache.commons.validator.routines.UrlValidator; //导入依赖的package包/类
@Override
public void validate(Object o, Errors errors) {
    UpdateUserDTO user = (UpdateUserDTO) o;

    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userId", "field.required",
            "User Id must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "googleId", "field.required",
            "googleId must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "fullName", "field.required",
            "User Full Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenName", "field.required",
            "User Given Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "familyName", "field.required",
            "User Family Name must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "imageURL", "field.required",
            "User Image URL must not be empty.");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "field.required",
            "User Email must not be empty");
    ValidationUtils.rejectIfEmpty(errors, "role", "field.required",
            "User Role must not be empty.");

    // doing specific input validaiton, so we need to make sure all of the fields are there
    if(!errors.hasErrors()) {
        if(user.getRole() < 0 || user.getRole() > 1) {
            errors.rejectValue("role", "field.invalid", "User Role must be 0 or 1");
        }

        if(!EmailValidator.getInstance().isValid(user.getEmail())) {
            errors.rejectValue("email", "field.invalid", "User Email must be a valid email address.");
        }

        if(!UrlValidator.getInstance().isValid(user.getImageURL())) {
            errors.rejectValue("imageURL", "field.invalid", "User Image URl must be a valid web address.");
        }
    }
}
 
开发者ID:jackcmeyer,项目名称:SmartSync,代码行数:37,代码来源:UpdateUserValidator.java

示例7: 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);
    }
}
 
开发者ID:benchdoos,项目名称:WeblocOpener,代码行数:19,代码来源:EditDialog.java

示例8: 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);
    }

}
 
开发者ID:benchdoos,项目名称:WeblocOpener,代码行数:26,代码来源:EditDialog.java

示例9: 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;
    }
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:26,代码来源:Utils.java

示例10: hasTabixIndex

import org.apache.commons.validator.routines.UrlValidator; //导入依赖的package包/类
/** Return true if fileName has a valid tabix index. 
 * @throws IOException 
 * */
public static boolean hasTabixIndex(String fileName) throws IOException{
	
	if((new UrlValidator()).isValid(fileName) && fileName.startsWith("ftp")){
		// Because of issue #51
		return false;
	}
	
	try{
		TabixReader tabixReader= new TabixReader(fileName);
		tabixReader.readLine();
		tabixReader.close();
		return true;
	} catch (Exception e){
		return false;
	}
}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:20,代码来源:Utils.java

示例11: 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;
		
	}
 
开发者ID:dariober,项目名称:ASCIIGenome,代码行数:26,代码来源:Utils.java

示例12: 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;
}
 
开发者ID:MarcelH91,项目名称:WikiOnto,代码行数:18,代码来源:InfoboxParser.java

示例13: 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;
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:27,代码来源:CSARParser.java

示例14: 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?");
  }
}
 
开发者ID:openbaton,项目名称:NFVO,代码行数:18,代码来源:NSDUtils.java

示例15: testGetBoards

import org.apache.commons.validator.routines.UrlValidator; //导入依赖的package包/类
@Test
public void testGetBoards() throws IOException, KomiCrawlerException {
    /**
     * boards.json
     * http://pastebin.com/NLBbVFaX
     */
    KomiCrawler komiCrawler = getCrawler();
    ArrayList<Board> boards = komiCrawler.getBoards();

    Assert.assertTrue("should have boards", boards.size() > 0);
    for (Board board : boards) {
        Assert.assertTrue("should have sid", board.sid instanceof Sid);
        Assert.assertTrue("sid's value should be string", board.sid.getValue().length() > 0);
        Assert.assertTrue("baseUrl should be valid URL", UrlValidator.getInstance().isValid(board.baseUrl));
        Assert.assertTrue("srcBaseUrl should be valid URL", UrlValidator.getInstance().isValid(board.srcBaseUrl));
        Assert.assertTrue("thumbBaseUrl should be valid URL", UrlValidator.getInstance().isValid(board.thumbBaseUrl));
    }
}
 
开发者ID:touhonoob,项目名称:KomiReader,代码行数:19,代码来源:KomiCrawlerTest.java


注:本文中的org.apache.commons.validator.routines.UrlValidator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。