Source Code Cross Referenced for CmsFileUtil.java in  » Content-Management-System » opencms » com » alkacon » opencms » formgenerator » database » 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 » Content Management System » opencms » com.alkacon.opencms.formgenerator.database 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * File   : $Source: /usr/local/cvs/alkacon/com.alkacon.opencms.formgenerator/src/com/alkacon/opencms/formgenerator/database/CmsFileUtil.java,v $
003:         * Date   : $Date: 2007-12-21 14:34:01 $
004:         * Version: $Revision: 1.1 $
005:         *
006:         * This file is part of the Alkacon OpenCms Add-On Module Package
007:         *
008:         * Copyright (c) 2007 Alkacon Software GmbH (http://www.alkacon.com)
009:         *
010:         * The Alkacon OpenCms Add-On Module Package is free software: 
011:         * you can redistribute it and/or modify
012:         * it under the terms of the GNU General Public License as published by
013:         * the Free Software Foundation, either version 3 of the License, or
014:         * (at your option) any later version.
015:         * 
016:         * The Alkacon OpenCms Add-On Module Package is distributed 
017:         * in the hope that it will be useful,
018:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
019:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020:         * GNU General Public License for more details.
021:         * 
022:         * You should have received a copy of the GNU General Public License
023:         * along with the Alkacon OpenCms Add-On Module Package.  
024:         * If not, see http://www.gnu.org/licenses/.
025:         *
026:         * For further information about Alkacon Software GmbH, please see the
027:         * company website: http://www.alkacon.com.
028:         *
029:         * For further information about OpenCms, please see the
030:         * project website: http://www.opencms.org.
031:         */
032:        package com.alkacon.opencms.formgenerator.database;
033:
034:        import org.opencms.util.CmsRfsException;
035:
036:        import java.io.File;
037:        import java.io.IOException;
038:
039:        /**
040:         * <code>{@link java.io.File}</code> handling utilities with extended verification 
041:         * for files and folders in the RFS.
042:         * <p>
043:         * 
044:         * @author Achim Westermann
045:         * 
046:         * @version $Revision: 1.1 $
047:         * 
048:         * @since 7.0.4
049:         * 
050:         */
051:        public final class CmsFileUtil {
052:
053:            /** Constant for read access to files. */
054:            public static final int MODE_READ = 1;
055:
056:            /** Constant for write access to files. */
057:            public static final int MODE_WRITE = 3;
058:
059:            /**
060:             * Utility class constructor: No instances is needed.
061:             * <p>
062:             * 
063:             */
064:            private CmsFileUtil() {
065:
066:                super ();
067:            }
068:
069:            /**
070:             * Asserts that the given file is not null, points to a valid file (no folder) and is accessible
071:             * in the given mode.
072:             * <p>
073:             * 
074:             * @param file the file to assert access to.
075:             * 
076:             * @param mode {@link #MODE_READ}, {@link #MODE_WRITE} or
077:             *            <code>{@link #MODE_READ} | {@link #MODE_WRITE}</code> (binary OR).
078:             * 
079:             * @param create if true this call will create the file if non-existant.
080:             * 
081:             * @throws CmsRfsException if the file does not exist, cannot be read, is no file (but a
082:             *             folder), or cannot be accessed in the given mode.
083:             */
084:            public static void assertFile(File file, int mode, boolean create)
085:                    throws CmsRfsException {
086:
087:                if (file == null) {
088:                    throw new CmsRfsException(Messages.get().container(
089:                            Messages.ERR_FILE_ARG_NULL_0));
090:                }
091:                if (!file.exists()) {
092:                    if (create) {
093:                        try {
094:                            file.createNewFile();
095:                        } catch (IOException ioex) {
096:                            throw new CmsRfsException(Messages.get().container(
097:                                    Messages.ERR_FILE_ARG_CREATE_1,
098:                                    file.getAbsolutePath()), ioex);
099:                        }
100:                    } else {
101:                        throw new CmsRfsException(Messages.get().container(
102:                                Messages.ERR_FILE_ARG_EXISTS_1,
103:                                file.getAbsolutePath()));
104:                    }
105:
106:                }
107:                if (file.isDirectory()) {
108:                    throw new CmsRfsException(Messages.get().container(
109:                            Messages.ERR_FILE_ARG_IS_FOLDER_1,
110:                            new Object[] { file.getAbsolutePath() }));
111:                } else if (!file.isFile()) {
112:                    throw new CmsRfsException(Messages.get().container(
113:                            Messages.ERR_FILE_ARG_NOT_FOUND_1,
114:                            new Object[] { file.getAbsolutePath() }));
115:
116:                }
117:
118:                if ((mode & MODE_READ) != 0) {
119:                    if (!file.canRead()) {
120:                        throw new CmsRfsException(Messages.get().container(
121:                                Messages.ERR_FILE_ARG_NOT_READ_1,
122:                                new Object[] { String.valueOf(file
123:                                        .getAbsolutePath()) }));
124:
125:                    }
126:                }
127:                if ((mode & MODE_WRITE) != 0) {
128:                    if (!file.canWrite()) {
129:
130:                        throw new CmsRfsException(Messages.get().container(
131:                                Messages.ERR_FILE_ARG_NOT_WRITE_1,
132:                                new Object[] { String.valueOf(file
133:                                        .getAbsolutePath()) }));
134:                    }
135:                }
136:            }
137:
138:            /**
139:             * Asserts that the given file is not null, points to a valid folder (no file) and is accessible
140:             * in the given mode.
141:             * <p>
142:             * 
143:             * @param file the file to assert access to.
144:             * 
145:             * @param create if true this call will create the file if non-existant.
146:             * 
147:             * @param mode {@link #MODE_READ}, {@link #MODE_WRITE} or
148:             *            <code>{@link #MODE_READ} | {@link #MODE_WRITE}</code> (binary OR).
149:             * 
150:             * @throws CmsRfsException if the file does not exist, cannot be read, is no file (but a
151:             *             folder), or cannot be accessed in the given mode.
152:             */
153:            public static void assertFolder(File file, int mode, boolean create)
154:                    throws CmsRfsException {
155:
156:                if (file == null) {
157:                    throw new CmsRfsException(Messages.get().container(
158:                            Messages.ERR_FILE_ARG_NULL_0));
159:                }
160:                if (!file.exists()) {
161:                    if (create) {
162:                        try {
163:                            if (!file.mkdirs()) {
164:                                throw new CmsRfsException(Messages.get()
165:                                        .container(
166:                                                Messages.ERR_FILE_ARG_CREATE_1,
167:                                                file.getAbsolutePath()));
168:                            }
169:                        } catch (SecurityException secex) {
170:                            throw new CmsRfsException(Messages.get().container(
171:                                    Messages.ERR_FILE_ARG_CREATE_1,
172:                                    file.getAbsolutePath()), secex);
173:                        }
174:                    } else {
175:                        throw new CmsRfsException(Messages.get().container(
176:                                Messages.ERR_FILE_ARG_EXISTS_1,
177:                                file.getAbsolutePath()));
178:                    }
179:
180:                }
181:                if (file.isFile()) {
182:                    throw new CmsRfsException(Messages.get().container(
183:                            Messages.ERR_FILE_ARG_IS_FILE_1,
184:                            new Object[] { file.getAbsolutePath() }));
185:                }
186:                if ((mode & MODE_READ) != 0) {
187:                    if (!file.canRead()) {
188:                        throw new CmsRfsException(Messages.get().container(
189:                                Messages.ERR_FILE_ARG_NOT_READ_1,
190:                                new Object[] { String.valueOf(file
191:                                        .getAbsolutePath()) }));
192:
193:                    }
194:                }
195:                if ((mode & MODE_WRITE) != 0) {
196:                    if (!file.canWrite()) {
197:
198:                        throw new CmsRfsException(Messages.get().container(
199:                                Messages.ERR_FILE_ARG_NOT_WRITE_1,
200:                                new Object[] { String.valueOf(file
201:                                        .getAbsolutePath()) }));
202:                    }
203:                }
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.