Save This Page
Home » org.apache.sling.launchpad.base-2.2.0-source-release » org.apache.sling.launchpad.base.impl » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.sling.launchpad.base.impl;
   18   
   19   import java.io.IOException;
   20   import java.io.InputStream;
   21   import java.net.URL;
   22   import java.util.Iterator;
   23   
   24   /**
   25    * The <code>ResourceProvider</code> defines a simple API to access resources
   26    * from the environment depending on how Sling is launched.
   27    */
   28   public abstract class ResourceProvider {
   29   
   30       /**
   31        * Returns an iterator of paths strings of the children of the given folder
   32        * defined by its path.
   33        */
   34       public abstract Iterator<String> getChildren(String path);
   35   
   36       /**
   37        * Returns an URL to the resource with the given path or <code>null</code>
   38        * if no such resource exists.
   39        */
   40       public abstract URL getResource(String path);
   41   
   42       /**
   43        * Returns an <code>InputStream</code> to the resource given by the path
   44        * or <code>null</code> if no such resource exists.
   45        */
   46       public InputStream getResourceAsStream(String path) {
   47           URL res = this.getResource(path);
   48           if (res != null) {
   49               try {
   50                   return res.openStream();
   51               } catch (IOException ioe) {
   52                   // ignore this one
   53               }
   54           }
   55   
   56           // no resource
   57           return null;
   58       }
   59   }

Save This Page
Home » org.apache.sling.launchpad.base-2.2.0-source-release » org.apache.sling.launchpad.base.impl » [javadoc | source]