incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r619782 - /incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Loader.java
Date Fri, 08 Feb 2008 06:52:01 GMT
Author: fmeschbe
Date: Thu Feb  7 22:51:59 2008
New Revision: 619782

URL: http://svn.apache.org/viewvc?rev=619782&view=rev
Log:
SLING-238 Add method to cut off any (optional) and well-known extension from a name

Modified:
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Loader.java

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Loader.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Loader.java?rev=619782&r1=619781&r2=619782&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Loader.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/loader/Loader.java
Thu Feb  7 22:51:59 2008
@@ -307,7 +307,7 @@
 
             if (clNode.getName() == null) {
                 // set the name without the [last] extension (xml or json)
-                clNode.setName(name.substring(0, name.lastIndexOf('.')));
+                clNode.setName(toPlainName(name));
             }
 
             return this.createNode(parent, clNode);
@@ -588,9 +588,7 @@
             session.importXML(parent.getPath(), ins, IMPORT_UUID_CREATE_NEW);
 
             // additionally check whether the expected child node exists
-            if (name.toLowerCase().endsWith(EXT_JCR_XML)) {
-                name = name.substring(0, name.length()-EXT_JCR_XML.length());
-            }
+            name = toPlainName(name);
             return (parent.hasNode(name)) ? parent.getNode(name) : null;
 
         } catch (InvalidSerializedDataException isde) {
@@ -620,5 +618,22 @@
             }
         }
 
+    }
+    
+    private String toPlainName(String name) {
+        int diff;
+        if (name.endsWith(EXT_JCR_XML)) {
+            diff = EXT_JCR_XML.length();
+        } else if (name.endsWith(EXT_XML)) {
+            diff = EXT_XML.length();
+        } else if (name.endsWith(EXT_JSON)) {
+            diff = EXT_JSON.length();
+        } else if (name.endsWith(EXT_XJSON)) {
+            diff = EXT_XJSON.length();
+        } else {
+            return name;
+        }
+        
+        return name.substring(0, name.length() - diff);
     }
 }



Mime
View raw message