incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r792860 - in /sling/trunk/contrib/extensions/jcrinstall/service/src: main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverter.java test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java
Date Fri, 10 Jul 2009 09:56:15 GMT
Author: bdelacretaz
Date: Fri Jul 10 09:56:15 2009
New Revision: 792860

URL: http://svn.apache.org/viewvc?rev=792860&view=rev
Log:
SLING-1044 - jcrinstall should only accept .jar, .cfg and .properties files as installable
resources, work in progress

Added:
    sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java
  (with props)
Modified:
    sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverter.java

Modified: sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverter.java?rev=792860&r1=792859&r2=792860&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverter.java
(original)
+++ sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverter.java
Fri Jul 10 09:56:15 2009
@@ -1,3 +1,19 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.apache.sling.jcr.jcrinstall.jcr.impl;
 
 import javax.jcr.Node;
@@ -24,7 +40,7 @@
 	public InstallableData convertNode(Node n) throws RepositoryException {
 		InstallableData result = null;
 		if(n.hasProperty(FileInstallableData.JCR_CONTENT_DATA) && n.hasProperty(FileInstallableData.JCR_CONTENT_LAST_MODIFIED))
{
-			if(filenameFilter.accept(n.getName())) {
+			if(acceptNodeName(n.getName())) {
 				result = new FileInstallableData(n, bundleStartLevel);
 			} else {
 				log.debug("Node {} ignored due to {}", n.getPath(), filenameFilter);
@@ -35,4 +51,8 @@
 				FileInstallableData.JCR_CONTENT_DATA + " or " + FileInstallableData.JCR_CONTENT_LAST_MODIFIED);
 		return null;
 	}
+	
+	boolean acceptNodeName(String name) {
+	    return filenameFilter.accept(name);
+	}
 }
\ No newline at end of file

Added: sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java?rev=792860&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java
(added)
+++ sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java
Fri Jul 10 09:56:15 2009
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.jcr.jcrinstall.jcr.impl;
+
+import junit.framework.TestCase;
+
+public class FileNodeConverterTest extends TestCase {
+    private final FileNodeConverter fc = new FileNodeConverter(0);
+    
+    public void testAcceptedFilenames() {
+        final String [] filenames = {
+                "a.cfg",
+                "longername.cfg",
+                "longername-with_various.things-And-CASES-9123456789.cfg",
+                "a.js",
+                "abc.cfg",
+                "a.b.c.cfg",
+                "1-2-3.cfg"
+        };
+        
+        for(String f : filenames) {
+            assertTrue("Filename must be accepted: '" + f + "'", fc.acceptNodeName(f));
+        }
+    }
+    
+    public void testRejectedFilenames() {
+        final String [] filenames = {
+                "noextension",
+                "toolongextension.1234",
+                "toolongextension..properties",
+                "numericextension.123",
+                "numericextension.12",
+                "tooshortextension.a"
+        };
+        
+        for(String f : filenames) {
+            assertFalse("Filename must be rejected: '" + f + "'", fc.acceptNodeName(f));
+        }
+    }
+}

Propchange: sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message