KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/util/TestCmsResourceTranslator.java,v $
3  * Date : $Date: 2005/06/26 11:23:00 $
4  * Version: $Revision: 1.9 $
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 the resource translator.<p>
38  *
39  * @author Alexander Kandzior
40  *
41  * @version $Revision: 1.9 $
42  *
43  * @since 6.0.0
44  */

45 public class TestCmsResourceTranslator extends TestCase {
46
47     // default rules (same as in "opencms.properties")
48
private static String JavaDoc[] rules = {
49         "s#/default/vfs/content/bodys/(.*)#/default/vfs/system/bodies/$1#",
50         "s#/default/vfs/pics/system/(.*)#/default/vfs/system/workplace/resources/$1#",
51         "s#/default/vfs/pics/(.*)#/default/vfs/system/galleries/pics/$1#",
52         "s#/default/vfs/download/(.*)#/default/vfs/system/galleries/download/$1#",
53         "s#/default/vfs/externallinks/(.*)#/default/vfs/system/galleries/externallinks/$1#",
54         "s#/default/vfs/htmlgalleries/(.*)#/default/vfs/system/galleries/htmlgalleries/$1#",
55         "s#/default/vfs/content/(.*)#/default/vfs/system/modules/default/$1#",
56         "s#/default/vfs/moduledemos/(.*)#/default/vfs/system/moduledemos/$1#",
57         "s#/default/vfs/system/workplace/config/language/(.*)#/default/vfs/system/workplace/locales/$1#",
58         "s#/default/vfs/system/workplace/css/(.*)#/default/vfs/system/workplace/resources/$1#",
59         "s#/default/vfs/system/workplace/templates/js/(.*)#/default/vfs/system/workplace/scripts/$1#",
60         "s#[\\s]+#_#g",
61         "s#[]#ae#g",
62         "s#[]#Ae#g",
63         "s#[]#oe#g",
64         "s#[]#Oe#g",
65         "s#[]#ue#g",
66         "s#[]#Ue#g",
67         "s#[]#ss#g",
68         "s#[^0-9a-zA-Z_\\.\\-\\/]#!#g",
69         "s#!+#x#g"};
70
71     /**
72      * Default JUnit constructor.<p>
73      *
74      * @param arg0 JUnit parameters
75      */

76     public TestCmsResourceTranslator(String JavaDoc arg0) {
77
78         super(arg0);
79     }
80
81     /**
82      * Tests for the resource name translation.<p>
83      */

84     public void testTranslateResource() {
85
86         CmsResourceTranslator translator = new CmsResourceTranslator(rules, false);
87         String JavaDoc test;
88
89         test = translator.translateResource("/default/vfs/content/bodys/test/index.html");
90         assertEquals(test, "/default/vfs/system/bodies/test/index.html");
91
92         test = translator.translateResource("/default/vfs/system/workplace/templates/js/test.js");
93         assertEquals(test, "/default/vfs/system/workplace/scripts/test.js");
94
95         translator = new CmsResourceTranslator(rules, true);
96         test = translator.translateResource("Schne bung mit Fu.js");
97         assertEquals(test, "Schoene_Uebung_mit_Fuss.js");
98     }
99
100 }
101
Popular Tags