01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/osp/tags/sakai_2-4-1/common/tool-lib/src/java/org/theospi/portfolio/shared/control/ContentResourceUriResolver.java $
03: * $Id: ContentResourceUriResolver.java 10835 2006-06-17 03:25:03Z lance@indiana.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 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.shared.control;
21:
22: import javax.xml.transform.Source;
23: import javax.xml.transform.TransformerException;
24: import javax.xml.transform.URIResolver;
25: import javax.xml.transform.stream.StreamSource;
26:
27: import org.apache.commons.logging.Log;
28: import org.apache.commons.logging.LogFactory;
29: import org.sakaiproject.component.api.ServerConfigurationService;
30: import org.sakaiproject.content.api.ContentResource;
31: import org.sakaiproject.entity.api.EntityManager;
32: import org.sakaiproject.entity.api.Reference;
33: import org.sakaiproject.exception.ServerOverloadException;
34:
35: public class ContentResourceUriResolver implements URIResolver {
36:
37: private EntityManager entityManager;
38: private ServerConfigurationService serverConfigurationService;
39:
40: protected final Log logger = LogFactory.getLog(getClass());
41:
42: public Source resolve(String href, String base)
43: throws TransformerException {
44: try {
45: String accessUrl = getServerConfigurationService()
46: .getAccessUrl();
47: String url = href.replaceAll(accessUrl, "");
48: Reference ref = getEntityManager().newReference(url);
49: return new StreamSource(((ContentResource) ref.getEntity())
50: .streamContent());
51: } catch (ServerOverloadException e) {
52: logger.error("", e);
53: }
54: return null;
55: }
56:
57: public EntityManager getEntityManager() {
58: return entityManager;
59: }
60:
61: public void setEntityManager(EntityManager entityManager) {
62: this .entityManager = entityManager;
63: }
64:
65: public ServerConfigurationService getServerConfigurationService() {
66: return serverConfigurationService;
67: }
68:
69: public void setServerConfigurationService(
70: ServerConfigurationService serverConfigurationService) {
71: this.serverConfigurationService = serverConfigurationService;
72: }
73:
74: }
|