jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rve...@apache.org
Subject [73/93] [abbrv] jena git commit: Make template substitution Lang sensitive.
Date Wed, 14 Jan 2015 10:32:15 GMT
Make template substitution Lang sensitive.


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/51eb5768
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/51eb5768
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/51eb5768

Branch: refs/heads/hadoop-rdf
Commit: 51eb5768db68b189a55fab52b3016151a387151b
Parents: 19fc55c
Author: Andy Seaborne <andy@apache.org>
Authored: Wed Jan 7 12:12:19 2015 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Wed Jan 7 12:52:23 2015 +0000

----------------------------------------------------------------------
 .../jena/fuseki/build/DataServiceDesc.java      |  2 +-
 .../jena/fuseki/build/TemplateFunctions.java    | 34 ++++++++++++++------
 .../apache/jena/fuseki/mgt/ActionDatasets.java  |  4 +--
 .../apache/jena/fuseki/server/FusekiServer.java |  2 +-
 4 files changed, 29 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/51eb5768/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/DataServiceDesc.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/DataServiceDesc.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/DataServiceDesc.java
index 2b85c99..8fa2edf 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/DataServiceDesc.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/DataServiceDesc.java
@@ -44,7 +44,7 @@ public abstract class DataServiceDesc
         Map<String, String> params = new HashMap<>() ;
         params.put(Template.NAME, dbName) ;
         FusekiServer.addGlobals(params); 
-        String template = TemplateFunctions.templateFile(templateFile, params) ;
+        String template = TemplateFunctions.templateFile(templateFile, params, Lang.TTL)
;
         Lang lang = RDFLanguages.filenameToLang(templateFile, Lang.TTL) ;
         StringReader sr = new StringReader(template) ;
         return create(sr, lang) ;

http://git-wip-us.apache.org/repos/asf/jena/blob/51eb5768/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/TemplateFunctions.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/TemplateFunctions.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/TemplateFunctions.java
index 61c4b68..5c12dbc 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/TemplateFunctions.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/build/TemplateFunctions.java
@@ -22,17 +22,17 @@ import java.io.IOException ;
 import java.io.InputStream ;
 import java.util.Map ;
 import java.util.Map.Entry ;
-import java.util.regex.Matcher ;
 
 import org.apache.jena.atlas.io.IO ;
 import org.apache.jena.fuseki.Fuseki ;
+import org.apache.jena.riot.Lang ;
 
 import com.hp.hpl.jena.util.FileUtils ;
 
 public class TemplateFunctions
 {
     /** Read in a template from a file, substitute for {NAME} and return the string. */
-    public static String templateFile(String templateName, Map<String, String> params)
{
+    public static String templateFile(String templateName, Map<String, String> params,
Lang lang) {
         String templateFilename = Template.getPath(templateName).toString() ;
         String template ;
         try { template = FileUtils.readWholeFileAsUTF8(templateFilename) ; }
@@ -40,11 +40,11 @@ public class TemplateFunctions
             Fuseki.serverLog.error("File not found: "+templateFilename);
             IO.exception(ex); return null ;
         }
-        return templateString(template, params) ;
+        return templateString(template, params, lang) ;
     }
     
     /** Read a template file, substitute for {NAME} and return the model. */
-    public static String templateResource(String resourceName, Map<String, String>
params) {
+    public static String templateResource(String resourceName, Map<String, String>
params, Lang lang) {
         String template ;
         try {
             InputStream in = TemplateFunctions.class.getClassLoader().getResourceAsStream(resourceName)
;
@@ -56,15 +56,31 @@ public class TemplateFunctions
             Fuseki.serverLog.error("Error reading resource: "+resourceName);
             IO.exception(ex); return null ;
         }
-        return templateString(template, params) ;
+        return templateString(template, params, lang) ;
     }
 
     /** Create a template from a String */ 
-    public static String templateString(String template, Map<String, String> params)
{
+    public static String templateString(String template, Map<String, String> params,
Lang lang) {
         for ( Entry<String, String> e : params.entrySet() ) {
-            // Backslashes (\) and dollar signs ($) in the replacement string have special
meaning.
-            String x = Matcher.quoteReplacement(e.getValue()) ; 
-            template = template.replaceAll("\\{"+e.getKey()+"\\}", x) ;
+            // Literal string replacement.
+            // If using .replaceAll, need to use Match.quoteReplacement on the value.
+            String x = e.getValue() ;
+            String k = "{"+e.getKey()+"}" ;
+            
+            if ( lang != null ) {
+                if ( Lang.TTL.equals(lang)     ||
+                     Lang.TRIG.equals(lang)    ||
+                     Lang.NT.equals(lang)      ||
+                     Lang.NQ.equals(lang)      ||
+                     Lang.JSONLD.equals(lang)  ||
+                     Lang.RDFJSON.equals(lang) 
+                    ) {
+                    // Make safe for a RDF language ""-string - especially MS Windows \ path
separators.
+                    x = x.replace("\\", "\\\\") ;
+                    x = x.replace("\"", "\\\"") ;
+                }
+            }
+            template = template.replace(k, x) ;
         }
         return template ;
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/51eb5768/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
index ea3d44e..4e9c916 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/mgt/ActionDatasets.java
@@ -261,9 +261,9 @@ public class ActionDatasets extends ActionContainerItem {
         
         String template = null ;
         if ( dbType.equalsIgnoreCase(tDatabasetTDB))
-            template = TemplateFunctions.templateFile(Template.templateTDBFN, params) ;
+            template = TemplateFunctions.templateFile(Template.templateTDBFN, params, Lang.TTL)
;
         if ( dbType.equalsIgnoreCase(tDatabasetMem))
-            template = TemplateFunctions.templateFile(Template.templateMemFN, params) ;
+            template = TemplateFunctions.templateFile(Template.templateMemFN, params, Lang.TTL)
;
         RDFDataMgr.parse(dest, new StringReader(template), "http://base/", Lang.TTL) ;
     }
 

http://git-wip-us.apache.org/repos/asf/jena/blob/51eb5768/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
----------------------------------------------------------------------
diff --git a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
index 83d5523..a466b8b 100644
--- a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
+++ b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/server/FusekiServer.java
@@ -290,7 +290,7 @@ public class FusekiServer
         
         addGlobals(params); 
 
-        String str = TemplateFunctions.templateFile(templateFile, params) ;
+        String str = TemplateFunctions.templateFile(templateFile, params, Lang.TTL) ;
         Lang lang = RDFLanguages.filenameToLang(str, Lang.TTL) ;
         StringReader sr =  new StringReader(str) ;
         Model model = ModelFactory.createDefaultModel() ;


Mime
View raw message