001 /* 002 * Copyright (C) 2012 eXo Platform SAS. 003 * 004 * This is free software; you can redistribute it and/or modify it 005 * under the terms of the GNU Lesser General Public License as 006 * published by the Free Software Foundation; either version 2.1 of 007 * the License, or (at your option) any later version. 008 * 009 * This software is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * You should have received a copy of the GNU Lesser General Public 015 * License along with this software; if not, write to the Free 016 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 017 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 018 */ 019 020 package org.crsh.vfs.spi.url; 021 022 import org.crsh.vfs.spi.AbstractFSDriver; 023 024 import java.io.IOException; 025 import java.io.InputStream; 026 import java.net.URISyntaxException; 027 import java.net.URL; 028 029 /** @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a> */ 030 public class URLDriver extends AbstractFSDriver<Node> { 031 032 /** . */ 033 private final Node.Dir root; 034 035 public URLDriver() { 036 this.root = new Node.Dir(); 037 } 038 039 public void merge(ClassLoader loader) throws IOException, URISyntaxException { 040 root.merge(loader); 041 } 042 043 public void merge(URL url) throws IOException, URISyntaxException { 044 root.merge(url); 045 } 046 047 public Node root() throws IOException { 048 return root; 049 } 050 051 public String name(Node handle) throws IOException { 052 return handle.name; 053 } 054 055 public boolean isDir(Node handle) throws IOException { 056 return handle instanceof Node.Dir; 057 } 058 059 public Iterable<Node> children(Node handle) throws IOException { 060 return ((Node.Dir)handle).children.values(); 061 } 062 063 public long getLastModified(Node handle) throws IOException { 064 return handle instanceof Node.File ? ((Node.File)handle).lastModified : 0; 065 } 066 067 public InputStream open(Node handle) throws IOException { 068 return ((Node.File)handle).resolver.open(); 069 } 070 }