diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java index ac0cd78c4..225d086ed 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/ManagePageGenerator.java @@ -282,6 +282,8 @@ public class ManagePageGenerator extends BaseEditConfigurationGenerator implemen private void addJSONArrayToFormSpecificData(JSONArray jsonArray, EditConfigurationVTwo editConfig) { HashMap data = editConfig.getFormSpecificData(); data.put("existingPageContentUnits", jsonArray.toString()); + //Experimenting with putting actual array in + data.put("existingPageContentUnitsJSONArray", jsonArray); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/ManagePagePreprocessor.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/ManagePagePreprocessor.java index be1b1ce4c..29077de2c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/ManagePagePreprocessor.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/ManagePagePreprocessor.java @@ -199,10 +199,14 @@ public class ManagePagePreprocessor extends if(jsonValue instanceof String) { //TODO: Deal with multiple submission values //This retrieves the value for this particular json object - literalValues.add(jsonObject.getString(literalLabel)); + String jsonString = jsonObject.getString(literalLabel); + jsonString = pn.replaceEncodedQuotesWithEscapedQuotes(jsonString); + literalValues.add(jsonString); } else if(jsonValue instanceof JSONArray) { JSONArray values = jsonObject.getJSONArray(literalLabel); literalValues = (List) JSONSerializer.toJava(values); + //Replacing encoded quotes here as well + this.replaceEncodedQuotesInList(pn, literalValues); } else if(jsonValue instanceof Boolean) { Boolean booleanValue = jsonObject.getBoolean(literalLabel); //Adds string version @@ -232,6 +236,7 @@ public class ManagePagePreprocessor extends //multiple values JSONArray values = jsonObject.getJSONArray(uriLabel); uriValues = (List) JSONSerializer.toJava(values); + } else { //This may include JSON Objects but no way to deal with these right now } @@ -254,7 +259,17 @@ public class ManagePagePreprocessor extends } - + private void replaceEncodedQuotesInList(ProcessDataGetterN3 pn, List values) { + int i; + int len = values.size(); + for(i = 0; i < len; i++) { + String value = values.get(i); + if(value.contains(""") || value.contains("'")) { + value = pn.replaceEncodedQuotesWithEscapedQuotes(value); + values.set(i,value); + } + } + } private void addFields(ProcessDataGetterN3 pn, int counter) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterAbstract.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterAbstract.java index 05743d168..9491590f1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterAbstract.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterAbstract.java @@ -54,6 +54,13 @@ public abstract class ProcessDataGetterAbstract implements ProcessDataGetterN3 { return "?" + getVarName(base, counter); } + //For handling encoded single and double quotes + //For fixed html and sparql data getters, replaces encoded quotes with escaped quotes + //Can be overridden in other processors if need be + public String replaceEncodedQuotesWithEscapedQuotes(String inputStr) { + return inputStr.replaceAll("'", "\'").replaceAll(""", "\""); + } + //Return name of new resources public List getNewResources(int counter) { //Each data getter requires a new resource diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3.java index 1eef4e473..6002e8043 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/preprocessors/utils/ProcessDataGetterN3.java @@ -36,5 +36,6 @@ public interface ProcessDataGetterN3 { public Map> retrieveExistingUriValues(); public void populateExistingValues(String dataGetterURI, int counter, OntModel queryModel); public JSONObject getExistingValuesJSON(String dataGetterURI, OntModel queryModel, ServletContext context); + public String replaceEncodedQuotesWithEscapedQuotes(String inputStr); } diff --git a/webapp/web/js/menupage/processFixedHTMLDataGetterContent.js b/webapp/web/js/menupage/processFixedHTMLDataGetterContent.js index 1c803526a..00395c7dd 100644 --- a/webapp/web/js/menupage/processFixedHTMLDataGetterContent.js +++ b/webapp/web/js/menupage/processFixedHTMLDataGetterContent.js @@ -14,7 +14,7 @@ var processFixedHTMLDataGetterContent = { //JSON parsing on the server side does not handle single quotes, as it appears it thinks the string has //ended. Different data getter types may handle apostrophes/single quotes differently //In this case, this is HTML so it simply html Encodes any apostrophes - htmlValue = processFixedHTMLDataGetterContent.replaceSingleQuote(htmlValue); + htmlValue = processFixedHTMLDataGetterContent.encodeQuotes(htmlValue); var returnObject = {saveToVar:saveToVarValue, htmlValue:htmlValue, dataGetterClass:this.dataGetterClass}; return returnObject; }, @@ -22,6 +22,8 @@ var processFixedHTMLDataGetterContent = { populatePageContentSection:function(existingContentObject, pageContentSection) { var saveToVarValue = existingContentObject["saveToVar"]; var htmlValue = existingContentObject["htmlValue"]; + //In displaying the html value for the edit field, replace the encoded quotes with regular quotes + htmlValue = processFixedHTMLDataGetterContent.replaceEncodedWithEscapedQuotes(htmlValue); //Now find and set value pageContentSection.find("input[name='saveToVar']").val(saveToVarValue); pageContentSection.find("textarea[name='htmlValue']").val(htmlValue); @@ -55,7 +57,7 @@ var processFixedHTMLDataGetterContent = { } return validationError; }, - replaceSingleQuote:function(inputStr) { + encodeQuotes:function(inputStr) { return inputStr.replace(/'/g, ''').replace(/"/g, '"'); }, //For the variable name, no single quote should be allowed @@ -65,6 +67,9 @@ var processFixedHTMLDataGetterContent = { }, stringHasDoubleQuote:function(inputStr) { return(inputStr.indexOf("\"") != -1); + }, + replaceEncodedWithEscapedQuotes: function(inputStr) { + return inputStr.replace(/'/g, "\'").replace(/"/g, "\""); } diff --git a/webapp/web/js/menupage/processSparqlDataGetterContent.js b/webapp/web/js/menupage/processSparqlDataGetterContent.js index 1935e8784..ee54c1bb6 100644 --- a/webapp/web/js/menupage/processSparqlDataGetterContent.js +++ b/webapp/web/js/menupage/processSparqlDataGetterContent.js @@ -11,6 +11,7 @@ var processSparqlDataGetterContent = { var variableValue = pageContentSection.find("input[name='saveToVar']").val(); var queryValue = pageContentSection.find("textarea[name='query']").val(); + queryValue = processSparqlDataGetterContent.encodeQuotes(queryValue); var queryModel = pageContentSection.find("input[name='queryModel']").val(); //query model should also be an input @@ -22,7 +23,11 @@ var processSparqlDataGetterContent = { populatePageContentSection:function(existingContentObject, pageContentSection) { var saveToVarValue = existingContentObject["saveToVar"]; var queryValue = existingContentObject["query"]; + //replace any encoded quotes with escaped quotes that will show up as quotes in the textarea + queryValue = processSparqlDataGetterContent.replaceEncodedWithEscapedQuotes(queryValue); var queryModelValue = existingContentObject["queryModel"]; + + //Now find and set value pageContentSection.find("input[name='saveToVar']").val(saveToVarValue); pageContentSection.find("textarea[name='query']").val(queryValue); @@ -45,11 +50,45 @@ var processSparqlDataGetterContent = { if(variableValue == "") { validationError += pageContentSectionLabel + ": You must supply a variable to save query results.
" } + if(processSparqlDataGetterContent.stringHasSingleQuote(variableValue)) { + validationError += pageContentSectionLabel + ": The variable name should not have an apostrophe .
"; + } + if(processSparqlDataGetterContent.stringHasDoubleQuote(variableValue)) { + validationError += pageContentSectionLabel + ": The variable name should not have a double quote .
"; + } + //Check that query model does not have single or double quotes within it + //Uncomment this/adapt this when we actually allow display the query model input + /* + var queryModelValue = pageContentSection.find("input[name='queryModel']").val(); + if(processSparqlDataGetterContent.stringHasSingleQuote(queryModelValue)) { + validationError += pageContentSectionLabel + ": The query model should not have an apostrophe .
"; + + } + if(processSparqlDataGetterContent.stringHasDoubleQuote(queryModelValue)) { + validationError += pageContentSectionLabel + ": The query model should not have a double quote .
"; + + }*/ + var queryValue = pageContentSection.find("textarea[name='query']").val(); if(queryValue == "") { validationError += pageContentSectionLabel + ": You must supply a Sparql query.
"; } return validationError; + }, + encodeQuotes:function(inputStr) { + return inputStr.replace(/'/g, ''').replace(/"/g, '"'); + }, + //For the variable name, no single quote should be allowed + //This can be extended for other special characters + stringHasSingleQuote:function(inputStr) { + return(inputStr.indexOf("'") != -1); + }, + stringHasDoubleQuote:function(inputStr) { + return(inputStr.indexOf("\"") != -1); + }, + replaceEncodedWithEscapedQuotes: function(inputStr) { + + return inputStr.replace(/'/g, "\'").replace(/"/g, "\""); }