incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From enor...@apache.org
Subject svn commit: r1125779 - in /sling/trunk/bundles/jcr: jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/ jackrabbit-accessmanager/src/main/resources/OSGI-INF/metatype/ jackrabbit-usermanager/src/main/java/org/apach...
Date Sat, 21 May 2011 19:51:22 GMT
Author: enorman
Date: Sat May 21 19:51:21 2011
New Revision: 1125779

URL: http://svn.apache.org/viewvc?rev=1125779&view=rev
Log:
cleanup metatype labels

Added:
    sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractPostServlet.java
  (with props)
Modified:
    sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/DeleteAcesServlet.java
    sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/GetAclServlet.java
    sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/GetEffectiveAclServlet.java
    sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/ModifyAceServlet.java
    sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/resources/OSGI-INF/metatype/metatype.properties
    sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java
    sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/ChangeUserPasswordServlet.java
    sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java
    sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/DeleteAuthorizableServlet.java
    sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java
    sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java
    sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/resource/AuthorizableResourceProvider.java
    sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/DeleteAcesServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/DeleteAcesServlet.java?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/DeleteAcesServlet.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/DeleteAcesServlet.java
Sat May 21 19:51:21 2011
@@ -68,7 +68,8 @@ import org.apache.sling.servlets.post.Sl
  * <dd>Failure. HTML explains the failure.</dd>
  * </dl>
  *
- * @scr.component immediate="true"
+ * @scr.component immediate="true" label="%deleteAces.post.operation.name"
+ *                description="%deleteAces.post.operation.description"
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.service interface="org.apache.sling.jcr.jackrabbit.accessmanager.DeleteAces"
  * @scr.property name="sling.servlet.resourceTypes" value="sling/servlet/default"

Modified: sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/GetAclServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/GetAclServlet.java?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/GetAclServlet.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/GetAclServlet.java
Sat May 21 19:51:21 2011
@@ -93,7 +93,8 @@ import org.apache.sling.jcr.jackrabbit.a
  * </pre>
  * </code>
  *
- * @scr.component immediate="true"
+ * @scr.component immediate="true" label="%getAcl.get.operation.name"
+ *                description="%getAcl.get.operation.description"
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.service interface="org.apache.sling.jcr.jackrabbit.accessmanager.GetAcl"
  * @scr.property name="sling.servlet.resourceTypes" value="sling/servlet/default"

Modified: sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/GetEffectiveAclServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/GetEffectiveAclServlet.java?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/GetEffectiveAclServlet.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/GetEffectiveAclServlet.java
Sat May 21 19:51:21 2011
@@ -93,7 +93,8 @@ import org.apache.sling.jcr.jackrabbit.a
  * </pre>
  * </code>
  *
- * @scr.component immediate="true"
+ * @scr.component immediate="true" label="%getEffectiveAcl.get.operation.name"
+ *                description="%getEffectiveAcl.get.operation.description"
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.service interface="org.apache.sling.jcr.jackrabbit.accessmanager.GetEffectiveAcl"
  * @scr.property name="sling.servlet.resourceTypes" value="sling/servlet/default"

Modified: sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/ModifyAceServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/ModifyAceServlet.java?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/ModifyAceServlet.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/java/org/apache/sling/jcr/jackrabbit/accessmanager/post/ModifyAceServlet.java
Sat May 21 19:51:21 2011
@@ -78,7 +78,8 @@ import org.apache.sling.servlets.post.Mo
  * will not be added to the group. The group will only contain granted privileges.
  * </p>
  *
- * @scr.component immediate="true"
+ * @scr.component immediate="true" label="%modifyAce.post.operation.name"
+ *                description="%modifyAce.post.operation.description"
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.service interface="org.apache.sling.jcr.jackrabbit.accessmanager.ModifyAce"
  * @scr.property name="sling.servlet.resourceTypes" value="sling/servlet/default"

Modified: sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-accessmanager/src/main/resources/OSGI-INF/metatype/metatype.properties
Sat May 21 19:51:21 2011
@@ -23,3 +23,19 @@
 # descriptions as used in the metatype.xml descriptor generated by the
 # the Sling SCR plugin
 
