KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > util > TestValidFilename


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/util/TestValidFilename.java,v $
3  * Date : $Date: 2005/06/23 14:27:27 $
4  * Version: $Revision: 1.6 $
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.util;
33
34 import junit.framework.TestCase;
35
36 /**
37  * Test cases for file name validation.<p>
38  *
39  * @author Alexander Kandzior
40  *
41  * @version $Revision: 1.6 $
42  *
43  * @since 6.0.0
44  */

45 public class TestValidFilename extends TestCase {
46
47     /**
48      * Default JUnit constructor.<p>
49      *
50      * @param arg0 JUnit parameters
51      */

52     public TestValidFilename(String JavaDoc arg0) {
53
54         super(arg0);
55     }
56
57     /**
58      * Tests the file name validation method in the class CmsDriverManager.<p>
59      *
60      * @throws Exception if something goes wrong
61      */

62     public void testValidateResourceName() throws Exception JavaDoc {
63
64         // PLEASE NOTE: This logic is NOT yet used by OpenCms, this is planned for the future
65

66         // according to windows, the following characters are illegal:
67
// \ / : * ? " < > |
68

69         // accoring to JSR 170, the following characters are illegal:
70
// / : [ ] * ' " |
71

72         // technically, for OpenCms only the following char can not be part of a file: /
73

74         // for HTML URL building, the following chars are "reserved characters" (see RFC 1738)
75
// ; / ? : @ = &
76

77         // stupidity tests
78
assertFalse(CmsStringUtil.validateResourceName(null));
79         assertFalse(CmsStringUtil.validateResourceName(""));
80
81         // all valid chard according to the "old" OpenCms logic
82
assertTrue(CmsStringUtil.validateResourceName("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~$"));
83
84         // add some of the new valid chars
85
assertTrue(CmsStringUtil.validateResourceName("Copy of abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~$"));
86         assertTrue(CmsStringUtil.validateResourceName("Some German umlauts - äöüÄÖÜß"));
87         assertTrue(CmsStringUtil.validateResourceName("Some more western European special chars - éèôáàûíì"));
88
89         assertTrue(CmsStringUtil.validateResourceName("my File"));
90         // Window logic invalid chars
91
assertFalse(CmsStringUtil.validateResourceName(" my File"));
92         assertFalse(CmsStringUtil.validateResourceName("my File "));
93         assertFalse(CmsStringUtil.validateResourceName("\tmy File"));
94         assertFalse(CmsStringUtil.validateResourceName("\rmy File"));
95         assertFalse(CmsStringUtil.validateResourceName("\nmy File"));
96         assertFalse(CmsStringUtil.validateResourceName("my/file"));
97         assertFalse(CmsStringUtil.validateResourceName("my\\file"));
98         assertFalse(CmsStringUtil.validateResourceName("my:file"));
99         assertFalse(CmsStringUtil.validateResourceName("my*file"));
100         assertFalse(CmsStringUtil.validateResourceName("my?file"));
101         assertFalse(CmsStringUtil.validateResourceName("my\"file"));
102         assertFalse(CmsStringUtil.validateResourceName("my<file"));
103         assertFalse(CmsStringUtil.validateResourceName("my>file"));
104         assertFalse(CmsStringUtil.validateResourceName("my|file"));
105
106         // JSR 170 chars
107
assertTrue(CmsStringUtil.validateResourceName("my[file"));
108         assertTrue(CmsStringUtil.validateResourceName("my]file"));
109         assertTrue(CmsStringUtil.validateResourceName("my'file"));
110
111         // HTML reserved chars
112
assertTrue(CmsStringUtil.validateResourceName("my&file"));
113         assertTrue(CmsStringUtil.validateResourceName("my=file"));
114         assertTrue(CmsStringUtil.validateResourceName("my@file"));
115     }
116 }
117
Popular Tags