You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2013/09/03 15:49:16 UTC

[4/5] git commit: MARMOTTA-150: fixed bnodes renderization in the lde

MARMOTTA-150: fixed bnodes renderization in the lde


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/819c97b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/819c97b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/819c97b7

Branch: refs/heads/develop
Commit: 819c97b71742ac93b7fb18cf5e59a917bdbe3edf
Parents: ed09ff2
Author: Sergio Fernández <wi...@apache.org>
Authored: Tue Sep 3 15:48:53 2013 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Tue Sep 3 15:48:53 2013 +0200

----------------------------------------------------------------------
 .../platform/core/rio/RDFHtmlWriterImpl.java    | 30 +++++++++-----
 .../webservices/resource/MetaWebService.java    |  1 -
 .../src/main/resources/templates/rdfhtml.ftl    | 43 ++++++++++++++++----
 3 files changed, 54 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/819c97b7/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/rio/RDFHtmlWriterImpl.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/rio/RDFHtmlWriterImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/rio/RDFHtmlWriterImpl.java
index 17513f0..bdaa063 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/rio/RDFHtmlWriterImpl.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/rio/RDFHtmlWriterImpl.java
@@ -33,6 +33,7 @@ import java.util.SortedSet;
 import java.util.TreeSet;
 
 import org.apache.commons.lang3.StringUtils;
+import org.apache.marmotta.commons.http.UriUtil;
 import org.apache.marmotta.kiwi.model.rdf.KiWiTriple;
 import org.apache.marmotta.platform.core.api.config.ConfigurationService;
 import org.apache.marmotta.platform.core.api.io.RDFHtmlWriter;
