Author: cziegeler
Date: Thu Aug 12 08:06:57 2010
New Revision: 984676
URL: http://svn.apache.org/viewvc?rev=984676&view=rev
Log:
SLING-1644 : Use configuration reader from Apache Felix ConfigAdmin
Modified:
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/FileNodeConverter.java
sling/trunk/installer/osgi/installer/pom.xml
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
Modified:
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/FileNodeConverter.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/FileNodeConverter.java?rev=984676&r1=984675&r2=984676&view=diff
==============================================================================
---
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/FileNodeConverter.java
(original)
+++
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/FileNodeConverter.java
Thu Aug 12 08:06:57 2010
@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
private final Logger log = LoggerFactory.getLogger(getClass());
/**
- * @see
org.apache.sling.jcr.jcrinstall.impl.JcrInstaller.NodeConverter#convertNode(javax.jcr.Node,
int, org.apache.sling.osgi.installer.InstallableResourceFactory)
+ * @see
org.apache.sling.jcr.jcrinstall.impl.JcrInstaller.NodeConverter#convertNode(javax.jcr.Node,
int)
*/
public InstallableResource convertNode(
final Node n,
@@ -84,7 +84,7 @@ import org.slf4j.LoggerFactory;
throw new IOException("Missing " + JCR_CONTENT_DATA + "
property");
}
- return new InstallableResource(path, is, null, digest,
InstallableResource.TYPE_BUNDLE, priority);
+ return new InstallableResource(path, is, null, digest, null, priority);
}
boolean acceptNodeName(String name) {
Modified: sling/trunk/installer/osgi/installer/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/pom.xml?rev=984676&r1=984675&r2=984676&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/pom.xml (original)
+++ sling/trunk/installer/osgi/installer/pom.xml Thu Aug 12 08:06:57 2010
@@ -53,11 +53,14 @@
<instructions>
<Bundle-Activator>
org.apache.sling.osgi.installer.impl.Activator
- </Bundle-Activator>
+ </Bundle-Activator>
<Export-Package>
org.apache.sling.osgi.installer
- </Export-Package>
+ </Export-Package>
<Private-Package>org.apache.sling.osgi.installer.impl.*</Private-Package>
+ <Embed-Dependency>
+
org.apache.felix.configadmin;inline="org/apache/felix/cm/file/ConfigurationHandler.*"
+ </Embed-Dependency>
</instructions>
</configuration>
</plugin>
@@ -105,20 +108,20 @@
</plugins>
</build>
- <dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.commons.testing</artifactId>
- <version>2.0.4-incubator</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.configadmin</artifactId>
+ <version>1.2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
</project>
Modified:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java?rev=984676&r1=984675&r2=984676&view=diff
==============================================================================
---
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
(original)
+++
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
Thu Aug 12 08:06:57 2010
@@ -18,16 +18,22 @@
*/
package org.apache.sling.osgi.installer;
+import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.Dictionary;
import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
import java.util.SortedSet;
import java.util.TreeSet;
+import org.apache.felix.cm.file.ConfigurationHandler;
+
/**
* A piece of data that can be installed by the {...@link OsgiInstaller}
@@ -71,8 +77,8 @@ public class InstallableResource {
* @throws IllegalArgumentException if something is wrong
*/
public InstallableResource(final String id,
- final InputStream is,
- final Dictionary<String, Object> dict,
+ InputStream is,
+ Dictionary<String, Object> dict,
String digest,
String type,
final Integer priority) {
@@ -94,7 +100,11 @@ public class InstallableResource {
final String resourceType = (type != null ? type :
computeResourceType(getExtension(id)));
if ( is != null && resourceType.equals(InstallableResource.TYPE_CONFIG
) ) {
- throw new IllegalArgumentException("Resource type config not
supported for input streams: " + id);
+ dict = readDictionary(is, getExtension(id));
+ if ( dict == null ) {
+ throw new IllegalArgumentException("Unable to read dictionary
from input stream: " + id);
+ }
+ is = null;
}
if ( resourceType == null ) {
throw new IllegalArgumentException("Resource type must not be
null");
@@ -185,7 +195,10 @@ public class InstallableResource {
if (extension.equals("jar")) {
return InstallableResource.TYPE_BUNDLE;
}
- if ( extension.equals("cfg") || extension.equals("config") ||
extension.equals("xml") ) {
+ if ( extension.equals("cfg")
+ || extension.equals("config")
+ || extension.equals("xml")
+ || extension.equals("properties")) {
return InstallableResource.TYPE_CONFIG;
}
return extension;
@@ -223,4 +236,52 @@ public class InstallableResource {
return data.toString();
}
}
+
+ /**
+ * Read dictionary from an input stream.
+ * We use the same logic as Apache Felix FileInstall here:
+ * - *.cfg files are treated as property files
+ * - *.config files are handled by the Apache Felix ConfigAdmin file reader
+ * @param is
+ * @param extension
+ * @return
+ * @throws IOException
+ */
+ private static Dictionary<String, Object> readDictionary(
+ final InputStream is, final String extension) {
+ final Hashtable<String, Object> ht = new Hashtable<String, Object>();
+ final InputStream in = new BufferedInputStream(is);
+ try {
+ if ( !extension.equals("config") ) {
+ final Properties p = new Properties();
+ in.mark(1);
+ boolean isXml = in.read() == '<';
+ in.reset();
+ if (isXml) {
+ p.loadFromXML(in);
+ } else {
+ p.load(in);
+ }
+ final Enumeration<Object> i = p.keys();
+ while ( i.hasMoreElements() ) {
+ final Object key = i.nextElement();
+ ht.put(key.toString(), p.get(key));
+ }
+ } else {
+ @SuppressWarnings("unchecked")
+ final Dictionary<String, Object> config =
ConfigurationHandler.read(in);
+ final Enumeration<String> i = config.keys();
+ while ( i.hasMoreElements() ) {
+ final String key = i.nextElement();
+ ht.put(key, config.get(key));
+ }
+ }
+ } catch ( IOException ignore ) {
+ return null;
+ } finally {
+ try { in.close(); } catch (IOException ignore) {}
+ }
+
+ return ht;
+ }
}