KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > configuration > CmsTestConfiguration


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/configuration/CmsTestConfiguration.java,v $
3  * Date : $Date: 2005/06/27 23:22:20 $
4  * Version: $Revision: 1.15 $
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.configuration;
33
34 import org.opencms.main.CmsLog;
35
36 import org.apache.commons.digester.Digester;
37
38 import org.dom4j.Element;
39
40 /**
41  * Dummy class for configuration testing.<p>
42  *
43  * @author Alexander Kandzior
44  *
45  * @version $Revision: 1.15 $
46  *
47  * @since 6.0.0
48  */

49 public class CmsTestConfiguration extends A_CmsXmlConfiguration implements I_CmsXmlConfiguration {
50
51     /** The name of the DTD for this configuration. */
52     private static final String JavaDoc CONFIGURATION_DTD_NAME = "opencms-tests.dtd";
53
54     /** The name of the default XML file for this configuration. */
55     private static final String JavaDoc DEFAULT_XML_FILE_NAME = "opencms-tests.xml";
56
57     /** Test content 1. */
58     private String JavaDoc m_content1;
59
60     /** Test content 2. */
61     private String JavaDoc m_content2;
62
63     /**
64      * The public contructor is hidden to prevent generation of instances of this class.<p>
65      */

66     public CmsTestConfiguration() {
67
68         setXmlFileName(DEFAULT_XML_FILE_NAME);
69         if (CmsLog.getLog(this).isDebugEnabled()) {
70             CmsLog.getLog(this).debug("Empty constructor called on " + this);
71         }
72     }
73
74     /**
75      * Test method to add a value.<p>
76      *
77      * @param name the name of the test
78      * @param value the value of the test
79      */

80     public void addTest(String JavaDoc name, String JavaDoc value) {
81
82         if ("test1".equals(name)) {
83             m_content1 = value;
84         }
85         if ("test2".equals(name)) {
86             m_content2 = value;
87         }
88     }
89
90     /**
91      * @see org.opencms.configuration.I_CmsXmlConfiguration#addXmlDigesterRules(org.apache.commons.digester.Digester)
92      */

93     public void addXmlDigesterRules(Digester digester) {
94
95         // add test rules
96
digester.addCallMethod("*/tests/test", "addTest", 2);
97         digester.addCallParam("*/tests/test", 0, A_NAME);
98         digester.addCallParam("*/tests/test", 1);
99     }
100
101     /**
102      * @see org.opencms.configuration.I_CmsXmlConfiguration#generateXml(org.dom4j.Element)
103      */

104     public Element generateXml(Element parent) {
105
106         Element testElement = parent.addElement("tests");
107         if (m_content1 != null) {
108             testElement.addElement("test").addAttribute(A_NAME, "test1").addText(m_content1);
109         }
110         if (m_content2 != null) {
111             testElement.addElement("test").addAttribute(A_NAME, "test2").addText(m_content2);
112         }
113         return testElement;
114     }
115
116     /**
117      * @see org.opencms.configuration.I_CmsXmlConfiguration#getDtdFilename()
118      */

119     public String JavaDoc getDtdFilename() {
120
121         return CONFIGURATION_DTD_NAME;
122     }
123 }
124
Popular Tags