+deleteAces.post.operation.name = Apache Sling Delete ACE
+deleteAces.post.operation.description = The Sling operation to handle \
+ access control entry delete requests in Sling.
+
+modifyAce.post.operation.name = Apache Sling Add/Update ACE
+modifyAce.post.operation.description = The Sling operation to handle \
+ access control entry add or update requests in Sling.
+
+getAcl.get.operation.name = Apache Sling Get ACL
+getAcl.get.operation.description = The Sling operation to handle \
+ get ACL requests in Sling.
+
+getEffectiveAcl.get.operation.name = Apache Sling Get Effective ACL
+getEffectiveAcl.get.operation.description = The Sling operation to handle \
+ get effective ACL requests in Sling.
+ 
\ No newline at end of file

Modified: sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractAuthorizablePostServlet.java
Sat May 21 19:51:21 2011
@@ -17,10 +17,8 @@
 package org.apache.sling.jackrabbit.usermanager.impl.post;
 
 import java.io.ByteArrayInputStream;
-import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Dictionary;
 import java.util.HashMap;
@@ -34,43 +32,26 @@ import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 import org.apache.jackrabbit.api.security.user.Authorizable;
-import org.apache.sling.api.SlingHttpServletRequest;
-import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.SlingIOException;
 import org.apache.sling.api.request.RequestParameter;
-import org.apache.sling.api.resource.ResourceNotFoundException;
-import org.apache.sling.api.resource.ResourceUtil;
-import org.apache.sling.api.servlets.HtmlResponse;
-import org.apache.sling.api.servlets.SlingAllMethodsServlet;
-import org.apache.sling.api.wrappers.SlingRequestPaths;
 import org.apache.sling.commons.osgi.OsgiUtil;
 import org.apache.sling.jackrabbit.usermanager.impl.resource.AuthorizableResourceProvider;
 import org.apache.sling.servlets.post.Modification;
 import org.apache.sling.servlets.post.SlingPostConstants;
 import org.apache.sling.servlets.post.impl.helper.DateParser;
-import org.apache.sling.servlets.post.impl.helper.JSONResponse;
 import org.apache.sling.servlets.post.impl.helper.RequestProperty;
 import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * Base class for all the POST servlets for the UserManager operations
  */
 public abstract class AbstractAuthorizablePostServlet extends
