use of org.interlis2.validator.Validator in project struts by apache.
the class PlexusObjectFactory method buildValidator.
/* (non-Javadoc)
* @see com.opensymphony.xwork2.ObjectFactory#buildValidator(java.lang.String, java.util.Map, java.util.Map)
*/
public Validator buildValidator(String className, Map params, Map extraContext) throws Exception {
Map context = new HashMap();
context.put(PLEXUS_COMPONENT_TYPE, Validator.class.getName());
Validator validator = (Validator) buildBean(className, context);
reflectionProvider.setProperties(params, validator);
return validator;
}
use of org.interlis2.validator.Validator in project struts by apache.
the class SpringObjectFactoryTest method testFallsBackToDefaultObjectFactoryValidatorBuilding.
public void testFallsBackToDefaultObjectFactoryValidatorBuilding() throws Exception {
Map<String, Object> extraContext = new HashMap<>();
Validator validator = objectFactory.buildValidator(RequiredStringValidator.class.getName(), new HashMap<String, Object>(), extraContext);
assertEquals(RequiredStringValidator.class, validator.getClass());
}
use of org.interlis2.validator.Validator in project gretl by sogis.
the class IliValidator method validate.
@TaskAction
public void validate() {
log = LogEnvironment.getLogger(IliValidator.class);
if (dataFiles == null) {
return;
}
FileCollection dataFilesCollection = null;
if (dataFiles instanceof FileCollection) {
dataFilesCollection = (FileCollection) dataFiles;
} else {
dataFilesCollection = getProject().files(dataFiles);
}
if (dataFilesCollection == null || dataFilesCollection.isEmpty()) {
return;
}
List<String> files = new ArrayList<String>();
for (java.io.File fileObj : dataFilesCollection) {
String fileName = fileObj.getPath();
files.add(fileName);
}
Settings settings = new Settings();
initSettings(settings);
List<String> userFunctionList = new ArrayList<String>();
userFunctionList.add("ch.so.agi.ilivalidator.ext.IsHttpResourceIoxPlugin");
userFunctionList.add("ch.so.agi.ilivalidator.ext.AreaIoxPlugin");
userFunctionList.add("ch.so.agi.ilivalidator.ext.LengthIoxPlugin");
userFunctionList.add("ch.so.agi.ilivalidator.ext.IsValidDocumentsCycleIoxPlugin");
userFunctionList.add("ch.so.agi.ilivalidator.ext.RingSelfIntersectionIoxPlugin");
userFunctionList.add("ch.so.agi.ilivalidator.ext.TooFewPointsPolylineIoxPlugin");
// userFunctionList.add("ch.so.agi.ilivalidator.ext.IsHttpResourceFromOerebMultilingualUriIoxPlugin");
Map<String, Class> userFunctions = new HashMap<String, Class>();
try {
for (String userFunction : userFunctionList) {
Class clazz = Class.forName(userFunction);
IoxPlugin plugin = (IoxPlugin) clazz.newInstance();
userFunctions.put(((InterlisFunction) plugin).getQualifiedIliName(), clazz);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
log.info("Class not found");
} catch (InstantiationException e) {
e.printStackTrace();
log.error("cannot instantiate class", e);
} catch (IllegalAccessException e) {
e.printStackTrace();
log.error("Class not accessible", e);
}
settings.setTransientObject(ch.interlis.iox_j.validator.Validator.CONFIG_CUSTOM_FUNCTIONS, userFunctions);
validationOk = new Validator().validate(files.toArray(new String[files.size()]), settings);
if (!validationOk && failOnError) {
throw new TaskExecutionException(this, new Exception("validation failed"));
}
}
use of org.interlis2.validator.Validator in project struts by apache.
the class ShowValidatorAction method execute.
public String execute() throws Exception {
loadValidators();
Validator validator = getSelectedValidator();
properties = new TreeSet<PropertyInfo>();
try {
Map<String, Object> context = reflectionContextFactory.createDefaultContext(validator);
BeanInfo beanInfoFrom;
try {
beanInfoFrom = Introspector.getBeanInfo(validator.getClass(), Object.class);
} catch (IntrospectionException e) {
LOG.error("An error occurred", e);
addActionError("An error occurred while introspecting a validator of type " + validator.getClass().getName());
return ERROR;
}
PropertyDescriptor[] pds = beanInfoFrom.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
String name = pd.getName();
Object value = null;
if (pd.getReadMethod() == null) {
value = "No read method for property";
} else {
try {
value = reflectionProvider.getValue(name, context, validator);
} catch (ReflectionException e) {
addActionError("Caught exception while getting property value for '" + name + "' on validator of type " + validator.getClass().getName());
}
}
properties.add(new PropertyInfo(name, pd.getPropertyType(), value));
}
} catch (Exception e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Unable to retrieve properties.", e);
}
addActionError("Unable to retrieve properties: " + e.toString());
}
if (hasErrors()) {
return ERROR;
} else {
return SUCCESS;
}
}
use of org.interlis2.validator.Validator in project struts by apache.
the class SpringObjectFactoryTest method testObtainValidatorBySpringName.
public void testObtainValidatorBySpringName() throws Exception {
sac.registerPrototype("expression-validator", ExpressionValidator.class, new MutablePropertyValues());
Map<String, Object> extraContext = new HashMap<>();
Validator validator = objectFactory.buildValidator("expression-validator", new HashMap<String, Object>(), extraContext);
assertEquals(ExpressionValidator.class, validator.getClass());
}
Aggregations