1 /*
2 * Copyright 2007 Hippo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS"
12 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package nl.hippo.portal.cms.source;
17
18 import java.io.InputStream;
19
20 /***
21 * @author <a href="mailto:d.dam@hippo.nl">Dennis Dam</a>
22 *
23 * @version $Id: ResourceSourceFactory.java 8564 2007-10-18 15:30:09Z ddam $
24 */
25 public class ResourceSourceFactory extends AbstractSourceFactory implements SourceFactory {
26
27 /* (non-Javadoc)
28 * @see nl.hippo.portal.cms.source.SourceFactory#getSource(java.lang.String)
29 */
30 public Source getSource(String url) throws SourceException {
31 String urlPath = getUrlPath(url);
32 if (urlPath != null){
33 return new ResourceSource(urlPath);
34 }
35 return null;
36 }
37
38 private class ResourceSource implements Source {
39
40 private String resourceUrl;
41
42 public ResourceSource(String resourceUrl){
43 this.resourceUrl=resourceUrl;
44 }
45
46 public InputStream getInputStream(){
47 return getClass().getResourceAsStream(resourceUrl);
48 }
49
50 }
51
52 }