sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1806185 - in /sling/trunk/bundles/extensions/bundleresource/src/test: ./ java/ java/org/ java/org/apache/ java/org/apache/sling/ java/org/apache/sling/bundleresource/ java/org/apache/sling/bundleresource/impl/ java/org/apache/sling/bundler...
Date Fri, 25 Aug 2017 15:21:35 GMT
Author: cziegeler
Date: Fri Aug 25 15:21:35 2017
New Revision: 1806185

URL: http://svn.apache.org/viewvc?rev=1806185&view=rev
Log:
SLING-6878 : Bundle resource provider: support mounting of JSON files

Added:
    sling/trunk/bundles/extensions/bundleresource/src/test/
    sling/trunk/bundles/extensions/bundleresource/src/test/java/
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java
  (with props)
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java
  (with props)
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java
  (with props)
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLConnection.java
  (with props)
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandler.java
  (with props)
    sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandlerFactory.java
  (with props)

Added: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java?rev=1806185&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java
(added)
+++ sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java
Fri Aug 25 15:21:35 2017
@@ -0,0 +1,84 @@
+/*
+ * 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.bundleresource.impl;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.sling.bundleresource.impl.url.ResourceURLStreamHandler;
+import org.apache.sling.bundleresource.impl.url.ResourceURLStreamHandlerFactory;
+import org.apache.sling.spi.resource.provider.ResolveContext;
+import org.apache.sling.spi.resource.provider.ResourceContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+public class BundleResourceProviderTest {
+
+    Bundle getBundle() {
+        Bundle bundle = mock(Bundle.class);
+        when(bundle.getLastModified()).thenReturn(System.currentTimeMillis());
+
+        return bundle;
+    }
+
+
+    void addContent(Bundle bundle, String path, Map<String, Object> content) throws
IOException {
+        final URL url = new URL("resource:" + path);
+
+        ResourceURLStreamHandler.addJSON(path, content);
+        when(bundle.getEntry(path)).thenReturn(url);
+    }
+
+    @Before
+    public void setup() {
+        ResourceURLStreamHandlerFactory.init();
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test public void testFileResource() throws IOException {
+        final Bundle bundle = getBundle();
+        addContent(bundle, "/libs/foo/test.json", Collections.singletonMap("test", (Object)"foo"));
+
+        final MappedPath path = new MappedPath("/libs/foo", null, null);
+
+        final BundleResourceProvider provider = new BundleResourceProvider(bundle, path);
+        assertNotNull(provider.getResource(mock(ResolveContext.class), "/libs/foo/test.json",
mock(ResourceContext.class), null));
+        assertNull(provider.getResource(mock(ResolveContext.class), "/libs/foo/test", mock(ResourceContext.class),
null));
+    }
+
+    @SuppressWarnings("unchecked")
+    @Test public void testJSONResource() throws IOException {
+        final Bundle bundle = getBundle();
+        addContent(bundle, "/libs/foo/test.json", Collections.singletonMap("test", (Object)"foo"));
+
+        final MappedPath path = new MappedPath("/libs/foo", null, "json");
+
+        final BundleResourceProvider provider = new BundleResourceProvider(bundle, path);
+        assertNull(provider.getResource(mock(ResolveContext.class), "/libs/foo/test.json",
mock(ResourceContext.class), null));
+        assertNotNull(provider.getResource(mock(ResolveContext.class), "/libs/foo/test",
mock(ResourceContext.class), null));
+    }
+}

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java?rev=1806185&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java
(added)
+++ sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java
Fri Aug 25 15:21:35 2017
@@ -0,0 +1,87 @@
+/*
+ * 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.bundleresource.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.bundleresource.impl.url.ResourceURLStreamHandler;
+import org.apache.sling.bundleresource.impl.url.ResourceURLStreamHandlerFactory;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+public class BundleResourceTest {
+
+    BundleResourceCache getBundleResourceCache() {
+        Bundle bundle = mock(Bundle.class);
+        when(bundle.getLastModified()).thenReturn(System.currentTimeMillis());
+
+        BundleResourceCache cache = mock(BundleResourceCache.class);
+        when(cache.getBundle()).thenReturn(bundle);
+
+        return cache;
+    }
+
+    @Before
+    public void setup() {
+        ResourceURLStreamHandlerFactory.init();
+    }
+
+    void addContent(BundleResourceCache cache, String path, Map<String, Object> content)
throws IOException {
+        final URL url = new URL("resource:" + path);
+
+        ResourceURLStreamHandler.addJSON(path, content);
+        when(cache.getEntry(path)).thenReturn(url);
+    }
+
+    @Test public void testFileResource() throws MalformedURLException {
+        final BundleResourceCache cache = getBundleResourceCache();
+        when(cache.getEntry("/libs/foo/test.json")).thenReturn(new URL("file:/libs/foo/test.json"));
+        final BundleResource rsrc = new BundleResource(null, cache,
+                new MappedPath("/libs/foo", null, null), "/libs/foo/test.json", null, false);
+        assertEquals(JcrConstants.NT_FILE, rsrc.getResourceType());
+        assertNull(rsrc.getResourceSuperType());
+        final ValueMap vm = rsrc.getValueMap();
+        assertEquals(JcrConstants.NT_FILE, vm.get(ResourceResolver.PROPERTY_RESOURCE_TYPE,
String.class));
+    }
+
+    @Test public void testJSONResource() throws IOException {
+        final BundleResourceCache cache = getBundleResourceCache();
+        addContent(cache, "/libs/foo/test.json", Collections.singletonMap("test", (Object)"foo"));
+        final BundleResource rsrc = new BundleResource(null, cache,
+                new MappedPath("/libs/foo", null, "json"), "/libs/foo/test", "/libs/foo/test.json",
false);
+        assertEquals(JcrConstants.NT_FILE, rsrc.getResourceType());
+        assertNull(rsrc.getResourceSuperType());
+        final ValueMap vm = rsrc.getValueMap();
+        assertEquals(JcrConstants.NT_FILE, vm.get(ResourceResolver.PROPERTY_RESOURCE_TYPE,
String.class));
+        assertEquals("foo", vm.get("test", String.class));
+    }
+}

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/BundleResourceTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java?rev=1806185&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java
(added)
+++ sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java
Fri Aug 25 15:21:35 2017
@@ -0,0 +1,47 @@
+/*
+ * 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.bundleresource.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+
+public class MappedPathTest {
+
+    @Test public void testSimpleRoot() {
+        final MappedPath[] paths = MappedPath.getRoots("/libs/foo");
+        assertEquals(1, paths.length);
+        assertNull(paths[0].getEntryRoot());
+        assertNull(paths[0].getEntryRootPrefix());
+        assertEquals("/libs/foo", paths[0].getResourceRoot());
+        assertEquals("/libs/foo/", paths[0].getResourceRootPrefix());
+        assertNull(paths[0].getJSONPropertiesExtension());
+    }
+
+    @Test public void testSimpleRootWithJSON() {
+        final MappedPath[] paths = MappedPath.getRoots("/libs/foo;" + MappedPath.DIR_JSON
+ ":=json");
+        assertEquals(1, paths.length);
+        assertNull(paths[0].getEntryRoot());
+        assertNull(paths[0].getEntryRootPrefix());
+        assertEquals("/libs/foo", paths[0].getResourceRoot());
+        assertEquals("/libs/foo/", paths[0].getResourceRootPrefix());
+        assertEquals(".json", paths[0].getJSONPropertiesExtension());
+    }
+}

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/MappedPathTest.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLConnection.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLConnection.java?rev=1806185&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLConnection.java
(added)
+++ sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLConnection.java
Fri Aug 25 15:21:35 2017
@@ -0,0 +1,52 @@
+/*
+ * 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.bundleresource.impl.url;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+public class ResourceURLConnection extends URLConnection {
+
+    private final String contents;
+
+    protected ResourceURLConnection(final URL url, final String contents) {
+        super(url);
+        this.contents = contents;
+    }
+
+    @Override
+    public void connect() throws IOException {
+        if ( contents == null ) {
+            throw new IOException("404");
+        }
+    }
+
+    @Override
+    public int getContentLength() {
+        return contents.length();
+    }
+
+    @Override
+    public InputStream getInputStream() throws IOException {
+        return new ByteArrayInputStream(this.contents.getBytes("UTF-8"));
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLConnection.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandler.java?rev=1806185&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandler.java
(added)
+++ sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandler.java
Fri Aug 25 15:21:35 2017
@@ -0,0 +1,102 @@
+/*
+ * 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.bundleresource.impl.url;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.json.Json;
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonObjectBuilder;
+import javax.json.JsonStructure;
+
+public class ResourceURLStreamHandler extends URLStreamHandler {
+
+    private static final Map<String, String> contents = new HashMap<>();
+
+    public static void addContents(final String path, final String c) {
+        contents.put(path, c);
+    }
+
+    public static void addJSON(final String path, final Map<String, Object> props)
{
+        final StringWriter writer = new StringWriter();
+        Json.createWriter(writer).write(build(props));
+        addContents(path, writer.toString());
+    }
+
+    @Override
+    protected URLConnection openConnection(URL url) throws IOException {
+        final ResourceURLConnection conn = new ResourceURLConnection(url, contents.get(url.getPath()));
+        conn.connect();
+        return conn;
+    }
+
+    private static JsonStructure build(final Object value) {
+        if ( value instanceof List ) {
+            @SuppressWarnings("unchecked")
+            final List<Object> list = (List<Object>)value;
+            final JsonArrayBuilder builder = Json.createArrayBuilder();
+            for(final Object obj : list) {
+                if ( obj instanceof String ) {
+                    builder.add(obj.toString());
+                } else if ( obj instanceof Long ) {
+                    builder.add((Long)obj);
+                } else if ( obj instanceof Double ) {
+                    builder.add((Double)obj);
+                } else if (obj instanceof Boolean ) {
+                    builder.add((Boolean)obj);
+                } else if ( obj instanceof Map ) {
+                    builder.add(build(obj));
+                } else if ( obj instanceof List ) {
+                    builder.add(build(obj));
+                }
+
+            }
+            return builder.build();
+        } else if ( value instanceof Map ) {
+            @SuppressWarnings("unchecked")
+            final Map<String, Object> map = (Map<String, Object>)value;
+            final JsonObjectBuilder builder = Json.createObjectBuilder();
+            for(final Map.Entry<String, Object> entry : map.entrySet()) {
+                if ( entry.getValue() instanceof String ) {
+                    builder.add(entry.getKey(), entry.getValue().toString());
+                } else if ( entry.getValue() instanceof Long ) {
+                    builder.add(entry.getKey(), (Long)entry.getValue());
+                } else if ( entry.getValue() instanceof Double ) {
+                    builder.add(entry.getKey(), (Double)entry.getValue());
+                } else if ( entry.getValue() instanceof Boolean ) {
+                    builder.add(entry.getKey(), (Boolean)entry.getValue());
+                } else if ( entry.getValue() instanceof Map ) {
+                    builder.add(entry.getKey(), build(entry.getValue()));
+                } else if ( entry.getValue() instanceof List ) {
+                    builder.add(entry.getKey(), build(entry.getValue()));
+                }
+            }
+            return builder.build();
+        }
+        return null;
+    }
+}
+

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandler.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Added: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandlerFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandlerFactory.java?rev=1806185&view=auto
==============================================================================
--- sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandlerFactory.java
(added)
+++ sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandlerFactory.java
Fri Aug 25 15:21:35 2017
@@ -0,0 +1,45 @@
+/*
+ * 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.bundleresource.impl.url;
+
+import java.net.URL;
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
+
+public class ResourceURLStreamHandlerFactory implements URLStreamHandlerFactory {
+
+    private static volatile boolean init = false;
+    @Override
+    public URLStreamHandler createURLStreamHandler(String protocol) {
+        if ("resource".equals(protocol)) {
+            return new ResourceURLStreamHandler();
+        }
+
+        return null;
+    }
+
+    public static void init() {
+        if ( !init ) {
+            URL.setURLStreamHandlerFactory(new ResourceURLStreamHandlerFactory());
+            init = true;
+        }
+    }
+
+}
+

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandlerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/bundles/extensions/bundleresource/src/test/java/org/apache/sling/bundleresource/impl/url/ResourceURLStreamHandlerFactory.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url



Mime
View raw message