@@ -129,17 +130,26 @@ public class RDFHtmlWriterImpl implements RDFHtmlWriter {
     public void endRDF() throws RDFHandlerException {
 
         List<Map<String, Object>> resources = new ArrayList<Map<String, Object>>();
-        for (Map.Entry<Resource, SortedSet<Statement>> entry : tripleMap
-                .entrySet()) {
+        for (Map.Entry<Resource, SortedSet<Statement>> entry : tripleMap.entrySet()) {
             SortedSet<Statement> ts = entry.getValue();
             Map<String, Object> resource = new HashMap<String, Object>();
-            String uri = ts.first().getSubject().stringValue();
-            resource.put("uri", uri);
-            try {
-                resource.put("encoded_uri", URLEncoder.encode(uri, "UTF-8"));
-            } catch (UnsupportedEncodingException e) {
-                log.error("Error trying to encode '{}': {}", uri, e.getMessage());
-                resource.put("encoded_uri", uri);
+            String subject = ts.first().getSubject().stringValue();
+            if (UriUtil.validate(subject)) {
+            	resource.put("uri", subject);
+	            try {
+	                resource.put("encoded_uri", URLEncoder.encode(subject, "UTF-8"));
+	            } catch (UnsupportedEncodingException e) {
+	                log.error("Error trying to encode '{}': {}", subject, e.getMessage());
+	                resource.put("encoded_uri", subject);
+	            }
+            } else {
+            	resource.put("genid", subject);
+	            try {
+	                resource.put("encoded_genid", URLEncoder.encode(subject, "UTF-8"));
+	            } catch (UnsupportedEncodingException e) {
+	                log.error("Error trying to encode '{}': {}", subject, e.getMessage());
+	                resource.put("encoded_genid", subject);
+	            }
             }
 
             List<Map<String, Object>> triples = new ArrayList<Map<String, Object>>();
@@ -169,7 +179,7 @@ public class RDFHtmlWriterImpl implements RDFHtmlWriter {
                     try {
                     	object.put("encoded_genid", URLEncoder.encode(objectValue, "UTF-8"));
                     } catch (UnsupportedEncodingException e) {
-                        log.error("Error trying to encode '{}': {}", uri, e.getMessage());
+                        log.error("Error trying to encode '{}': {}", subject, e.getMessage());
                         object.put("encoded_genid", objectValue);
                     }                 
                 } else if (value instanceof Literal) { //literal

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/819c97b7/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
index 885dcb3..54e2c9a 100644
--- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
+++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/webservices/resource/MetaWebService.java
@@ -53,7 +53,6 @@ import org.apache.marmotta.platform.core.api.triplestore.SesameService;
 import org.apache.marmotta.platform.core.services.sesame.KiWiSesameUtil;
 import org.apache.marmotta.platform.core.services.sesame.ResourceSubjectMetadata;
 import org.openrdf.model.Resource;
-import org.openrdf.model.URI;
 import org.openrdf.repository.RepositoryConnection;
 import org.openrdf.repository.RepositoryException;
 import org.openrdf.repository.event.InterceptingRepositoryConnection;

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/819c97b7/platform/marmotta-core/src/main/resources/templates/rdfhtml.ftl
----------------------------------------------------------------------
diff --git a/platform/marmotta-core/src/main/resources/templates/rdfhtml.ftl b/platform/marmotta-core/src/main/resources/templates/rdfhtml.ftl
index db00981..45d8e5d 100644
--- a/platform/marmotta-core/src/main/resources/templates/rdfhtml.ftl
+++ b/platform/marmotta-core/src/main/resources/templates/rdfhtml.ftl
@@ -28,11 +28,19 @@
   <link href="${SERVER_URL}${DEFAULT_STYLE}style.css" rel="stylesheet" type="text/css" />
   <link href="${SERVER_URL}${DEFAULT_STYLE}rdfhtml.css" rel="stylesheet" type="text/css" />
   <#if resources?size = 1>
+  <#if resources[0].uri?has_content>
   <link rel="alternate" type="application/rdf+xml" href="${SERVER_URL}resource?uri=${resources[0].encoded_uri}&amp;format=application/rdf%2Bxml" /> 
   <link rel="alternate" type="text/rdf+n3" href="${SERVER_URL}resource?uri=${resources[0].encoded_uri}&amp;format=text/rdf%2Bn3" /> 
   <link rel="alternate" type="text/turtle" href="${SERVER_URL}resource?uri=${resources[0].encoded_uri}&amp;format=text/turtle" /> 
   <link rel="alternate" type="application/rdf+json" href="${SERVER_URL}resource?uri=${resources[0].encoded_uri}&amp;format=application/rdf%2Bjson" /> 
   <link rel="alternate" type="application/ld+json" href="${SERVER_URL}resource?uri=${resources[0].encoded_uri}&amp;format=application/ld%2Bjson" /> 
+  <#else>
+  <link rel="alternate" type="application/rdf+xml" href="${SERVER_URL}resource?genid=${resources[0].encoded_genid}&amp;format=application/rdf%2Bxml" /> 
+  <link rel="alternate" type="text/rdf+n3" href="${SERVER_URL}resource?genid=${resources[0].encoded_genid}&amp;format=text/rdf%2Bn3" /> 
+  <link rel="alternate" type="text/turtle" href="${SERVER_URL}resource?genid=${resources[0].encoded_genid}&amp;format=text/turtle" /> 
+  <link rel="alternate" type="application/rdf+json" href="${SERVER_URL}resource?genid=${resources[0].encoded_genid}&amp;format=application/rdf%2Bjson" /> 
+  <link rel="alternate" type="application/ld+json" href="${SERVER_URL}resource?genid=${resources[0].encoded_genid}&amp;format=application/ld%2Bjson" />   
+  </#if>
   </#if>
       
   <script>
@@ -117,7 +125,7 @@
               };
           }
 
-      <#if resources?size = 1>
+      <#if resources?size = 1 && resources[0].uri?has_content>
           var subjLoader = new loader("${resources[0].uri}", "subject", "inspect_subject");
           subjLoader.fetch();
           $("#s0").click(function() {subjLoader.first();});
@@ -182,11 +190,19 @@
         <h1>RDF/HTML</h1>
         <#if resources?size = 1>
         <div id="top_serialisation_links">
+          <#if resources[0].uri?has_content>
             <a href="${SERVER_URL}resource?uri=${resources[0].encoded_uri}&amp;format=application/rdf%2Bxml">RDF/XML</a>&nbsp;|&nbsp;
             <a href="${SERVER_URL}resource?uri=${resources[0].encoded_uri}&amp;format=text/rdf%2Bn3">N3</a>&nbsp;|&nbsp;
             <a href="${SERVER_URL}resource?uri=${resources[0].encoded_uri}&amp;format=text/turtle">Turtle</a>&nbsp;|&nbsp;
             <a href="${SERVER_URL}resource?uri=${resources[0].encoded_uri}&amp;format=application/rdf%2Bjson">RDF/JSON</a>&nbsp;|&nbsp;
             <a href="${SERVER_URL}resource?uri=${resources[0].encoded_uri}&amp;format=application/ld%2Bjson">JSON-LD</a>
+          <#else>
+            <a href="${SERVER_URL}resource?genid=${resources[0].encoded_genid}&amp;format=application/rdf%2Bxml">RDF/XML</a>&nbsp;|&nbsp;
+            <a href="${SERVER_URL}resource?genid=${resources[0].encoded_genid}&amp;format=text/rdf%2Bn3">N3</a>&nbsp;|&nbsp;
+            <a href="${SERVER_URL}resource?genid=${resources[0].encoded_genid}&amp;format=text/turtle">Turtle</a>&nbsp;|&nbsp;
+            <a href="${SERVER_URL}resource?genid=${resources[0].encoded_genid}&amp;format=application/rdf%2Bjson">RDF/JSON</a>&nbsp;|&nbsp;
+            <a href="${SERVER_URL}resource?genid=${resources[0].encoded_genid}&amp;format=application/ld%2Bjson">JSON-LD</a>          
+          </#if>
         </div>
         <div class="clean"></div>
         </#if>
@@ -212,12 +228,17 @@
             <h1>Triples</h1>
             <#if resources?has_content>
                 <#list resources as resource>
-                    <h2><a href="${resource.uri}" class="ldcache">${resource.uri}</a>
-                        <#if timemaplink??>
-                            <a style="float:right" id="timemap_link" href="${SERVER_URL}${timemaplink}${resource.uri}">
-                                <img style="width: 24px" title="browser versions" alt="memento" src="${SERVER_URL}core/public/img/icon/memento_logo_128.png">
-                            </a>
-                        </#if>
+                    <h2>
+                	<#if resource.uri?has_content>
+                		<a href="${resource.uri}" class="ldcache">${resource.uri}</a>
+                	<#else>
+                		<a href="${SERVER_URL}resource?genid=${resource.encoded_genid}">bnode://${resource.genid}</a>
+                    </#if>                		
+                    <#if timemaplink?? && resource.uri?has_content>
+                        <a style="float:right" id="timemap_link" href="${SERVER_URL}${timemaplink}${resource.uri}">
+                            <img style="width: 24px" title="browser versions" alt="memento" src="${SERVER_URL}core/public/img/icon/memento_logo_128.png">
+                        </a>
+                    </#if>
                     </h2>
                     <table class="simple_table">
                         <tr class="trClassHeader">
@@ -231,7 +252,11 @@
                                 <td>
                                     <a href="${triple.predicate.uri}" class="ldcache">${triple.predicate.curie}</a>
                                 </td>
+                                <#if resource.uri?has_content>
                                 <td about="${resource.uri}">
+                                <#else>
+                                <td>
+                                </#if>
                                     <#if triple.object.uri?has_content>
                                     	<a rel="${triple.predicate.curie}" href="${triple.object.uri}" class="${cacheClass(triple.object)}">${triple.object.curie}</a>
                                     <#elseif triple.object.genid?has_content>	
@@ -245,7 +270,7 @@
                             </tr>
                         </#list>
                     </table>
-                    <#if resources?size != 1>
+                    <#if resources?size != 1 && resource.uri?has_content>
                     <p id="rawrdf">
                         Get this resource in raw RDF:
                         <a href="${SERVER_URL}resource?uri=${resource.encoded_uri}&amp;format=application/rdf%2Bxml">RDF/XML</a>,
@@ -264,7 +289,7 @@
 
             </div>
 
-        <#if resources?size = 1>
+        <#if resources?size = 1 && resources[0].uri?has_content>
             <div id="tab-inspection" style="display: none">
                 <h1>Inspection of <a href="${resources[0].uri}" class="ldcache">${resources[0].uri}</a></h1>
                 <div class="introspectionDetails">