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.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) throws CmsException, CmsIllegalArgumentException {
103
104        if (m_isWrappedResource) {
105            return cms.createResource(resourcename, type, content, properties);
106        }
107
108        return null;
109    }
110
111    /**
112     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#deleteResource(org.opencms.file.CmsObject, java.lang.String, org.opencms.file.CmsResource.CmsResourceDeleteMode)
113     */
114    public boolean deleteResource(CmsObject cms, String resourcename, CmsResourceDeleteMode siblingMode)
115    throws CmsException {
116
117        if (m_isWrappedResource) {
118            cms.deleteResource(resourcename, siblingMode);
119            return true;
120        }
121
122        return false;
123    }
124
125    /**
126     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#getLock(org.opencms.file.CmsObject, org.opencms.file.CmsResource)
127     */
128    public CmsLock getLock(CmsObject cms, CmsResource resource) throws CmsException {
129
130        if (m_isWrappedResource) {
131            return cms.getLock(resource);
132        }
133
134        return null;
135    }
136
137    /**
138     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#lockResource(org.opencms.file.CmsObject, java.lang.String, boolean)
139     */
140    public boolean lockResource(CmsObject cms, String resourcename, boolean temporary) throws CmsException {
141
142        if (m_isWrappedResource) {
143            if (temporary) {
144                cms.lockResourceTemporary(resourcename);
145            } else {
146                cms.lockResource(resourcename);
147            }
148            return true;
149        }
150
151        return false;
152    }
153
154    /**
155     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#moveResource(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
156     */
157    public boolean moveResource(CmsObject cms, String source, String destination)
158    throws CmsException, CmsIllegalArgumentException {
159
160        if (m_isWrappedResource) {
161            cms.moveResource(source, destination);
162            return true;
163        }
164
165        return false;
166    }
167
168    /**
169     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#readFile(org.opencms.file.CmsObject, java.lang.String, org.opencms.file.CmsResourceFilter)
170     */
171    public CmsFile readFile(CmsObject cms, String resourcename, CmsResourceFilter filter) throws CmsException {
172
173        if (m_isWrappedResource) {
174            return cms.readFile(resourcename, filter);
175        }
176
177        return null;
178    }
179
180    /**
181     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#readResource(org.opencms.file.CmsObject, java.lang.String, org.opencms.file.CmsResourceFilter)
182     */
183    public CmsResource readResource(CmsObject cms, String resourcename, CmsResourceFilter filter) throws CmsException {
184
185        if (m_isWrappedResource) {
186            return cms.readResource(resourcename, filter);
187        }
188
189        return null;
190    }
191
192    /**
193     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#restoreLink(org.opencms.file.CmsObject, java.lang.String)
194     */
195    public String restoreLink(CmsObject cms, String uri) {
196
197        return null;
198    }
199
200    /**
201     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#rewriteLink(CmsObject, CmsResource)
202     */
203    public String rewriteLink(CmsObject cms, CmsResource res) {
204
205        return null;
206    }
207
208    /**
209     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#unlockResource(CmsObject, String)
210     */
211    public boolean unlockResource(CmsObject cms, String resourcename) throws CmsException {
212
213        if (m_isWrappedResource) {
214            cms.unlockResource(resourcename);
215            return true;
216        }
217
218        return false;
219    }
220
221    /**
222     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#wrapResource(org.opencms.file.CmsObject, org.opencms.file.CmsResource)
223     */
224    public CmsResource wrapResource(CmsObject cms, CmsResource resource) {
225
226        return resource;
227    }
228
229    /**
230     * @see org.opencms.file.wrapper.I_CmsResourceWrapper#writeFile(org.opencms.file.CmsObject, org.opencms.file.CmsFile)
231     */
232    public CmsFile writeFile(CmsObject cms, CmsFile resource) throws CmsException {
233
234        if (m_isWrappedResource) {
235            return cms.writeFile(resource);
236        }
237
238        return null;
239    }
240
241}