001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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.file.wrapper;
029
030import org.opencms.file.CmsFile;
031import org.opencms.file.CmsObject;
032import org.opencms.file.CmsProperty;
033import org.opencms.file.CmsResource;
034import org.opencms.file.CmsResource.CmsResourceCopyMode;
035import org.opencms.file.CmsResource.CmsResourceDeleteMode;
036import org.opencms.file.CmsResourceFilter;
037import org.opencms.lock.CmsLock;
038import org.opencms.main.CmsException;
039import org.opencms.main.CmsIllegalArgumentException;
040
041import java.util.List;
042
043/**
044 * Default abstract implementation of the interface {@link I_CmsResourceWrapper}.<p>
045 *
046 * This class returns for all methods that the action is not handled by the
047 * resource wrapper.<p>
048 *
049 * Subclasses can only implement those methods where they want to change the default
050 * behaviour.<p>
051 *
052 * @since 6.5.6
053 */
054public abstract class A_CmsResourceWrapper implements I_CmsResourceWrapper {
055
056    /** Is handled by this resource wrapper. */
057    protected boolean m_isWrappedResource;
058
059    /**
060     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#addResourcesToFolder(org.opencms.file.CmsObject, java.lang.String, org.opencms.file.CmsResourceFilter)
061     */
062    public List<CmsResource> addResourcesToFolder(CmsObject cms, String resourcename, CmsResourceFilter filter)
063    throws CmsException {
064
065        if (m_isWrappedResource) {
066            return cms.getResourcesInFolder(resourcename, filter);
067        }
068
069        return null;
070    }
071
072    /**
073     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#configure(java.lang.String)
074     */
075    public void configure(String configString) {
076
077        // ignore
078
079    }
080
081    /**
082     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#copyResource(org.opencms.file.CmsObject, java.lang.String, java.lang.String, org.opencms.file.CmsResource.CmsResourceCopyMode)
083     */
084    public boolean copyResource(CmsObject cms, String source, String destination, CmsResourceCopyMode siblingMode)
085    throws CmsException, CmsIllegalArgumentException {
086
087        if (m_isWrappedResource) {
088            cms.copyResource(source, destination, siblingMode);
089            return true;
090        }
091        return false;
092    }
093
094    /**
095     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#createResource(org.opencms.file.CmsObject, java.lang.String, int, byte[], java.util.List)
096     */
097    public CmsResource createResource(
098        CmsObject cms,
099        String resourcename,
100        int type,
101        byte[] content,
102        List<CmsProperty> properties)
103    throws CmsException, CmsIllegalArgumentException {
104
105        if (m_isWrappedResource) {
106            return cms.createResource(resourcename, type, content, properties);
107        }
108
109        return null;
110    }
111
112    /**
113     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#deleteResource(org.opencms.file.CmsObject, java.lang.String, org.opencms.file.CmsResource.CmsResourceDeleteMode)
114     */
115    public boolean deleteResource(CmsObject cms, String resourcename, CmsResourceDeleteMode siblingMode)
116    throws CmsException {
117
118        if (m_isWrappedResource) {
119            cms.deleteResource(resourcename, siblingMode);
120            return true;
121        }
122
123        return false;
124    }
125
126    /**
127     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#getLock(org.opencms.file.CmsObject, org.opencms.file.CmsResource)
128     */
129    public CmsLock getLock(CmsObject cms, CmsResource resource) throws CmsException {
130
131        if (m_isWrappedResource) {
132            return cms.getLock(resource);
133        }
134
135        return null;
136    }
137
138    /**
139     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#lockResource(org.opencms.file.CmsObject, java.lang.String, boolean)
140     */
141    public boolean lockResource(CmsObject cms, String resourcename, boolean temporary) throws CmsException {
142
143        if (m_isWrappedResource) {
144            if (temporary) {
145                cms.lockResourceTemporary(resourcename);
146            } else {
147                cms.lockResource(resourcename);
148            }
149            return true;
150        }
151
152        return false;
153    }
154
155    /**
156     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#moveResource(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
157     */
158    public boolean moveResource(CmsObject cms, String source, String destination)
159    throws CmsException, CmsIllegalArgumentException {
160
161        if (m_isWrappedResource) {
162            cms.moveResource(source, destination);
163            return true;
164        }
165
166        return false;
167    }
168
169    /**
170     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#readFile(org.opencms.file.CmsObject, java.lang.String, org.opencms.file.CmsResourceFilter)
171     */
172    public CmsFile readFile(CmsObject cms, String resourcename, CmsResourceFilter filter) throws CmsException {
173
174        if (m_isWrappedResource) {
175            return cms.readFile(resourcename, filter);
176        }
177
178        return null;
179    }
180
181    /**
182     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#readResource(org.opencms.file.CmsObject, java.lang.String, org.opencms.file.CmsResourceFilter)
183     */
184    public CmsResource readResource(CmsObject cms, String resourcename, CmsResourceFilter filter) throws CmsException {
185
186        if (m_isWrappedResource) {
187            return cms.readResource(resourcename, filter);
188        }
189
190        return null;
191    }
192
193    /**
194     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#restoreLink(org.opencms.file.CmsObject, java.lang.String)
195     */
196    public String restoreLink(CmsObject cms, String uri) {
197
198        return null;
199    }
200
201    /**
202     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#rewriteLink(CmsObject, CmsResource)
203     */
204    public String rewriteLink(CmsObject cms, CmsResource res) {
205
206        return null;
207    }
208
209    /**
210     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#unlockResource(CmsObject, String)
211     */
212    public boolean unlockResource(CmsObject cms, String resourcename) throws CmsException {
213
214        if (m_isWrappedResource) {
215            cms.unlockResource(resourcename);
216            return true;
217        }
218
219        return false;
220    }
221
222    /**
223     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#wrapResource(org.opencms.file.CmsObject, org.opencms.file.CmsResource)
224     */
225    public CmsResource wrapResource(CmsObject cms, CmsResource resource) {
226
227        return resource;
228    }
229
230    /**
231     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#writeFile(org.opencms.file.CmsObject, org.opencms.file.CmsFile)
232     */
233    public CmsFile writeFile(CmsObject cms, CmsFile resource) throws CmsException {
234
235        if (m_isWrappedResource) {
236            return cms.writeFile(resource);
237        }
238
239        return null;
240    }
241
242}