| 1 | |
package org.webslinger.ext.types; |
| 2 | |
|
| 3 | |
import java.io.IOException; |
| 4 | |
import java.sql.Timestamp; |
| 5 | |
import java.text.DateFormat; |
| 6 | |
import java.util.ArrayList; |
| 7 | |
import java.util.Comparator; |
| 8 | |
import java.util.HashMap; |
| 9 | |
import java.util.Iterator; |
| 10 | |
import java.util.LinkedHashMap; |
| 11 | |
import java.util.Map; |
| 12 | |
import java.util.TreeSet; |
| 13 | |
import java.util.Set; |
| 14 | |
import javax.servlet.ServletException; |
| 15 | |
import javax.servlet.http.HttpServletRequest; |
| 16 | |
import javax.servlet.http.HttpServletResponse; |
| 17 | |
|
| 18 | |
import org.apache.commons.collections.Transformer; |
| 19 | |
import org.apache.commons.collections.map.AbstractReferenceMap; |
| 20 | |
import org.apache.commons.collections.map.LazyMap; |
| 21 | |
import org.apache.commons.collections.map.ReferenceMap; |
| 22 | |
import org.apache.commons.vfs.FileContent; |
| 23 | |
import org.apache.commons.vfs.FileName; |
| 24 | |
import org.apache.commons.vfs.FileObject; |
| 25 | |
|
| 26 | |
import org.webslinger.PathContext; |
| 27 | |
import org.webslinger.TypeHandler; |
| 28 | |
import org.webslinger.Webslinger; |
| 29 | |
import org.webslinger.WebslingerServletContext; |
| 30 | |
import org.webslinger.collections.KeyedMapEntryComparator; |
| 31 | |
import org.webslinger.container.FileInfo; |
| 32 | |
import org.webslinger.ext.types.thumb; |
| 33 | |
import org.webslinger.ext.support.DirectoryLister; |
| 34 | |
import org.webslinger.StandardThemingCachingLister; |
| 35 | |
import org.webslinger.ThemingFactory; |
| 36 | |
|
| 37 | 1 | public class directory extends TypeHandler { |
| 38 | |
protected Map<PathContext, DirectoryLister> listers; |
| 39 | |
protected DirectoryLister.StandardThemingOutputConfig configFactory; |
| 40 | |
|
| 41 | |
public void init(WebslingerServletContext context, String type) throws IOException { |
| 42 | 1 | super.init(context, type); |
| 43 | 1 | configFactory = new DirectoryLister.StandardThemingOutputConfig(context.getWWW(), "DirectoryLister/Views", "DirectoryLister/GlobalActions", "DirectoryLister/FileActions"); |
| 44 | 1 | listers = LazyMap.decorate(new ReferenceMap(AbstractReferenceMap.SOFT, AbstractReferenceMap.SOFT), new Transformer() { |
| 45 | |
public Object transform(Object key) { |
| 46 | 2 | PathContext pc = (PathContext) key; |
| 47 | |
try { |
| 48 | 2 | return new DirectoryLister(getContext(), pc.getFile(), pc.getPathInfo()); |
| 49 | 0 | } catch (IOException e) { |
| 50 | 0 | throw (InternalError) new InternalError(e.getMessage()).initCause(e); |
| 51 | |
} |
| 52 | |
} |
| 53 | |
}); |
| 54 | 1 | } |
| 55 | |
|
| 56 | |
public Object run(Webslinger webslinger) throws IOException, ServletException { |
| 57 | 3 | DirectoryLister lister = listers.get(webslinger.getPathContext()); |
| 58 | 3 | lister.list(webslinger, webslinger.getServletPath(), configFactory); |
| 59 | 3 | return null; |
| 60 | |
} |
| 61 | |
} |