Package org.apache.commons.validator.routines

Examples of org.apache.commons.validator.routines.UrlValidator


    * Testing the same method of URL validator used in validate method. Its was really hard to create Error object
    */
@Test
public void testValidation() throws Exception {
      RegexValidator regex = new RegexValidator(new String[]{"http","https","((localhost)(:[0-9]+))",".*\\.linux-server(:[0-9]+)"});
      UrlValidator validator = new UrlValidator(regex, 0);
      assertTrue("localhost URL should validate",
                validator.isValid("http://localhost:8080/demogadgets/CTSSResourcesMapView.xml"));
        assertTrue("127.0.0.1 should validate",
                validator.isValid("http://127.0.0.1:8080/demogadgets/CTSSResourcesMapView.xml"));
        assertTrue("my.linux-server should validate",
                validator.isValid("http://my.linux-server:8080/demogadgets/CTSSResourcesMapView.xml"));

        assertFalse("broke.my-test should not validate",
                validator.isValid("http://broke.my-test/test/index.html"));

        assertTrue("www.apache.org should still validate",
                validator.isValid("http://www.apache.org/test/index.html"));
    }
View Full Code Here


    }
  }

  private void checkUrlValidity(String urlValue) {
    String[] schemes = { "http", "https" };
    if (urlValue == null || !new UrlValidator(schemes).isValid(urlValue)) {
      throw new IllegalArgumentException("provide a valid URL like http://example.com");
    }
  }
View Full Code Here

  }

  private void checkUrlValidity(String urlValue) {
    String[] schemes = { "http", "https" };
    if (urlValue == null || !new UrlValidator(schemes).isValid(urlValue)) {
      throw new IllegalArgumentException("provide a valid URL like http://example.com");
    }
  }
View Full Code Here

    UrlValidator urlValidator;

    public void init(FilterConfig filterConfig) throws ServletException {
        String[] schemes = {"http","https"};
        RegexValidator authorityValidator = new RegexValidator("^([\\p{Alnum}\\-\\.]*)(:\\d*)?(.*)?", false);
        urlValidator = new UrlValidator(schemes, authorityValidator, UrlValidator.ALLOW_LOCAL_URLS);
    }
