View Javadoc

1   /* 
2    * Copyright 2002-2004 The Apache Software Foundation
3    * Licensed  under the  Apache License,  Version 2.0  (the "License");
4    * you may not use  this file  except in  compliance with the License.
5    * You may obtain a copy of the License at 
6    * 
7    *   http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed  under the  License is distributed on an "AS IS" BASIS,
11   * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY KIND, either  express  or
12   * implied.
13   * 
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.struts.flow.core.source.impl;
18  
19  import java.io.IOException;
20  import java.net.MalformedURLException;
21  import java.util.Map;
22  
23  import org.apache.struts.flow.core.source.Source;
24  import org.apache.struts.flow.core.source.SourceFactory;
25  import org.apache.struts.flow.core.source.URIAbsolutizer;
26  import org.apache.struts.flow.core.source.SourceUtil;
27  
28  /***
29   * A factory for filesystem-based sources (see {@link FileSource}).
30   * 
31   * @avalon.component
32   * @avalon.service type=SourceFactory
33   * @x-avalon.info name=file-source
34   * @x-avalon.lifestyle type=singleton
35   * 
36   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
37   * @version $Id: FileSourceFactory.java,v 1.4 2004/02/28 11:47:24 cziegeler Exp $
38   */
39  public class FileSourceFactory implements SourceFactory, URIAbsolutizer
40  {
41  
42      /***
43       * @see org.apache.struts.flow.core.source.SourceFactory#getSource(java.lang.String, java.util.Map)
44       */
45      public Source getSource(String location, Map parameters) throws IOException, MalformedURLException
46      {
47          return new FileSource(location);
48      }
49  
50      /***
51       * Does nothing, since {@link FileSource}s don't need to be released.
52       * 
53       * @see org.apache.struts.flow.core.source.SourceFactory#release(org.apache.struts.flow.core.source.Source)
54       */
55      public void release(Source source)
56      {
57          // Nothing to do here
58      }
59  
60      public String absolutize(String baseURI, String location)
61      {
62          // Call the absolutize utility method with false for the normalizePath argument.
63          // This avoids the removal of "../" from the path.
64          // This way, the "../" will be resolved by the operating system, which might
65          // do things differently e.g. in case of symbolic links.
66          return SourceUtil.absolutize(baseURI, location, false, false);
67      }
68  }