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.source.impl;
18:
19: import org.apache.avalon.framework.context.Context;
20: import org.apache.avalon.framework.context.ContextException;
21: import org.apache.avalon.framework.context.Contextualizable;
22: import org.apache.avalon.framework.thread.ThreadSafe;
23: import org.apache.cocoon.components.ContextHelper;
24: import org.apache.excalibur.source.Source;
25: import org.apache.excalibur.source.SourceFactory;
26:
27: import java.io.IOException;
28: import java.net.MalformedURLException;
29: import java.util.Map;
30:
31: /**
32: * A factory for {@link org.apache.cocoon.servlet.multipart.Part} based sources (see {@link PartSource}).
33: *
34: * @author <a href="mailto:paul.crabtree@dna.co.uk">Paul Crabtree</a>
35: * @version $Id: PartSourceFactory.java 433543 2006-08-22 06:22:54Z crossley $
36: */
37: public class PartSourceFactory implements SourceFactory,
38: Contextualizable, ThreadSafe {
39: Context context;
40:
41: /*
42: * Returns a new {@link PartSource} based on the uri.
43: *
44: * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
45: */
46: public Source getSource(String uri, Map parameters)
47: throws IOException, MalformedURLException {
48: Map objectModel = ContextHelper.getObjectModel(context);
49: return new PartSource(uri, objectModel);
50: }
51:
52: /**
53: * Do nothing, {@link PartSource}s don't need to be released.
54: *
55: * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source)
56: */
57: public void release(Source source) {
58: // Nothing to do here
59: }
60:
61: /**
62: * Get the objectModel from the Context
63: */
64: public void contextualize(
65: org.apache.avalon.framework.context.Context context)
66: throws ContextException {
67: this.context = context;
68: }
69: }
|