01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/portal/webapp/src/java/org/theospi/portfolio/portal/web/PortalResourceUriResolver.java $
03: * $Id:PortalResourceUriResolver.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.portal.web;
21:
22: import org.theospi.portfolio.portal.intf.PortalManager;
23:
24: import javax.servlet.ServletContext;
25: import javax.xml.transform.Source;
26: import javax.xml.transform.TransformerException;
27: import javax.xml.transform.URIResolver;
28: import javax.xml.transform.stream.StreamSource;
29: import java.io.ByteArrayInputStream;
30:
31: /**
32: * Created by IntelliJ IDEA.
33: * User: John Ellis
34: * Date: Feb 22, 2006
35: * Time: 10:08:45 PM
36: * To change this template use File | Settings | File Templates.
37: */
38: public class PortalResourceUriResolver implements URIResolver {
39:
40: private ServletContext context;
41: private PortalManager manager;
42:
43: public PortalResourceUriResolver(PortalManager manager,
44: ServletContext context) {
45: this .manager = manager;
46: this .context = context;
47: }
48:
49: public Source resolve(String href, String base)
50: throws TransformerException {
51: if (manager.isUseDb()) {
52: return new StreamSource(new ByteArrayInputStream(manager
53: .getCategoryPage(href)));
54: }
55:
56: return new StreamSource(context.getResourceAsStream(href));
57: }
58: }
|