You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2016/07/29 07:11:24 UTC

svn commit: r1754481 - /sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java

Author: olli
Date: Fri Jul 29 07:11:24 2016
New Revision: 1754481

URL: http://svn.apache.org/viewvc?rev=1754481&view=rev
Log:
SLING-5917 parseRawText flag in getRepoInitText() is ambiguous

fix meaning of parseRawText flag and make getRepoInitText() more readable

Modified:
    sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java

Modified: sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java?rev=1754481&r1=1754480&r2=1754481&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java (original)
+++ sling/trunk/bundles/jcr/repoinit/src/main/java/org/apache/sling/jcr/repoinit/impl/RepositoryInitializer.java Fri Jul 29 07:11:24 2016
@@ -135,33 +135,32 @@ public class RepositoryInitializer imple
     }
     
     private String getRepoInitText() {
-        final boolean parseRawText = modelSectionName.trim().length() > 0;
-        if(parseRawText) {
-            log.info("Reading repoinit statements from {}", textURL);
+        final String rawText = getRawRepoInitText();
+        log.debug("Raw text from {}: \n{}", textURL, rawText);
+        log.info("Got {} characters from {}", rawText.length(), textURL);
+        final boolean parseRawText = modelSectionName.trim().length() == 0;
+        if (parseRawText) {
+            log.info("Parsing raw repoinit statements from {}", textURL);
+            return rawText;
         } else {
-            log.info("Extracting repoinit statements from section {} of provisioning model {}", modelSectionName, textURL);
-        }
-        String result = getRawRepoInitText();
-        log.debug("Raw text from {}: \n{}", textURL, result);
-        log.info("Got {} characters from {}", result.length(), textURL);
-        if(parseRawText) {
-            final StringReader r = new StringReader(result);
+            log.info("Extracting repoinit statements from section '{}' of provisioning model {}", modelSectionName, textURL);
+            final StringReader reader = new StringReader(rawText);
             try {
-                final Model m = ModelReader.read(r, textURL);
-                final StringBuilder b = new StringBuilder();
-                for(Feature f : m.getFeatures()) {
-                    for(Section s : f.getAdditionalSections(modelSectionName)) {
-                        b.append("# ").append(modelSectionName).append(" from ").append(f.getName()).append("\n");
-                        b.append("# ").append(s.getComment()).append("\n");
-                        b.append(s.getContents()).append("\n");
+                final Model model = ModelReader.read(reader, textURL);
+                final StringBuilder sb = new StringBuilder();
+                for (final Feature feature : model.getFeatures()) {
+                    for (final Section section : feature.getAdditionalSections(modelSectionName)) {
+                        sb.append("# ").append(modelSectionName).append(" from ").append(feature.getName()).append("\n");
+                        sb.append("# ").append(section.getComment()).append("\n");
+                        sb.append(section.getContents()).append("\n");
                     }
                 }
-                result = b.toString();
+                return sb.toString();
             } catch (IOException e) {
-                result = "";
                 log.warn("Error parsing provisioning model from " + textURL, e);
+                return "";
             }
         }
-        return result;
     }
+
 }