Author: cziegeler Date: Thu Apr 13 14:42:02 2017 New Revision: 1791262 URL: http://svn.apache.org/viewvc?rev=1791262&view=rev Log: SLING-6723 : Make dependency to javax.jcr, jcr.contentloader and jcr.api optional
Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupport.java sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupportImpl.java sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupport.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupport.java?rev=1791262&r1=1791261&r2=1791262&view=diff ============================================================================== --- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupport.java (original) +++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupport.java Thu Apr 13 14:42:02 2017 @@ -187,4 +187,13 @@ public class JCRSupport { } return null; } + + public void setPrimaryNodeType(final Object node, final String type) + throws PersistenceException { + if ( node != null && supportImpl != null ) { + ((JCRSupportImpl)supportImpl).setPrimaryNodeType(node, type); + } else { + throw new PersistenceException("Node type should be set but JCR support is not available"); + } + } } Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupportImpl.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupportImpl.java?rev=1791262&r1=1791261&r2=1791262&view=diff ============================================================================== --- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupportImpl.java (original) +++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/helper/JCRSupportImpl.java Thu Apr 13 14:42:02 2017 @@ -394,4 +394,13 @@ public class JCRSupportImpl { public Object getNode(final Resource rsrc) { return rsrc.adaptTo(Node.class); } + + public void setPrimaryNodeType(final Object node, final String type) + throws PersistenceException { + try { + ((Node)node).setPrimaryType(type); + } catch ( final RepositoryException re) { + throw new PersistenceException(re.getMessage(), re); + } + } } Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java?rev=1791262&r1=1791261&r2=1791262&view=diff ============================================================================== --- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java (original) +++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java Thu Apr 13 14:42:02 2017 @@ -25,10 +25,6 @@ import java.util.Map; import java.util.Random; import java.util.regex.Pattern; -import javax.jcr.Node; -import javax.jcr.RepositoryException; -import javax.servlet.ServletException; - import org.apache.jackrabbit.JcrConstants; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.request.RequestParameter; @@ -141,7 +137,7 @@ abstract class AbstractCreateOperation e final PostResponse response, final List<Modification> changes, final VersioningConfiguration versioningConfiguration) - throws PersistenceException, RepositoryException { + throws PersistenceException { final String path = response.getPath(); final Resource resource = resolver.getResource(path); @@ -161,18 +157,18 @@ abstract class AbstractCreateOperation e final Map<String, RequestProperty> reqProperties, final List<Modification> changes, final VersioningConfiguration versioningConfiguration) - throws PersistenceException, RepositoryException { + throws PersistenceException { final String nodeType = getPrimaryType(reqProperties, path); if (nodeType != null) { final Resource rsrc = resolver.getResource(path); final ModifiableValueMap mvm = rsrc.adaptTo(ModifiableValueMap.class); if ( mvm != null ) { - final Node node = rsrc.adaptTo(Node.class); + final Object node = this.jcrSsupport.getNode(rsrc); final boolean wasVersionable = (node == null ? false : this.jcrSsupport.isVersionable(rsrc)); if ( node != null ) { this.jcrSsupport.checkoutIfNecessary(rsrc, changes, versioningConfiguration); - node.setPrimaryType(nodeType); + this.jcrSsupport.setPrimaryNodeType(node, nodeType); } else { mvm.put(JcrConstants.JCR_PRIMARYTYPE, nodeType); } @@ -220,9 +216,6 @@ abstract class AbstractCreateOperation e /** * Collects the properties that form the content to be written back to the * resource tree. - * - * @throws RepositoryException if a repository error occurs - * @throws ServletException if an internal error occurs */ protected Map<String, RequestProperty> collectContent( final SlingHttpServletRequest request, @@ -530,7 +523,7 @@ abstract class AbstractCreateOperation e final Map<String, RequestProperty> reqProperties, final List<Modification> changes, final VersioningConfiguration versioningConfiguration) - throws PersistenceException, RepositoryException { + throws PersistenceException { if (log.isDebugEnabled()) { log.debug("Deep-creating resource '{}'", path); } @@ -642,7 +635,7 @@ abstract class AbstractCreateOperation e protected String generateName(SlingHttpServletRequest request, String basePath) - throws RepositoryException { + throws PersistenceException { // SLING-1091: If a :name parameter is supplied, the (first) value of this parameter is used unmodified as the name // for the new node. If the name is illegally formed with respect to JCR name requirements, an exception will be @@ -658,7 +651,7 @@ abstract class AbstractCreateOperation e // if the resulting path already exists then report an error if (request.getResourceResolver().getResource(basePath) != null) { - throw new RepositoryException( + throw new PersistenceException( "Collision in node names for path=" + basePath); } @@ -692,7 +685,7 @@ abstract class AbstractCreateOperation e } /** Generate a unique path in case the node name generator didn't */ - private String ensureUniquePath(SlingHttpServletRequest request, String basePath) throws RepositoryException { + private String ensureUniquePath(SlingHttpServletRequest request, String basePath) throws PersistenceException { // if resulting path exists, add a suffix until it's not the case // anymore final ResourceResolver resolver = request.getResourceResolver(); @@ -713,7 +706,7 @@ abstract class AbstractCreateOperation e // Give up after MAX_TRIES if (resolver.getResource(basePath) != null ) { - throw new RepositoryException( + throw new PersistenceException( "Collision in generated node names under " + basePath + ", generated path " + basePath + " already exists"); } } Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java?rev=1791262&r1=1791261&r2=1791262&view=diff ============================================================================== --- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java (original) +++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java Thu Apr 13 14:42:02 2017 @@ -164,7 +164,7 @@ public class ModifyOperation extends Abs if (doGenerateName) { try { path = generateName(request, path); - } catch (RepositoryException re) { + } catch (PersistenceException re) { throw new SlingException("Failed to generate name", re); } }