Author: olli
Date: Tue Apr 29 09:27:19 2014
New Revision: 1590925

URL: http://svn.apache.org/r1590925
Log:
style

Modified:
    
sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java

Modified: 
sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java?rev=1590925&r1=1590924&r2=1590925&view=diff
==============================================================================
--- 
sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
 (original)
+++ 
sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
 Tue Apr 29 09:27:19 2014
@@ -18,17 +18,6 @@
  */
 package org.apache.sling.jcr.contentloader.internal;
 
-import org.apache.jackrabbit.api.security.principal.PrincipalManager;
-import org.apache.jackrabbit.api.security.user.Authorizable;
-import org.apache.jackrabbit.api.security.user.Group;
-import org.apache.jackrabbit.api.security.user.User;
-import org.apache.jackrabbit.api.security.user.UserManager;
-import org.apache.sling.jcr.base.util.AccessControlUtil;
-import org.apache.sling.jcr.contentloader.ContentImportListener;
-import org.apache.sling.jcr.contentloader.ImportOptions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.security.MessageDigest;
@@ -43,10 +32,10 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.Stack;
 import java.util.StringTokenizer;
-import java.util.Map.Entry;
 import java.util.regex.Pattern;
 
 import javax.jcr.Item;
@@ -58,27 +47,44 @@ import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.ValueFactory;
 
+import org.apache.jackrabbit.api.security.principal.PrincipalManager;
+import org.apache.jackrabbit.api.security.user.Authorizable;
+import org.apache.jackrabbit.api.security.user.Group;
+import org.apache.jackrabbit.api.security.user.User;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.sling.jcr.base.util.AccessControlUtil;
+import org.apache.sling.jcr.contentloader.ContentImportListener;
+import org.apache.sling.jcr.contentloader.ImportOptions;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * The <code>ContentLoader</code> creates the nodes and properties.
+ *
  * @since 2.0.4
  */
 public class DefaultContentCreator implements ContentCreator {
 
-    /** default log */
-    final Logger log = LoggerFactory.getLogger(getClass());
+    final Logger log = LoggerFactory.getLogger(DefaultContentCreator.class);
 
-       private ImportOptions configuration;
+    private ImportOptions configuration;
 
     private final Pattern jsonDatePattern = 
Pattern.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}[-+]{1}[0-9]{2}[:]{0,1}[0-9]{2}$");
+
     private final SimpleDateFormat jsonDateFormat = new 
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
 
     private final Stack<Node> parentNodeStack = new Stack<Node>();
 
-    /** The list of versionables. */
+    /**
+     * The list of versionables.
+     */
     private final List<Node> versionables = new ArrayList<Node>();
 
-    /** Delayed references during content loading for the reference property. 
*/
+    /**
+     * Delayed references during content loading for the reference property.
+     */
     private final Map<String, List<String>> delayedReferences = new 
HashMap<String, List<String>>();
+
     private final Map<String, String[]> delayedMultipleReferences = new 
HashMap<String, String[]>();
 
     private String defaultName;
@@ -92,18 +98,26 @@ public class DefaultContentCreator imple
     // default content type for createFile()
     private static final String DEFAULT_CONTENT_TYPE = 
"application/octet-stream";
 
-    /** Helper class to get the mime type of a file. */
+    /**
+     * Helper class to get the mime type of a file.
+     */
     private final JcrContentHelper jcrContentHelper;
 
-    /** List of active import providers mapped by extension. */
+    /**
+     * List of active import providers mapped by extension.
+     */
     private Map<String, ImportProvider> importProviders;
 
-    /** Optional list of created nodes (for uninstall) */
+    /**
+     * Optional list of created nodes (for uninstall)
+     */
     private List<String> createdNodes;
 
-    /** Optional listener to get notified about changes */
+    /**
+     * Optional listener to get notified about changes
+     */
     private ContentImportListener importListener;
-    
+
     /**
      * A one time use seed to randomize the user location.
      */