View Full Code Here

    {
        if ( solr == null)
        {
            String solrService = new DSpace().getConfigurationService().getProperty("discovery.search.server");

            UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS);
            if (urlValidator.isValid(solrService)||ConfigurationManager.getBooleanProperty("discovery","solr.url.validation.enabled",true))
            {
                try {
                    log.debug("Solr URL: " + solrService);
                    solr = new HttpSolrServer(solrService);
View Full Code Here

  }

  private void checkUrlValidity(String urlValue) {
    String[] schemes = { "http", "https" };
    if (urlValue == null || !new UrlValidator(schemes).isValid(urlValue)) {
      throw new IllegalArgumentException("provide a valid URL like http://example.com");
    }
  }
View Full Code Here

    writer.flush();
  }

  private void checkUrlValidity(String urlValue) {
    String[] schemes = { "http", "https" };
    if (urlValue == null || !new UrlValidator(schemes).isValid(urlValue)) {
      throw new IllegalArgumentException("provide a valid URL like http://example.com");
    }
  }
View Full Code Here

     */
    protected static URL getLicenseURL( MavenProject project, String url )
        throws IOException
    {
        URL licenseUrl;
        UrlValidator urlValidator = new UrlValidator( UrlValidator.ALLOW_ALL_SCHEMES );
        // UrlValidator does not accept file URLs because the file
        // URLs do not contain a valid authority (no hostname).
        // As a workaround accept license URLs that start with the
        // file scheme.
        if ( urlValidator.isValid( url ) || StringUtils.defaultString( url ).startsWith( "file://" ) )
        {
            try
            {
                licenseUrl = new URL( url );
            }
View Full Code Here

    private final UrlValidator urlValidator;

    public WidgetValidator() {
        super();
        RegexValidator regex = new RegexValidator(new String[] {"http", "https","((localhost)(:[0-9]+))"});
        urlValidator = new UrlValidator(regex, 0);
    }
View Full Code Here

                return new CloseableIteration<BindingSet, QueryEvaluationException>() {

                    private Cursor cursor = query.fetchLazy(50);

                    private UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES | UrlValidator.ALLOW_LOCAL_URLS);

                    // in case we need to split one SQL query row into several SPARQL query rows, we do it by creating
                    // a temporary iterator
                    private Iterator<BindingSet> splitBindings = null;

                    @Override
                    public void close() throws QueryEvaluationException {
                        if(!cursor.isClosed()) {
                            cursor.close();
                        }
                        try {
                            if(!connection.getAutoCommit()) {
                                connection.commit();
                            }
                            connection.close();
                        } catch (SQLException e) {
                            log.error("SQL exception while closing JDBC connection",e);
                        }
                        em.close();
                    }

                    @Override
                    public boolean hasNext() throws QueryEvaluationException {
                        return (splitBindings !=null && splitBindings.hasNext()) || cursor.hasNext();
                    }

                    @Override
                    public BindingSet next() throws QueryEvaluationException {
                        if(splitBindings != null) {
                            return splitBindings.next();
                        } else {
                            Record record = cursor.fetchOne();

                            // check if the result contains multiple SPARQL bindings in a single row or
                            // only one SPARQL row; we can do this by checking whether the first result starts
                            // with _multi
                            if(record.getField(0).getName().startsWith("_multi")) {
                                log.info("transforming single-row SQL result into multi-row SPARQL result");
                                List<BindingSet> results = new ArrayList<BindingSet>();
                                for(int i=1; true; i++) {
                                    MapBindingSet result = new MapBindingSet();
                                    for(String var : mapper.getProjectedVariables()) {
                                        if(var.startsWith("_multi") && var.endsWith("_"+i)) {
                                            Long nodeId = record.getValue(var, Long.class);

                                            if(nodeId != null) {
                                                Value value = em.find(KiWiNode.class, nodeId);

                                                result.addBinding(var.substring(var.indexOf('_',1)+1,var.lastIndexOf('_')),value);
                                            }
                                        }
                                    }
                                    for(Map.Entry<String,Class> ext : mapper.getExtensionVariables().entrySet()) {
                                        String var = ext.getKey();
                                        if(var.startsWith("_multi") && var.endsWith("_"+i)) {
                                            Object val = record.getValue(ext.getKey(),ext.getValue());

                                            // this is truly a hack: we check whether the string is a URI, and if yes create a URI resource...
                                            // it would be better to carry over this information from the value constants
                                            if(urlValidator.isValid(val.toString())) {
                                                URI value = new URIImpl(val.toString());
                                                result.addBinding(var.substring(var.indexOf('_',1)+1,var.lastIndexOf('_')),value);
                                            } else {
                                                String type = LiteralCommons.getXSDType(ext.getValue());

                                                // we only create an in-memory representation of the value, the LMF methods
                                                // would automatically persist it, so we create a Sesame value
                                                Value value = new LiteralImpl(val.toString(),sesameService.getValueFactory().createURI(type));
                                                result.addBinding(var.substring(var.indexOf('_',1)+1,var.lastIndexOf('_')),value);
                                            }
                                        }
                                    }
                                    if(result.size() == 0) {
                                        break;
                                    } else {
                                        results.add(result);
                                    }
                                }
                                em.clear();
                                splitBindings = results.iterator();
                                return splitBindings.next();
                            } else {

                                MapBindingSet result = new MapBindingSet();
                                for(String var : mapper.getProjectedVariables()) {
                                    Long nodeId = record.getValue(var, Long.class);

                                    if(nodeId != null) {
                                        Value value = em.find(KiWiNode.class, nodeId);
                                        result.addBinding(var,value);
                                    }
                                }
                                for(Map.Entry<String,Class> ext : mapper.getExtensionVariables().entrySet()) {
                                    Object val = record.getValue(ext.getKey(),ext.getValue());

                                    // this is truly a hack: we check whether the string is a URI, and if yes create a URI resource...
                                    // it would be better to carry over this information from the value constants
                                    if(urlValidator.isValid(val.toString())) {
                                        URI value = new URIImpl(val.toString());
                                        result.addBinding(ext.getKey(),value);
                                    } else {
                                        String type = LiteralCommons.getXSDType(ext.getValue());
View Full Code Here

TOP

Related Classes of org.apache.commons.validator.routines.UrlValidator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.