KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > setup > xml > CmsXmlAddImageLoader


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/setup/xml/CmsXmlAddImageLoader.java,v $
3  * Date : $Date: 2006/03/27 14:52:44 $
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.xml;
33
34 import org.opencms.configuration.CmsConfigurationManager;
35 import org.opencms.configuration.CmsVfsConfiguration;
36 import org.opencms.configuration.I_CmsXmlConfiguration;
37 import org.opencms.loader.CmsImageLoader;
38 import org.opencms.setup.CmsSetupBean;
39 import org.opencms.util.CmsStringUtil;
40
41 import java.util.Collections JavaDoc;
42 import java.util.List JavaDoc;
43
44 import org.dom4j.Document;
45 import org.dom4j.Node;
46
47 /**
48  * Adds the new image loader.<p>
49  *
50  * @author Michael Moossen
51  *
52  * @version $Revision: 1.2 $
53  *
54  * @since 6.1.8
55  */

56 public class CmsXmlAddImageLoader extends A_CmsSetupXmlUpdate {
57
58     /** List of xpaths to update. */
59     private List JavaDoc m_xpaths;
60
61     /**
62      * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getName()
63      */

64     public String JavaDoc getName() {
65
66         return "Add new Image Loader";
67     }
68
69     /**
70      * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getXmlFilename()
71      */

72     public String JavaDoc getXmlFilename() {
73
74         return CmsVfsConfiguration.DEFAULT_XML_FILE_NAME;
75     }
76
77     /**
78      * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#validate(org.opencms.setup.CmsSetupBean)
79      */

80     public boolean validate(CmsSetupBean setupBean) throws Exception JavaDoc {
81
82         return CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCodeToChange(setupBean));
83     }
84
85     /**
86      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#executeUpdate(org.dom4j.Document, java.lang.String)
87      */

88     protected boolean executeUpdate(Document document, String JavaDoc xpath) {
89
90         Node node = document.selectSingleNode(xpath);
91         if (node == null) {
92             if (xpath.equals(getXPathsToUpdate().get(0))) {
93                 CmsSetupXmlHelper.setValue(
94                     document,
95                     xpath + "/@" + I_CmsXmlConfiguration.A_CLASS,
96                     CmsImageLoader.class.getName());
97                 CmsSetupXmlHelper.setValue(
98                     document,
99                     xpath + "/" + I_CmsXmlConfiguration.N_PARAM,
100                     Boolean.TRUE.toString());
101                 CmsSetupXmlHelper.setValue(document, xpath
102                     + "/"
103                     + I_CmsXmlConfiguration.N_PARAM
104                     + "/@"
105                     + I_CmsXmlConfiguration.A_NAME, CmsImageLoader.CONFIGURATION_SCALING_ENABLED);
106             }
107             return true;
108         }
109         return false;
110     }
111
112     /**
113      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getCommonPath()
114      */

115     protected String JavaDoc getCommonPath() {
116
117         // /opencms/vfs/resources/resourceloaders
118
return new StringBuffer JavaDoc("/").append(CmsConfigurationManager.N_ROOT).append("/").append(
119             CmsVfsConfiguration.N_VFS).append("/").append(CmsVfsConfiguration.N_RESOURCES).append("/").append(
120             CmsVfsConfiguration.N_RESOURCELOADERS).toString();
121     }
122
123     /**
124      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getXPathsToUpdate()
125      */

126     protected List JavaDoc getXPathsToUpdate() {
127
128         if (m_xpaths == null) {
129             // "/opencms/vfs/resources/resourceloaders/loader[@class='org.opencms.loader.CmsImageLoader']";
130
StringBuffer JavaDoc xp = new StringBuffer JavaDoc(256);
131             xp.append("/").append(CmsConfigurationManager.N_ROOT);
132             xp.append("/").append(CmsVfsConfiguration.N_VFS);
133             xp.append("/").append(CmsVfsConfiguration.N_RESOURCES);
134             xp.append("/").append(CmsVfsConfiguration.N_RESOURCELOADERS);
135             xp.append("/").append(CmsVfsConfiguration.N_LOADER);
136             xp.append("[@").append(I_CmsXmlConfiguration.A_CLASS);
137             xp.append("='").append(CmsImageLoader.class.getName()).append("']");
138             m_xpaths = Collections.singletonList(xp.toString());
139         }
140         return m_xpaths;
141     }
142
143 }
Popular Tags