Author: cziegeler
Date: Wed Dec 30 16:27:28 2009
New Revision: 894663
URL: http://svn.apache.org/viewvc?rev=894663&view=rev
Log:
Exclude special folders (like those starting with a dot) and add support for
preview images.
Modified:
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/Constants.java
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Album/photolist.html.jsp
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Album/tree.html.jsp
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Photo/main.html.jsp
Modified:
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/Constants.java
URL:
http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/Constants.java?rev=894663&r1=894662&r2=894663&view=diff
==============================================================================
---
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/Constants.java
(original)
+++
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/Constants.java
Wed Dec 30 16:27:28 2009
@@ -16,29 +16,58 @@
*/
package org.apache.sling.sample.slingshot;
-public interface Constants {
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceUtil;
+
+public abstract class Constants {
/** This is the resource path for the root of our application. */
- String APP_ROOT = "/slingshot";
+ public static final String APP_ROOT = "/slingshot";
/** This is the resource path for the root album. */
- String ALBUMS_ROOT = APP_ROOT + "/albums";
+ public static final String ALBUMS_ROOT = APP_ROOT + "/albums";
/** The resource type of a folder (= album) */
- String RESOURCETYPE_FOLDER = "nt:folder";
+ public static final String RESOURCETYPE_FOLDER = "nt:folder";
/** The resource type of an extended folder (= album) */
- String RESOURCETYPE_EXT_FOLDER = "sling:Folder";
+ public static final String RESOURCETYPE_EXT_FOLDER = "sling:Folder";
/** The resource type for an album. */
- String RESOURCETYPE_ALBUM = "slingshot/Album";
+ public static final String RESOURCETYPE_ALBUM = "slingshot/Album";
/** The resource type of a file (= photo) */
- String RESOURCETYPE_FILE = "nt:file";
+ public static final String RESOURCETYPE_FILE = "nt:file";
/** The resource type for a photo. */
- String RESOURCETYPE_PHOTO = "slingshot/Photo";
+ public static final String RESOURCETYPE_PHOTO = "slingshot/Photo";
/** The property containing the tags. */
- String PROPERTY_SLINGSHOT_TAGS = "slingshot:tags";
+ public static final String PROPERTY_SLINGSHOT_TAGS = "slingshot:tags";
+
+ /** Name of the preview folder */
+ public static final String FOLDER_NAME_PREVIEW = "preview";
+
+ /**
+ * We only include resource which names do not start with a dot
+ * and we also exclude the preview folder.
+ */
+ public static boolean includeAsAlbum(final Resource resource) {
+ final String name = ResourceUtil.getName(resource);
+ if ( name.equals(FOLDER_NAME_PREVIEW) || name.startsWith(".") ) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Exclude all files starting with a dot
+ */
+ public static boolean includeAsMedia(final Resource resource) {
+ final String name = ResourceUtil.getName(resource);
+ if ( name.startsWith(".") ) {
+ return false;
+ }
+ return true;
+ }
}
Modified:
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Album/photolist.html.jsp
URL:
http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Album/photolist.html.jsp?rev=894663&r1=894662&r2=894663&view=diff
==============================================================================
---
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Album/photolist.html.jsp
(original)
+++
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Album/photolist.html.jsp
Wed Dec 30 16:27:28 2009
@@ -29,7 +29,8 @@
final Iterator<Resource> fi = ResourceUtil.listChildren(resource);
while ( fi.hasNext()) {
final Resource current = fi.next();
- if ( ResourceUtil.isA(current, Constants.RESOURCETYPE_FILE) ) {
+ if ( ResourceUtil.isA(current, Constants.RESOURCETYPE_FILE)
+ && Constants.includeAsMedia(current)) {
%>
<sling:include resource="<%= current %>"
resourceType="slingshot/Photo" replaceSelectors="main"/>
<%
Modified:
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Album/tree.html.jsp
URL:
http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Album/tree.html.jsp?rev=894663&r1=894662&r2=894663&view=diff
==============================================================================
---
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Album/tree.html.jsp
(original)
+++
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Album/tree.html.jsp
Wed Dec 30 16:27:28 2009
@@ -23,16 +23,17 @@
%><%...@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"
%><%
%><sling:defineObjects/><%
%><div class="tree">
- <div class="albumlist">
+ <div class="albumlist">
<h2>Contained Albums</h2>
<%
- final Iterator<Resource> ri = ResourceUtil.listChildren(resource);
- while ( ri.hasNext()) {
- final Resource current = ri.next();
- if ( ResourceUtil.isA(current, Constants.RESOURCETYPE_FOLDER) ) {
- %><sling:include resource="<%= current %>"
resourceType="slingshot/Album" replaceSelectors="treeentry"/><%
- }
- }
- %>
+ final Iterator<Resource> ri = ResourceUtil.listChildren(resource);
+ while ( ri.hasNext()) {
+ final Resource current = ri.next();
+ if ( ResourceUtil.isA(current, Constants.RESOURCETYPE_FOLDER)
+ && Constants.includeAsAlbum(current)) {
+ %><sling:include resource="<%= current %>"
resourceType="slingshot/Album" replaceSelectors="treeentry"/><%
+ }
+ }
+ %>
</div>
</div>
\ No newline at end of file
Modified:
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Photo/main.html.jsp
URL:
http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Photo/main.html.jsp?rev=894663&r1=894662&r2=894663&view=diff
==============================================================================
---
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Photo/main.html.jsp
(original)
+++
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Photo/main.html.jsp
Wed Dec 30 16:27:28 2009
@@ -18,7 +18,8 @@
--%><%...@page session="false" %><%
%><%...@page import="org.apache.sling.api.resource.Resource,
org.apache.sling.api.resource.ResourceUtil,
- org.apache.sling.api.resource.ValueMap" %><%
+ org.apache.sling.api.resource.ValueMap,
+ org.apache.sling.sample.slingshot.Constants" %><%
%><%...@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0"
%><%
%><sling:defineObjects/><%
%><div class="photo">
@@ -27,9 +28,13 @@
final String albumName =
ResourceUtil.getName(ResourceUtil.getParent(resource));
final String photoName = attr.get("jcr:title",
ResourceUtil.getName(resource));
final String relPath = resource.getPath();
-
+ String imagePath = relPath;
+ String previewPath = ResourceUtil.getParent(resource).getPath() + '/' +
Constants.FOLDER_NAME_PREVIEW + '/' + ResourceUtil.getName(resource);
+ if ( resource.getResourceResolver().getResource(previewPath) != null ) {
+ imagePath = previewPath;
+ }
%>
- <a href="<%= request.getContextPath() %><%=relPath%>.slingshot.html"><img
src="<%=relPath%>" width="100" height="100"/></a><br/>
+ <a href="<%= request.getContextPath() %><%=relPath%>.slingshot.html"><img
src="<%=imagePath%>" width="100" height="100"/></a><br/>
<p><a href="<%= request.getContextPath()
%><%=relPath%>.slingshot.html"><%= photoName %></a></p>
<p>Tags:
<%