KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > setup > comptest > CmsSetupTestFolderPermissions


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/setup/comptest/CmsSetupTestFolderPermissions.java,v $
3  * Date : $Date: 2006/03/27 14:52:42 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.setup.comptest;
33
34 import org.opencms.setup.CmsSetupBean;
35
36 import java.io.File JavaDoc;
37 import java.io.FileReader JavaDoc;
38 import java.io.FileWriter JavaDoc;
39
40 /**
41  * Tests the permission on the target installation folders.<p>
42  *
43  * @author Michael Moossen
44  *
45  * @version $Revision: 1.2 $
46  *
47  * @since 6.1.8
48  */

49 public class CmsSetupTestFolderPermissions implements I_CmsSetupTest {
50
51     /** The test name. */
52     public static final String JavaDoc TEST_NAME = "Folder Permissions";
53
54     /**
55      * @see org.opencms.setup.comptest.I_CmsSetupTest#getName()
56      */

57     public String JavaDoc getName() {
58
59         return TEST_NAME;
60     }
61
62     /**
63      * @see org.opencms.setup.comptest.I_CmsSetupTest#execute(org.opencms.setup.CmsSetupBean)
64      */

65     public CmsSetupTestResult execute(CmsSetupBean setupBean) {
66
67         CmsSetupTestResult testResult = new CmsSetupTestResult(this);
68
69         String JavaDoc basePath = setupBean.getWebAppRfsPath();
70         if (!basePath.endsWith(File.separator)) {
71             basePath += File.separator;
72         }
73         File JavaDoc file1;
74         do {
75             file1 = new File JavaDoc(basePath + "test" + (int)(Math.random() * 1000));
76         } while (file1.exists());
77         boolean success = false;
78         try {
79             file1.createNewFile();
80             FileWriter JavaDoc fw = new FileWriter JavaDoc(file1);
81             fw.write("aA1");
82             fw.close();
83             success = true;
84             FileReader JavaDoc fr = new FileReader JavaDoc(file1);
85             success = success && (fr.read() == 'a');
86             success = success && (fr.read() == 'A');
87             success = success && (fr.read() == '1');
88             success = success && (fr.read() == -1);
89             fr.close();
90             success = file1.delete();
91             success = !file1.exists();
92         } catch (Exception JavaDoc e) {
93             success = false;
94         }
95         if (!success) {
96             testResult.setRed();
97             testResult.setInfo("OpenCms cannot be installed without read and write privileges for path "
98                 + basePath
99                 + "! Please check you are running your servlet container with the right user and privileges.");
100             testResult.setHelp("Not enough permissions to create/read/write a file");
101             testResult.setResult(RESULT_FAILED);
102         } else {
103             testResult.setGreen();
104             testResult.setResult(RESULT_PASSED);
105         }
106         return testResult;
107     }
108 }
109
Popular Tags