001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.setup.xml.v7;
029
030import org.opencms.configuration.CmsConfigurationManager;
031import org.opencms.configuration.CmsWorkplaceConfiguration;
032import org.opencms.configuration.I_CmsXmlConfiguration;
033import org.opencms.file.types.CmsResourceTypeBinary;
034import org.opencms.file.types.CmsResourceTypeFolder;
035import org.opencms.file.types.CmsResourceTypeImage;
036import org.opencms.file.types.CmsResourceTypeJsp;
037import org.opencms.file.types.CmsResourceTypePlain;
038import org.opencms.file.types.CmsResourceTypePointer;
039import org.opencms.setup.xml.A_CmsXmlWorkplace;
040import org.opencms.setup.xml.CmsSetupXmlHelper;
041import org.opencms.util.CmsStringUtil;
042
043import java.util.ArrayList;
044import java.util.List;
045
046import org.dom4j.Document;
047import org.dom4j.Node;
048
049/**
050 * Adds the auto set features in new dialog.<p>
051 *
052 * @since 6.1.8
053 */
054public class CmsXmlAddAutoSetFeatures extends A_CmsXmlWorkplace {
055
056    /** List of xpaths to update. */
057    private List<String> m_xpaths;
058
059    /**
060     * @see org.opencms.setup.xml.I_CmsSetupXmlUpdate#getName()
061     */
062    public String getName() {
063
064        return "Add auto set features in new dialog";
065    }
066
067    /**
068     * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#executeUpdate(org.dom4j.Document, java.lang.String, boolean)
069     */
070    @Override
071    protected boolean executeUpdate(Document document, String xpath, boolean forReal) {
072
073        Node node = document.selectSingleNode(xpath);
074        if (node == null) {
075            CmsSetupXmlHelper.setValue(document, xpath, Boolean.FALSE.toString());
076            return true;
077        }
078        return false;
079    }
080
081    /**
082     * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getCommonPath()
083     */
084    @Override
085    protected String getCommonPath() {
086
087        // /opencms/workplace/explorertypes
088        return new StringBuffer("/").append(CmsConfigurationManager.N_ROOT).append("/").append(
089            CmsWorkplaceConfiguration.N_WORKPLACE).append("/").append(
090                CmsWorkplaceConfiguration.N_EXPLORERTYPES).toString();
091    }
092
093    /**
094     * @see org.opencms.setup.xml.A_CmsSetupXmlUpdate#getXPathsToUpdate()
095     */
096    @Override
097    protected List<String> getXPathsToUpdate() {
098
099        if (m_xpaths == null) {
100            // /opencms/workplace/explorertypes/explorertype[@name='${etype}']/newresource/@${attr}
101            StringBuffer xp = new StringBuffer(256);
102            xp.append("/").append(CmsConfigurationManager.N_ROOT);
103            xp.append("/").append(CmsWorkplaceConfiguration.N_WORKPLACE);
104            xp.append("/").append(CmsWorkplaceConfiguration.N_EXPLORERTYPES);
105            xp.append("/").append(CmsWorkplaceConfiguration.N_EXPLORERTYPE);
106            xp.append("[@").append(I_CmsXmlConfiguration.N_NAME);
107            xp.append("='${etype}']/").append(CmsWorkplaceConfiguration.N_NEWRESOURCE);
108            xp.append("/@");
109            m_xpaths = new ArrayList<String>();
110            // ${etype}: folder, imagegallery, downloadgallery, xmlcontent, xmlpage, plain, image, jsp, binary, pointer, XMLTemplate, link, upload, extendedfolder, structurecontent
111            // ${attr}: autosetnavigation, autosettitle
112            m_xpaths.add(
113                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeFolder.getStaticTypeName())
114                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
115            m_xpaths.add(
116                CmsStringUtil.substitute(xp.toString(), "${etype}", "imagegallery")
117                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
118            m_xpaths.add(
119                CmsStringUtil.substitute(xp.toString(), "${etype}", "downloadgallery")
120                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
121            m_xpaths.add(
122                CmsStringUtil.substitute(xp.toString(), "${etype}", "xmlcontent")
123                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
124            m_xpaths.add(
125                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypePlain.getStaticTypeName())
126                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
127            m_xpaths.add(
128                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeImage.getStaticTypeName())
129                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
130            m_xpaths.add(
131                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeJsp.getStaticTypeName())
132                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
133            m_xpaths.add(
134                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeBinary.getStaticTypeName())
135                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
136            m_xpaths.add(
137                CmsStringUtil.substitute(xp.toString(), "${etype}", "XMLTemplate")
138                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
139            m_xpaths.add(
140                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypePointer.getStaticTypeName())
141                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
142            m_xpaths.add(
143                CmsStringUtil.substitute(xp.toString(), "${etype}", "link")
144                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
145            m_xpaths.add(
146                CmsStringUtil.substitute(xp.toString(), "${etype}", "upload")
147                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
148            m_xpaths.add(
149                CmsStringUtil.substitute(xp.toString(), "${etype}", "extendedfolder")
150                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
151            m_xpaths.add(
152                CmsStringUtil.substitute(xp.toString(), "${etype}", "structurecontent")
153                    + CmsWorkplaceConfiguration.A_AUTOSETNAVIGATION);
154
155            m_xpaths.add(
156                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeFolder.getStaticTypeName())
157                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
158            m_xpaths.add(
159                CmsStringUtil.substitute(xp.toString(), "${etype}", "imagegallery")
160                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
161            m_xpaths.add(
162                CmsStringUtil.substitute(xp.toString(), "${etype}", "downloadgallery")
163                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
164            m_xpaths.add(
165                CmsStringUtil.substitute(xp.toString(), "${etype}", "xmlcontent")
166                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
167            m_xpaths.add(
168                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypePlain.getStaticTypeName())
169                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
170            m_xpaths.add(
171                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeImage.getStaticTypeName())
172                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
173            m_xpaths.add(
174                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeJsp.getStaticTypeName())
175                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
176            m_xpaths.add(
177                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypeBinary.getStaticTypeName())
178                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
179            m_xpaths.add(
180                CmsStringUtil.substitute(xp.toString(), "${etype}", "XMLTemplate")
181                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
182            m_xpaths.add(
183                CmsStringUtil.substitute(xp.toString(), "${etype}", CmsResourceTypePointer.getStaticTypeName())
184                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
185            m_xpaths.add(
186                CmsStringUtil.substitute(xp.toString(), "${etype}", "link") + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
187            m_xpaths.add(
188                CmsStringUtil.substitute(xp.toString(), "${etype}", "upload")
189                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
190            m_xpaths.add(
191                CmsStringUtil.substitute(xp.toString(), "${etype}", "extendedfolder")
192                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
193            m_xpaths.add(
194                CmsStringUtil.substitute(xp.toString(), "${etype}", "structurecontent")
195                    + CmsWorkplaceConfiguration.A_AUTOSETTITLE);
196        }
197        return m_xpaths;
198    }
199
200}