Example usage for org.apache.commons.validator UrlValidator UrlValidator

List of usage examples for org.apache.commons.validator UrlValidator UrlValidator

Introduction

In this page you can find the example usage for org.apache.commons.validator UrlValidator UrlValidator.

Prototype

public UrlValidator() 

Source Link

Document

Create a UrlValidator with default properties.

Usage

From source file:conversores.UrlConverter.java

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
    String HTTP = "http://";
    StringBuilder url = new StringBuilder();

    if (!value.startsWith(HTTP, 0)) {
        url.append(HTTP);/*from  ww w  .java 2  s. co  m*/
    }
    url.append(value);

    UrlValidator urlValidator = new UrlValidator();

    if (!urlValidator.isValid(url.toString())) {

        FacesMessage msg = new FacesMessage("Error al converir la url.", "Formato URL invalido.");
        msg.setSeverity(FacesMessage.SEVERITY_ERROR);
        throw new ConverterException(msg);
    }

    URLBookmark urlBookmark = new URLBookmark(url.toString());

    return urlBookmark;
}

From source file:de.knurt.heinzelmann.ui.html.Text2Html.java

public String linkUrls(String string) {
    return this.linkUrls(new UrlValidator(), string, "_parent");
}

From source file:com.pkrete.locationservice.admin.util.WebUtil.java

/**
 * Checks the form of the given URL address.
 *
 * @param url the URL to be checked//from  w  ww  . j  av  a  2s  .c o m
 * @return if the URL is badly formed returns false, otherwise returns true
 */
public static boolean validateUrl(String url) {
    UrlValidator urlValidator = new UrlValidator();
    return urlValidator.isValid(url);
}

From source file:es.bsc.demiurge.openstackjclouds.OpenStackGlance.java

/**
 * Uploads an image to OpenStack. The image is downloaded from a given URL.
 *
 * @param imageToUpload the image to upload
 * @return the ID of the image just created. This ID is the same as the ID assigned in OpenStack.
 *///from   www .  j  a  va 2s.c om
public String createImageFromUrl(ImageToUpload imageToUpload) throws CloudMiddlewareException {
    String responseContent;
    if (new UrlValidator().isValid(imageToUpload.getUrl())) {
        responseContent = HttpUtils.executeHttpRequest("POST",
                HttpUtils.buildURI("http", openStackCredentials.getOpenStackIP(),
                        openStackCredentials.getGlancePort(), "/v1/images"),
                getHeadersForCreateImageRequest(imageToUpload), "");
        log.debug("Creating image from Valid URL " + imageToUpload.getUrl() + " :\n" + responseContent);
        return getIdFromCreateImageImageResponse(responseContent);
    } else {

        try {
            String glanceCommandOutput = CommandExecutor.executeCommand("glance --os-username "
                    + openStackCredentials.getKeyStoneUser() + " --os-password "
                    + openStackCredentials.getKeyStonePassword() + " " + "--os-tenant-id "
                    + openStackCredentials.getKeyStoneTenantId() + " " + "--os-auth-url http://"
                    + openStackCredentials.getOpenStackIP() + ":35357/v2.0 " + "image-create --name="
                    + imageToUpload.getName() + " " + "--disk-format=" + getImageFormat(imageToUpload.getUrl())
                    + " " + "--container-format=bare --is-public=True " + "--file " + imageToUpload.getUrl());

            log.debug("Creating image from non-valid URL. Glance command:\n" + glanceCommandOutput);
            String outputIdLine = glanceCommandOutput.split(System.getProperty("line.separator"))[9];
            String id = outputIdLine.split("\\|")[2]; // Get the line where that specifies the ID
            return id.substring(1, id.length() - 1); // Remove first and last characters (spaces)
        } catch (Exception e) {
            throw new CloudMiddlewareException(
                    "Error creating image from " + imageToUpload.getUrl() + ": " + e.getMessage(), e);
        }
    }
}

From source file:dept_integration.Dept_Integbean.java

@SuppressWarnings("empty-statement")
public String deptValidation(Connection con, Dept_Integbean tbeans) throws Exception {
    // String flag = "";

    String deptname = tbeans.getDept_name();
    System.out.println("Department Name is..." + deptname);
    String pattern = "[a-zA-Z]+(\\s[a-zA-Z]+)+";
    String nameEx = "/^[a-zA-Z]+$/";
    Boolean b = !deptname.matches(nameEx);
    System.out.println("boolean value is...." + b);
    // String nameEx = "/^[a-zA-Z]+$/";
    String nameEx1 = "/^[a-zA-Z0-9]+$/";
    String msg = "Please Fill The Appropriate";//(!deptname.matches(nameEx))

    if ((b == false) || (deptname == null) || (deptname == "")) {
        msg = msg + "Department Name\n";
    }//from   w  w  w  . j  ava2 s. co m
    String deptcod = tbeans.getDept_code();
    Boolean c = !deptcod.matches(nameEx1);
    if ((c == false) || (deptcod == null) || (deptcod == "")) {
        msg = msg + "Department Code" + "\n";
    }
    String ipadrs = tbeans.getIp_adrs();

    IPAddressValidator ipv = new IPAddressValidator();
    if (!ipv.validate(ipadrs)) {
        msg = msg + "Ip Address" + "\n";
    }
    String url = tbeans.getResponse_url();
    UrlValidator urlValidator = new UrlValidator();
    if (!urlValidator.isValid(url)) {
        msg = msg + "Response Url" + "\n";
    }
    if (!urlValidator.isValid(tbeans.getError_url())) {
        msg = msg + "Error Url" + "\n";
    }
    return msg;

}