@@ -116,6 +130,7 @@ public class DefaultContentCreator imple
 
     /**
      * Constructor.
+     *
      * @param jcrContentHelper Helper class to get the mime type of a file
      */
     public DefaultContentCreator(JcrContentHelper jcrContentHelper) {
@@ -124,21 +139,19 @@ public class DefaultContentCreator imple
 
     /**
      * Initialize this component.
-     * @param pathEntry The configuration for this import.
+     *
+     * @param pathEntry              The configuration for this import.
      * @param defaultImportProviders List of all import providers.
-     * @param createdNodes Optional list to store new nodes (for uninstall)
+     * @param createdNodes           Optional list to store new nodes (for 
uninstall)
      */
-    public void init(final ImportOptions pathEntry,
-                     final Map<String, ImportProvider> defaultImportProviders,
-                     final List<String> createdNodes,
-                     final ContentImportListener importListener) {
+    public void init(final ImportOptions pathEntry, final Map<String, 
ImportProvider> defaultImportProviders, final List<String> createdNodes, final 
ContentImportListener importListener) {
         this.configuration = pathEntry;
         // create list of allowed import providers
         this.importProviders = new HashMap<String, ImportProvider>();
         final Iterator<Map.Entry<String, ImportProvider>> entryIter = 
defaultImportProviders.entrySet().iterator();
-        while ( entryIter.hasNext() ) {
+        while (entryIter.hasNext()) {
             final Map.Entry<String, ImportProvider> current = entryIter.next();
-            if (!configuration.isIgnoredImportProvider(current.getKey()) ) {
+            if (!configuration.isIgnoredImportProvider(current.getKey())) {
                 importProviders.put(current.getKey(), current.getValue());
             }
         }
@@ -147,13 +160,12 @@ public class DefaultContentCreator imple
     }
 
     /**
-     *
      * If the defaultName is null, we are in PARENT_NODE import mode.
+     *
      * @param parentNode
      * @param defaultName
      */
-    public void prepareParsing(final Node parentNode,
-                               final String defaultName) {
+    public void prepareParsing(final Node parentNode, final String 
defaultName) {
         this.parentNodeStack.clear();
         this.parentNodeStack.push(parentNode);
         this.defaultName = defaultName;
@@ -177,6 +189,7 @@ public class DefaultContentCreator imple
 
     /**
      * Set the ignore overwrite flag.
+     *
      * @param flag
      */
     public void setIgnoreOverwriteFlag(boolean flag) {
@@ -192,6 +205,7 @@ public class DefaultContentCreator imple
 
     /**
      * Get all active import providers.
+     *
      * @return A map of providers
      */
     public Map<String, ImportProvider> getImportProviders() {
@@ -200,6 +214,7 @@ public class DefaultContentCreator imple
 
     /**
      * Return the import provider for the name
+     *
      * @param name The file name.
      * @return The provider or <code>null</code>
      */
@@ -217,6 +232,7 @@ public class DefaultContentCreator imple
 
     /**
      * Get the extension of the file name.
+     *
      * @param name The file name.
      * @return The extension a provider is registered for - or 
<code>null</code>
      */
@@ -235,54 +251,48 @@ public class DefaultContentCreator imple
     /**
      * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createNode(java.lang.String,
 java.lang.String, java.lang.String[])
      */
-    public void createNode(String name,
-                           String primaryNodeType,
-                           String[] mixinNodeTypes)
-    throws RepositoryException {
+    public void createNode(String name, String primaryNodeType, String[] 
mixinNodeTypes) throws RepositoryException {
         final Node parentNode = this.parentNodeStack.peek();
         boolean isParentImport = (name == null && isParentNodeImport);
-        if ( name == null ) {
-            if ( this.parentNodeStack.size() > 1 ) {
+        if (name == null) {
+            if (this.parentNodeStack.size() > 1) {
                 throw new RepositoryException("Node needs to have a name.");
             }
             name = this.defaultName;
         }
 
         // if we are in parent node import mode, we don't create the root top 
level node!
-        if ( !isParentImport || this.parentNodeStack.size() > 1 ) {
+        if (!isParentImport || this.parentNodeStack.size() > 1) {
             // if node already exists but should be overwritten, delete it
             if (!this.ignoreOverwriteFlag && this.configuration.isOverwrite() 
&& parentNode.hasNode(name)) {
-               checkoutIfNecessary(parentNode);
+                checkoutIfNecessary(parentNode);
                 parentNode.getNode(name).remove();
             }
 
             // ensure repository node
             Node node;
             if (parentNode.hasNode(name)) {
-
                 // use existing node
                 node = parentNode.getNode(name);
             } else if (primaryNodeType == null) {
-
                 // no explicit node type, use repository default
-               checkoutIfNecessary(parentNode);
+                checkoutIfNecessary(parentNode);
                 node = parentNode.addNode(name);
                 addNodeToCreatedList(node);
-                if ( this.importListener != null ) {
-                       this.importListener.onCreate(node.getPath());
+                if (this.importListener != null) {
+                    this.importListener.onCreate(node.getPath());
                 }
             } else {
-
                 // explicit primary node type
-               checkoutIfNecessary(parentNode);
+                checkoutIfNecessary(parentNode);
                 node = parentNode.addNode(name, primaryNodeType);
                 addNodeToCreatedList(node);
-                if ( this.importListener != null ) {
-                       this.importListener.onCreate(node.getPath());
+                if (this.importListener != null) {
+                    this.importListener.onCreate(node.getPath());
                 }
             }
 
-            // ammend mixin node types
+            // amend mixin node types
             if (mixinNodeTypes != null) {
                 for (final String mixin : mixinNodeTypes) {
                     if (!node.isNodeType(mixin)) {
@@ -292,14 +302,13 @@ public class DefaultContentCreator imple
             }
 
             // check if node is versionable
-            final boolean addToVersionables = this.configuration.isCheckin()
-                                        && node.isNodeType("mix:versionable");
-            if ( addToVersionables ) {
+            final boolean addToVersionables = this.configuration.isCheckin() 
&& node.isNodeType("mix:versionable");
+            if (addToVersionables) {
                 this.versionables.add(node);
             }
 
             this.parentNodeStack.push(node);
-            if ( this.createdRootNode == null ) {
+            if (this.createdRootNode == null) {
                 this.createdRootNode = node;
             }
         }
@@ -308,50 +317,43 @@ public class DefaultContentCreator imple
     /**
      * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createProperty(java.lang.String,
 int, java.lang.String)
      */
-    public void createProperty(String name, int propertyType, String value)
-    throws RepositoryException {
+    public void createProperty(String name, int propertyType, String value) 
throws RepositoryException {
         final Node node = this.parentNodeStack.peek();
         // check if the property already exists and isPropertyOverwrite() is 
false, don't overwrite it in this case
-        if (node.hasProperty(name)
-            && !this.configuration.isPropertyOverwrite()
-            && !node.getProperty(name).isNew()) { 
+        if (node.hasProperty(name) && 
!this.configuration.isPropertyOverwrite() && !node.getProperty(name).isNew()) {
             return;
         }
 
-        if ( propertyType == PropertyType.REFERENCE ) {
+        if (propertyType == PropertyType.REFERENCE) {
             // need to resolve the reference
             String propPath = node.getPath() + "/" + name;
             String uuid = getUUID(node.getSession(), propPath, 
getAbsPath(node, value));
             if (uuid != null) {
                 checkoutIfNecessary(node);
                 node.setProperty(name, uuid, propertyType);
-                
-                if ( this.importListener != null ) {
-                       
this.importListener.onCreate(node.getProperty(name).getPath());
+                if (this.importListener != null) {
+                    
this.importListener.onCreate(node.getProperty(name).getPath());
                 }
             }
-
         } else if ("jcr:isCheckedOut".equals(name)) {
-
             // don't try to write the property but record its state
             // for later checkin if set to false
             final boolean checkedout = Boolean.valueOf(value);
             if (!checkedout) {
-                if ( !this.versionables.contains(node) ) {
+                if (!this.versionables.contains(node)) {
                     this.versionables.add(node);
                 }
             }
-        } else if ( propertyType == PropertyType.DATE ) {
+        } else if (propertyType == PropertyType.DATE) {
             checkoutIfNecessary(node);
             try {
-              node.setProperty(name, parseDateString(value) );
-            }
-            catch (ParseException e) {
-              // Fall back to default behaviour if this fails
-              node.setProperty(name, value, propertyType);
+                node.setProperty(name, parseDateString(value));
+            } catch (ParseException e) {
+                // Fall back to default behaviour if this fails
+                node.setProperty(name, value, propertyType);
             }
-            if ( this.importListener != null ) {
-               this.importListener.onCreate(node.getProperty(name).getPath());
+            if (this.importListener != null) {
+                this.importListener.onCreate(node.getProperty(name).getPath());
             }
         } else {
             checkoutIfNecessary(node);
@@ -360,8 +362,8 @@ public class DefaultContentCreator imple
             } else {
                 node.setProperty(name, value, propertyType);
             }
-            if ( this.importListener != null ) {
-               this.importListener.onCreate(node.getProperty(name).getPath());
+            if (this.importListener != null) {
+                this.importListener.onCreate(node.getProperty(name).getPath());
             }
         }
     }
@@ -369,18 +371,14 @@ public class DefaultContentCreator imple
     /**
      * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createProperty(java.lang.String,
 int, java.lang.String[])
      */
-    public void createProperty(String name, int propertyType, String[] values)
-    throws RepositoryException {
+    public void createProperty(String name, int propertyType, String[] values) 
throws RepositoryException {
         final Node node = this.parentNodeStack.peek();
         // check if the property already exists and isPropertyOverwrite() is 
false, don't overwrite it in this case
-        if (node.hasProperty(name)
-            && !this.configuration.isPropertyOverwrite()
-            && !node.getProperty(name).isNew()) {
+        if (node.hasProperty(name) && 
!this.configuration.isPropertyOverwrite() && !node.getProperty(name).isNew()) {
             return;
         }
-        if ( propertyType == PropertyType.REFERENCE ) {
+        if (propertyType == PropertyType.REFERENCE) {
             String propPath = node.getPath() + "/" + name;
-
             boolean hasAll = true;
             String[] uuids = new String[values.length];
             String[] uuidOrPaths = new String[values.length];
@@ -389,36 +387,33 @@ public class DefaultContentCreator imple
                 uuidOrPaths[i] = uuids[i] != null ? uuids[i] : 
getAbsPath(node, values[i]);
                 if (uuids[i] == null) hasAll = false;
             }
-
             checkoutIfNecessary(node);
             node.setProperty(name, uuids, propertyType);
-            if ( this.importListener != null ) {
-               this.importListener.onCreate(node.getProperty(name).getPath());
+            if (this.importListener != null) {
+                this.importListener.onCreate(node.getProperty(name).getPath());
             }
-
             if (!hasAll) {
                 delayedMultipleReferences.put(propPath, uuidOrPaths);
             }
-        } else if ( propertyType == PropertyType.DATE ) {
+        } else if (propertyType == PropertyType.DATE) {
             checkoutIfNecessary(node);
             try {
-              // This modification is to remove the colon in the JSON Timezone
-              ValueFactory valueFactory = node.getSession().getValueFactory();
-              Value[] jcrValues = new Value[values.length];
-
-              for (int i = 0; i < values.length; i++) {
-                jcrValues[i] = valueFactory.createValue( parseDateString( 
values[i] ) );
-              }
-
-              node.setProperty(name, jcrValues, propertyType);
-            }
-            catch (ParseException e) {
-              // If this failes, fallback to the default
-              log.warn("Could not create dates for property, fallingback to 
defaults", e);
-              node.setProperty(name, values, propertyType);
+                // This modification is to remove the colon in the JSON 
Timezone
+                ValueFactory valueFactory = 
node.getSession().getValueFactory();
+                Value[] jcrValues = new Value[values.length];
+
+                for (int i = 0; i < values.length; i++) {
+                    jcrValues[i] = 
valueFactory.createValue(parseDateString(values[i]));
+                }
+
+                node.setProperty(name, jcrValues, propertyType);
+            } catch (ParseException e) {
+                // If this failes, fallback to the default
+                log.warn("Could not create dates for property, fallingback to 
defaults", e);
+                node.setProperty(name, values, propertyType);
             }
-            if ( this.importListener != null ) {
-               this.importListener.onCreate(node.getProperty(name).getPath());
+            if (this.importListener != null) {
+                this.importListener.onCreate(node.getProperty(name).getPath());
             }
         } else {
             checkoutIfNecessary(node);
@@ -427,69 +422,68 @@ public class DefaultContentCreator imple
             } else {
                 node.setProperty(name, values, propertyType);
             }
-            if ( this.importListener != null ) {
-               this.importListener.onCreate(node.getProperty(name).getPath());
+            if (this.importListener != null) {
+                this.importListener.onCreate(node.getProperty(name).getPath());
             }
         }
     }
 
     protected Value createValue(final ValueFactory factory, Object value) {
-        if ( value == null ) {
+        if (value == null) {
             return null;
         }
-        if ( value instanceof Long ) {
-            return factory.createValue((Long)value);
-        } else if ( value instanceof Date ) {
+        if (value instanceof Long) {
+            return factory.createValue((Long) value);
+        } else if (value instanceof Date) {
             final Calendar c = Calendar.getInstance();
-            c.setTime((Date)value);
+            c.setTime((Date) value);
             return factory.createValue(c);
-        } else if ( value instanceof Calendar ) {
-            return factory.createValue((Calendar)value);
-        } else if ( value instanceof Double ) {
-            return factory.createValue((Double)value);
-        } else if ( value instanceof Boolean ) {
-            return factory.createValue((Boolean)value);
-        } else if ( value instanceof InputStream ) {
-            return factory.createValue((InputStream)value);
+        } else if (value instanceof Calendar) {
+            return factory.createValue((Calendar) value);
+        } else if (value instanceof Double) {
+            return factory.createValue((Double) value);
+        } else if (value instanceof Boolean) {
+            return factory.createValue((Boolean) value);
+        } else if (value instanceof InputStream) {
+            return factory.createValue((InputStream) value);
         } else {
             return factory.createValue(value.toString());
         }
-
     }
+
     /**
      * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createProperty(java.lang.String,
 java.lang.Object)
      */
-    public void createProperty(String name, Object value)
-    throws RepositoryException {
-       createProperty(name, value, false);
+    public void createProperty(String name, Object value) throws 
RepositoryException {
+        createProperty(name, value, false);
     }
 
     /**
      * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createProperty(java.lang.String,
 java.lang.Object[])
      */
-    public void createProperty(String name, Object[] values)
-    throws RepositoryException {
+    public void createProperty(String name, Object[] values) throws 
RepositoryException {
         createProperty(name, values, false);
     }
 
     /**
      * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#finishNode()
      */
-    public void finishNode()
-    throws RepositoryException {
+    public void finishNode() throws RepositoryException {
         final Node node = this.parentNodeStack.pop();
         // resolve REFERENCE property values pointing to this node
         resolveReferences(node);
     }
 
     private void addNodeToCreatedList(Node node) throws RepositoryException {
-        if ( this.createdNodes != null ) {
+        if (this.createdNodes != null) {
             this.createdNodes.add(node.getSession().getWorkspace().getName() + 
":" + node.getPath());
         }
     }
 
     private String getAbsPath(Node node, String path) throws 
RepositoryException {
-        if (path.startsWith("/")) return path;
+        if (path.startsWith("/")) {
+            return path;
+        }
 
         while (path.startsWith("../")) {
             path = path.substring(3);
@@ -503,9 +497,7 @@ public class DefaultContentCreator imple
         return node.getPath() + "/" + path;
     }
 
-    private String getUUID(Session session, String propPath,
-                          String referencePath)
-    throws RepositoryException {
+    private String getUUID(Session session, String propPath, String 
referencePath) throws RepositoryException {
         if (session.itemExists(referencePath)) {
             Item item = session.getItem(referencePath);
             if (item.isNode()) {
@@ -566,17 +558,16 @@ public class DefaultContentCreator imple
                         }
                     }
                     parentNode.setProperty(name, uuids, 
PropertyType.REFERENCE);
-                    if ( this.importListener != null ) {
-                       
this.importListener.onCreate(parentNode.getProperty(name).getPath());
+                    if (this.importListener != null) {
+                        
this.importListener.onCreate(parentNode.getProperty(name).getPath());
                     }
-
                     if (hasAll) {
                         delayedMultipleReferences.remove(property);
                     }
                 } else {
                     parentNode.setProperty(name, uuid, PropertyType.REFERENCE);
-                    if ( this.importListener != null ) {
-                       
this.importListener.onCreate(parentNode.getProperty(name).getPath());
+                    if (this.importListener != null) {
+                        
this.importListener.onCreate(parentNode.getProperty(name).getPath());
                     }
                 }
             }
@@ -594,12 +585,10 @@ public class DefaultContentCreator imple
     private String getName(String path) {
         int lastSlash = path.lastIndexOf('/');
         String name = (lastSlash < 0) ? path : path.substring(lastSlash + 1);
-
         return name;
     }
 
-    private Node getParentNode(Session session, String path)
-            throws RepositoryException {
+    private Node getParentNode(Session session, String path) throws 
RepositoryException {
         int lastSlash = path.lastIndexOf('/');
 
         // not an absolute path, cannot find parent
@@ -623,77 +612,73 @@ public class DefaultContentCreator imple
     }
 
     private Calendar parseDateString(String value) throws ParseException {
-      if (jsonDatePattern.matcher(value).matches()) {
-        String modifiedJsonDate = value;
+        if (jsonDatePattern.matcher(value).matches()) {
+            String modifiedJsonDate = value;
 
-        // This modification is to remove the colon in the JSON Timezone
-        // to match the Java Version
-        if (value.lastIndexOf(":") == 26) {
-          modifiedJsonDate = value.substring(0, 26) + value.substring(27);
-        }
+            // This modification is to remove the colon in the JSON Timezone
+            // to match the Java Version
+            if (value.lastIndexOf(":") == 26) {
+                modifiedJsonDate = value.substring(0, 26) + 
value.substring(27);
+            }
 
-        Calendar cal = Calendar.getInstance();
-        cal.setTime( jsonDateFormat.parse( modifiedJsonDate ) );
+            Calendar cal = Calendar.getInstance();
+            cal.setTime(jsonDateFormat.parse(modifiedJsonDate));
 
-        return cal;
-      }
+            return cal;
+        }
 
-      return null;
+        return null;
     }
 
-    private void createProperty(String name, Object value, boolean 
overwriteExisting)
-    throws RepositoryException {
+    private void createProperty(String name, Object value, boolean 
overwriteExisting) throws RepositoryException {
         final Node node = this.parentNodeStack.peek();
         // check if the property already exists, don't overwrite it in this 
case
-        if (node.hasProperty(name)
-            && !node.getProperty(name).isNew() && !overwriteExisting) {
+        if (node.hasProperty(name) && !node.getProperty(name).isNew() && 
!overwriteExisting) {
             return;
         }
-        if ( value == null ) {
-            if ( node.hasProperty(name) ) {
-               checkoutIfNecessary(node);
-               String propPath = node.getProperty(name).getPath();
+        if (value == null) {
+            if (node.hasProperty(name)) {
+                checkoutIfNecessary(node);
+                String propPath = node.getProperty(name).getPath();
                 node.getProperty(name).remove();
-                if ( this.importListener != null ) {
-                       this.importListener.onDelete(propPath);
+                if (this.importListener != null) {
+                    this.importListener.onDelete(propPath);
                 }
             }
         } else {
-               checkoutIfNecessary(node);
+            checkoutIfNecessary(node);
             final Value jcrValue = 
this.createValue(node.getSession().getValueFactory(), value);
             node.setProperty(name, jcrValue);
-            if ( this.importListener != null ) {
-               this.importListener.onModify(node.getProperty(name).getPath());
+            if (this.importListener != null) {
+                this.importListener.onModify(node.getProperty(name).getPath());
             }
         }
     }
 
-    private void createProperty(String name, Object[] values, boolean 
overwriteExisting)
-    throws RepositoryException {
+    private void createProperty(String name, Object[] values, boolean 
overwriteExisting) throws RepositoryException {
         final Node node = this.parentNodeStack.peek();
         // check if the property already exists, don't overwrite it in this 
case
-        if (node.hasProperty(name)
-            && !node.getProperty(name).isNew() && !overwriteExisting) {
+        if (node.hasProperty(name) && !node.getProperty(name).isNew() && 
!overwriteExisting) {
             return;
         }
-        if ( values == null || values.length == 0 ) {
-            if ( node.hasProperty(name) ) {
-               checkoutIfNecessary(node);
-               String propPath = node.getProperty(name).getPath();
+        if (values == null || values.length == 0) {
+            if (node.hasProperty(name)) {
+                checkoutIfNecessary(node);
+                String propPath = node.getProperty(name).getPath();
                 node.getProperty(name).remove();
-                if ( this.importListener != null ) {
-                       this.importListener.onDelete(propPath);
+                if (this.importListener != null) {
+                    this.importListener.onDelete(propPath);
                 }
             }
         } else {
-               checkoutIfNecessary(node);
+            checkoutIfNecessary(node);
             final Value[] jcrValues = new Value[values.length];
-            for(int i = 0; i < values.length; i++) {
+            for (int i = 0; i < values.length; i++) {
                 jcrValues[i] = 
this.createValue(node.getSession().getValueFactory(), values[i]);
             }
             node.setProperty(name, jcrValues);
-            if ( this.importListener != null ) {
-               this.importListener.onModify(node.getProperty(name).getPath());
+            if (this.importListener != null) {
+                this.importListener.onModify(node.getProperty(name).getPath());
             }
         }
     }
@@ -701,11 +686,7 @@ public class DefaultContentCreator imple
     /**
      * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createFileAndResourceNode(java.lang.String,
 java.io.InputStream, java.lang.String, long)
      */
-    public void createFileAndResourceNode(String name,
-                                          InputStream data,
-                                          String mimeType,
-                                          long lastModified)
-    throws RepositoryException {
+    public void createFileAndResourceNode(String name, InputStream data, 
String mimeType, long lastModified) throws RepositoryException {
         int lastSlash = name.lastIndexOf('/');
         name = (lastSlash < 0) ? name : name.substring(lastSlash + 1);
         final Node parentNode = this.parentNodeStack.peek();
@@ -716,16 +697,13 @@ public class DefaultContentCreator imple
             Node contentNode = parentNode.getNode(name).getNode("jcr:content");
             this.parentNodeStack.push(contentNode);
             long nodeLastModified = 0L;
-            if ( contentNode.hasProperty("jcr:lastModified") ) {
+            if (contentNode.hasProperty("jcr:lastModified")) {
                 nodeLastModified = 
contentNode.getProperty("jcr:lastModified").getDate().getTimeInMillis();
             }
-            if (!this.configuration.isOverwrite() && nodeLastModified >= 
lastModified ) {
+            if (!this.configuration.isOverwrite() && nodeLastModified >= 
lastModified) {
                 return;
             }
-            log.info(
-                    "Updating {} lastModified:{} New Content LastModified:{}",
-                    new Object[] { parentNode.getNode(name).getPath(),
-                            new Date(nodeLastModified), new Date(lastModified) 
});
+            log.info("Updating {} lastModified:{} New Content 
LastModified:{}", new Object[]{parentNode.getNode(name).getPath(), new 
Date(nodeLastModified), new Date(lastModified)});
         } else {
             this.createNode(name, "nt:file", null);
             this.createNode("jcr:content", "nt:resource", null);
@@ -735,9 +713,7 @@ public class DefaultContentCreator imple
         if (mimeType == null) {
             mimeType = jcrContentHelper.getMimeType(name);
             if (mimeType == null) {
-                log.info(
-                    "createFile: Cannot find content type for {}, using {}",
-                    name, DEFAULT_CONTENT_TYPE);
+                log.info("createFile: Cannot find content type for {}, using 
{}", name, DEFAULT_CONTENT_TYPE);
                 mimeType = DEFAULT_CONTENT_TYPE;
             }
         }
@@ -754,24 +730,23 @@ public class DefaultContentCreator imple
     /**
      * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#switchCurrentNode(java.lang.String,
 java.lang.String)
      */
-    public boolean switchCurrentNode(String subPath, String newNodeType)
-    throws RepositoryException {
-        if ( subPath.startsWith("/") ) {
+    public boolean switchCurrentNode(String subPath, String newNodeType) 
throws RepositoryException {
+        if (subPath.startsWith("/")) {
             subPath = subPath.substring(1);
         }
         final StringTokenizer st = new StringTokenizer(subPath, "/");
         Node node = this.parentNodeStack.peek();
-        while ( st.hasMoreTokens() ) {
+        while (st.hasMoreTokens()) {
             final String token = st.nextToken();
-            if ( !node.hasNode(token) ) {
-                if ( newNodeType == null ) {
+            if (!node.hasNode(token)) {
+                if (newNodeType == null) {
                     return false;
                 }
-               checkoutIfNecessary(node);
+                checkoutIfNecessary(node);
                 final Node n = node.addNode(token, newNodeType);
                 addNodeToCreatedList(n);
-                if ( this.importListener != null ) {
-                       this.importListener.onCreate(node.getPath());
+                if (this.importListener != null) {
+                    this.importListener.onCreate(node.getPath());
                 }
             }
             node = node.getNode(token);
@@ -780,139 +755,129 @@ public class DefaultContentCreator imple
         return true;
     }
 
+    /* (non-Javadoc)
+     * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createGroup(java.lang.String,
 java.lang.String[], java.util.Map)
+     */
+    public void createGroup(final String name, String[] members, Map<String, 
Object> extraProperties) throws RepositoryException {
 
-       /* (non-Javadoc)
-        * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createGroup(java.lang.String,
 java.lang.String[], java.util.Map)
-        */
-       public void createGroup(final String name, String[] members,
-                       Map<String, Object> extraProperties) throws 
RepositoryException {
-
-               final Node parentNode = this.parentNodeStack.peek();
-               Session session = parentNode.getSession();
+        final Node parentNode = this.parentNodeStack.peek();
+        Session session = parentNode.getSession();
 
         UserManager userManager = AccessControlUtil.getUserManager(session);
         Authorizable authorizable = userManager.getAuthorizable(name);
         if (authorizable == null) {
             //principal does not exist yet, so create it
-               Group group = userManager.createGroup(new Principal() {
-                    public String getName() {
-                        return name;
-                    }
-                },
-                hashPath(name));
-               authorizable = group;
+            Group group = userManager.createGroup(new Principal() {
+                                                      public String getName() {
+                                                          return name;
+                                                      }
+                                                  },
+                hashPath(name)
+            );
+            authorizable = group;
         } else {
-               //principal already exists, check to make sure it is the 
expected type
-               if (!authorizable.isGroup()) {
-                throw new RepositoryException(
-                        "A user already exists with the requested name: "
-                            + name);
+            //principal already exists, check to make sure it is the expected 
type
+            if (!authorizable.isGroup()) {
+                throw new RepositoryException("A user already exists with the 
requested name: " + name);
             }
-               //group already exists so just update it below
+            //group already exists so just update it below
         }
         //update the group members
         if (members != null) {
-               Group group = (Group)authorizable;
-               for (String member : members) {
-                       Authorizable memberAuthorizable = 
userManager.getAuthorizable(member);
-                       if (memberAuthorizable != null) {
-                               group.addMember(memberAuthorizable);
-                       }
-               }
+            Group group = (Group) authorizable;
+            for (String member : members) {
+                Authorizable memberAuthorizable = 
userManager.getAuthorizable(member);
+                if (memberAuthorizable != null) {
+                    group.addMember(memberAuthorizable);
+                }
+            }
         }
         if (extraProperties != null) {
-               ValueFactory valueFactory = session.getValueFactory();
-               Set<Entry<String, Object>> entrySet = 
extraProperties.entrySet();
-               for (Entry<String, Object> entry : entrySet) {
-                       Value value = createValue(valueFactory, 
entry.getValue());
-                       authorizable.setProperty(entry.getKey(), value);
-                       }
+            ValueFactory valueFactory = session.getValueFactory();
+            Set<Entry<String, Object>> entrySet = extraProperties.entrySet();
+            for (Entry<String, Object> entry : entrySet) {
+                Value value = createValue(valueFactory, entry.getValue());
+                authorizable.setProperty(entry.getKey(), value);
+            }
         }
-       }
+    }
 
-       /* (non-Javadoc)
-        * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createUser(java.lang.String,
 java.lang.String, java.util.Map)
-        */
-       public void createUser(final String name, String password,
-                       Map<String, Object> extraProperties) throws 
RepositoryException {
-               final Node parentNode = this.parentNodeStack.peek();
-               Session session = parentNode.getSession();
+    /* (non-Javadoc)
+     * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createUser(java.lang.String,
 java.lang.String, java.util.Map)
+     */
+    public void createUser(final String name, String password, Map<String, 
Object> extraProperties) throws RepositoryException {
+        final Node parentNode = this.parentNodeStack.peek();
+        Session session = parentNode.getSession();
 
         UserManager userManager = AccessControlUtil.getUserManager(session);
         Authorizable authorizable = userManager.getAuthorizable(name);
         if (authorizable == null) {
             //principal does not exist yet, so create it
-               User user = userManager.createUser(name,
-                               password,
-                               new Principal() {
-                                               public String getName() {
-                                                       return name;
-                                               }
-                               },
-                               hashPath(name));
-               authorizable = user;
+            User user = userManager.createUser(name,
+                password,
+                new Principal() {
+                    public String getName() {
+                        return name;
+                    }
+                },
+                hashPath(name)
+            );
+            authorizable = user;
         } else {
-               //principal already exists, check to make sure it is the 
expected type
-               if (authorizable.isGroup()) {
-                throw new RepositoryException(
-                        "A group already exists with the requested name: "
-                            + name);
+            //principal already exists, check to make sure it is the expected 
type
+            if (authorizable.isGroup()) {
+                throw new RepositoryException("A group already exists with the 
requested name: " + name);
             }
-               //user already exists so just update it below
+            //user already exists so just update it below
         }
         if (extraProperties != null) {
-               ValueFactory valueFactory = session.getValueFactory();
-               Set<Entry<String, Object>> entrySet = 
extraProperties.entrySet();
-               for (Entry<String, Object> entry : entrySet) {
-                       Value value = createValue(valueFactory, 
entry.getValue());
-                       authorizable.setProperty(entry.getKey(), value);
-                       }
-        }
-       }
-
-       /**
-        * @param item
-        * @return a parent path fragment for the item.
-        */
-       protected String hashPath(String item) throws RepositoryException {
-               try {
-                       String hash = digest("sha1", (INSTANCE_SEED + 
item).getBytes("UTF-8"));
-                       StringBuilder sb = new StringBuilder();
-                       for (int i = 0; i < STORAGE_LEVELS; i++) {
-                               sb.append(hash, i * 2, (i * 2) + 2).append("/");
-                       }
-                       return sb.toString();
-               } catch (NoSuchAlgorithmException e) {
-                       throw new RepositoryException("Unable to hash the 
path.", e);
-               } catch (UnsupportedEncodingException e) {
-                       throw new RepositoryException("Unable to hash the 
path.", e);
-               }
-       }
+            ValueFactory valueFactory = session.getValueFactory();
+            Set<Entry<String, Object>> entrySet = extraProperties.entrySet();
+            for (Entry<String, Object> entry : entrySet) {
+                Value value = createValue(valueFactory, entry.getValue());
+                authorizable.setProperty(entry.getKey(), value);
+            }
+        }
+    }
 
+    /**
+     * @param item
+     * @return a parent path fragment for the item.
+     */
+    protected String hashPath(String item) throws RepositoryException {
+        try {
+            String hash = digest("sha1", (INSTANCE_SEED + 
item).getBytes("UTF-8"));
+            StringBuilder sb = new StringBuilder();
+            for (int i = 0; i < STORAGE_LEVELS; i++) {
+                sb.append(hash, i * 2, (i * 2) + 2).append("/");
+            }
+            return sb.toString();
+        } catch (NoSuchAlgorithmException e) {
+            throw new RepositoryException("Unable to hash the path.", e);
+        } catch (UnsupportedEncodingException e) {
+            throw new RepositoryException("Unable to hash the path.", e);
+        }
+    }
 
     /* (non-Javadoc)
-        * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createAce(java.lang.String,
 java.lang.String, java.lang.String[], java.lang.String[])
+     * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createAce(java.lang.String,
 java.lang.String, java.lang.String[], java.lang.String[])
         */
-       public void createAce(String principalId,
-                       String[] grantedPrivilegeNames, String[] 
deniedPrivilegeNames,
-                       String order)
-                       throws RepositoryException {
-               final Node parentNode = this.parentNodeStack.peek();
-               Session session = parentNode.getSession();
-               PrincipalManager principalManager = 
AccessControlUtil.getPrincipalManager(session);
-               Principal principal = 
principalManager.getPrincipal(principalId);
-               if (principal == null) {
-                       throw new RepositoryException("No principal found for 
id: " + principalId);
-               }
-               String resourcePath = parentNode.getPath();
-
-               if ((grantedPrivilegeNames != null) || (deniedPrivilegeNames != 
null)) {
-                       AccessControlUtil.replaceAccessControlEntry(session, 
resourcePath, principal,
-                                       grantedPrivilegeNames, 
deniedPrivilegeNames, null, order);
-               }
-       }
+    public void createAce(String principalId, String[] grantedPrivilegeNames, 
String[] deniedPrivilegeNames, String order) throws RepositoryException {
+        final Node parentNode = this.parentNodeStack.peek();
+        Session session = parentNode.getSession();
+        PrincipalManager principalManager = 
AccessControlUtil.getPrincipalManager(session);
+        Principal principal = principalManager.getPrincipal(principalId);
+        if (principal == null) {
+            throw new RepositoryException("No principal found for id: " + 
principalId);
+        }
+        String resourcePath = parentNode.getPath();
 
-       /**
+        if ((grantedPrivilegeNames != null) || (deniedPrivilegeNames != null)) 
{
+            AccessControlUtil.replaceAccessControlEntry(session, resourcePath, 
principal, grantedPrivilegeNames, deniedPrivilegeNames, null, order);
+        }
+    }
+
+    /**
      * used for the md5
      */
     private static final char[] hexTable = "0123456789abcdef".toCharArray();
@@ -925,11 +890,9 @@ public class DefaultContentCreator imple
      * @param data      the data to digest with the given algorithm
      * @return The digested plain text String represented as Hex digits.
      * @throws java.security.NoSuchAlgorithmException if the desired algorithm 
is not supported by
-     *                                  the MessageDigest class.
+     *                                                the MessageDigest class.
      */
-    public static String digest(String algorithm, byte[] data)
-            throws NoSuchAlgorithmException {
-
+    public static String digest(String algorithm, byte[] data) throws 
NoSuchAlgorithmException {
         MessageDigest md = MessageDigest.getInstance(algorithm);
         byte[] digest = md.digest(data);
         StringBuffer res = new StringBuffer(digest.length * 2);
@@ -940,15 +903,14 @@ public class DefaultContentCreator imple
         }
         return res.toString();
     }
-    
 
     /**
      * Find an ancestor that is versionable
      */
     protected Node findVersionableAncestor(Node node) throws 
RepositoryException {
-       if (node == null) {
-               return null;
-       } else  if (isVersionable(node)) {
+        if (node == null) {
+            return null;
+        } else if (isVersionable(node)) {
             return node;
         } else {
             try {
@@ -974,12 +936,12 @@ public class DefaultContentCreator imple
             if (versionableNode != null) {
                 if (!versionableNode.isCheckedOut()) {
                     versionableNode.checkout();
-                    if ( this.importListener != null ) {
-                       
this.importListener.onCheckout(versionableNode.getPath());
+                    if (this.importListener != null) {
+                        
this.importListener.onCheckout(versionableNode.getPath());
                     }
                 }
             }
         }
     }
-    
+
 }


Reply via email to