001: /*
002: * This file is part of PFIXCORE.
003: *
004: * PFIXCORE is free software; you can redistribute it and/or modify
005: * it under the terms of the GNU Lesser General Public License as published by
006: * the Free Software Foundation; either version 2 of the License, or
007: * (at your option) any later version.
008: *
009: * PFIXCORE 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
012: * GNU Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public License
015: * along with PFIXCORE; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package de.schlund.pfixxml.resources.internal;
020:
021: import java.io.File;
022: import java.io.FileInputStream;
023: import java.io.FileNotFoundException;
024: import java.io.FileOutputStream;
025: import java.io.IOException;
026: import java.io.InputStream;
027: import java.io.OutputStream;
028: import java.net.MalformedURLException;
029: import java.net.URI;
030: import java.net.URL;
031:
032: import de.schlund.pfixxml.resources.AbstractDocrootResourceImpl;
033: import de.schlund.pfixxml.resources.DocrootResource;
034:
035: /**
036: * Actual implementation of the {@link DocrootResource}. This class should never
037: * be exposed to any other packages as only the interface should be used to access
038: * the class.
039: *
040: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
041: */
042: class DocrootResourceOnFileSystemImpl extends
043: AbstractDocrootResourceImpl {
044: private File file;
045:
046: DocrootResourceOnFileSystemImpl(URI uri, String docroot) {
047: super (uri);
048:
049: this .file = new File(docroot, path.substring(1));
050:
051: if (this .trailingSlash && this .exists() && !this .isDirectory()) {
052: throw new IllegalArgumentException("URI \""
053: + uri.toString()
054: + "\" points to a non-existent directory");
055: }
056: }
057:
058: public boolean canRead() {
059: return file.canRead();
060: }
061:
062: public boolean canWrite() {
063: return file.canWrite();
064: }
065:
066: public boolean createNewFile() throws IOException {
067: return file.createNewFile();
068: }
069:
070: public boolean delete() {
071: return file.delete();
072: }
073:
074: public boolean exists() {
075: return file.exists();
076: }
077:
078: public boolean isDirectory() {
079: return file.isDirectory();
080: }
081:
082: public boolean isFile() {
083: return file.isFile();
084: }
085:
086: public boolean isHidden() {
087: return file.isHidden();
088: }
089:
090: public long lastModified() {
091: return file.lastModified();
092: }
093:
094: public String[] list() {
095: return file.list();
096: }
097:
098: public boolean mkdir() {
099: return file.mkdir();
100: }
101:
102: public boolean mkdirs() {
103: return file.mkdirs();
104: }
105:
106: public URL toURL() throws MalformedURLException {
107: return file.toURI().toURL();
108: }
109:
110: public InputStream getInputStream() throws FileNotFoundException {
111: return new FileInputStream(file);
112: }
113:
114: public OutputStream getOutputStream() throws FileNotFoundException {
115: return new FileOutputStream(file);
116: }
117:
118: public OutputStream getOutputStream(boolean append)
119: throws FileNotFoundException {
120: return new FileOutputStream(file, append);
121: }
122:
123: }
|