741 |
10 Oct 06 |
olle |
1 |
/* |
1652 |
22 May 07 |
gregory |
$Id$ |
741 |
10 Oct 06 |
olle |
3 |
|
1916 |
31 Aug 07 |
jari |
Copyright (C) 2006 Olle Mansson |
1916 |
31 Aug 07 |
jari |
Copyright (C) 2007 Gregory Vincic |
741 |
10 Oct 06 |
olle |
6 |
|
1652 |
22 May 07 |
gregory |
This file is part of Proteios. |
1652 |
22 May 07 |
gregory |
Available at http://www.proteios.org/ |
741 |
10 Oct 06 |
olle |
9 |
|
1652 |
22 May 07 |
gregory |
Proteios is free software; you can redistribute it and/or modify it |
1652 |
22 May 07 |
gregory |
under the terms of the GNU General Public License as published by |
1652 |
22 May 07 |
gregory |
the Free Software Foundation; either version 2 of the License, or |
1652 |
22 May 07 |
gregory |
(at your option) any later version. |
741 |
10 Oct 06 |
olle |
14 |
|
1652 |
22 May 07 |
gregory |
Proteios is distributed in the hope that it will be useful, but |
1652 |
22 May 07 |
gregory |
WITHOUT ANY WARRANTY; without even the implied warranty of |
1652 |
22 May 07 |
gregory |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1652 |
22 May 07 |
gregory |
General Public License for more details. |
741 |
10 Oct 06 |
olle |
19 |
|
1652 |
22 May 07 |
gregory |
You should have received a copy of the GNU General Public License |
1652 |
22 May 07 |
gregory |
along with this program; if not, write to the Free Software |
1652 |
22 May 07 |
gregory |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
1652 |
22 May 07 |
gregory |
02111-1307, USA. |
1652 |
22 May 07 |
gregory |
24 |
*/ |
741 |
10 Oct 06 |
olle |
25 |
|
741 |
10 Oct 06 |
olle |
// Xerver Free Web Server |
741 |
10 Oct 06 |
olle |
// Copyright (C) 2002-2005 Omid Rouhani |
741 |
10 Oct 06 |
olle |
28 |
// |
741 |
10 Oct 06 |
olle |
29 |
// |
741 |
10 Oct 06 |
olle |
// This program is free software; you can redistribute it and/or |
741 |
10 Oct 06 |
olle |
// modify it under the terms of the GNU General Public License |
741 |
10 Oct 06 |
olle |
// as published by the Free Software Foundation; either version 2 |
741 |
10 Oct 06 |
olle |
// of the License, or (at your option) any later version. |
741 |
10 Oct 06 |
olle |
34 |
// |
741 |
10 Oct 06 |
olle |
// This program is distributed in the hope that it will be useful, |
741 |
10 Oct 06 |
olle |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
741 |
10 Oct 06 |
olle |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
741 |
10 Oct 06 |
olle |
// GNU General Public License for more details. |
741 |
10 Oct 06 |
olle |
39 |
// |
741 |
10 Oct 06 |
olle |
// You should have received a copy of the GNU General Public License |
741 |
10 Oct 06 |
olle |
// along with this program; if not, write to the Free Software |
741 |
10 Oct 06 |
olle |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
741 |
10 Oct 06 |
olle |
43 |
// |
741 |
10 Oct 06 |
olle |
44 |
// |
741 |
10 Oct 06 |
olle |
45 |
// ############################################################# |
741 |
10 Oct 06 |
olle |
// ## YOU CAN CONTACT THE AUTHOR (OMID ROUHANI) AT: ## |
741 |
10 Oct 06 |
olle |
// ## HTTP://WWW.JAVASCRIPT.NU/XERVER/ ## |
741 |
10 Oct 06 |
olle |
48 |
// ## ## |
741 |
10 Oct 06 |
olle |
// ## IF YOUR SOFTWARE IS NOT RELEASED UNDER THE ## |
741 |
10 Oct 06 |
olle |
// ## GNU GENERAL PUBLIC LICENSE (GPL), ## |
741 |
10 Oct 06 |
olle |
// ## PLEASE DO NOT COPY ANYTHING FROM THIS SOURCE CODE!!! ## |
741 |
10 Oct 06 |
olle |
52 |
// ## ## |
741 |
10 Oct 06 |
olle |
// ## FOR FULL LICENSE, PLEASE READ "XERVER LICENSE". ## |
741 |
10 Oct 06 |
olle |
54 |
// ############################################################# |
741 |
10 Oct 06 |
olle |
55 |
|
1652 |
22 May 07 |
gregory |
56 |
package se.lu.thep.coreftpd.webserver; |
741 |
10 Oct 06 |
olle |
57 |
|
741 |
10 Oct 06 |
olle |
58 |
import java.io.File; |
741 |
10 Oct 06 |
olle |
59 |
|
741 |
10 Oct 06 |
olle |
60 |
/** |
1652 |
22 May 07 |
gregory |
61 |
* |
1652 |
22 May 07 |
gregory |
* <B>About this class:</B> <BR> |
1652 |
22 May 07 |
gregory |
* <CODE>MyFile</CODE> is like <CODE>File</CODE> but has an modified |
1652 |
22 May 07 |
gregory |
* toString() method and a boolean which decides if a file shall be represented |
1652 |
22 May 07 |
gregory |
* as ".." when toString() is called. <BR> |
1652 |
22 May 07 |
gregory |
* With a normal <CODE>File</CODE> you will get "getPath()" when you call |
1652 |
22 May 07 |
gregory |
* "toString()". With this class you will get ".." if b_isUpOneDir==true (if |
1652 |
22 May 07 |
gregory |
* isUpOneDir() has been called). Otherwise you will get getName(). However, if |
1652 |
22 May 07 |
gregory |
* "getName()" returns "", then "getPath()" is returned (This happenes as far as |
1652 |
22 May 07 |
gregory |
* I know only when <CODE>MyFile</CODE> represents a root, such as c:\, d:\ or / ). |
1652 |
22 May 07 |
gregory |
71 |
* |
741 |
10 Oct 06 |
olle |
* @author <a href="http://www.JavaScript.nu/xerver/" TARGET="_top">Omid Rouhani</a> |
741 |
10 Oct 06 |
olle |
* @version 1.0 |
741 |
10 Oct 06 |
olle |
74 |
*/ |
1223 |
18 Feb 07 |
gregory |
75 |
@SuppressWarnings("serial") |
1652 |
22 May 07 |
gregory |
76 |
final public class MyFile extends File { |
1652 |
22 May 07 |
gregory |
77 |
/** |
1652 |
22 May 07 |
gregory |
* toString() will return ".." iff b_isUpOneDir==true (if isUpOneDir() has |
1652 |
22 May 07 |
gregory |
* been called). |
1652 |
22 May 07 |
gregory |
80 |
*/ |
1652 |
22 May 07 |
gregory |
81 |
private boolean b_isUpOneDir = false; |
741 |
10 Oct 06 |
olle |
82 |
|
1652 |
22 May 07 |
gregory |
83 |
MyFile(File parent, String child) { |
741 |
10 Oct 06 |
olle |
84 |
super(parent, child); |
741 |
10 Oct 06 |
olle |
85 |
} |
1652 |
22 May 07 |
gregory |
86 |
|
1652 |
22 May 07 |
gregory |
87 |
MyFile(String pathname) { |
741 |
10 Oct 06 |
olle |
88 |
super(pathname); |
741 |
10 Oct 06 |
olle |
89 |
} |
1652 |
22 May 07 |
gregory |
90 |
|
1652 |
22 May 07 |
gregory |
91 |
MyFile(String parent, String child) { |
741 |
10 Oct 06 |
olle |
92 |
super(parent, child); |
741 |
10 Oct 06 |
olle |
93 |
} |
1652 |
22 May 07 |
gregory |
94 |
|
1652 |
22 May 07 |
gregory |
95 |
MyFile(File f) { |
741 |
10 Oct 06 |
olle |
96 |
this(f.getPath()); |
741 |
10 Oct 06 |
olle |
97 |
} |
741 |
10 Oct 06 |
olle |
98 |
|
1652 |
22 May 07 |
gregory |
99 |
/** |
1652 |
22 May 07 |
gregory |
* If isUpOneDir() is called toString() will always return "..". |
1652 |
22 May 07 |
gregory |
101 |
*/ |
1652 |
22 May 07 |
gregory |
102 |
public void isUpOneDir() { |
1652 |
22 May 07 |
gregory |
103 |
b_isUpOneDir = true; |
741 |
10 Oct 06 |
olle |
104 |
} |
741 |
10 Oct 06 |
olle |
105 |
|
1652 |
22 May 07 |
gregory |
106 |
/** |
1652 |
22 May 07 |
gregory |
* Set the b_isUpOneDir variable with this method. setIsUpOneDir(true) is |
1652 |
22 May 07 |
gregory |
* equivalent to isUpOneDir(). |
1652 |
22 May 07 |
gregory |
109 |
*/ |
1652 |
22 May 07 |
gregory |
110 |
public void setIsUpOneDir(boolean isUpOneDir) { |
1652 |
22 May 07 |
gregory |
111 |
b_isUpOneDir = isUpOneDir; |
741 |
10 Oct 06 |
olle |
112 |
} |
741 |
10 Oct 06 |
olle |
113 |
|
1652 |
22 May 07 |
gregory |
114 |
/** |
1652 |
22 May 07 |
gregory |
* With a normal <CODE>File</CODE> you will get "<CODE>getPath()</CODE>" |
1652 |
22 May 07 |
gregory |
* when you call "toString()". With this class you will get ".." if |
1652 |
22 May 07 |
gregory |
* b_isUpOneDir==true (if <CODE>isUpOneDir()</CODE> has been called). |
1652 |
22 May 07 |
gregory |
* Otherwise you will get <CODE>getName()</CODE>. However, if "<CODE>getName()</CODE>" |
1652 |
22 May 07 |
gregory |
* returns "", then "<CODE>getPath()</CODE>" is returned (This happenes |
1652 |
22 May 07 |
gregory |
* as far as I know only when <CODE>MyFile</CODE> represents a root, such |
1652 |
22 May 07 |
gregory |
* as c:\, d:\ or / ). |
1652 |
22 May 07 |
gregory |
122 |
*/ |
2386 |
14 Nov 07 |
gregory |
123 |
@Override |
1652 |
22 May 07 |
gregory |
124 |
public String toString() { |
741 |
10 Oct 06 |
olle |
125 |
if (b_isUpOneDir) |
741 |
10 Oct 06 |
olle |
126 |
return ".."; |
1652 |
22 May 07 |
gregory |
127 |
else if (!getName().equals("")) |
1652 |
22 May 07 |
gregory |
128 |
return getName(); |
741 |
10 Oct 06 |
olle |
129 |
else |
1652 |
22 May 07 |
gregory |
130 |
return getPath(); // If it's a root such as "c:\" or "/". |
741 |
10 Oct 06 |
olle |
131 |
} |
741 |
10 Oct 06 |
olle |
132 |
} |