Author: fmeschbe
Date: Thu Jul 4 04:31:42 2013
New Revision: 1499645
URL: http://svn.apache.org/r1499645
Log:
Implement support for service based ResourceResolver and Session access
- Update with latest changes from trunk
Added:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/RefreshableResourceProvider.java
- copied unchanged from r1499644,
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/resource/RefreshableResourceProvider.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/security/
- copied from r1499644,
sling/trunk/bundles/api/src/main/java/org/apache/sling/api/security/
Removed:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/AccessSecurityException.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceAccessSecurity.java
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/ (props
changed)
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/pom.xml
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ModifiableValueMap.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ModifyingResourceProvider.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProvider.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProviderFactory.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolverFactory.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/package-info.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/servlets/HtmlResponse.java
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
Propchange: sling/whiteboard/fmeschbe/deprecate_login_administrative/api/
------------------------------------------------------------------------------
svn:mergeinfo = /sling/trunk/bundles/api:1458683-1499644
Modified: sling/whiteboard/fmeschbe/deprecate_login_administrative/api/pom.xml
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/pom.xml?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
--- sling/whiteboard/fmeschbe/deprecate_login_administrative/api/pom.xml
(original)
+++ sling/whiteboard/fmeschbe/deprecate_login_administrative/api/pom.xml Thu
Jul 4 04:31:42 2013
@@ -23,12 +23,12 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>15</version>
+ <version>16</version>
<relativePath>../../parent/pom.xml</relativePath>
</parent>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.3.1-SNAPSHOT</version>
+ <version>2.4.3-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>Apache Sling API</name>
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ModifiableValueMap.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ModifiableValueMap.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ModifiableValueMap.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ModifiableValueMap.java
Thu Jul 4 04:31:42 2013
@@ -49,6 +49,10 @@ package org.apache.sling.api.resource;
* <li>{@link #clear()}</li>
* </ul>
* <p>
+ *
+ * A modifiable value map should value {@link
ResourceResolver#PROPERTY_RESOURCE_TYPE}
+ * to set the resource type of a resource.
+ *
* @since 2.2
*/
public interface ModifiableValueMap extends ValueMap {
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ModifyingResourceProvider.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ModifyingResourceProvider.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ModifyingResourceProvider.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ModifyingResourceProvider.java
Thu Jul 4 04:31:42 2013
@@ -48,6 +48,9 @@ public interface ModifyingResourceProvid
* The new resource is put into the transient space of this provider
* until {@link #commit(ResourceResolver)} is called.
*
+ * A resource provider should value {@link
ResourceResolver#PROPERTY_RESOURCE_TYPE}
+ * to set the resource type of a resource.
+ *
* @param resolver The current resource resolver.
* @param path The resource path.
* @param properties Optional properties
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
Thu Jul 4 04:31:42 2013
@@ -296,6 +296,7 @@ public class ResourceMetadata extends Ha
/**
* Make this object read-only. All method calls trying to modify this
object
* result in an exception!
+ * @since 2.3
*/
public void lock() {
this.isReadOnly = true;
@@ -350,7 +351,7 @@ public class ResourceMetadata extends Ha
}
}
}
-
+
@Override
public Set<Map.Entry<String, Object>> entrySet() {
getLockedData();
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProvider.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProvider.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProvider.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProvider.java
Thu Jul 4 04:31:42 2013
@@ -65,6 +65,17 @@ public interface ResourceProvider {
String OWNS_ROOTS = "provider.ownsRoots";
/**
+ * The name of the service registration property containing the a boolean
+ * flag indicating if the ResourceAccessSecurity service should be used for
+ * this provider or not. ResourceProvider implementations are encouraged
+ * to use the ResourceAccessSecurity service for access control unless
+ * the underlying storage already provides it.
+ * The default for this value is <code>false</code>.
+ * (value is "provider.useResourceAccessSecurity")
+ */
+ String USE_RESOURCE_ACCESS_SECURITY = "provider.useResourceAccessSecurity";
+
+ /**
* The resource type be set on resources returned by the
* {@link #listChildren(Resource)} method to enable traversing the
* resource
@@ -82,9 +93,9 @@ public interface ResourceProvider {
* <p>
* This method is called to resolve a resource for the given request.
* The properties of the request, such as request
- * parameters, may be use to parametrize the resource resolution. An
- * example of such parametrization is support for a JSR-311
- * style resource provider to support the parametrized URL patterns.
+ * parameters, may be use to parameterize the resource resolution. An
+ * example of such parameterization is support for a JSR-311
+ * style resource provider to support the parameterized URL patterns.
*
* @param resourceResolver
* The {@link ResourceResolver} to which the returned
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProviderFactory.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProviderFactory.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProviderFactory.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceProviderFactory.java
Thu Jul 4 04:31:42 2013
@@ -35,11 +35,10 @@ import java.util.Map;
public interface ResourceProviderFactory {
/**
- * A required resource provider factory is accessed directly when a new
- * resource resolver is created. Only if authentication against all
required
- * resource provider factories is successful, a resource resolver is
created
- * by the resource resolver factory. Boolean service property, default
vaule
- * is <code>false</true>
+ * A required resource provider factory is accessed directly when a new
resource resolver
+ * is created. Only if authentication against all required resource
provider factories
+ * is successful, a resource resolver is created by the resource resolver
factory.
+ * Boolean service property, default value is <code>false</true>
*/
String PROPERTY_REQUIRED = "required";
@@ -75,14 +74,14 @@ public interface ResourceProviderFactory
* <code>ResourceProvider</code> returned will generally not be
* authenticated and only provide minimal privileges, if any at all.
*
- * @param authenticationInfo A map of further credential information which
- * may be used by the implementation to parametrize how the
- * resource provider is created. This may be <code>null</code>.
- * @return A {@link ResourceProvider} according to the
- * <code>authenticationInfo</code>.
- * @throws LoginException If an error occurrs creating the new
- * <code>ResourceProvider</code> with the provided credential
- * data.
+ * @param authenticationInfo
+ * A map of further credential information which may be used by
+ * the implementation to parameterize how the resource provider
is
+ * created. This may be <code>null</code>.
+ * @return A {@link ResourceProvider} according to the
<code>authenticationInfo</code>.
+ * @throws LoginException
+ * If an error occurs creating the new
<code>ResourceProvider</code> with the
+ * provided credential data.
*/
ResourceProvider getResourceProvider(Map<String, Object>
authenticationInfo) throws LoginException;
@@ -100,15 +99,15 @@ public interface ResourceProviderFactory
* Implementations of this method should throw {@code LoginException} if
* they don't support it.
*
- * @param authenticationInfo A map of further credential information which
- * may be used by the implementation to parametrize how the
- * resource provider is created. This may be <code>null</code>.
+ * @param authenticationInfo
+ * A map of further credential information which may be used by
+ * the implementation to parameterize how the resource provider
is
+ * created. This may be <code>null</code>.
* @return A {@link ResourceProvider} with administrative privileges unless
- * the {@link ResourceResolverFactory#USER_IMPERSONATION} was set
in
- * the <code>authenticationInfo</code>.
- * @throws LoginException If an error occurrs creating the new
- * <code>ResourceResolverFactory</code> with the provided
- * credential data.
+ * the {@link ResourceResolverFactory#USER_IMPERSONATION} was set
in the <code>authenticationInfo</code>.
+ * @throws LoginException
+ * If an error occurs creating the new
<code>ResourceResolverFactory</code> with the
+ * provided credential data.
* @deprecated as of 2.4 (bundle version 2.4.0) because of inherent
security
* issues. Implementations may implement this method at their
* discretion but must support the new service based resource
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolver.java
Thu Jul 4 04:31:42 2013
@@ -49,7 +49,7 @@ import org.apache.sling.api.adapter.Adap
* This interface defines two kinds of methods to access resources: The
* <code>resolve</code> methods and the <code>getResource</code> methods. The
* difference lies in the algorithm applied to find the requested resource and
- * in the behaviour in case a resource cannot be found:
+ * in the behavior in case a resource cannot be found:
* <table>
* <tr>
* <th>Method Kind</th>
@@ -121,6 +121,17 @@ public interface ResourceResolver extend
String USER_IMPERSONATOR = "user.impersonator";
/**
+ * This is the suggested property to be used for setting the resource type
+ * of a resource during either creation ({@link #create(Resource, String,
Map)})
+ * or modifying ({@link ModifiableValueMap}).
+ * However the exact way to set the resource type of a resource is defined
+ * by the underlying resource provider. It should value this property but
+ * is not required to do so.
+ * @since 2.3
+ */
+ String PROPERTY_RESOURCE_TYPE = "sling:resourceType";
+
+ /**
* Resolves the resource from the given <code>absPath</code> optionally
* taking <code>HttpServletRequest</code> into account, such as the value
of
* the <code>Host</code> request header. Returns a
@@ -144,7 +155,7 @@ public interface ResourceResolver extend
* @return The {@link Resource} addressed by the <code>absPath</code> or a
* {@link NonExistingResource} if no such resource can be resolved.
* @throws org.apache.sling.api.SlingException Or a subclass thereof may be
- * thrown if an error occurrs trying to resolve the resource.
+ * thrown if an error occurs trying to resolve the resource.
* @throws IllegalStateException if this resource resolver has already been
* {@link #close() closed}.
* @since 2.0.4
@@ -173,7 +184,7 @@ public interface ResourceResolver extend
* @return The {@link Resource} addressed by the <code>absPath</code> or a
* {@link NonExistingResource} if no such resource can be resolved.
* @throws org.apache.sling.api.SlingException Or a subclass thereof may be
- * thrown if an error occurrs trying to resolve the resource.
+ * thrown if an error occurs trying to resolve the resource.
* @throws IllegalStateException if this resource resolver has already been
* {@link #close() closed}.
*/
@@ -198,7 +209,7 @@ public interface ResourceResolver extend
* @throws NullPointerException If <code>request</code> is
<code>null</code>
* .
* @throws org.apache.sling.api.SlingException Or a subclass thereof may be
- * thrown if an error occurrs trying to resolve the resource.
+ * thrown if an error occurs trying to resolve the resource.
* @throws IllegalStateException if this resource resolver has already been
* {@link #close() closed}.
* @deprecated as of 2.0.4, use {@link #resolve(HttpServletRequest,
String)}
@@ -279,7 +290,7 @@ public interface ResourceResolver extend
* relative path to a resource.
* @return The <code>Resource</code> object loaded from the path or
* <code>null</code> if the path does not resolve to a resource.
- * @throws org.apache.sling.api.SlingException If an error occurrs trying
to
+ * @throws org.apache.sling.api.SlingException If an error occurs trying to
* load the resource object from the path.
* @throws IllegalStateException if this resource resolver has already been
* {@link #close() closed}.
@@ -307,7 +318,7 @@ public interface ResourceResolver extend
* (parent location), which are resolved by this method.
* @return The <code>Resource</code> object loaded from the path or
* <code>null</code> if the path does not resolve to a resource.
- * @throws org.apache.sling.api.SlingException If an error occurrs trying
to
+ * @throws org.apache.sling.api.SlingException If an error occurs trying to
* load the resource object from the path or if
* <code>base</code> is <code>null</code> and <code>path</code>
* is relative.
@@ -382,7 +393,7 @@ public interface ResourceResolver extend
* <p>
* The semantic meaning of the query and language depend on the actual
* implementation and storage used for the resources. For JCR repository
- * being used as storage, the query and lanuage parameters are used to
+ * being used as storage, the query and language parameters are used to
* create a JCR <code>Query</code> through the <code>QueryManager</code>.
* The result returned is then based on the <code>NodeIterator</code>
* provided by the query result.
@@ -396,7 +407,7 @@ public interface ResourceResolver extend
* query.
* @throws QuerySyntaxException If the query is not syntactically correct
* according to the query language indicator.
- * @throws org.apache.sling.api.SlingException If an error occurrs querying
+ * @throws org.apache.sling.api.SlingException If an error occurs querying
* for the resources.
* @throws IllegalStateException if this resource resolver has already been
* {@link #close() closed}.
@@ -409,7 +420,7 @@ public interface ResourceResolver extend
* <p>
* The semantic meaning of the query and language depend on the actual
* implementation and storage used for the resources. For JCR repository
- * being used as storage, the query and lanuage parameters are used to
+ * being used as storage, the query and language parameters are used to
* create a JCR <code>Query</code> through the <code>QueryManager</code>.
* The result returned is then based on the <code>RowIterator</code>
* provided by the query result. The map returned for each row is indexed
by
@@ -426,7 +437,7 @@ public interface ResourceResolver extend
* access to the query result.
* @throws QuerySyntaxException If the query is not syntactically correct
* according to the query language indicator.
- * @throws org.apache.sling.api.SlingException If an error occurrs querying
+ * @throws org.apache.sling.api.SlingException If an error occurs querying
* for the resources.
* @throws IllegalStateException if this resource resolver has already been
* {@link #close() closed}.
@@ -449,12 +460,12 @@ public interface ResourceResolver extend
* </pre>
*
* @param authenticationInfo The map or credential data to overlay the
- * orignal credential data with for the creation of a new
+ * original credential data with for the creation of a new
* resource resolver. This may be <code>null</code> in which
case
* the same credential data is used as was used to create this
* instance.
* @return A new <code>ResourceResolver</code>
- * @throws LoginException If an error occurrs creating the new
+ * @throws LoginException If an error occurs creating the new
* <code>ResourceResolver</code> with the provided credential
* data.
* @throws IllegalStateException if this resource resolver has already been
@@ -483,7 +494,8 @@ public interface ResourceResolver extend
* Close this resource resolver. This method should be called by clients
* when the resource resolver is not used anymore. Once this method has
been
* called, the resource resolver is considered unusable and will throw
- * exceptions if still used.
+ * exceptions if still used - with the exception of this method, which
+ * can be called several times with no ill effects.
*
* @since 2.1
*/
@@ -623,4 +635,12 @@ public interface ResourceResolver extend
* @since 2.3
*/
boolean isResourceType(final Resource resource, final String resourceType);
+
+ /**
+ * The resolver is updated to reflect the latest state.
+ * Resources which have changes pending are not discarded.
+ * @since 2.3
+ */
+ void refresh();
+
}
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolverFactory.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolverFactory.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolverFactory.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceResolverFactory.java
Thu Jul 4 04:31:42 2013
@@ -90,11 +90,11 @@ public interface ResourceResolverFactory
* authenticated and only provide minimal privileges, if any at all.
*
* @param authenticationInfo A map of further credential information which
- * may be used by the implementation to parametrize how the
+ * may be used by the implementation to parameterize how the
* resource resolver is created. This may be <code>null</code>.
* @return A {@link ResourceResolver} according to the
* <code>authenticationInfo</code>.
- * @throws LoginException If an error occurrs creating the new
+ * @throws LoginException If an error occurs creating the new
* <code>ResourceResolver</code> with the provided credential
* data.
*/
@@ -122,12 +122,12 @@ public interface ResourceResolverFactory
* they don't support it.
*
* @param authenticationInfo A map of further credential information which
- * may be used by the implementation to parametrize how the
+ * may be used by the implementation to parameterize how the
* resource resolver is created. This may be <code>null</code>.
* @return A {@link ResourceResolver} with administrative privileges unless
* the {@link #USER_IMPERSONATION} was set in the
* <code>authenticationInfo</code>.
- * @throws LoginException If an error occurrs creating the new
+ * @throws LoginException If an error occurs creating the new
* <code>ResourceResolver</code> with the provided credential
* data.
* @deprecated as of 2.4 (bundle version 2.4.0) because of inherent
security
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/ResourceUtil.java
Thu Jul 4 04:31:42 2013
@@ -18,6 +18,7 @@
*/
package org.apache.sling.api.resource;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -437,6 +438,9 @@ public class ResourceUtil {
*/
@Deprecated
public static String findResourceSuperType(final Resource resource) {
+ if ( resource == null ) {
+ return null;
+ }
return resource.getResourceResolver().getParentResourceType(resource);
}
@@ -456,6 +460,9 @@ public class ResourceUtil {
*/
@Deprecated
public static boolean isA(final Resource resource, final String
resourceType) {
+ if ( resource == null ) {
+ return false;
+ }
return resource.getResourceResolver().isResourceType(resource,
resourceType);
}
@@ -504,4 +511,98 @@ public class ResourceUtil {
}
};
}
+
+ /**
+ * Creates or gets the resource at the given path.
+ *
+ * @param resolver The resource resolver to use for creation
+ * @param path The full path to be created
+ * @param resourceType The optional resource type of the final resource to
create
+ * @param intermediateResourceType THe optional resource type of all
intermediate resources
+ * @param autoCommit If set to true, a commit is performed after each
resource creation.
+ * @since 2.3.0
+ */
+ public static Resource getOrCreateResource(
+ final ResourceResolver resolver,
+ final String path,
+ final String resourceType,
+ final String intermediateResourceType,
+ final boolean autoCommit)
+ throws PersistenceException {
+ final Map<String, Object> props;
+ if ( resourceType == null ) {
+ props = null;
+ } else {
+ props =
Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE,
(Object)resourceType);
+ }
+ return getOrCreateResource(resolver, path, props,
intermediateResourceType, autoCommit);
+ }
+
+ /**
+ * Creates or gets the resource at the given path.
+ *
+ * @param resolver The resource resolver to use for creation
+ * @param path The full path to be created
+ * @param resourceProperties The optional resource properties of the final
resource to create
+ * @param intermediateResourceType THe optional resource type of all
intermediate resources
+ * @param autoCommit If set to true, a commit is performed after each
resource creation.
+ * @since 2.3.0
+ */
+ public static Resource getOrCreateResource(
+ final ResourceResolver resolver,
+ final String path,
+ final Map<String, Object> resourceProperties,
+ final String intermediateResourceType,
+ final boolean autoCommit)
+ throws PersistenceException {
+ Resource rsrc = resolver.getResource(path);
+ if ( rsrc == null ) {
+ final int lastPos = path.lastIndexOf('/');
+ final String name = path.substring(lastPos + 1);
+
+ final Resource parentResource;
+ if ( lastPos == 0 ) {
+ parentResource = resolver.getResource("/");
+ } else {
+ final String parentPath = path.substring(0, lastPos);
+ parentResource = getOrCreateResource(resolver,
+ parentPath,
+ intermediateResourceType,
+ intermediateResourceType,
+ autoCommit);
+ }
+ if ( autoCommit ) {
+ resolver.refresh();
+ }
+ try {
+ rsrc = resolver.create(parentResource, name,
resourceProperties);
+ } catch ( final PersistenceException pe ) {
+ // this could be thrown because someone else tried to create
this
+ // node concurrently
+ resolver.refresh();
+ rsrc = resolver.getResource(parentResource, name);
+ if ( rsrc == null ) {
+ throw pe;
+ }
+ }
+ if ( autoCommit ) {
+ try {
+ resolver.commit();
+ resolver.refresh();
+ rsrc = resolver.getResource(parentResource, name);
+ } catch ( final PersistenceException pe ) {
+ // try again - maybe someone else did create the resource
in the meantime
+ // or we ran into Jackrabbit's stale item exception in a
clustered environment
+ resolver.revert();
+ resolver.refresh();
+ rsrc = resolver.getResource(parentResource, name);
+ if ( rsrc == null ) {
+ rsrc = resolver.create(parentResource, name,
resourceProperties);
+ resolver.commit();
+ }
+ }
+ }
+ }
+ return rsrc;
+ }
}
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
Thu Jul 4 04:31:42 2013
@@ -26,7 +26,7 @@ package org.apache.sling.api.resource;
*/
public class SyntheticResource extends AbstractResource {
- /** The resoure resolver to which this resource is related */
+ /** The resource resolver to which this resource is related */
private final ResourceResolver resourceResolver;
/** The path of the synthetic resource */
@@ -35,7 +35,7 @@ public class SyntheticResource extends A
/** The type this synthetic resource assumes */
private final String resourceType;
- /** The metadata of this resource just containig the resource path */
+ /** The metadata of this resource just containing the resource path */
private final ResourceMetadata resourceMetadata;
/**
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/package-info.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/package-info.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/package-info.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/resource/package-info.java
Thu Jul 4 04:31:42 2013
@@ -17,7 +17,7 @@
* under the License.
*/
-@Version("2.3")
+@Version("2.3.2")
package org.apache.sling.api.resource;
import aQute.bnd.annotation.Version;
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/servlets/HtmlResponse.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/servlets/HtmlResponse.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/servlets/HtmlResponse.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/main/java/org/apache/sling/api/servlets/HtmlResponse.java
Thu Jul 4 04:31:42 2013
@@ -33,9 +33,10 @@ import org.apache.sling.api.request.Resp
* Generator for a HTML status response that displays the changes made in a
post
* request. see <a href="HtmlResponse.html">HtmlResponse.html</a> for the
* format.
- *
+ *
* @deprecated use org.apache.sling.servlets.post.HtmlResponse instead.
*/
+@Deprecated
public class HtmlResponse {
/**
@@ -101,7 +102,7 @@ public class HtmlResponse {
/**
* list of changes
*/
- private final StringBuffer changes = new StringBuffer();
+ private final StringBuilder changes = new StringBuilder();
/**
* Properties of the response
@@ -322,19 +323,19 @@ public class HtmlResponse {
* method call, where the <code>type</code> is the method name and the
* <code>arguments</code> are the string arguments to the method enclosed
in
* double quotes. For example, the the call
- *
+ *
* <pre>
* onChange("sameple", "arg1", "arg2");
* </pre>
- *
+ *
* is aded as
- *
+ *
* <pre>
* sample("arg1", "arg2")
* </pre>
- *
+ *
* to the internal list of changes.
- *
+ *
* @param type The type of the modification
* @param arguments The arguments to the modifications
*/
Modified:
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java?rev=1499645&r1=1499644&r2=1499645&view=diff
==============================================================================
---
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
(original)
+++
sling/whiteboard/fmeschbe/deprecate_login_administrative/api/src/test/java/org/apache/sling/api/resource/ResourceUtilTest.java
Thu Jul 4 04:31:42 2013
@@ -405,4 +405,12 @@ public class ResourceUtilTest {
assertEquals("/", ResourceUtil.getParent("/b/c/d", 3));
assertEquals("/", ResourceUtil.getParent("/b///", 1));
}
+
+ @Test public void testIsA() {
+ assertFalse(ResourceUtil.isA(null, "something"));
+ }
+
+ @Test public void testFindResourceSuperType() {
+ assertNull(ResourceUtil.findResourceSuperType(null));
+ }
}