01: /*******************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-util/tool-lib/src/java/org/sakaiproject/metaobj/utils/xml/ResourceUriResolver.java $
03: * $Id: ResourceUriResolver.java 19974 2006-12-22 17:36:45Z john.ellis@rsmart.com $
04: * **********************************************************************************
05: *
06: * Copyright (c) 2004, 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.sakaiproject.metaobj.utils.xml;
21:
22: import org.sakaiproject.content.api.ContentHostingService;
23: import org.sakaiproject.content.api.ContentResource;
24: import org.sakaiproject.exception.PermissionException;
25: import org.sakaiproject.exception.IdUnusedException;
26: import org.sakaiproject.exception.TypeException;
27: import org.sakaiproject.exception.ServerOverloadException;
28:
29: import javax.xml.transform.URIResolver;
30: import javax.xml.transform.Source;
31: import javax.xml.transform.TransformerException;
32: import javax.xml.transform.stream.StreamSource;
33:
34: /**
35: * Created by IntelliJ IDEA.
36: * User: johnellis
37: * Date: Nov 7, 2006
38: * Time: 10:45:51 AM
39: * To change this template use File | Settings | File Templates.
40: */
41: public class ResourceUriResolver implements URIResolver {
42:
43: private ContentHostingService contentHostingService = null;
44:
45: public Source resolve(String string, String string1)
46: throws TransformerException {
47: try {
48: ContentResource resource = getContentHostingService()
49: .getResource(string);
50: return new StreamSource(
51: resource.streamContent(),
52: "jar:file:sakai-metaobj-api-dev.jar!"
53: + "/org/sakaiproject/metaobj/shared/control/");
54: } catch (PermissionException e) {
55: throw new TransformerException(e);
56: } catch (IdUnusedException e) {
57: throw new TransformerException(e);
58: } catch (TypeException e) {
59: throw new TransformerException(e);
60: } catch (ServerOverloadException e) {
61: throw new TransformerException(e);
62: }
63: }
64:
65: public ContentHostingService getContentHostingService() {
66: return contentHostingService;
67: }
68:
69: public void setContentHostingService(
70: ContentHostingService contentHostingService) {
71: this.contentHostingService = contentHostingService;
72: }
73:
74: }
|