incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1377808 - in /sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog: html.esp xml.esp
Date Mon, 27 Aug 2012 19:49:48 GMT
Author: bdelacretaz
Date: Mon Aug 27 19:49:48 2012
New Revision: 1377808

URL: http://svn.apache.org/viewvc?rev=1377808&view=rev
Log:
SLING-1540 - currentNode might not be available

Modified:
    sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp
    sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/xml.esp

Modified: sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp
URL: http://svn.apache.org/viewvc/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp?rev=1377808&r1=1377807&r2=1377808&view=diff
==============================================================================
--- sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp (original)
+++ sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/html.esp Mon
Aug 27 19:49:48 2012
@@ -24,6 +24,11 @@
 load("header.esp");
 load("constants.esp");
 
+// SLING-1540 - currentNode might not be present
+if(typeof(currentNode) == 'undefined') {
+    currentNode = null;
+}    
+
 function render(attachmentNode) {
   if(attachmentNode.getNode("jcr:content").getProperty("jcr:mimeType").getString().substring(0,5)
== "image") {
     %><p><img src="<%=attachmentNode%>"></p><%
@@ -35,10 +40,12 @@ function render(attachmentNode) {
 function renderMedia(postNode, mediaFolderName) {
 	if(postNode.hasNode(mediaFolderName)) {
 		%><h3><%= mediaFolderName %></h3><%
-		var nodes = currentNode.getNode(mediaFolderName).getNodes();
-		for(i in nodes) {
-	      render(nodes[i]);
-		}
+		if(currentNode) {
+		  var nodes = currentNode.getNode(mediaFolderName).getNodes();
+		  for(i in nodes) {
+	       render(nodes[i]);
+		  }
+        }
 	}
 }
 %>
@@ -60,11 +67,11 @@ function renderMedia(postNode, mediaFold
        <div class="main">
 			<h1><%= BLOG_TITLE %></h1>
 			<div id="postbody">	
-				<h2><%=currentNode.title ? currentNode.title : ""%></h2>	
-				<p><%=currentNode.posttext ? currentNode.posttext : ""%></p>
+				<h2><%=(currentNode && currentNode.title) ? currentNode.title : ""%></h2>

+				<p><%=(currentNode && currentNode.posttext) ? currentNode.posttext :
""%></p>
 				
 				<%
-				if(currentNode.hasNode("comments")) {
+				if(currentNode && currentNode.hasNode("comments")) {
 				    %><h3>Comments</h3><%
 					comments = currentNode.getNode("comments").getNodes()
 					for (a in comments) {
@@ -83,7 +90,7 @@ function renderMedia(postNode, mediaFold
 				}
 				%>
 						
-				<% if(currentNode.title) { %>							
+				<% if(currentNode && currentNode.title) { %>							
 			    <h3>Comment on this post</h3>
 				<form class="hform" method="POST" action="<%=currentNode%>/comments/*">
                     <p>
@@ -99,8 +106,10 @@ function renderMedia(postNode, mediaFold
 				<% } %>
 			</div>
 			<div id="resources">
-				<% renderMedia(currentNode, "attachments"); %>
-				<% renderMedia(currentNode, "thumbnails"); %>
+                <% if(currentNode) { %>                            
+				    <% renderMedia(currentNode, "attachments"); %>
+				    <% renderMedia(currentNode, "thumbnails"); %>
+                <% } %>
 			</div>
 		</div>			
 	</body>

Modified: sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/xml.esp
URL: http://svn.apache.org/viewvc/sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/xml.esp?rev=1377808&r1=1377807&r2=1377808&view=diff
==============================================================================
--- sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/xml.esp (original)
+++ sling/trunk/samples/espblog/src/main/resources/initial-content/apps/espblog/xml.esp Mon
Aug 27 19:49:48 2012
@@ -20,10 +20,17 @@
 %>
 
 <%    
-   var queryManager = currentNode.getSession().getWorkspace().getQueryManager();  
-   var query = queryManager.createQuery("/jcr:root/content/espblog/posts/element(*, nt:unstructured)
order by @created descending", "xpath");
-   var result = query.execute().getNodes();
-   
+    // SLING-1540 - currentNode might not be present
+    if(typeof(currentNode) == 'undefined') {
+        currentNode = null;
+    }    
+
+   var result = null;
+   if(currentNode) {
+       var queryManager = currentNode.getSession().getWorkspace().getQueryManager();  
+       var query = queryManager.createQuery("/jcr:root/content/espblog/posts/element(*, nt:unstructured)
order by @created descending", "xpath");
+       result = query.execute().getNodes();
+   }       
 %>
 
 <rss version="2.0">
@@ -33,11 +40,11 @@
       <description>RSS 2.0 feed of my Sling blog</description>
       
       <%
-      	df = new java.text.SimpleDateFormat( "EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z", Packages.java.util.Locale.US);
-	var counter = 0;
-	while(result.hasNext() && counter < 10) {
-		counter++;
-		post = result.nextNode()
+        df = new java.text.SimpleDateFormat( "EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z", Packages.java.util.Locale.US);
+        var counter = 0;
+        while(result && result.hasNext() && counter < 10) {
+            counter++;
+            post = result.nextNode()
       %>
       
       <item>



Mime
View raw message