KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/setup/xml/CmsXmlUpdateDefaultPermissions.java,v $
3  * Date : $Date: 2006/03/29 11:06:22 $
4  * Version: $Revision: 1.3 $
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.CmsWorkplaceConfiguration;
36 import org.opencms.configuration.I_CmsXmlConfiguration;
37 import org.opencms.file.types.CmsResourceTypeBinary;
38 import org.opencms.file.types.CmsResourceTypeFolder;
39 import org.opencms.file.types.CmsResourceTypeImage;
40 import org.opencms.file.types.CmsResourceTypeJsp;
41 import org.opencms.file.types.CmsResourceTypePlain;
42 import org.opencms.file.types.CmsResourceTypePointer;
43 import org.opencms.file.types.CmsResourceTypeXmlPage;
44 import org.opencms.util.CmsStringUtil;
45
46 import java.util.ArrayList JavaDoc;
47 import java.util.List JavaDoc;
48
49 import org.dom4j.Document;
50 import org.dom4j.Node;
51
52 /**
53  * Updates default permissions for explorer access.<p>
54  *
55  * @author Michael Moossen
56  *
57  * @version $Revision: 1.3 $
58  *
59  * @since 6.1.8
60  */

61 public class CmsXmlUpdateDefaultPermissions extends A_CmsXmlWorkplace {
62
63     /** List of xpaths to update. */
64     private List JavaDoc m_xpaths;
65
66     /**
67      * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getName()
68      */

69     public String JavaDoc getName() {
70
71         return "Update default permissions for explorer access";
72     }
73
74     /**
75      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#executeUpdate(org.dom4j.Document, java.lang.String)
76      */

77     protected boolean executeUpdate(Document document, String JavaDoc xpath) {
78
79         boolean changed = false;
80         if (xpath.endsWith(CmsWorkplaceConfiguration.N_ACCESSCONTROL)) {
81             Node node = document.selectSingleNode(xpath);
82             if (node != null) {
83                 String JavaDoc xp = xpath
84                     + "/"
85                     + CmsWorkplaceConfiguration.N_ACCESSENTRY
86                     + "[@"
87                     + CmsWorkplaceConfiguration.A_PRINCIPAL
88                     + "='???']";
89                 if (xpath.indexOf(CmsResourceTypeJsp.getStaticTypeName()) < 0 && xpath.indexOf("XMLTemplate") < 0) {
90                     if (xpath.indexOf(CmsWorkplaceConfiguration.N_DEFAULTACCESSCONTROL) < 0) {
91                         changed = (0 < CmsSetupXmlHelper.setValue(
92                             document,
93                             CmsStringUtil.substitute(xp, "???", "DEFAULT"),
94                             null)) || changed;
95                         changed = (0 < CmsSetupXmlHelper.setValue(document, CmsStringUtil.substitute(
96                             xp,
97                             "???",
98                             "GROUP.Guests"), null)) || changed;
99                     }
100                     changed = (0 < CmsSetupXmlHelper.setValue(document, CmsStringUtil.substitute(
101                             xp,
102                             "???",
103                             "GROUP.Administrators"), null)) || changed;
104                 }
105                 changed = (0 < CmsSetupXmlHelper.setValue(document, CmsStringUtil.substitute(
106                         xp,
107                         "???",
108                         "GROUP.Projectmanagers"), null)) || changed;
109                 changed = (0 < CmsSetupXmlHelper.setValue(
110                         document,
111                         CmsStringUtil.substitute(xp, "???", "GROUP.Users"),
112                         null)) || changed;
113                 changed = (0 < CmsSetupXmlHelper.setValue(
114                         document,
115                         CmsStringUtil.substitute(xp, "???", "GROUP.TestGroup"),
116                         null)) || changed;
117                 if (CmsSetupXmlHelper.getValue(document, xpath + "/" + CmsWorkplaceConfiguration.N_ACCESSENTRY) == null) {
118                     if (xpath.indexOf(CmsResourceTypeJsp.getStaticTypeName()) < 0 && xpath.indexOf("XMLTemplate") < 0) {
119                         changed = (0 < CmsSetupXmlHelper.setValue(document, xpath, null)) || changed;
120                     }
121                 }
122             }
123             if (xpath.indexOf(CmsResourceTypeJsp.getStaticTypeName()) > 0 || xpath.indexOf("XMLTemplate") > 0) {
124                 changed = setAccessEntry(document, xpath, "DEFAULT", "+r+v") || changed;
125                 changed = setAccessEntry(document, xpath, "GROUP.Administrators", "+r+v+w+c") || changed;
126                 changed = setAccessEntry(document, xpath, "GROUP.Guests", "-r-v-w-c") || changed;
127             } else if (xpath.indexOf(CmsWorkplaceConfiguration.N_DEFAULTACCESSCONTROL) > 0) {
128                 changed = setAccessEntry(document, xpath, "DEFAULT", "+r+v+w+c") || changed;
129                 changed = setAccessEntry(document, xpath, "GROUP.Guests", "-r-v-w-c") || changed;
130             }
131         }
132         return changed;
133     }
134
135     /**
136      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getCommonPath()
137      */

138     protected String JavaDoc getCommonPath() {
139
140         // /opencms/workplace/explorertypes
141
return new StringBuffer JavaDoc("/").append(CmsConfigurationManager.N_ROOT).append("/").append(
142             CmsWorkplaceConfiguration.N_WORKPLACE).append("/").append(CmsWorkplaceConfiguration.N_EXPLORERTYPES).toString();
143     }
144
145     /**
146      * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getXPathsToUpdate()
147      */

148     protected List JavaDoc getXPathsToUpdate() {
149
150         if (m_xpaths == null) {
151             // /opencms/workplace/explorertypes/explorertype[@name='${etype}']/accesscontrol
152
StringBuffer JavaDoc xp = new StringBuffer JavaDoc(256);
153             xp.append("/").append(CmsConfigurationManager.N_ROOT);
154             xp.append("/").append(CmsWorkplaceConfiguration.N_WORKPLACE);
155             xp.append("/").append(CmsWorkplaceConfiguration.N_EXPLORERTYPES);
156             xp.append("/").append(CmsWorkplaceConfiguration.N_EXPLORERTYPE);
157             xp.append("[@").append(I_CmsXmlConfiguration.N_NAME);
158             xp.append("='${etype}']/");
159             xp.append(CmsWorkplaceConfiguration.N_ACCESSCONTROL);
160             m_xpaths = new ArrayList JavaDoc();
161             // ${etype}: folder, imagegallery, downloadgallery, xmlcontent, xmlpage, plain, image, jsp, binary, pointer, XMLTemplate, link, upload
162
m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeFolder.getStaticTypeName()));
163             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", "imagegallery"));
164             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", "downloadgallery"));
165             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", "xmlcontent"));
166             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeXmlPage.getStaticTypeName()));
167             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypePlain.getStaticTypeName()));
168             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeImage.getStaticTypeName()));
169             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeJsp.getStaticTypeName()));
170             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeBinary.getStaticTypeName()));
171             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", "XMLTemplate"));
172             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypePointer.getStaticTypeName()));
173             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", "link"));
174             m_xpaths.add(CmsStringUtil.substitute(xp.toString(), "${etype}", "upload"));
175
176             // /opencms/workplace/explorertypes/defaultaccesscontrol/accesscontrol
177
xp = new StringBuffer JavaDoc(256);
178             xp.append("/").append(CmsConfigurationManager.N_ROOT);
179             xp.append("/").append(CmsWorkplaceConfiguration.N_WORKPLACE);
180             xp.append("/").append(CmsWorkplaceConfiguration.N_EXPLORERTYPES);
181             xp.append("/").append(CmsWorkplaceConfiguration.N_DEFAULTACCESSCONTROL);
182             xp.append("/").append(CmsWorkplaceConfiguration.N_ACCESSCONTROL);
183             m_xpaths.add(xp.toString());
184         }
185         return m_xpaths;
186     }
187
188 }
Popular Tags