001    package org.mycore.frontend.fileupload;
002    
003    import java.io.File;
004    import java.io.FileFilter;
005    import java.io.FilenameFilter;
006    import java.io.IOException;
007    import java.io.PrintWriter;
008    import java.net.MalformedURLException;
009    import java.net.URI;
010    import java.net.URL;
011    
012    import javax.servlet.http.HttpServletRequest;
013    import javax.servlet.http.HttpServletResponse;
014    
015    import org.mycore.frontend.servlets.MCRServlet;
016    import org.mycore.frontend.servlets.MCRServletJob;
017    
018    public class MCRRemoteFileServlet extends MCRServlet {
019    
020        /**
021         * 
022         */
023        private static final long serialVersionUID = 1L;
024    
025        private File f;
026    
027        public void doGetPost(MCRServletJob job) throws Exception {
028            HttpServletRequest request = job.getRequest();
029            HttpServletResponse response = job.getResponse();
030            String mode = request.getParameter("method");
031            String pathname = request.getParameter("pathname");
032    
033            if (pathname != null && !pathname.equals("")) {
034                f = new File(pathname);
035    
036                /*if (mode.equals("exists")) {
037                    output(response, exists());
038                } else if (mode.equals("isAbsolute")) {
039                    output(response, isAbsolute());
040                } else if (mode.equals("isDirectory")) {
041                    output(response, isDirectory());
042                } else if (mode.equals("isFile")) {
043                    output(response, isFile());
044                } else if (mode.equals("isHidden")) {
045                    output(response, isHidden());
046                } else if (mode.equals("canExecute")) {
047                    output(response, canExecute());
048                } else if (mode.equals("canRead")) {
049                    output(response, canRead());
050                } else if (mode.equals("canWrite")) {
051                    output(response, canWrite());
052                } else if (mode.equals("list")) {
053                    output(response, list());
054                } else if (mode.equals("canExecute")) {
055                    boolean canExecute = f.canExecute();
056                    output(response, String.valueOf(canExecute));
057                }*/
058            } else
059                output(response, "Error!");
060        }
061    
062        private void output(HttpServletResponse response, String string) throws IOException {
063            PrintWriter out = response.getWriter();
064            out.println(string);
065            out.close();
066        }
067    
068        /*private String canExecute() {
069            return String.valueOf(f.canExecute());
070        }
071    
072        private String canRead() {
073            return String.valueOf(f.canRead());
074        }
075    
076        private String canWrite() {
077            return String.valueOf(f.canWrite());
078        }
079    
080        public int compareTo(File pathname) {
081            return f.compareTo(pathname);
082        }
083    
084        public boolean createNewFile() throws IOException {
085            return f.createNewFile();
086        }
087    
088        public boolean delete() {
089            return f.delete();
090        }
091    
092        public void deleteOnExit() {
093            f.deleteOnExit();
094        }
095    
096        public boolean equals(Object obj) {
097            return f.equals(obj);
098        }
099    
100        private String exists() {
101            return String.valueOf(f.exists());
102        }
103    
104        public File getAbsoluteFile() {
105            return f.getAbsoluteFile();
106        }
107    
108        public String getAbsolutePath() {
109            return f.getAbsolutePath();
110        }
111    
112        public File getCanonicalFile() throws IOException {
113            return f.getCanonicalFile();
114        }
115    
116        public String getCanonicalPath() throws IOException {
117            return f.getCanonicalPath();
118        }
119    
120        public long getFreeSpace() {
121            return f.getFreeSpace();
122        }
123    
124        public String getName() {
125            return f.getName();
126        }
127    
128        public String getParent() {
129            return f.getParent();
130        }
131    
132        public File getParentFile() {
133            return f.getParentFile();
134        }
135    
136        public String getPath() {
137            return f.getPath();
138        }
139    
140        public long getTotalSpace() {
141            return f.getTotalSpace();
142        }
143    
144        public long getUsableSpace() {
145            return f.getUsableSpace();
146        }
147    
148        public int hashCode() {
149            return f.hashCode();
150        }
151    
152        private String isAbsolute() {
153            return String.valueOf(f.isAbsolute());
154        }
155    
156        private String isDirectory() {
157            return String.valueOf(f.isDirectory());
158        }
159    
160        private String isFile() {
161            return String.valueOf(f.isFile());
162        }
163    
164        private String isHidden() {
165            return String.valueOf(f.isHidden());
166        }
167    
168        public long lastModified() {
169            return f.lastModified();
170        }
171    
172        public long length() {
173            return f.length();
174        }
175    
176        private String list() {
177            String[] fileList = f.list();
178            StringBuffer strBuffer = new StringBuffer();
179    
180            for (String string : fileList) {
181                strBuffer.append(string + "\n");
182            }
183    
184            return strBuffer.toString();
185        }
186    
187        public String[] list(FilenameFilter filter) {
188            return f.list(filter);
189        }
190    
191        public File[] listFiles() {
192            return f.listFiles();
193        }
194    
195        public File[] listFiles(FileFilter filter) {
196            return f.listFiles(filter);
197        }
198    
199        public File[] listFiles(FilenameFilter filter) {
200            return f.listFiles(filter);
201        }
202    
203        public boolean mkdir() {
204            return f.mkdir();
205        }
206    
207        public boolean mkdirs() {
208            return f.mkdirs();
209        }
210    
211        public boolean renameTo(File dest) {
212            return f.renameTo(dest);
213        }
214    
215        public boolean setExecutable(boolean executable, boolean ownerOnly) {
216            return f.setExecutable(executable, ownerOnly);
217        }
218    
219        public boolean setExecutable(boolean executable) {
220            return f.setExecutable(executable);
221        }
222    
223        public boolean setLastModified(long time) {
224            return f.setLastModified(time);
225        }
226    
227        public boolean setReadable(boolean readable, boolean ownerOnly) {
228            return f.setReadable(readable, ownerOnly);
229        }
230    
231        public boolean setReadable(boolean readable) {
232            return f.setReadable(readable);
233        }
234    
235        public boolean setReadOnly() {
236            return f.setReadOnly();
237        }
238    
239        public boolean setWritable(boolean writable, boolean ownerOnly) {
240            return f.setWritable(writable, ownerOnly);
241        }
242    
243        public boolean setWritable(boolean writable) {
244            return f.setWritable(writable);
245        }
246    
247        public String toString() {
248            return f.toString();
249        }
250    
251        public URI toURI() {
252            return f.toURI();
253        }
254    
255        public URL toURL() throws MalformedURLException {
256            return f.toURL();
257        }*/
258    
259    }