From source file:es.bsc.demiurge.openstackjclouds.OpenStackGlance.java

/**
 * Returns the headers for the call used to created an image
 *
 * @param imageToUpload the image to be uploaded
 * @return the headers//w w  w .  j a v a  2 s.  co  m
 */
private Map<String, String> getHeadersForCreateImageRequest(ImageToUpload imageToUpload) {
    Map<String, String> result = new HashMap<>();
    result.put("X-Auth-Token", getToken());
    result.put("x-image-meta-container_format", "bare");
    result.put("User-Agent", "python-glanceclient");
    result.put("x-image-meta-is_public", "True");
    if (new UrlValidator().isValid(imageToUpload.getUrl())) {
        result.put("x-image-meta-location", imageToUpload.getUrl());
    }
    result.put("Content-Type", "application/octet-stream");
    // For the moment, assume that if the image comes from a URL the format is qcow2
    result.put("x-image-meta-disk_format", "qcow2");
    result.put("x-image-meta-name", imageToUpload.getName());
    return result;
}

From source file:mx.jalan.gdcu.Vista.Gestor.Detalles.java

private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
    ok = true;/*from w ww.  j a v  a2 s . c o m*/
    String mensaje = "";
    UrlValidator validador = new UrlValidator();

    if (!txtFuente.getText().trim().isEmpty()) {
        if (!validador.isValid(txtFuente.getText())) {
            mensaje += "La url fuente no es valida\n";

        } else {
            fuente = txtFuente.getText();
        }
    }

    if (!txtDescarga.getText().trim().isEmpty()) {
        if (!validador.isValid(txtDescarga.getText())) {
            mensaje += "La url descarga no es valida\n";
        } else {
            descarga = txtDescarga.getText();
        }
    }

    if (!mensaje.equals("")) {
        JOptionPane.showMessageDialog(this, mensaje, "Revisa los campos", JOptionPane.ERROR_MESSAGE);
        return;
    }

    this.dispose();
}

From source file:es.bsc.demiurge.openstackjclouds.OpenStackJclouds.java

/**
 * Returns the ID of the image that a VM should use when it is deployed.
 *
 * @param vm the VM to be deployed/*w  w w  .j  a  va2  s  .  c  o  m*/
 * @return the ID of the image
 */
private String getImageIdForDeployment(Vm vm) throws CloudMiddlewareException {
    // If the vm description contains a URL, create the image using Glance and return its ID
    if (new UrlValidator().isValid(vm.getImage())) {
        return glanceConnector.createImageFromUrl(new ImageToUpload(vm.getImage(), vm.getImage()));
    } else { // If the VM description contains the ID of an image, return it unless there is an error
        String imageId = vm.getImage();
        if (!existsImageWithId(imageId)) {
            throw new IllegalArgumentException("There is not an image with the specified ID");
        }
        if (!glanceConnector.imageIsActive(imageId)) {
            throw new IllegalArgumentException("The image specified is not active");
        }
        return imageId;
    }
}

From source file:com.codejumble.opentube.Main.java

/**
 * Initializes the parameters of the program such as folder paths, program
 * icons, etc.//from   w ww.ja va 2s.co m
 */
private void initParameters() {
    logger.info("Initilizing parameters");
    String relativePathToDownloadFolder = (String) configuration.getProperty("downloadFolder");
    configuredFolderForDownloadedMedia = new File(relativePathToDownloadFolder).getAbsolutePath()
            + File.separator;
    String relativePathToTmpFolder = (String) configuration.getProperty("tmpFolder");
    tmpFilesFolder = new File(relativePathToTmpFolder).getAbsolutePath() + File.separator;
    String relativePathToLogsFolder = (String) configuration.getProperty("logsFolder");
    logsFolder = new File(relativePathToLogsFolder).getAbsolutePath() + File.separator;
    defaultDownloadManager = new DownloadManager(this, tmpFilesFolder, configuredFolderForDownloadedMedia);
    //        ImageIcon img = new ImageIcon("C:\\Users\\lope115\\Documents\\NetBeansProjects\\tmpot\\src\\main\\resources\\media" + File.separator + "icon.png");
    //        this.appLogo = img;
    urlValidator = new UrlValidator();
}

From source file:org.encuestame.core.integration.transformer.TinyUrlTransformer.java

private boolean validUrl(String token) {
    UrlValidator urlValidator = new UrlValidator();
    return urlValidator.isValid(token);
}