You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/05/10 14:05:09 UTC
svn commit: r1678557 - in /sling/trunk/samples/slingshot: ./
src/main/java/org/apache/sling/sample/slingshot/
src/main/java/org/apache/sling/sample/slingshot/comments/
src/main/java/org/apache/sling/sample/slingshot/comments/impl/
src/main/java/org/apa...
Author: cziegeler
Date: Sun May 10 12:05:08 2015
New Revision: 1678557
URL: http://svn.apache.org/r1678557
Log:
Refactor sample to user service user. Refactor utility methods into services, change content model
Added:
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java (with props)
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java (with props)
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentPostServlet.java
- copied, changed from r1678554, sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/CommentPostServlet.java
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java (with props)
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java (with props)
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java (with props)
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServlet.java
- copied, changed from r1678172, sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/RatingPostServlet.java
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java (with props)
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content/
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content.json (with props)
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content/itemlist.html.jsp (with props)
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/docs/
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/docs/content-model.html (with props)
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/
- copied from r1678172, sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/public/
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users.json
- copied unchanged from r1678172, sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/public.json
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content.json (with props)
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/
- copied from r1678172, sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/public/slingshot1/travel/
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel.json
- copied unchanged from r1678172, sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/public/slingshot1/travel.json
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/info/
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/info.json (with props)
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/profile/
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/profile.json (with props)
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/ugc/
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/ugc.json (with props)
Removed:
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/CommentPostServlet.java
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/RatingPostServlet.java
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/public/
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/public.json
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/travel/
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/travel.json
Modified:
sling/trunk/samples/slingshot/pom.xml
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotConstants.java
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotUtil.java
sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/SetupService.java
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Home/user.html.jsp
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Item/html.jsp
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Item/main.html.jsp
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/User/html.jsp
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/home.json
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/pet.json
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/sea.json
sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/view.json
Modified: sling/trunk/samples/slingshot/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/pom.xml?rev=1678557&r1=1678556&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/pom.xml (original)
+++ sling/trunk/samples/slingshot/pom.xml Sun May 10 12:05:08 2015
@@ -115,6 +115,10 @@
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
Modified: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotConstants.java
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotConstants.java?rev=1678557&r1=1678556&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotConstants.java (original)
+++ sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotConstants.java Sun May 10 12:05:08 2015
@@ -22,29 +22,17 @@ public abstract class SlingshotConstants
/** This is the resource path for the root of our application. */
public static final String APP_ROOT_PATH = "/slingshot";
- /** The resource type for a category. */
- public static final String RESOURCETYPE_CATEGORY = "slingshot/Category";
-
- /** The resource type for an item. */
- public static final String RESOURCETYPE_ITEM = "slingshot/Item";
-
/** The resource type for a user. */
public static final String RESOURCETYPE_USER = "slingshot/User";
- /** The resource type for a comment. */
- public static final String RESOURCETYPE_COMMENT = "slingshot/Comment";
-
- /** The resource type for a rating. */
- public static final String RESOURCETYPE_RATING = "slingshot/Rating";
-
- /** The resource type for the resource holder of the comments. */
- public static final String RESOURCETYPE_COMMENTS = "slingshot/Comments";
+ /** The resource type for the content. */
+ public static final String RESOURCETYPE_CONTENT = "slingshot/Content";
- /** The resource type for the resource holder of the ratings */
- public static final String RESOURCETYPE_RATINGS = "slingshot/Ratings";
+ /** The resource type for a category. */
+ public static final String RESOURCETYPE_CATEGORY = "slingshot/Category";
- /** The resource type for a user. */
- public static final String RESOURCETYPE_HOME = "slingshot/Home";
+ /** The resource type for an item. */
+ public static final String RESOURCETYPE_ITEM = "slingshot/Item";
public static final String PROPERTY_TITLE = "title";
@@ -53,10 +41,4 @@ public abstract class SlingshotConstants
public static final String PROPERTY_LOCATION = "location";
public static final String PROPERTY_TAGS = "tags";
-
- public static final String PROPERTY_USER = "user";
-
- public static final String PROPERTY_CREATED = "jcr:created";
-
- public static final String PROPERTY_RATING = "rating";
}
Modified: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotUtil.java?rev=1678557&r1=1678556&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotUtil.java (original)
+++ sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/SlingshotUtil.java Sun May 10 12:05:08 2015
@@ -16,15 +16,7 @@
*/
package org.apache.sling.sample.slingshot;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.sling.api.resource.ModifiableValueMap;
-import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.ResourceUtil;
-import org.apache.sling.api.resource.ValueMap;
public abstract class SlingshotUtil {
@@ -46,52 +38,10 @@ public abstract class SlingshotUtil {
return id;
}
- public static int getRating(final Resource resource) {
- int rating = 0;
-
- final Resource ratingsResource = resource.getChild("ratings");
- if ( ratingsResource != null ) {
- int count = 0;
- for(final Resource r : ratingsResource.getChildren()) {
- final ValueMap vm = r.getValueMap();
- final int current = vm.get(SlingshotConstants.PROPERTY_RATING, 0);
- rating += current;
- count++;
- }
- if ( count > 0 ) {
- rating = rating / count;
- }
- }
- return rating;
- }
-
- public static int getOwnRating(final Resource resource, final String userId) {
- int rating = 0;
-
- final Resource r = resource.getResourceResolver().getResource(resource.getParent() + "/ratings/" + userId);
- if ( r != null ) {
- final ValueMap vm = r.getValueMap();
- rating = vm.get(SlingshotConstants.PROPERTY_RATING, 0);
- }
- return rating;
-
- }
-
- public static void setOwnRating(final Resource resource, final String userId, final int rating)
- throws PersistenceException {
- final Map<String, Object> props = new HashMap<String, Object>();
- props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, SlingshotConstants.RESOURCETYPE_RATINGS);
- final Resource ratingsResource = ResourceUtil.getOrCreateResource(resource.getResourceResolver(),
- resource.getPath() + "/ratings", props, null, true);
-
- props.clear();
- props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, SlingshotConstants.RESOURCETYPE_RATING);
- final Resource r = ResourceUtil.getOrCreateResource(resource.getResourceResolver(),
- ratingsResource.getPath() + "/" + userId, props, null, false);
-
- final ModifiableValueMap mv = r.adaptTo(ModifiableValueMap.class);
- mv.put(SlingshotConstants.PROPERTY_RATING, rating);
+ public static String getContentPath(final Resource resource) {
+ final String path = resource.getPath();
+ final int i = path.indexOf("/content/");
- r.getResourceResolver().commit();
+ return (i == -1 ? null : path.substring(i + 8));
}
}
Added: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java (added)
+++ sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java Sun May 10 12:05:08 2015
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.sample.slingshot.comments;
+
+import java.util.Calendar;
+
+public interface Comment {
+
+ String getTitle();
+
+ String getDescription();
+
+ Calendar getCreated();
+
+ String getCreatedBy();
+}
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/Comment.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java (added)
+++ sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java Sun May 10 12:05:08 2015
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.sample.slingshot.comments;
+
+
+public abstract class CommentsUtil {
+
+ /** The resource type for a comment. */
+ public static final String RESOURCETYPE_COMMENT = "slingshot/Comment";
+
+ public static final String PROPERTY_TITLE = "title";
+
+ public static final String PROPERTY_DESCRIPTION = "description";
+
+ public static final String PROPERTY_USER = "user";
+
+ public static final String PROPERTY_CREATED = "jcr:created";
+}
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/CommentsUtil.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentPostServlet.java (from r1678554, sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/CommentPostServlet.java)
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentPostServlet.java?p2=sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentPostServlet.java&p1=sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/CommentPostServlet.java&r1=1678554&r2=1678557&rev=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/CommentPostServlet.java (original)
+++ sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/comments/impl/CommentPostServlet.java Sun May 10 12:05:08 2015
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sling.sample.slingshot.impl;
+package org.apache.sling.sample.slingshot.comments.impl;
import java.io.IOException;
import java.util.HashMap;
@@ -36,10 +36,12 @@ import org.apache.sling.api.resource.Res
import org.apache.sling.api.resource.ResourceUtil;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.sample.slingshot.SlingshotConstants;
+import org.apache.sling.sample.slingshot.comments.CommentsUtil;
+import org.apache.sling.sample.slingshot.impl.Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@SlingServlet(methods="POST", resourceTypes=SlingshotConstants.RESOURCETYPE_COMMENTS)
+@SlingServlet(methods="POST", extensions="comments", resourceTypes=SlingshotConstants.RESOURCETYPE_ITEM)
public class CommentPostServlet extends SlingAllMethodsServlet {
private static final long serialVersionUID = 1L;
@@ -69,10 +71,10 @@ public class CommentPostServlet extends
final Resource reqResource = resolver.getResource(request.getResource().getPath());
final Map<String, Object> properties = new HashMap<String, Object>();
- properties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, SlingshotConstants.RESOURCETYPE_COMMENT);
+ properties.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, CommentsUtil.RESOURCETYPE_COMMENT);
properties.put(SlingshotConstants.PROPERTY_TITLE, title);
properties.put(SlingshotConstants.PROPERTY_DESCRIPTION, description);
- properties.put(SlingshotConstants.PROPERTY_USER, userId);
+ properties.put(CommentsUtil.PROPERTY_USER, userId);
// we try it five times
PersistenceException exception = null;
Added: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java (added)
+++ sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java Sun May 10 12:05:08 2015
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.sample.slingshot.impl;
+
+
+public abstract class InternalConstants {
+
+ /** This is name of the service user. */
+ public static final String SERVICE_USER_NAME = "slingshot-service";
+
+ /** The resource type for the root of slingshot. */
+ public static final String RESOURCETYPE_HOME = "slingshot/Home";
+
+}
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/InternalConstants.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/SetupService.java
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/SetupService.java?rev=1678557&r1=1678556&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/SetupService.java (original)
+++ sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/SetupService.java Sun May 10 12:05:08 2015
@@ -16,8 +16,11 @@
*/
package org.apache.sling.sample.slingshot.impl;
+import java.io.IOException;
import java.security.Principal;
+import java.util.Dictionary;
import java.util.HashMap;
+import java.util.Hashtable;
import java.util.Map;
import javax.jcr.RepositoryException;
@@ -38,9 +41,16 @@ import org.apache.sling.api.resource.Res
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.jcr.base.util.AccessControlUtil;
import org.apache.sling.sample.slingshot.SlingshotConstants;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * The setup service sets up difference things.
+ */
@Component
public class SetupService {
@@ -49,15 +59,24 @@ public class SetupService {
@Reference
private ResourceResolverFactory factory;
+ @Reference
+ private ConfigurationAdmin configAdmin;
+
private static final String[] USERS = new String[] {"slingshot1", "slingshot2"};
+ private static final String[] FOLDERS = new String[] {
+ "content:" + SlingshotConstants.RESOURCETYPE_CONTENT,
+ "info",
+ "profile",
+ "ugc"};
+
@Activate
- protected void activate() throws LoginException, PersistenceException, RepositoryException {
+ protected void activate(final BundleContext bc) throws IOException, LoginException, PersistenceException, RepositoryException {
logger.info("Setting up SlingShot...");
ResourceResolver resolver = null;
try {
resolver = this.factory.getAdministrativeResourceResolver(null);
- setupUsers(resolver);
+ setupUsers(bc, resolver);
setupContent(resolver);
setupACL(resolver);
} finally {
@@ -71,15 +90,22 @@ public class SetupService {
private void setupACL(final ResourceResolver resolver) throws RepositoryException {
final Session session = resolver.adaptTo(Session.class);
+ // create default slingshot users
for(final String principalId : USERS) {
- final String resourcePath = SlingshotConstants.APP_ROOT_PATH + "/public/" + principalId;
+ final String resourcePath = SlingshotConstants.APP_ROOT_PATH + "/users/" + principalId;
final Map<String, String> privileges = new HashMap<String, String>();
privileges.put(Privilege.JCR_ALL, "granted");
modifyAce(session, resourcePath, principalId, Privilege.JCR_ALL, true);
+ // ugc path
+ final String ugcPath = resourcePath + "/ugc";
privileges.clear();
+ privileges.put(Privilege.JCR_ALL, "granted");
+
+ modifyAce(session, ugcPath, InternalConstants.SERVICE_USER_NAME,
+ Privilege.JCR_ALL, true);
}
}
@@ -112,7 +138,7 @@ public class SetupService {
}
}
- private void setupUsers(final ResourceResolver resolver) throws RepositoryException {
+ private void setupUsers(final BundleContext bc, final ResourceResolver resolver) throws RepositoryException, IOException {
final UserManager um = AccessControlUtil.getUserManager(resolver.adaptTo(Session.class));
for(final String userName : USERS) {
Authorizable user = um.getAuthorizable(userName);
@@ -121,27 +147,73 @@ public class SetupService {
um.createUser(userName, userName);
}
}
+
+ // create a service user
+ Authorizable user = um.getAuthorizable(InternalConstants.SERVICE_USER_NAME);
+ if ( user == null ) {
+ logger.info("Creating user {}", InternalConstants.SERVICE_USER_NAME);
+ um.createUser(InternalConstants.SERVICE_USER_NAME, InternalConstants.SERVICE_USER_NAME);
+ }
+
+ // check for service user config
+ boolean exists = false;
+ try {
+ if ( this.configAdmin.listConfigurations("(&("
+ + ConfigurationAdmin.SERVICE_FACTORYPID + "=org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended"
+ + ")(user.mapping=" + bc.getBundle().getSymbolicName() + "*"
+ + "))") != null ) {
+ exists = true;
+ }
+ } catch (final InvalidSyntaxException e) {
+ exists = false;
+ }
+ if ( !exists ) {
+ logger.info("Creating service user mapping");
+ final Configuration c = this.configAdmin.createFactoryConfiguration("org.apache.sling.serviceusermapping.impl.ServiceUserMapperImpl.amended", null);
+ final Dictionary<String, Object> dict = new Hashtable<String, Object>();
+ dict.put("user.mapping", bc.getBundle().getSymbolicName() + "=" + InternalConstants.SERVICE_USER_NAME);
+
+ c.update(dict);
+ }
}
private void setupContent(final ResourceResolver resolver) throws PersistenceException {
final Resource root = resolver.getResource(SlingshotConstants.APP_ROOT_PATH);
if ( root != null ) {
// fix resource type of root folder
- if ( !root.isResourceType(SlingshotConstants.RESOURCETYPE_HOME)) {
+ if ( !root.isResourceType(InternalConstants.RESOURCETYPE_HOME)) {
final ModifiableValueMap mvm = root.adaptTo(ModifiableValueMap.class);
- mvm.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, SlingshotConstants.RESOURCETYPE_HOME);
+ mvm.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, InternalConstants.RESOURCETYPE_HOME);
resolver.commit();
}
- final Resource publicResource = root.getChild("public");
+ final Resource usersResource = root.getChild("users");
for(final String userName : USERS) {
- final String path = SlingshotConstants.APP_ROOT_PATH + "/public/" + userName;
- final Resource homeResource = resolver.getResource(path);
+ Resource homeResource = resolver.getResource(usersResource, userName);
if ( homeResource == null ) {
final Map<String, Object> props = new HashMap<String, Object>();
props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, SlingshotConstants.RESOURCETYPE_USER);
- resolver.create(publicResource, userName, props);
+ homeResource = resolver.create(usersResource, userName, props);
resolver.commit();
}
+ for(final String def : FOLDERS) {
+ final int index = def.indexOf(':');
+ final String name;
+ final String rt;
+ if ( index == -1 ) {
+ name = def;
+ rt = "sling:OrderedFolder";
+ } else {
+ name = def.substring(0, index);
+ rt = def.substring(index + 1);
+ }
+ final Resource rsrc = resolver.getResource(homeResource, name);
+ if ( rsrc == null ) {
+ final Map<String, Object> props = new HashMap<String, Object>();
+ props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, rt);
+ resolver.create(homeResource, name, props);
+ resolver.commit();
+ }
+ }
}
}
}
Added: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java (added)
+++ sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java Sun May 10 12:05:08 2015
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.sample.slingshot.ratings;
+
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+
+/**
+ * Service for handling the ratings
+ */
+public interface RatingsService {
+
+ /**
+ * Return the path to the ratings resource for a resource.
+ * @param resource The content resource, this is usually an item.
+ * @return The path to the ratings resource or {@code null} if
+ * the passed in content resource is not part of
+ * Slingshot.
+ */
+ String getRatingsResourcePath(final Resource resource);
+
+
+ /**
+ * Get the overall rating for a resource.
+ * @param resource The content resource, this is usually an item.
+ * @return The rating or {@code 0} if
+ * the passed in content resource is not part of
+ * Slingshot.
+ */
+ int getRating(final Resource resource);
+
+ /**
+ * Get the rating of a user for a resource.
+ * @param resource The content resource, this is usually an item.
+ * @param userId The user id
+ * @return The rating or {@code 0} if
+ * the passed in content resource is not part of
+ * Slingshot.
+ */
+ int getRating(final Resource resource, final String userId);
+
+ /**
+ * Set the rating of a user for a resource.
+ * @param resource The content resource, this is usually an item.
+ * @param userId The user id
+ * @return The rating or {@code 0} if
+ * the passed in content resource is not part of
+ * Slingshot.
+ */
+ void setRating(final Resource resource, final String userId, final int rating)
+ throws PersistenceException;
+}
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsService.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java (added)
+++ sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java Sun May 10 12:05:08 2015
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.sample.slingshot.ratings;
+
+
+/**
+ * Utility class for handling ratings.
+ */
+public abstract class RatingsUtil {
+
+ /** The resource type for a rating. */
+ public static final String RESOURCETYPE_RATING = "slingshot/Rating";
+
+ /** The property of a rating resource holding the rating for a user. */
+ public static final String PROPERTY_RATING = "rating";
+}
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/RatingsUtil.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServlet.java (from r1678172, sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/RatingPostServlet.java)
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServlet.java?p2=sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServlet.java&p1=sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/RatingPostServlet.java&r1=1678172&r2=1678557&rev=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/impl/RatingPostServlet.java (original)
+++ sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingPostServlet.java Sun May 10 12:05:08 2015
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sling.sample.slingshot.impl;
+package org.apache.sling.sample.slingshot.ratings.impl;
import java.io.IOException;
import java.io.PrintWriter;
@@ -26,16 +26,20 @@ import org.apache.felix.scr.annotations.
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.LoginException;
-import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.sample.slingshot.SlingshotConstants;
-import org.apache.sling.sample.slingshot.SlingshotUtil;
+import org.apache.sling.sample.slingshot.ratings.RatingsService;
+import org.apache.sling.sample.slingshot.ratings.RatingsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-@SlingServlet(methods="POST", resourceTypes=SlingshotConstants.RESOURCETYPE_RATINGS)
+/**
+ * The ratings post servlet is registered for a POST to an item with
+ * the selector "rating".
+ */
+@SlingServlet(methods="POST", extensions="ratings", resourceTypes=SlingshotConstants.RESOURCETYPE_ITEM)
public class RatingPostServlet extends SlingAllMethodsServlet {
private static final long serialVersionUID = 1L;
@@ -45,12 +49,14 @@ public class RatingPostServlet extends S
@Reference
private ResourceResolverFactory factory;
+ @Reference
+ private RatingsService ratingsService;
+
@Override
protected void doPost(final SlingHttpServletRequest request,
final SlingHttpServletResponse response)
throws ServletException, IOException {
- final String rating = request.getParameter(SlingshotConstants.PROPERTY_RATING);
-
+ final String rating = request.getParameter(RatingsUtil.PROPERTY_RATING);
final String userId = request.getRemoteUser();
logger.debug("New rating from {} : {}", userId, rating);
@@ -58,11 +64,9 @@ public class RatingPostServlet extends S
// save rating
ResourceResolver resolver = null;
try {
- resolver = factory.getAdministrativeResourceResolver(null);
-
- final Resource reqResource = resolver.getResource(request.getResource().getPath());
+ resolver = factory.getServiceResourceResolver(null);
- SlingshotUtil.setOwnRating(reqResource.getParent(), userId, Integer.valueOf(rating));
+ ratingsService.setRating(request.getResource(), userId, Integer.valueOf(rating));
} catch ( final LoginException le ) {
throw new ServletException("Unable to login", le);
} finally {
@@ -78,7 +82,7 @@ public class RatingPostServlet extends S
final PrintWriter pw = response.getWriter();
pw.print("{ ");
pw.print(" \"rating\" : ");
- pw.print(String.valueOf(SlingshotUtil.getRating(request.getResource().getParent())));
+ pw.print(String.valueOf(ratingsService.getRating(request.getResource())));
pw.println("}");
}
Added: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java (added)
+++ sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java Sun May 10 12:05:08 2015
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.sample.slingshot.ratings.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.resource.PersistenceException;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.sample.slingshot.SlingshotConstants;
+import org.apache.sling.sample.slingshot.SlingshotUtil;
+import org.apache.sling.sample.slingshot.ratings.RatingsService;
+import org.apache.sling.sample.slingshot.ratings.RatingsUtil;
+
+/**
+ * Implementation of the ratings service
+ */
+@Component
+@Service(value=RatingsService.class)
+public class RatingsServiceImpl implements RatingsService {
+
+ /** The resource type for the rating holder. */
+ public static final String RESOURCETYPE_RATINGS = "sling:Folder";
+
+ /**
+ * @see org.apache.sling.sample.slingshot.ratings.RatingsService#getRatingsResourcePath(org.apache.sling.api.resource.Resource)
+ */
+ public String getRatingsResourcePath(final Resource resource) {
+ final String contentPath = SlingshotUtil.getContentPath(resource);
+ if ( contentPath != null ) {
+ final String fullPath = SlingshotConstants.APP_ROOT_PATH
+ + "/users/" + SlingshotUtil.getUserId(resource)
+ + "/ugc/ratings" + contentPath;
+ return fullPath;
+ }
+ return null;
+ }
+
+ /**
+ * @see org.apache.sling.sample.slingshot.ratings.RatingsService#getRating(org.apache.sling.api.resource.Resource)
+ */
+ public int getRating(final Resource resource) {
+ final String fullPath = getRatingsResourcePath(resource);
+ int rating = 0;
+ if ( fullPath != null ) {
+ final Resource ratingsResource = resource.getChild(fullPath);
+ if ( ratingsResource != null ) {
+ int count = 0;
+ for(final Resource r : ratingsResource.getChildren()) {
+ final ValueMap vm = r.getValueMap();
+ final int current = vm.get(RatingsUtil.PROPERTY_RATING, 0);
+ rating += current;
+ count++;
+ }
+ if ( count > 0 ) {
+ rating = rating / count;
+ }
+ }
+ }
+ return rating;
+ }
+
+ /**
+ * @see org.apache.sling.sample.slingshot.ratings.RatingsService#getRating(org.apache.sling.api.resource.Resource, java.lang.String)
+ */
+ public int getRating(final Resource resource, final String userId) {
+ final String fullPath = getRatingsResourcePath(resource);
+ int rating = 0;
+
+ final Resource r = resource.getResourceResolver().getResource(fullPath + "/" + userId);
+ if ( r != null ) {
+ final ValueMap vm = r.getValueMap();
+ rating = vm.get(RatingsUtil.PROPERTY_RATING, 0);
+ }
+ return rating;
+ }
+
+ /**
+ * @see org.apache.sling.sample.slingshot.ratings.RatingsService#setRating(org.apache.sling.api.resource.Resource, java.lang.String, int)
+ */
+ public void setRating(final Resource resource, final String userId, final int rating)
+ throws PersistenceException {
+ final String ratingsPath = getRatingsResourcePath(resource) ;
+
+ final Map<String, Object> props = new HashMap<String, Object>();
+ props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, RESOURCETYPE_RATINGS);
+ final Resource ratingsResource = ResourceUtil.getOrCreateResource(resource.getResourceResolver(),
+ ratingsPath, props, null, true);
+
+ props.clear();
+ props.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, RatingsUtil.RESOURCETYPE_RATING);
+ props.put(RatingsUtil.PROPERTY_RATING, rating);
+ ResourceUtil.getOrCreateResource(resource.getResourceResolver(),
+ ratingsResource.getPath() + "/" + userId, props, null, false);
+ }
+}
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange: sling/trunk/samples/slingshot/src/main/java/org/apache/sling/sample/slingshot/ratings/impl/RatingsServiceImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content.json
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content.json?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content.json (added)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content.json Sun May 10 12:05:08 2015
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType":"sling:Folder",
+ "sling:resourceSuperType":"slingshot/Component"
+}
\ No newline at end of file
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content.json
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content.json
------------------------------------------------------------------------------
svn:keywords = Id
Added: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content/itemlist.html.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content/itemlist.html.jsp?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content/itemlist.html.jsp (added)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content/itemlist.html.jsp Sun May 10 12:05:08 2015
@@ -0,0 +1,38 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+--%><%@page session="false" %><%
+%><%@page import="java.util.Iterator,
+ java.util.List,
+ org.apache.sling.api.resource.Resource,
+ org.apache.sling.sample.slingshot.SlingshotConstants" %><%
+%><%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %><%
+%><sling:defineObjects/><%
+%><div class="metro ui-slingshot-content">
+ <%
+ int i = 0;
+ final Iterator<Resource> fi = resource.listChildren();
+ while ( fi.hasNext()) {
+ final Resource current = fi.next();
+ if ( current.isResourceType(SlingshotConstants.RESOURCETYPE_CATEGORY)) {
+ %>
+ <sling:include resource="<%= current %>" replaceSelectors="user"/>
+ <%
+ }
+ }
+ %>
+</div>
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content/itemlist.html.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content/itemlist.html.jsp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Content/itemlist.html.jsp
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Home/user.html.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Home/user.html.jsp?rev=1678557&r1=1678556&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Home/user.html.jsp (original)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Home/user.html.jsp Sun May 10 12:05:08 2015
@@ -23,6 +23,6 @@
%><%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %><%
%><sling:defineObjects/><%
- response.sendRedirect(request.getContextPath() + SlingshotConstants.APP_ROOT_PATH + "/public/" + request.getRemoteUser() + ".html");
+ response.sendRedirect(request.getContextPath() + SlingshotConstants.APP_ROOT_PATH + "/users/" + request.getRemoteUser() + ".html");
return;
%>
\ No newline at end of file
Modified: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Item/html.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Item/html.jsp?rev=1678557&r1=1678556&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Item/html.jsp (original)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Item/html.jsp Sun May 10 12:05:08 2015
@@ -21,9 +21,12 @@
org.apache.sling.api.resource.ValueMap,
org.apache.sling.api.request.ResponseUtil,
org.apache.sling.sample.slingshot.SlingshotConstants,
- org.apache.sling.sample.slingshot.SlingshotUtil"%><%
+ org.apache.sling.sample.slingshot.SlingshotUtil,
+ org.apache.sling.sample.slingshot.ratings.RatingsService,
+ org.apache.sling.sample.slingshot.ratings.RatingsUtil"%><%
%><%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %><%
%><sling:defineObjects/><%
+ final RatingsService ratingsService = sling.getService(RatingsService.class);
final ValueMap attributes = resource.getValueMap();
final String title = ResponseUtil.escapeXml(attributes.get(SlingshotConstants.PROPERTY_TITLE, resource.getName()));
final String categoryName = ResponseUtil.escapeXml(resource.getParent().getValueMap().get(SlingshotConstants.PROPERTY_TITLE, resource.getParent().getName()));
@@ -64,25 +67,25 @@
data-show-score="true"
data-role="rating"
data-stars="5"
- data-score="<%= SlingshotUtil.getRating(resource) %>"
+ data-score="<%= ratingsService.getRating(resource) %>"
data-static="false"
class="rating large" style="height: auto;">
<ul><li></li><li></li><li></li><li></li><li></li></ul>
- <span class="score-hint">Rating: <%= SlingshotUtil.getRating(resource) %></span>
+ <span class="score-hint">Rating: <%= ratingsService.getRating(resource) %></span>
</div>
<div class="fg-green rating active" id="own_rating" style="height: auto;">
- <ul><li title="bad" class="rated"></li><li title="poor"></li><li title="regular"></li><li title="good"></li><li title="gorgeous"></li></ul><span class="score-hint">Current score: <%= SlingshotUtil.getOwnRating(resource, request.getRemoteUser()) %></span></div>
+ <ul><li title="bad" class="rated"></li><li title="poor"></li><li title="regular"></li><li title="good"></li><li title="gorgeous"></li></ul><span class="score-hint">Current score: <%= ratingsService.getRating(resource, request.getRemoteUser()) %></span></div>
<script>
$(function(){
$("#own_rating").rating({
static: false,
- score: <%= SlingshotUtil.getOwnRating(resource, request.getRemoteUser()) %>,
+ score: <%= ratingsService.getRating(resource, request.getRemoteUser()) %>,
stars: 5,
showHint: true,
showScore: true,
click: function(value, rating) {
rating.rate(value);
- $.post( "<%= resource.getName() %>/ratings", { <%= SlingshotConstants.PROPERTY_RATING %> : value }, function( data ) {
+ $.post( "<%= resource.getName() %>.ratings", { <%= RatingsUtil.PROPERTY_RATING %> : value }, function( data ) {
$("#rating").rating("rate", data.rating);
}, "json");
}
Modified: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Item/main.html.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Item/main.html.jsp?rev=1678557&r1=1678556&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Item/main.html.jsp (original)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/Item/main.html.jsp Sun May 10 12:05:08 2015
@@ -21,10 +21,12 @@
org.apache.sling.api.resource.ValueMap,
org.apache.sling.sample.slingshot.SlingshotConstants,
org.apache.sling.sample.slingshot.SlingshotUtil,
+ org.apache.sling.sample.slingshot.ratings.RatingsService,
org.apache.sling.api.request.ResponseUtil" %><%
%><%@taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0" %><%
%><sling:defineObjects/><%
%><%
+ final RatingsService ratingsService = sling.getService(RatingsService.class);
final ValueMap attr = resource.getValueMap();
final String itemTitle = attr.get(SlingshotConstants.PROPERTY_TITLE, resource.getName());
@@ -45,6 +47,6 @@
</div>
<div class="brand">
<span class="label fg-white"><%= ResponseUtil.escapeXml(itemTitle) %></span>
- <span class="badge bg-orange"><%= SlingshotUtil.getRating(resource) %></span>
+ <span class="badge bg-orange"><%= ratingsService.getRating(resource) %></span>
</div>
</div>
Modified: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/User/html.jsp
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/User/html.jsp?rev=1678557&r1=1678556&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/User/html.jsp (original)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/libs/slingshot/User/html.jsp Sun May 10 12:05:08 2015
@@ -35,7 +35,7 @@
<sling:include resource="<%= resource %>" replaceSelectors="trail"/>
<h1><%= title %></h1>
<hr/>
- <sling:include resource="<%= resource %>" replaceSelectors="itemlist"/>
+ <sling:include resource="<%= resource.getChild("content") %>" replaceSelectors="itemlist"/>
</div>
</body>
</html>
\ No newline at end of file
Added: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/docs/content-model.html
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/docs/content-model.html?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/docs/content-model.html (added)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/docs/content-model.html Sun May 10 12:05:08 2015
@@ -0,0 +1,58 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<html>
+ <head>
+ <title>Slingshot Content Model</title>
+ </head>
+ <body>
+ <p>
+ Draft description of the Slingshot content model.
+ </p>
+ <ul>
+ <li>/slingshot</li>
+ <li><ul>
+ <li>/users</li>
+ <li><ul>
+ <li><username></li>
+ <li><ul>
+ <li>content</li>
+ <li><ul>
+ <li><category></li>
+ <li><ul>
+ <li><item></li>
+ <li><ul>
+ <li>images</li>
+ </ul></li>
+ <li><ul>
+ <li>ratings</li>
+ </ul></li>
+ <li><ul>
+ <li>comments</li>
+ </ul></li>
+ </ul></li>
+ </ul></li>
+ <li>info</li>
+ <li>profile</li>
+ <li>ugc</li>
+ </ul></li>
+ </ul></li>
+ </ul></li>
+ </ul>
+ </body>
+</html>
\ No newline at end of file
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/docs/content-model.html
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/docs/content-model.html
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/docs/content-model.html
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content.json
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content.json?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content.json (added)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content.json Sun May 10 12:05:08 2015
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType":"sling:Folder",
+ "sling:resourceType":"slingshot/Content"
+}
\ No newline at end of file
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content.json
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content.json
------------------------------------------------------------------------------
svn:keywords = Id
Modified: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/home.json
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/home.json?rev=1678557&r1=1678172&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/home.json (original)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/home.json Sun May 10 12:05:08 2015
@@ -2,14 +2,5 @@
"jcr:primaryType":"sling:OrderedFolder",
"sling:resourceType":"slingshot/Item",
"title":"Home Sweet Home",
- "description":"This is the place where I live...",
-
- comments : {
- "jcr:primaryType":"sling:OrderedFolder",
- "sling:resourceType":"slingshot/Comments",
- },
- ratings : {
- "jcr:primaryType":"sling:OrderedFolder",
- "sling:resourceType":"slingshot/Ratings",
- }
+ "description":"This is the place where I live..."
}
\ No newline at end of file
Modified: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/pet.json
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/pet.json?rev=1678557&r1=1678172&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/pet.json (original)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/pet.json Sun May 10 12:05:08 2015
@@ -2,14 +2,5 @@
"jcr:primaryType":"sling:OrderedFolder",
"sling:resourceType":"slingshot/Item",
"title":"My Pet",
- "description":"Always hungry...but never gets fat",
-
- comments : {
- "jcr:primaryType":"sling:OrderedFolder",
- "sling:resourceType":"slingshot/Comments",
- },
- ratings : {
- "jcr:primaryType":"sling:OrderedFolder",
- "sling:resourceType":"slingshot/Ratings",
- }
+ "description":"Always hungry...but never gets fat"
}
Modified: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/sea.json
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/sea.json?rev=1678557&r1=1678172&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/sea.json (original)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/sea.json Sun May 10 12:05:08 2015
@@ -2,14 +2,5 @@
"jcr:primaryType":"sling:OrderedFolder",
"sling:resourceType":"slingshot/Item",
"title":"The Sea",
- "description":"You can see my boat in the distance",
-
- comments : {
- "jcr:primaryType":"sling:OrderedFolder",
- "sling:resourceType":"slingshot/Comments",
- },
- ratings : {
- "jcr:primaryType":"sling:OrderedFolder",
- "sling:resourceType":"slingshot/Ratings",
- }
+ "description":"You can see my boat in the distance"
}
\ No newline at end of file
Modified: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/view.json
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/view.json?rev=1678557&r1=1678172&r2=1678557&view=diff
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/view.json (original)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/content/travel/view.json Sun May 10 12:05:08 2015
@@ -2,14 +2,5 @@
"jcr:primaryType":"sling:OrderedFolder",
"sling:resourceType":"slingshot/Item",
"title":"Nice View",
- "description":"A view from the top of my home",
-
- comments : {
- "jcr:primaryType":"sling:OrderedFolder",
- "sling:resourceType":"slingshot/Comments",
- },
- ratings : {
- "jcr:primaryType":"sling:OrderedFolder",
- "sling:resourceType":"slingshot/Ratings",
- }
+ "description":"A view from the top of my home"
}
\ No newline at end of file
Added: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/info.json
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/info.json?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/info.json (added)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/info.json Sun May 10 12:05:08 2015
@@ -0,0 +1,3 @@
+{
+ "jcr:primaryType":"sling:Folder"
+}
\ No newline at end of file
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/info.json
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/info.json
------------------------------------------------------------------------------
svn:keywords = Id
Added: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/profile.json
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/profile.json?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/profile.json (added)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/profile.json Sun May 10 12:05:08 2015
@@ -0,0 +1,3 @@
+{
+ "jcr:primaryType":"sling:Folder"
+}
\ No newline at end of file
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/profile.json
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/profile.json
------------------------------------------------------------------------------
svn:keywords = Id
Added: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/ugc.json
URL: http://svn.apache.org/viewvc/sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/ugc.json?rev=1678557&view=auto
==============================================================================
--- sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/ugc.json (added)
+++ sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/ugc.json Sun May 10 12:05:08 2015
@@ -0,0 +1,3 @@
+{
+ "jcr:primaryType":"sling:Folder"
+}
\ No newline at end of file
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/ugc.json
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/samples/slingshot/src/main/resources/SLING-INF/content/slingshot/users/slingshot1/ugc.json
------------------------------------------------------------------------------
svn:keywords = Id