Working on date time with precision edit element, NIHVIVO-295. Changed EditN3Generator to use a different regex to substitute values into the N3.
This commit is contained in:
parent
13c1808d38
commit
57ff1c461b
5 changed files with 55 additions and 20 deletions
|
@ -134,7 +134,7 @@
|
|||
<body-content>empty</body-content>
|
||||
<attribute>
|
||||
<name>type</name>
|
||||
<required>true</required>
|
||||
<required>false</required>
|
||||
<rtexprvalue>true</rtexprvalue>
|
||||
</attribute>
|
||||
<attribute>
|
||||
|
|
|
@ -330,8 +330,13 @@ public class FreemarkerHttpServlet extends VitroHttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
// Add any Java directives the templates should have access to
|
||||
private Map<String, Object> getDirectives() {
|
||||
/**
|
||||
* Add any Java directives the templates should have access to.
|
||||
* This is public and static so that these may be used by other classes during
|
||||
* the transition from JSP to Freemarker.
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, Object> getDirectives() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("describe", new edu.cornell.mannlib.vitro.webapp.web.directives.dump.DescribeDirective());
|
||||
map.put("dump", new edu.cornell.mannlib.vitro.webapp.web.directives.dump.DumpDirective());
|
||||
|
|
|
@ -20,6 +20,18 @@ public interface EditElement {
|
|||
public Map<String,Literal>
|
||||
getLiterals(String fieldName, EditConfiguration editConfig, Map<String,String[]> queryParameters );
|
||||
|
||||
/**
|
||||
* This is a method to get a map of variable name to URI value from the submitted form.
|
||||
*/
|
||||
public Map<String,String>
|
||||
getURIs(String fieldName, EditConfiguration editConfig, Map<String,String[]> queryParameters );
|
||||
|
||||
/**
|
||||
* Gets validation error messages. Returns an empty list if there are no errors.
|
||||
*/
|
||||
public Map<String,String>
|
||||
getValidationMessages(String fieldName, EditConfiguration editConfig, Map<String,String[]> queryParameters);
|
||||
|
||||
/**
|
||||
* This is a method to generate the HTML output for a form element. It should use a freemarker template
|
||||
* to produce the output.
|
||||
|
|
|
@ -52,11 +52,13 @@ public class EditN3Generator {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public static String subInUris(String var, String value, String target){
|
||||
//empty URIs get skipped
|
||||
if( var == null || var.length() == 0 || value==null )
|
||||
return target;
|
||||
String varRegex = "\\?" + var + "(?=[\\W])";
|
||||
/* var followed by dot some whitespace or var followed by whitespace*/
|
||||
String varRegex = "\\?" + var + "(?=\\.\\p{Space}|\\p{Space})";
|
||||
String out = null;
|
||||
if("".equals(value))
|
||||
out = target.replaceAll(varRegex,">::" + var + " was BLANK::< ");
|
||||
|
@ -106,7 +108,7 @@ public class EditN3Generator {
|
|||
*
|
||||
*/
|
||||
protected String subInLiterals(String var, Literal literal, String target){
|
||||
String varRegex = "\\?" + var + "(?=[\\W])";
|
||||
String varRegex = "\\?" + var + "(?=\\.\\p{Space}|\\p{Space})";
|
||||
if (target==null ) {
|
||||
log.error("subInLiterals was passed a null target");
|
||||
return "blankBecauseTargetOrValueWasNull";
|
||||
|
|
|
@ -109,7 +109,7 @@ public class EditSubmission {
|
|||
log.debug("time fields for parameter " + var + " were not on form" );
|
||||
}
|
||||
} else if( field.getEditElement() != null ){
|
||||
literalsFromForm.putAll( getLiteralForField(var,editConfig,queryParameters));
|
||||
log.debug("skipping field with edit element, it should not be in literals on form list");
|
||||
}else{
|
||||
String[] valuesArray = queryParameters.get(var);
|
||||
List<String> valueList = (valuesArray != null) ? Arrays.asList(valuesArray) : null;
|
||||
|
@ -154,23 +154,39 @@ public class EditSubmission {
|
|||
}
|
||||
}
|
||||
|
||||
processEditElementFields(editConfig,queryParameters);
|
||||
|
||||
if( log.isDebugEnabled() )
|
||||
log.debug( this.toString() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the literals for the field using the field's special editElement.
|
||||
* @param var
|
||||
* @param editConfig
|
||||
* @param queryParameters
|
||||
* @return
|
||||
*/
|
||||
private Map<? extends String, ? extends Literal> getLiteralForField(
|
||||
String var, EditConfiguration editConfig,
|
||||
Map<String, String[]> queryParameters) {
|
||||
Field field = editConfig.getField(var);
|
||||
EditElement ee = field.getEditElement();
|
||||
return ee.getLiterals(var, editConfig, queryParameters);
|
||||
protected void processEditElementFields(EditConfiguration editConfig, Map<String,String[]> queryParameters ){
|
||||
for( String fieldName : editConfig.getFields().keySet()){
|
||||
Field field = editConfig.getFields().get(fieldName);
|
||||
if( field != null && field.getEditElement() != null ){
|
||||
EditElement element = field.getEditElement();
|
||||
log.debug("Checking EditElement for field " + fieldName + " type: " + element.getClass().getName());
|
||||
|
||||
//check for validation error messages
|
||||
Map<String,String> errMsgs =
|
||||
element.getValidationMessages(fieldName, editConfig, queryParameters);
|
||||
validationErrors.putAll(errMsgs);
|
||||
|
||||
if( errMsgs == null || errMsgs.isEmpty()){
|
||||
//only check for uris and literals when element has no validation errors
|
||||
Map<String,String> urisFromElement = element.getURIs(fieldName, editConfig, queryParameters);
|
||||
if( urisFromElement != null )
|
||||
urisFromForm.putAll(urisFromElement);
|
||||
Map<String,Literal> literalsFromElement = element.getLiterals(fieldName, editConfig, queryParameters);
|
||||
if( literalsFromElement != null )
|
||||
literalsFromForm.putAll(literalsFromElement);
|
||||
}else{
|
||||
log.debug("got validation errors for field " + fieldName + " not processing field for literals or URIs");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public EditSubmission(Map<String, String[]> queryParameters, EditConfiguration editConfig,
|
||||
Map<String, List<FileItem>> fileItems) {
|
||||
this(queryParameters,editConfig);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue