001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.environment;
018:
019: import org.apache.excalibur.source.SourceException;
020: import org.apache.avalon.framework.component.ComponentException;
021: import org.apache.avalon.framework.component.ComponentManager;
022: import org.apache.cocoon.ProcessingException;
023: import org.apache.cocoon.components.source.URLSource;
024: import org.apache.cocoon.components.url.URLFactory;
025: import org.xml.sax.ContentHandler;
026: import org.xml.sax.SAXException;
027:
028: import java.io.IOException;
029: import java.net.MalformedURLException;
030: import java.net.URL;
031: import java.util.Map;
032:
033: /**
034: * A <code>SourceResolver</code> based on a <code>URLFactory</code>.
035: * @deprecated by the new source resolving
036: *
037: * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
038: * @version CVS $Id: URLFactorySourceResolver.java 433543 2006-08-22 06:22:54Z crossley $
039: */
040:
041: public class URLFactorySourceResolver implements SourceResolver {
042:
043: /** The component manager */
044: protected ComponentManager manager;
045:
046: /** The URL factory */
047: protected URLFactory urlFactory;
048:
049: /**
050: * Creates an <code>URLFactorySourceResolver</code> with a component manager.
051: * The <code>URLFactory</code> is looked up in the component manager.
052: */
053: public URLFactorySourceResolver(ComponentManager manager)
054: throws ComponentException {
055: this .manager = manager;
056: this .urlFactory = (URLFactory) manager.lookup(URLFactory.ROLE);
057: }
058:
059: /**
060: * Creates an <code>URLFactorySourceResolver</code> with a component manager and
061: * a <code>URLFactory</code> that will be used to resolve URLs.
062: */
063: public URLFactorySourceResolver(URLFactory factory,
064: ComponentManager manager) {
065: this .urlFactory = factory;
066: this .manager = manager;
067: }
068:
069: /**
070: * Resolve the source.
071: *
072: * @param systemID This is either a system identifier
073: * (<code>java.net.URL</code>) or a local file.
074: */
075: public Source resolve(String systemID) throws ProcessingException,
076: SAXException, IOException {
077:
078: URL url = this .urlFactory.getURL(systemID);
079: return new URLSource(url, this .manager);
080: }
081:
082: /**
083: * Get a <code>Source</code> object.
084: */
085: public org.apache.excalibur.source.Source resolveURI(
086: final String location) throws MalformedURLException,
087: IOException, SourceException {
088: return this .resolveURI(location, null, null);
089: }
090:
091: /**
092: * Get a <code>Source</code> object.
093: */
094: public org.apache.excalibur.source.Source resolveURI(
095: final String location, String baseURI, final Map parameters)
096: throws MalformedURLException, IOException, SourceException {
097: throw new RuntimeException(
098: "URLFactorySourceResolver.resolveURI() is not implemented yet.");
099: }
100:
101: /**
102: * Releases a resolved resource
103: */
104: public void release(final org.apache.excalibur.source.Source source) {
105: throw new RuntimeException(
106: "URLFactorySourceResolver.release() is not implemented yet.");
107: }
108:
109: /**
110: * Generates SAX events from the given source
111: * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
112: * that <code>handler</code> can actually
113: * directly implement the LexicalHandler interface!
114: * @param source the data
115: * @throws ProcessingException if no suitable converter is found
116: */
117: public void toSAX(org.apache.excalibur.source.Source source,
118: ContentHandler handler) throws SAXException, IOException,
119: ProcessingException {
120: throw new RuntimeException(
121: "ProcessingException.toSAX() is not implemented yet.");
122: }
123:
124: /**
125: * Generates SAX events from the given source
126: * <b>NOTE</b> : if the implementation can produce lexical events, care should be taken
127: * that <code>handler</code> can actually
128: * directly implement the LexicalHandler interface!
129: * @param source the data
130: * @throws ProcessingException if no suitable converter is found
131: */
132: public void toSAX(org.apache.excalibur.source.Source source,
133: String mimeTypeHint, ContentHandler handler)
134: throws SAXException, IOException, ProcessingException {
135: throw new RuntimeException(
136: "ProcessingException.toSAX() is not implemented yet.");
137: }
138: }
|