-        SlingAllMethodsServlet {
+        AbstractPostServlet {
     private static final long serialVersionUID = -5918670409789895333L;
 
     /**
-     * default log
-     */
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
-    /**
      * @scr.property values.0="EEE MMM dd yyyy HH:mm:ss 'GMT'Z"
      *               values.1="yyyy-MM-dd'T'HH:mm:ss.SSSZ"
      *               values.2="yyyy-MM-dd'T'HH:mm:ss" values.3="yyyy-MM-dd"
@@ -96,207 +77,6 @@ public abstract class AbstractAuthorizab
         dateParser = null;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see
-     * org.apache.sling.api.servlets.SlingAllMethodsServlet#doPost(org.apache
-     * .sling.api.SlingHttpServletRequest,
-     * org.apache.sling.api.SlingHttpServletResponse)
-     */
-    @Override
-    protected void doPost(SlingHttpServletRequest request,
-            SlingHttpServletResponse httpResponse) throws ServletException,
-            IOException {
-        // prepare the response
-        HtmlResponse htmlResponse = createHtmlResponse(request);
-        htmlResponse.setReferer(request.getHeader("referer"));
-
-        // calculate the paths
-        String path = getItemPath(request);
-        htmlResponse.setPath(path);
-
-        // location
-        htmlResponse.setLocation(externalizePath(request, path));
-
-        // parent location
-        path = ResourceUtil.getParent(path);
-        if (path != null) {
-            htmlResponse.setParentLocation(externalizePath(request, path));
-        }
-
-        Session session = request.getResourceResolver().adaptTo(Session.class);
-
-        final List<Modification> changes = new ArrayList<Modification>();
-
-        try {
-            handleOperation(request, htmlResponse, changes);
-
-            // TODO: maybe handle SlingAuthorizablePostProcessor handlers here
-
-            // set changes on html response
-            for (Modification change : changes) {
-                switch (change.getType()) {
-                    case MODIFY:
-                        htmlResponse.onModified(change.getSource());
-                        break;
-                    case DELETE:
-                        htmlResponse.onDeleted(change.getSource());
-                        break;
-                    case MOVE:
-                        htmlResponse.onMoved(change.getSource(),
-                            change.getDestination());
-                        break;
-                    case COPY:
-                        htmlResponse.onCopied(change.getSource(),
-                            change.getDestination());
-                        break;
-                    case CREATE:
-                        htmlResponse.onCreated(change.getSource());
-                        break;
-                    case ORDER:
-                        htmlResponse.onChange("ordered", change.getSource(),
-                            change.getDestination());
-                        break;
-                }
-            }
-
-            if (session.hasPendingChanges()) {
-                session.save();
-            }
-        } catch (ResourceNotFoundException rnfe) {
-            htmlResponse.setStatus(HttpServletResponse.SC_NOT_FOUND,
-                rnfe.getMessage());
-        } catch (Throwable throwable) {
-            log.debug("Exception while handling POST "
-                + request.getResource().getPath() + " with "
-                + getClass().getName(), throwable);
-            htmlResponse.setError(throwable);
-        } finally {
-            try {
-                if (session.hasPendingChanges()) {
-                    session.refresh(false);
-                }
-            } catch (RepositoryException e) {
-                log.warn("RepositoryException in finally block: {}",
-                    e.getMessage(), e);
-            }
-        }
-
-        // check for redirect URL if processing succeeded
-        if (htmlResponse.isSuccessful()) {
-            String redirect = getRedirectUrl(request, htmlResponse);
-            if (redirect != null) {
-                httpResponse.sendRedirect(redirect);
-                return;
-            }
-        }
-
-        // create a html response and send if unsuccessful or no redirect
-        htmlResponse.send(httpResponse, isSetStatus(request));
-    }
-
-    /**
-     * Creates an instance of a HtmlResponse.
-     * @param req The request being serviced
-     * @return a {@link org.apache.sling.servlets.post.impl.helper.JSONResponse} if any of
these conditions are true:
-     * <ul>
-     *   <li>the response content type is application/json
-     * </ul>
-     * or a {@link org.apache.sling.api.servlets.HtmlResponse} otherwise
-     */
-    protected HtmlResponse createHtmlResponse(SlingHttpServletRequest req) {
-    	if (JSONResponse.RESPONSE_CONTENT_TYPE.equals(req.getResponseContentType())) {
-    		return new JSONResponse();
-    	} else {
-            return new HtmlResponse();
-    	}
-    }
-    
-    /**
-     * Extending Servlet should implement this operation to do the work
-     * 
-     * @param request the sling http request to process
-     * @param htmlResponse the response
-     * @param changes
-     */
-    abstract protected void handleOperation(SlingHttpServletRequest request,
-            HtmlResponse htmlResponse, List<Modification> changes)
-            throws RepositoryException;
-
-    /**
-     * compute redirect URL (SLING-126)
-     * 
-     * @param ctx the post processor
-     * @return the redirect location or <code>null</code>
-     */
-    protected String getRedirectUrl(HttpServletRequest request, HtmlResponse ctx) {
-        // redirect param has priority (but see below, magic star)
-        String result = request.getParameter(SlingPostConstants.RP_REDIRECT_TO);
-        if (result != null && ctx.getPath() != null) {
-
-            // redirect to created/modified Resource
-            int star = result.indexOf('*');
-            if (star >= 0) {
-                StringBuffer buf = new StringBuffer();
-
-                // anything before the star
-                if (star > 0) {
-                    buf.append(result.substring(0, star));
-                }
-
-                // append the name of the manipulated node
-                buf.append(ResourceUtil.getName(ctx.getPath()));
-
-                // anything after the star
-                if (star < result.length() - 1) {
-                    buf.append(result.substring(star + 1));
-                }
-
-                // use the created path as the redirect result
-                result = buf.toString();
-
-            } else if (result.endsWith(SlingPostConstants.DEFAULT_CREATE_SUFFIX)) {
-                // if the redirect has a trailing slash, append modified node
-                // name
-                result = result.concat(ResourceUtil.getName(ctx.getPath()));
-            }
-
-            if (log.isDebugEnabled()) {
-                log.debug("Will redirect to " + result);
-            }
-        }
-        return result;
-    }
-
-    protected boolean isSetStatus(SlingHttpServletRequest request) {
-        String statusParam = request.getParameter(SlingPostConstants.RP_STATUS);
-        if (statusParam == null) {
-            log.debug(
-                "getStatusMode: Parameter {} not set, assuming standard status code",
-                SlingPostConstants.RP_STATUS);
-            return true;
-        }
-
-        if (SlingPostConstants.STATUS_VALUE_BROWSER.equals(statusParam)) {
-            log.debug(
-                "getStatusMode: Parameter {} asks for user-friendly status code",
-                SlingPostConstants.RP_STATUS);
-            return false;
-        }
-
-        if (SlingPostConstants.STATUS_VALUE_STANDARD.equals(statusParam)) {
-            log.debug(
-                "getStatusMode: Parameter {} asks for standard status code",
-                SlingPostConstants.RP_STATUS);
-            return true;
-        }
-
-        log.debug(
-            "getStatusMode: Parameter {} set to unknown value {}, assuming standard status
code",
-            SlingPostConstants.RP_STATUS);
-        return true;
-    }
-
     // ------ The methods below are based on the private methods from the
     // ModifyOperation class -----
 
@@ -690,41 +470,6 @@ public abstract class AbstractAuthorizab
     // ------ These methods were copied from AbstractSlingPostOperation ------
 
     /**
-     * Returns the path of the resource of the request as the item path.
-     * <p>
-     * This method may be overwritten by extension if the operation has
-     * different requirements on path processing.
-     */
-    protected String getItemPath(SlingHttpServletRequest request) {
-        return request.getResource().getPath();
-    }
-
-    /**
-     * Returns an external form of the given path prepending the context path
-     * and appending a display extension.
-     * 
-     * @param path the path to externalize
-     * @return the url
-     */
-    protected final String externalizePath(SlingHttpServletRequest request,
-            String path) {
-        StringBuffer ret = new StringBuffer();
-        ret.append(SlingRequestPaths.getContextPath(request));
-        ret.append(request.getResourceResolver().map(path));
-
-        // append optional extension
-        String ext = request.getParameter(SlingPostConstants.RP_DISPLAY_EXTENSION);
-        if (ext != null && ext.length() > 0) {
-            if (ext.charAt(0) != '.') {
-                ret.append('.');
-            }
-            ret.append(ext);
-        }
-
-        return ret.toString();
-    }
-
-    /**
      * Returns <code>true</code> if the <code>name</code> starts
with either of
      * the prefixes {@link SlingPostConstants#ITEM_PREFIX_RELATIVE_CURRENT
      * <code>./</code>}, {@link SlingPostConstants#ITEM_PREFIX_RELATIVE_PARENT

Added: sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractPostServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractPostServlet.java?rev=1125779&view=auto
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractPostServlet.java
(added)
+++ sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractPostServlet.java
Sat May 21 19:51:21 2011
@@ -0,0 +1,293 @@
+/*
+ * 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.jackrabbit.usermanager.impl.post;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.resource.ResourceNotFoundException;
+import org.apache.sling.api.resource.ResourceUtil;
+import org.apache.sling.api.servlets.HtmlResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.api.wrappers.SlingRequestPaths;
+import org.apache.sling.servlets.post.Modification;
+import org.apache.sling.servlets.post.SlingPostConstants;
+import org.apache.sling.servlets.post.impl.helper.JSONResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Base class for all the POST servlets for the UserManager operations
+ */
+public abstract class AbstractPostServlet extends
+        SlingAllMethodsServlet {
+
+	private static final long serialVersionUID = 7408267654653472120L;
+	
+	/**
+     * default log
+     */
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    /*
+     * (non-Javadoc)
+     * @see
+     * org.apache.sling.api.servlets.SlingAllMethodsServlet#doPost(org.apache
+     * .sling.api.SlingHttpServletRequest,
+     * org.apache.sling.api.SlingHttpServletResponse)
+     */
+    @Override
+    protected void doPost(SlingHttpServletRequest request,
+            SlingHttpServletResponse httpResponse) throws ServletException,
+            IOException {
+        // prepare the response
+        HtmlResponse htmlResponse = createHtmlResponse(request);
+        htmlResponse.setReferer(request.getHeader("referer"));
+
+        // calculate the paths
+        String path = getItemPath(request);
+        htmlResponse.setPath(path);
+
+        // location
+        htmlResponse.setLocation(externalizePath(request, path));
+
+        // parent location
+        path = ResourceUtil.getParent(path);
+        if (path != null) {
+            htmlResponse.setParentLocation(externalizePath(request, path));
+        }
+
+        Session session = request.getResourceResolver().adaptTo(Session.class);
+
+        final List<Modification> changes = new ArrayList<Modification>();
+
+        try {
+            handleOperation(request, htmlResponse, changes);
+
+            // TODO: maybe handle SlingAuthorizablePostProcessor handlers here
+
+            // set changes on html response
+            for (Modification change : changes) {
+                switch (change.getType()) {
+                    case MODIFY:
+                        htmlResponse.onModified(change.getSource());
+                        break;
+                    case DELETE:
+                        htmlResponse.onDeleted(change.getSource());
+                        break;
+                    case MOVE:
+                        htmlResponse.onMoved(change.getSource(),
+                            change.getDestination());
+                        break;
+                    case COPY:
+                        htmlResponse.onCopied(change.getSource(),
+                            change.getDestination());
+                        break;
+                    case CREATE:
+                        htmlResponse.onCreated(change.getSource());
+                        break;
+                    case ORDER:
+                        htmlResponse.onChange("ordered", change.getSource(),
+                            change.getDestination());
+                        break;
+                }
+            }
+
+            if (session.hasPendingChanges()) {
+                session.save();
+            }
+        } catch (ResourceNotFoundException rnfe) {
+            htmlResponse.setStatus(HttpServletResponse.SC_NOT_FOUND,
+                rnfe.getMessage());
+        } catch (Throwable throwable) {
+            log.debug("Exception while handling POST "
+                + request.getResource().getPath() + " with "
+                + getClass().getName(), throwable);
+            htmlResponse.setError(throwable);
+        } finally {
+            try {
+                if (session.hasPendingChanges()) {
+                    session.refresh(false);
+                }
+            } catch (RepositoryException e) {
+                log.warn("RepositoryException in finally block: {}",
+                    e.getMessage(), e);
+            }
+        }
+
+        // check for redirect URL if processing succeeded
+        if (htmlResponse.isSuccessful()) {
+            String redirect = getRedirectUrl(request, htmlResponse);
+            if (redirect != null) {
+                httpResponse.sendRedirect(redirect);
+                return;
+            }
+        }
+
+        // create a html response and send if unsuccessful or no redirect
+        htmlResponse.send(httpResponse, isSetStatus(request));
+    }
+
+    /**
+     * Creates an instance of a HtmlResponse.
+     * @param req The request being serviced
+     * @return a {@link org.apache.sling.servlets.post.impl.helper.JSONResponse} if any of
these conditions are true:
+     * <ul>
+     *   <li>the response content type is application/json
+     * </ul>
+     * or a {@link org.apache.sling.api.servlets.HtmlResponse} otherwise
+     */
+    protected HtmlResponse createHtmlResponse(SlingHttpServletRequest req) {
+    	if (JSONResponse.RESPONSE_CONTENT_TYPE.equals(req.getResponseContentType())) {
+    		return new JSONResponse();
+    	} else {
+            return new HtmlResponse();
+    	}
+    }
+    
+    /**
+     * Extending Servlet should implement this operation to do the work
+     * 
+     * @param request the sling http request to process
+     * @param htmlResponse the response
+     * @param changes
+     */
+    abstract protected void handleOperation(SlingHttpServletRequest request,
+            HtmlResponse htmlResponse, List<Modification> changes)
+            throws RepositoryException;
+
+    /**
+     * compute redirect URL (SLING-126)
+     * 
+     * @param ctx the post processor
+     * @return the redirect location or <code>null</code>
+     */
+    protected String getRedirectUrl(HttpServletRequest request, HtmlResponse ctx) {
+        // redirect param has priority (but see below, magic star)
+        String result = request.getParameter(SlingPostConstants.RP_REDIRECT_TO);
+        if (result != null && ctx.getPath() != null) {
+
+            // redirect to created/modified Resource
+            int star = result.indexOf('*');
+            if (star >= 0) {
+                StringBuffer buf = new StringBuffer();
+
+                // anything before the star
+                if (star > 0) {
+                    buf.append(result.substring(0, star));
+                }
+
+                // append the name of the manipulated node
+                buf.append(ResourceUtil.getName(ctx.getPath()));
+
+                // anything after the star
+                if (star < result.length() - 1) {
+                    buf.append(result.substring(star + 1));
+                }
+
+                // use the created path as the redirect result
+                result = buf.toString();
+
+            } else if (result.endsWith(SlingPostConstants.DEFAULT_CREATE_SUFFIX)) {
+                // if the redirect has a trailing slash, append modified node
+                // name
+                result = result.concat(ResourceUtil.getName(ctx.getPath()));
+            }
+
+            if (log.isDebugEnabled()) {
+                log.debug("Will redirect to " + result);
+            }
+        }
+        return result;
+    }
+
+    protected boolean isSetStatus(SlingHttpServletRequest request) {
+        String statusParam = request.getParameter(SlingPostConstants.RP_STATUS);
+        if (statusParam == null) {
+            log.debug(
+                "getStatusMode: Parameter {} not set, assuming standard status code",
+                SlingPostConstants.RP_STATUS);
+            return true;
+        }
+
+        if (SlingPostConstants.STATUS_VALUE_BROWSER.equals(statusParam)) {
+            log.debug(
+                "getStatusMode: Parameter {} asks for user-friendly status code",
+                SlingPostConstants.RP_STATUS);
+            return false;
+        }
+
+        if (SlingPostConstants.STATUS_VALUE_STANDARD.equals(statusParam)) {
+            log.debug(
+                "getStatusMode: Parameter {} asks for standard status code",
+                SlingPostConstants.RP_STATUS);
+            return true;
+        }
+
+        log.debug(
+            "getStatusMode: Parameter {} set to unknown value {}, assuming standard status
code",
+            SlingPostConstants.RP_STATUS);
+        return true;
+    }
+
+    // ------ These methods were copied from AbstractSlingPostOperation ------
+
+    /**
+     * Returns the path of the resource of the request as the item path.
+     * <p>
+     * This method may be overwritten by extension if the operation has
+     * different requirements on path processing.
+     */
+    protected String getItemPath(SlingHttpServletRequest request) {
+        return request.getResource().getPath();
+    }
+
+    /**
+     * Returns an external form of the given path prepending the context path
+     * and appending a display extension.
+     * 
+     * @param path the path to externalize
+     * @return the url
+     */
+    protected final String externalizePath(SlingHttpServletRequest request,
+            String path) {
+        StringBuffer ret = new StringBuffer();
+        ret.append(SlingRequestPaths.getContextPath(request));
+        ret.append(request.getResourceResolver().map(path));
+
+        // append optional extension
+        String ext = request.getParameter(SlingPostConstants.RP_DISPLAY_EXTENSION);
+        if (ext != null && ext.length() > 0) {
+            if (ext.charAt(0) != '.') {
+                ret.append('.');
+            }
+            ret.append(ext);
+        }
+
+        return ret.toString();
+    }
+
+}

Propchange: sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/AbstractPostServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/ChangeUserPasswordServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/ChangeUserPasswordServlet.java?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/ChangeUserPasswordServlet.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/ChangeUserPasswordServlet.java
Sat May 21 19:51:21 2011
@@ -79,7 +79,8 @@ import org.slf4j.LoggerFactory;
  * <h4>Notes</h4>
  *
  *
- * @scr.component immediate="true"
+ * @scr.component immediate="true" label="%changeUserPassword.post.operation.name"
+ *                description="%changeUserPassword.post.operation.description"
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.service interface="org.apache.sling.jackrabbit.usermanager.ChangeUserPassword"
  * @scr.property name="sling.servlet.resourceTypes" value="sling/user"

Modified: sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/CreateGroupServlet.java
Sat May 21 19:51:21 2011
@@ -76,7 +76,8 @@ import org.apache.sling.servlets.post.Sl
  * 
  * <h4>Notes</h4>
  * 
- * @scr.component immediate="true"
+ * @scr.component immediate="true" label="%createGroup.post.operation.name"
+ *                description="%createGroup.post.operation.description"
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.service interface="org.apache.sling.jackrabbit.usermanager.CreateGroup"
  * @scr.property name="sling.servlet.resourceTypes" value="sling/groups"

Modified: sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/DeleteAuthorizableServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/DeleteAuthorizableServlet.java?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/DeleteAuthorizableServlet.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/DeleteAuthorizableServlet.java
Sat May 21 19:51:21 2011
@@ -76,7 +76,8 @@ import org.apache.sling.servlets.post.Sl
  * </code>
  *
  *
- * @scr.component metatype="no" immediate="true"
+ * @scr.component immediate="true" label="%deleteAuthorizable.post.operation.name"
+ *                description="%deleteAuthorizable.post.operation.description"
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.service interface="org.apache.sling.jackrabbit.usermanager.DeleteUser"
  * @scr.service interface="org.apache.sling.jackrabbit.usermanager.DeleteGroup"
@@ -86,7 +87,7 @@ import org.apache.sling.servlets.post.Sl
  * @scr.property name="sling.servlet.methods" value="POST"
  * @scr.property name="sling.servlet.selectors" value="delete"
  */
-public class DeleteAuthorizableServlet extends AbstractAuthorizablePostServlet
+public class DeleteAuthorizableServlet extends AbstractPostServlet
 		implements DeleteUser, DeleteGroup, DeleteAuthorizables {
     private static final long serialVersionUID = 5874621724096106496L;
 

Modified: sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateGroupServlet.java
Sat May 21 19:51:21 2011
@@ -76,7 +76,8 @@ import org.apache.sling.servlets.post.im
  * curl -Fprop1=value2 -Fproperty1=value1 http://localhost:8080/system/userManager/group/testGroup.update.html
  * </code>
  *
- * @scr.component metatype="no" immediate="true"
+ * @scr.component immediate="true" label="%updateGroup.post.operation.name"
+ *                description="%updateGroup.post.operation.description"
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.service interface="org.apache.sling.jackrabbit.usermanager.UpdateGroup"
  * @scr.property name="sling.servlet.resourceTypes" values="sling/group"

Modified: sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/post/UpdateUserServlet.java
Sat May 21 19:51:21 2011
@@ -75,7 +75,8 @@ import org.apache.sling.servlets.post.im
  * 
  *
  *
- * @scr.component metatype="no" immediate="true"
+ * @scr.component immediate="true" label="%updateUser.post.operation.name"
+ *                description="%updateUser.post.operation.description"
  * @scr.service interface="javax.servlet.Servlet"
  * @scr.service interface="org.apache.sling.jackrabbit.usermanager.UpdateUser"
  * @scr.property name="sling.servlet.resourceTypes" value="sling/user"

Modified: sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/resource/AuthorizableResourceProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/resource/AuthorizableResourceProvider.java?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/resource/AuthorizableResourceProvider.java
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/java/org/apache/sling/jackrabbit/usermanager/impl/resource/AuthorizableResourceProvider.java
Sat May 21 19:51:21 2011
@@ -42,7 +42,7 @@ import org.slf4j.LoggerFactory;
  * Resource Provider implementation for jackrabbit UserManager resources.
  *
  * @scr.component immediate="true" label="%authorizable.resourceprovider.name"
- *                description="authorizable.resourceprovider.description"
+ *                description="%authorizable.resourceprovider.description"
  * @scr.property name="service.description"
  *               value="Resource provider implementation for UserManager resources"
  * @scr.property name="service.vendor" value="The Apache Software Foundation"

Modified: sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1125779&r1=1125778&r2=1125779&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/bundles/jcr/jackrabbit-usermanager/src/main/resources/OSGI-INF/metatype/metatype.properties
Sat May 21 19:51:21 2011
@@ -23,14 +23,36 @@
 # descriptions as used in the metatype.xml descriptor generated by the
 # the Sling SCR plugin
 
-authorizable.resourceprovider.name = Resolver for UserManager resources
+authorizable.resourceprovider.name = Apache Sling Resolver for UserManager resources
 authorizable.resourceprovider.description = Handles resolving resources for the \
  jackrabbit UserManager.
 
-createUser.post.operation.name = Create User Sling Post Operation
-createUser.post.operation.description = The Sling POST Operation to handle create user \
+createUser.post.operation.name = Apache Sling Create User
+createUser.post.operation.description = The Sling operation to handle create user \
  requests in Sling.
  
 self.registration.enabled.name = Self-Registration Enabled
 self.registration.enabled.description = When selected, the anonymous user is allowed to \
  register a new user with the system.
+
+ 
+changeUserPassword.post.operation.name = Apache Sling Change User Password
+changeUserPassword.post.operation.description = The Sling operation to handle change user
\
+ password requests in Sling.
+ 
+createGroup.post.operation.name = Apache Sling Create Group
+createGroup.post.operation.description = The Sling operation to handle create group \
+ requests in Sling.
+
+updateUser.post.operation.name = Apache Sling Update User
+updateUser.post.operation.description = The Sling operation to handle update user \
+ requests in Sling.
+
+updateGroup.post.operation.name = Apache Sling Update Group
+updateGroup.post.operation.description = The Sling operation to handle update group \
+ requests in Sling.
+
+deleteAuthorizable.post.operation.name = Apache Sling Delete User/Group
+deleteAuthorizable.post.operation.description = The Sling operation to handle delete user
\
+ or group requests in Sling.
+ 
\ No newline at end of file



Mime
View raw message