Source Code Cross Referenced for Directories.java in  » IDE » J » org » armedbear » j » 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 » IDE » J » org.armedbear.j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Directories.java
003:         *
004:         * Copyright (C) 1998-2003 Peter Graves
005:         * $Id: Directories.java,v 1.2 2003/06/28 23:52:27 piso Exp $
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or (at your option) any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         */
021:
022:        package org.armedbear.j;
023:
024:        public final class Directories {
025:            private static File userHomeDirectory; // ~
026:            private static File editorDirectory; // ~/.j
027:            private static File tempDirectory; // ~/.j/temp
028:            private static File mailDirectory; // ~/.j/mail
029:            private static File draftsFolder; // ~/.j/mail/local/drafts
030:            private static File registersDirectory; // ~/.j/registers
031:
032:            public static void initialize(File userHome) {
033:                userHomeDirectory = userHome;
034:                if (userHomeDirectory == null) {
035:                    // Home directory was not specified on the command line.
036:                    if (Platform.isPlatformWindows()) {
037:                        FastStringBuffer sb = new FastStringBuffer("C:\\");
038:                        for (char c = 'C'; c <= 'Z'; c++) {
039:                            sb.setCharAt(0, c);
040:                            File dir = File.getInstance(sb.toString());
041:                            if (dir != null && dir.isDirectory()
042:                                    && dir.canWrite()) {
043:                                userHomeDirectory = dir;
044:                                break;
045:                            }
046:                        }
047:                    } else {
048:                        // Not Windows.
049:                        userHomeDirectory = File.getInstance(System
050:                                .getProperty("user.home"));
051:                    }
052:                    if (userHomeDirectory == null)
053:                        Editor
054:                                .fatal("Use \"--home\" option to specify home directory.");
055:                }
056:                // Make sure required directories exist and are writable.
057:                editorDirectory = provideDirectory(File.getInstance(
058:                        userHomeDirectory, ".j"));
059:                tempDirectory = provideDirectory(File.getInstance(
060:                        editorDirectory, "temp"));
061:                mailDirectory = provideDirectory(File.getInstance(
062:                        editorDirectory, "mail"));
063:                draftsFolder = provideDirectory(File.getInstance(mailDirectory,
064:                        "local/drafts"));
065:                registersDirectory = provideDirectory(File.getInstance(
066:                        editorDirectory, "registers"));
067:                // Avoid garbage collection.
068:                Editor.protect(Directories.class);
069:            }
070:
071:            private static File provideDirectory(final File dir) {
072:                if (dir == null)
073:                    return null;
074:                if (!dir.isDirectory()) {
075:                    dir.mkdirs();
076:                    if (!dir.isDirectory())
077:                        Editor.fatal("Unable to create directory " + dir);
078:                }
079:                if (!dir.canWrite())
080:                    Editor.fatal("The directory " + dir + " is not writable");
081:                return dir;
082:            }
083:
084:            public static final File getUserHomeDirectory() {
085:                return userHomeDirectory;
086:            }
087:
088:            public static File getEditorDirectory() {
089:                return editorDirectory;
090:            }
091:
092:            public static File getTempDirectory() {
093:                return tempDirectory;
094:            }
095:
096:            public static final File getMailDirectory() {
097:                return mailDirectory;
098:            }
099:
100:            public static final File getDraftsFolder() {
101:                return draftsFolder;
102:            }
103:
104:            public static final File getRegistersDirectory() {
105:                return registersDirectory;
106:            }
107:
108:            public static final void cleanTempDirectory() {
109:                if (tempDirectory != null && tempDirectory.isDirectory()) {
110:                    String[] files = tempDirectory.list();
111:                    for (int i = files.length; i-- > 0;)
112:                        File.getInstance(tempDirectory, files[i]).delete();
113:                }
114:            }
115:
116:            public static final void moveUnsentMessagesToDraftsFolder() {
117:                File unsentMessagesDirectory = File.getInstance(mailDirectory,
118:                        "unsent");
119:                if (unsentMessagesDirectory == null) {
120:                    Debug.bug();
121:                    return;
122:                }
123:                if (!unsentMessagesDirectory.isDirectory())
124:                    return; // Nothing to do.
125:                String[] files = unsentMessagesDirectory.list();
126:                if (files.length == 0) {
127:                    unsentMessagesDirectory.delete();
128:                    return;
129:                }
130:                File draftsFolder = getDraftsFolder();
131:                if (draftsFolder == null) {
132:                    Debug.bug();
133:                    return;
134:                }
135:                Log.info("moving unsent messages to drafts folder...");
136:                if (!draftsFolder.isDirectory()) {
137:                    draftsFolder.mkdirs();
138:                    if (!draftsFolder.isDirectory()) {
139:                        Log.error("unable to create directory " + draftsFolder);
140:                        return;
141:                    }
142:                }
143:                if (!draftsFolder.canWrite()) {
144:                    Log.error(draftsFolder.netPath() + " is not writable");
145:                }
146:                for (int i = 0; i < files.length; i++) {
147:                    File source = File.getInstance(unsentMessagesDirectory,
148:                            files[i]);
149:                    File destination = File.getInstance(draftsFolder, files[i]);
150:                    Log.debug("moving " + source + " to " + destination);
151:                    if (!source.renameTo(destination))
152:                        Log.error("error moving " + source + " to "
153:                                + destination);
154:                }
155:                files = unsentMessagesDirectory.list();
156:                if (files.length == 0) {
157:                    Log.debug("removing empty directory "
158:                            + unsentMessagesDirectory);
159:                    unsentMessagesDirectory.delete();
160:                } else
161:                    Log.debug("not removing directory "
162:                            + unsentMessagesDirectory
163:                            + " (directory is not empty)");
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.