updates for handling single and double quotes as well as enabling self contained template option for page management

This commit is contained in:
hjkhjk54 2012-08-03 15:24:58 +00:00
parent 6a63de6144
commit 8225bcf91f
7 changed files with 97 additions and 20 deletions

View file

@ -98,7 +98,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
private void setUrisAndLiteralsOnForm(EditConfigurationVTwo conf,
VitroRequest vreq) {
conf.setUrisOnForm(new String[]{"page", "menuItem"}); //new resources: should this be on form for new - should be for existing
conf.setLiteralsOnForm(new String[]{"pageName", "prettyUrl", "menuPosition", "menuLinkText", "customTemplate", "pageContentUnit"}); //page content unit = data getter JSON object
conf.setLiteralsOnForm(new String[]{"pageName", "prettyUrl", "menuPosition", "menuLinkText", "customTemplate", "isSelfContainedTemplate", "pageContentUnit"}); //page content unit = data getter JSON object
}
@ -116,7 +116,8 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
private void setN3Optional(EditConfigurationVTwo conf) {
//body template is not required, and a given page may or may not be a menu item, but should linked to menu if menu item
conf.setN3Optional(new ArrayList<String>(Arrays.asList(prefixes + pageBodyTemplateN3,
prefixes + menuItemN3 + menuN3)));
prefixes + menuItemN3 + menuN3,
prefixes + isSelfContainedTemplateN3)));
}
private void setN3Required(EditConfigurationVTwo conf) {
@ -149,6 +150,10 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
FieldVTwo menuItemPositionField = new FieldVTwo().setName("menuPosition").setRangeDatatypeUri(XSD.integer.getURI());
conf.addField(menuItemPositionField);
//If this is a self contained template, the appropriate flag will be set
FieldVTwo isSelfContainedTemplateField = new FieldVTwo().setName("isSelfContainedTemplate");
conf.addField(isSelfContainedTemplateField);
//The actual page content information is stored in this field, and then
//interpreted using the preprocessor
FieldVTwo pageContentUnitField = new FieldVTwo().setName("pageContentUnit");
@ -423,6 +428,7 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen
map.put("menuPosition", getExistingMenuPositionQuery());
map.put("menuLinkText", getExistingMenuLinkTextQuery());
map.put("customTemplate", getExistingCustomTemplateQuery());
map.put("isSelfContainedTemplate", getExistingIsSelfContainedTemplateQuery());
return map;
}
@ -462,6 +468,12 @@ private String getExistingCustomTemplateQuery() {
return query;
}
private String getExistingIsSelfContainedTemplateQuery() {
String query = getSparqlPrefix() + "SELECT ?isSelfContainedTemplate WHERE {?page display:isSelfContainedTemplate ?isSelfContainedTemplate .}";
return query;
}
//Form specific data
//In this case, need to get all the different data getter TYPES and labels
//Also need to pass back the map for the options presented to the user
@ -533,6 +545,10 @@ private String getExistingCustomTemplateQuery() {
final static String pageBodyTemplateN3 = "?page display:requiresBodyTemplate ?customTemplate .";
//If self contained template, n3 will denote this using a flag
final static String isSelfContainedTemplateN3 = "?page display:isSelfContainedTemplate ?isSelfContainedTemplate .";
//Menu position is added dynamically at end by default and can be changed on reordering page
final static String menuItemN3 = "?menuItem a display:NavigationElement ; \n" +
"display:menuPosition ?menuPosition; \n" +

View file

@ -172,11 +172,14 @@ public class ManagePagePreprocessor extends
private void convertToJson() {
//Iterate through list of inputs
pageContentUnitsJSON = new ArrayList<JSONObject>();
for(String pageContentUnit: pageContentUnits) {
JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( pageContentUnit );
pageContentUnitsJSON.add(jsonObject);
//page content units might return null in case self-contained template is selected
//otherwise there should be page content units returned from the form
if(pageContentUnits != null) {
for(String pageContentUnit: pageContentUnits) {
JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( pageContentUnit );
pageContentUnitsJSON.add(jsonObject);
}
}
}
//This is where the actual values will be submitted as if they were separate input fields

View file

@ -142,8 +142,11 @@ public class ProcessFixedHTMLN3 extends ProcessDataGetterAbstract {
QuerySolution qs = results.nextSolution();
Literal saveToVarLiteral = qs.getLiteral("saveToVar");
Literal htmlValueLiteral = qs.getLiteral("htmlValue");
String htmlValueString = htmlValueLiteral.getString();
htmlValueString = this.replaceQuotes(htmlValueString);
jObject.element("saveToVar", saveToVarLiteral.getString());
jObject.element("htmlValue", htmlValueLiteral.getString());
//TODO: Handle single and double quotes within string and escape properlyu
jObject.element("htmlValue", htmlValueString);
}
} catch(Exception ex) {
log.error("Exception occurred in retrieving existing values with query " + querystr, ex);
@ -151,6 +154,12 @@ public class ProcessFixedHTMLN3 extends ProcessDataGetterAbstract {
return jObject;
}
//Escape single and double quotes for html string to be returned to form
public String replaceQuotes(String inputStr) {
return inputStr.replaceAll("\'", "&#39;").replaceAll("\"", "&quot;");
}
}