01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.cocoon.components.xscript;
18:
19: import org.apache.excalibur.source.Source;
20: import org.apache.excalibur.source.SourceException;
21: import org.apache.excalibur.source.SourceResolver;
22: import org.apache.excalibur.source.SourceNotFoundException;
23:
24: import java.io.IOException;
25: import java.io.InputStream;
26:
27: /**
28: * An <code>XScriptObject</code> created from the contents of a URL.
29: *
30: * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
31: * @version CVS $Id: XScriptObjectFromURL.java 433543 2006-08-22 06:22:54Z crossley $
32: * @since August 30, 2001
33: */
34: public class XScriptObjectFromURL extends XScriptObject {
35:
36: /**
37: * The content obtained from this URL becomes the content of this
38: * instance.
39: */
40: String systemId;
41:
42: /**
43: * When was the content of the URL last modified.
44: */
45: long lastModified;
46:
47: public XScriptObjectFromURL(XScriptManager manager, String systemId) {
48: super (manager);
49: this .systemId = systemId;
50: }
51:
52: public InputStream getInputStream() throws IOException,
53: SourceNotFoundException {
54: SourceResolver resolver = null;
55: Source source = null;
56: try {
57: resolver = (SourceResolver) serviceManager
58: .lookup(SourceResolver.ROLE);
59: source = resolver.resolveURI(this .systemId);
60: return source.getInputStream();
61: } catch (Exception e) {
62: throw new SourceException("Exception during processing of "
63: + this .systemId, e);
64: } finally {
65: if (resolver != null) {
66: resolver.release(source);
67: serviceManager.release(resolver);
68: }
69: }
70: }
71:
72: public long getContentLength() {
73: return -1;
74: }
75:
76: public long getLastModified() {
77: return 0;
78: }
79:
80: public String toString() {
81: return new StringBuffer("XScriptObjectFromURL(systemId = ")
82: .append(systemId).append(")").toString();
83: }
84:
85: public String getURI() {
86: // FIXME: generate a real system id to represent this object
87: return "xscript:url:" + systemId;
88: }
89: }
|