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>
|
<body-content>empty</body-content>
|
||||||
<attribute>
|
<attribute>
|
||||||
<name>type</name>
|
<name>type</name>
|
||||||
<required>true</required>
|
<required>false</required>
|
||||||
<rtexprvalue>true</rtexprvalue>
|
<rtexprvalue>true</rtexprvalue>
|
||||||
</attribute>
|
</attribute>
|
||||||
<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<String, Object> map = new HashMap<String, Object>();
|
||||||
map.put("describe", new edu.cornell.mannlib.vitro.webapp.web.directives.dump.DescribeDirective());
|
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());
|
map.put("dump", new edu.cornell.mannlib.vitro.webapp.web.directives.dump.DumpDirective());
|
||||||
|
|
|
@ -20,6 +20,18 @@ public interface EditElement {
|
||||||
public Map<String,Literal>
|
public Map<String,Literal>
|
||||||
getLiterals(String fieldName, EditConfiguration editConfig, Map<String,String[]> queryParameters );
|
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
|
* This is a method to generate the HTML output for a form element. It should use a freemarker template
|
||||||
* to produce the output.
|
* to produce the output.
|
||||||
|
|
|
@ -52,11 +52,13 @@ public class EditN3Generator {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String subInUris(String var, String value, String target){
|
public static String subInUris(String var, String value, String target){
|
||||||
//empty URIs get skipped
|
//empty URIs get skipped
|
||||||
if( var == null || var.length() == 0 || value==null )
|
if( var == null || var.length() == 0 || value==null )
|
||||||
return target;
|
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;
|
String out = null;
|
||||||
if("".equals(value))
|
if("".equals(value))
|
||||||
out = target.replaceAll(varRegex,">::" + var + " was BLANK::< ");
|
out = target.replaceAll(varRegex,">::" + var + " was BLANK::< ");
|
||||||
|
@ -106,7 +108,7 @@ public class EditN3Generator {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected String subInLiterals(String var, Literal literal, String target){
|
protected String subInLiterals(String var, Literal literal, String target){
|
||||||
String varRegex = "\\?" + var + "(?=[\\W])";
|
String varRegex = "\\?" + var + "(?=\\.\\p{Space}|\\p{Space})";
|
||||||
if (target==null ) {
|
if (target==null ) {
|
||||||
log.error("subInLiterals was passed a null target");
|
log.error("subInLiterals was passed a null target");
|
||||||
return "blankBecauseTargetOrValueWasNull";
|
return "blankBecauseTargetOrValueWasNull";
|
||||||
|
|
|
@ -109,7 +109,7 @@ public class EditSubmission {
|
||||||
log.debug("time fields for parameter " + var + " were not on form" );
|
log.debug("time fields for parameter " + var + " were not on form" );
|
||||||
}
|
}
|
||||||
} else if( field.getEditElement() != null ){
|
} 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{
|
}else{
|
||||||
String[] valuesArray = queryParameters.get(var);
|
String[] valuesArray = queryParameters.get(var);
|
||||||
List<String> valueList = (valuesArray != null) ? Arrays.asList(valuesArray) : null;
|
List<String> valueList = (valuesArray != null) ? Arrays.asList(valuesArray) : null;
|
||||||
|
@ -154,21 +154,37 @@ public class EditSubmission {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processEditElementFields(editConfig,queryParameters);
|
||||||
|
|
||||||
|
if( log.isDebugEnabled() )
|
||||||
|
log.debug( this.toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected void processEditElementFields(EditConfiguration editConfig, Map<String,String[]> queryParameters ){
|
||||||
* Get the literals for the field using the field's special editElement.
|
for( String fieldName : editConfig.getFields().keySet()){
|
||||||
* @param var
|
Field field = editConfig.getFields().get(fieldName);
|
||||||
* @param editConfig
|
if( field != null && field.getEditElement() != null ){
|
||||||
* @param queryParameters
|
EditElement element = field.getEditElement();
|
||||||
* @return
|
log.debug("Checking EditElement for field " + fieldName + " type: " + element.getClass().getName());
|
||||||
*/
|
|
||||||
private Map<? extends String, ? extends Literal> getLiteralForField(
|
//check for validation error messages
|
||||||
String var, EditConfiguration editConfig,
|
Map<String,String> errMsgs =
|
||||||
Map<String, String[]> queryParameters) {
|
element.getValidationMessages(fieldName, editConfig, queryParameters);
|
||||||
Field field = editConfig.getField(var);
|
validationErrors.putAll(errMsgs);
|
||||||
EditElement ee = field.getEditElement();
|
|
||||||
return ee.getLiterals(var, editConfig, queryParameters);
|
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,
|
public EditSubmission(Map<String, String[]> queryParameters, EditConfiguration editConfig,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue