merging URL validation in defaultLinkForm.jsp
This commit is contained in:
parent
30890a7b5f
commit
0b97ec523b
3 changed files with 57 additions and 13 deletions
|
@ -2,6 +2,19 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.apache.commons.fileupload.FileItem;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.datatypes.RDFDatatype;
|
import com.hp.hpl.jena.datatypes.RDFDatatype;
|
||||||
import com.hp.hpl.jena.datatypes.TypeMapper;
|
import com.hp.hpl.jena.datatypes.TypeMapper;
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
|
@ -12,13 +25,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.Datatype;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatatypeDaoJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatatypeDaoJena;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.apache.commons.fileupload.FileItem;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: bdc34
|
* User: bdc34
|
||||||
* Date: Jan 24, 2008
|
* Date: Jan 24, 2008
|
||||||
|
@ -146,7 +152,7 @@ public class BasicValidation {
|
||||||
return REQUIRED_FIELD_EMPTY_MSG;
|
return REQUIRED_FIELD_EMPTY_MSG;
|
||||||
}
|
}
|
||||||
// Format validation
|
// Format validation
|
||||||
if("isDate".equalsIgnoreCase(validationType)){
|
else if("isDate".equalsIgnoreCase(validationType)){
|
||||||
if( isDate( value))
|
if( isDate( value))
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
else
|
else
|
||||||
|
@ -160,10 +166,16 @@ public class BasicValidation {
|
||||||
} else {
|
} else {
|
||||||
return errorMsg;
|
return errorMsg;
|
||||||
}
|
}
|
||||||
}
|
} else if ("httpUrl".equalsIgnoreCase(validationType)){
|
||||||
|
//check if it has http or https, we could do more but for now this is all.
|
||||||
|
if(! value.startsWith("http://") && ! value.startsWith("https://") ){
|
||||||
|
return "This URL must start with http:// or https://";
|
||||||
|
}else{
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
//Date not past validation
|
//Date not past validation
|
||||||
if( "dateNotPast".equalsIgnoreCase(validationType)){
|
else if( "dateNotPast".equalsIgnoreCase(validationType)){
|
||||||
//if( ! past (value) )
|
//if( ! past (value) )
|
||||||
// return "date must not be in the past";
|
// return "date must not be in the past";
|
||||||
//Current date
|
//Current date
|
||||||
|
@ -239,6 +251,9 @@ public class BasicValidation {
|
||||||
return (value == null || value.trim().length() == 0);
|
return (value == null || value.trim().length() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static Pattern urlRX = Pattern.compile("(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)/{0,2}[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?");
|
||||||
|
|
||||||
/** we use null to indicate success */
|
/** we use null to indicate success */
|
||||||
public final static String SUCCESS = null;
|
public final static String SUCCESS = null;
|
||||||
|
@ -253,7 +268,7 @@ public class BasicValidation {
|
||||||
static final List<String> basicValidations;
|
static final List<String> basicValidations;
|
||||||
static{
|
static{
|
||||||
basicValidations = Arrays.asList(
|
basicValidations = Arrays.asList(
|
||||||
"nonempty","isDate","dateNotPast" );
|
"nonempty","isDate","dateNotPast","httpUrl" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private Log log = LogFactory.getLog(BasicValidation.class);
|
private Log log = LogFactory.getLog(BasicValidation.class);
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.edit.n3editing;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class BasicValidationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidate() {
|
||||||
|
BasicValidation bv = new BasicValidation(Collections.EMPTY_MAP);
|
||||||
|
String res;
|
||||||
|
res = bv.validate("httpUrl", "http://example.com/index");
|
||||||
|
Assert.assertEquals(res, bv.SUCCESS);
|
||||||
|
|
||||||
|
res = bv.validate("httpUrl", "http://example.com/index?bogus=skjd%20skljd&something=sdkf");
|
||||||
|
Assert.assertEquals(res, bv.SUCCESS);
|
||||||
|
|
||||||
|
res = bv.validate("httpUrl", "http://example.com/index#2.23?bogus=skjd%20skljd&something=sdkf");
|
||||||
|
Assert.assertEquals(res, bv.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -131,7 +131,7 @@
|
||||||
"fields" : {
|
"fields" : {
|
||||||
"url" : {
|
"url" : {
|
||||||
"newResource" : "false",
|
"newResource" : "false",
|
||||||
"validators" : [ "nonempty", "datatype:${uriDatatypeUriJson}" ],
|
"validators" : [ "nonempty", "datatype:${uriDatatypeUriJson}" , "httpUrl" ],
|
||||||
"optionsType" : "UNDEFINED",
|
"optionsType" : "UNDEFINED",
|
||||||
"literalOptions" : [ ],
|
"literalOptions" : [ ],
|
||||||
"predicateUri" : "",
|
"predicateUri" : "",
|
||||||
|
|
Loading…
Add table
Reference in a new issue