Source Code Cross Referenced for FileStatus.java in  » Web-Mail » Jwma » dtw » webmail » admin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Mail » Jwma » dtw.webmail.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /***
002:         * jwma Java WebMail
003:         * Copyright (c) 2000-2003 jwma team
004:         *
005:         * jwma is free software; you can distribute and use this source
006:         * under the terms of the BSD-style license received along with
007:         * the distribution.
008:         ***/package dtw.webmail.admin;
009:
010:        import java.util.*;
011:        import java.io.*;
012:
013:        import org.apache.log4j.Logger;
014:
015:        import dtw.webmail.model.*;
016:
017:        /**
018:         * Class that implements a file status wrapper.
019:         *
020:         * @author Dieter Wimberger
021:         * @version 0.9.7 07/02/2003
022:         */
023:        public class FileStatus {
024:
025:            //logging
026:            private static Logger log = Logger.getLogger(FileStatus.class);
027:
028:            //instance attributes
029:            private BitSet m_Status;
030:            private String m_Filename;
031:            private boolean m_Ok;
032:
033:            /**
034:             * Constructs a new file status instance.
035:             */
036:            public FileStatus(String filename) throws JwmaException {
037:                m_Status = new BitSet(4);
038:                m_Filename = filename;
039:                gatherStatus();
040:            }//constructor
041:
042:            /**
043:             * Returns the filename of the file that is
044:             * described through this <tt>FileStatus</tt>.
045:             *
046:             * @return the filename of the file described by this
047:             *         <tt>FileStatus</tt>.
048:             */
049:            public String getFilename() {
050:                return m_Filename;
051:            }//getFilename
052:
053:            /**
054:             * Tests if the file is writeable.
055:             *
056:             * @return true if writeable, false otherwise.
057:             */
058:            public boolean isWriteable() {
059:                return m_Status.get(WRITEABLE);
060:            }//isWriteable
061:
062:            /**
063:             * Tests if the file is a directory.
064:             *
065:             * @return true if it is a directory, false otherwise.
066:             */
067:            public boolean isDirectory() {
068:                return m_Status.get(DIRECTORY);
069:            }//isDirectory
070:
071:            /**
072:             * Tests if the file is readable.
073:             *
074:             * @return true if readable, false otherwise.
075:             */
076:            public boolean isReadable() {
077:                return m_Status.get(READABLE);
078:            }//isReadable
079:
080:            /**
081:             * Tests if the file exists.
082:             *
083:             * @return true if it exists, false otherwise.
084:             */
085:            public boolean isExisting() {
086:                return m_Status.get(EXISTS);
087:            }//isExisting
088:
089:            /**
090:             * Returns the IS state of the file described
091:             * by this <tt>FileStatus</tt>.
092:             *
093:             * @return the is state as <tt>String</tt>.
094:             */
095:            public String getIsState() {
096:                StringBuffer sbuf = new StringBuffer();
097:                if (isExisting()) {
098:                    sbuf.append('[');
099:                }
100:                sbuf.append(((isDirectory()) ? "D" : "!D"));
101:                sbuf.append(',');
102:                sbuf.append(((isReadable()) ? "R" : "!R"));
103:                sbuf.append(',');
104:                sbuf.append(((isWriteable()) ? "W" : "!W"));
105:                if (isExisting()) {
106:                    sbuf.append(']');
107:                }
108:                return sbuf.toString();
109:            }//isState
110:
111:            /**
112:             * Tests if the file described by this
113:             * <tt>FileStatus</tt> represents the given type.
114:             * <p>
115:             * The types are encoded through given constants.
116:             *
117:             * @return true if of the given type, false otherwise.
118:             */
119:            public boolean isType(int TYPE) {
120:                switch (TYPE) {
121:                case READABLE_FILE:
122:                    return (!m_Status.get(DIRECTORY) && m_Status.get(EXISTS)
123:                            && m_Status.get(READABLE) && !m_Status
124:                            .get(WRITEABLE));
125:                case WRITEABLE_FILE:
126:                    return (!m_Status.get(DIRECTORY) && m_Status.get(EXISTS)
127:                            && m_Status.get(READABLE) && m_Status
128:                            .get(WRITEABLE));
129:                case READABLE_DIRECTORY:
130:                    return (m_Status.get(DIRECTORY) && m_Status.get(EXISTS)
131:                            && m_Status.get(READABLE) && !m_Status
132:                            .get(WRITEABLE));
133:                case WRITEABLE_DIRECTORY:
134:                    return (m_Status.get(DIRECTORY) && m_Status.get(EXISTS)
135:                            && m_Status.get(READABLE) && m_Status
136:                            .get(WRITEABLE));
137:                default:
138:                    return false;
139:                }
140:            }//isType
141:
142:            /**
143:             * Gathers the status of the file that is
144:             * refered to by the filename of this
145:             * <tt>FileStatus</tt> instance.
146:             *
147:             * @throws JwmaException if file checking fails.
148:             */
149:            private void gatherStatus() throws JwmaException {
150:
151:                File testf = new File(m_Filename);
152:                try {
153:                    if (testf.isDirectory()) {
154:                        m_Status.set(DIRECTORY);
155:                    }
156:                    if (testf.exists()) {
157:                        m_Status.set(EXISTS);
158:                    }
159:                    if (testf.canRead()) {
160:                        m_Status.set(READABLE);
161:                    }
162:                    if (testf.canWrite()) {
163:                        m_Status.set(WRITEABLE);
164:                    }
165:                } catch (Exception ex) {
166:                    JwmaException jex = new JwmaException(
167:                            "jwma.admin.filestatus").setException(ex);
168:                }
169:            }//gatherStatus
170:
171:            //constants
172:            private static final int DIRECTORY = 0;
173:            private static final int EXISTS = 1;
174:            private static final int READABLE = 2;
175:            private static final int WRITEABLE = 3;
176:
177:            /**
178:             * Represents an existing and readable file.
179:             * [Exists,!D,R,!W]
180:             */
181:            public static final int READABLE_FILE = 0;
182:
183:            /**
184:             * Represents an existing and writeable file.
185:             * [Exists,!D,R,W]
186:             */
187:            public static final int WRITEABLE_FILE = 1;
188:
189:            /**
190:             * Represents an existing and readable directory.
191:             * [Exists,D,R,!W]
192:             */
193:            public static final int READABLE_DIRECTORY = 2;
194:
195:            /**
196:             * Represents an existing and writeable directory.
197:             * [Exists,D,R,W]
198:             */
199:            public static final int WRITEABLE_DIRECTORY = 3;
200:
201:            public static final String[] SHOULD_STATE = { "[!D,R,!W]",
202:                    "[!D,R,W]", "[D,R,!W]", "[D,R,W]" };
203:
204:        }//class FileStatus
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.