incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1086910 - /sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
Date Wed, 30 Mar 2011 11:40:55 GMT
Author: cziegeler
Date: Wed Mar 30 11:40:54 2011
New Revision: 1086910

URL: http://svn.apache.org/viewvc?rev=1086910&view=rev
Log:
Clean up code

Modified:
    sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java

Modified: sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java?rev=1086910&r1=1086909&r2=1086910&view=diff
==============================================================================
--- sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
(original)
+++ sling/trunk/installer/providers/jcr/src/main/java/org/apache/sling/installer/provider/jcr/impl/JcrInstaller.java
Wed Mar 30 11:40:54 2011
@@ -85,6 +85,15 @@ public class JcrInstaller implements Eve
     public static final int RUN_LOOP_COUNTER = 2;
     public static final int COUNTERS_COUNT = 3;
 
+    private static final String NT_FILE = "nt:file";
+    private static final String NT_RESOURCE = "nt:resource";
+    private static final String PROP_DATA = "jcr:data";
+    private static final String PROP_MODIFIED = "jcr:lastModified";
+    private static final String PROP_ENC = "jcr:encoding";
+    private static final String PROP_MIME = "jcr:mimeType";
+    private static final String MIME_TXT = "text/plain";
+    private static final String ENCODING = "UTF-8";
+
     /**
      * This class watches the repository for installable resources
      */
@@ -610,6 +619,7 @@ public class JcrInstaller implements Eve
                 final int pos = url.indexOf(':');
                 final String oldPath = url.substring(pos + 1);
                 final String nodePath = getPathWithHighestPrio(oldPath);
+                // ensure extension 'config'
                 if ( !nodePath.endsWith(".config") && session.itemExists(nodePath)
) {
                     session.getItem(nodePath).remove();
                     path = nodePath + ".config";
@@ -631,10 +641,17 @@ public class JcrInstaller implements Eve
                         } else {
                             int slashPos = hint.lastIndexOf('/', lastSlash - 1);
                             final String dirName = hint.substring(slashPos + 1, lastSlash);
-                            if ( "install".equals(dirName) ) {
-                                hint = this.getPathWithHighestPrio(hint.substring(0, slashPos
+ 1) + "config/");
+                            // we prefer having "config" as the dir name
+                            if ( !"config".equals(dirName) ) {
+                                hint = this.getPathWithHighestPrio(hint.substring(0, slashPos
+ 1) + "config");
+                                // check if config is in regexp
+                                if ( this.folderNameFilter.getPriority(hint) > -1 ) {
+                                    hint = hint + '/';
+                                } else {
+                                    hint = this.getPathWithHighestPrio(hint);
+                                }
                             } else {
-                                hint = null;
+                                hint = this.getPathWithHighestPrio(hint);
                             }
                         }
                     }
@@ -650,14 +667,14 @@ public class JcrInstaller implements Eve
             baos.close();
 
             // get or create file node
-            JcrUtil.createPath(session, path, "nt:file");
+            JcrUtil.createPath(session, path, NT_FILE);
             // get or create resource node
-            final Node dataNode = JcrUtil.createPath(session, path + "/jcr:content", "nt:resource");
+            final Node dataNode = JcrUtil.createPath(session, path + "/jcr:content", NT_RESOURCE);
 
-            dataNode.setProperty("jcr:data", new ByteArrayInputStream(baos.toByteArray()));
-            dataNode.setProperty("jcr:lastModified", Calendar.getInstance());
-            dataNode.setProperty("jcr:encoding", "UTF-8");
-            dataNode.setProperty("jcr:mimeType", "text/plain");
+            dataNode.setProperty(PROP_DATA, new ByteArrayInputStream(baos.toByteArray()));
+            dataNode.setProperty(PROP_MODIFIED, Calendar.getInstance());
+            dataNode.setProperty(PROP_ENC, ENCODING);
+            dataNode.setProperty(PROP_MIME, MIME_TXT);
             session.save();
 
             final UpdateResult result = new UpdateResult(JcrInstaller.URL_SCHEME + ':' +
path);
@@ -677,4 +694,5 @@ public class JcrInstaller implements Eve
             }
         }
     }
+
 }
\ No newline at end of file



Mime
View raw message