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.db;
029
030import org.opencms.main.OpenCms;
031
032import java.io.Serializable;
033
034/**
035 * Contains the data of a single export point.<p>
036 *
037 * @since 6.0.0
038 */
039public class CmsExportPoint implements Serializable {
040
041    /** The serial version id. */
042    private static final long serialVersionUID = -4743473053188740993L;
043
044    /** The configured destination path. */
045    private String m_configuredDestination;
046
047    /** The destination path in the "real" file system, relative to the web application folder. */
048    private String m_destinationPath;
049
050    /** The URI of the OpenCms VFS resource (folder) of the export point. */
051    private String m_uri;
052
053    /**
054     * Creates a new, empty export point.<p>
055     */
056    public CmsExportPoint() {
057
058        m_uri = "";
059        m_configuredDestination = "";
060        m_destinationPath = "";
061    }
062
063    /**
064     * Creates a new export point.<p>
065     *
066     * @param uri the folder in the OpenCms VFS to write as export point
067     * @param destination the destination folder in the "real" file system,
068     *     relative to the web application root
069     */
070    public CmsExportPoint(String uri, String destination) {
071
072        m_uri = uri;
073        m_configuredDestination = destination;
074        m_destinationPath = null;
075    }
076
077    /**
078     * @see java.lang.Object#clone()
079     */
080    @Override
081    public Object clone() {
082
083        CmsExportPoint clone = new CmsExportPoint(m_uri, m_configuredDestination);
084        clone.setDestinationPath(getDestinationPath());
085        return clone;
086    }
087
088    /**
089     * @see java.lang.Object#equals(java.lang.Object)
090     */
091    @Override
092    public boolean equals(Object obj) {
093
094        if (obj == this) {
095            return true;
096        }
097        if (obj instanceof CmsExportPoint) {
098            return ((CmsExportPoint)obj).m_uri.equals(m_uri);
099        }
100        return false;
101    }
102
103    /**
104     * Returns the configured destination path.<p>
105     *
106     * The configured destination path is always relative to the
107     * web application path.<p>
108     *
109     * @return the configured destination path
110     *
111     * @see #getDestinationPath()
112     */
113    public String getConfiguredDestination() {
114
115        return m_configuredDestination;
116    }
117
118    /**
119     * Returns the destination path in the "real" file system.<p>
120     *
121     * @return the destination
122     */
123    public String getDestinationPath() {
124
125        if (m_destinationPath == null) {
126            m_destinationPath = OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebApplication(
127                m_configuredDestination);
128        }
129        return m_destinationPath;
130    }
131
132    /**
133     * Returns the uri of the OpenCms VFS folder to write as export point.<p>
134     *
135     * @return the uri
136     */
137    public String getUri() {
138
139        return m_uri;
140    }
141
142    /**
143     * @see java.lang.Object#hashCode()
144     */
145    @Override
146    public int hashCode() {
147
148        return getUri().hashCode();
149    }
150
151    /**
152     * Sets the configured destination path.<p>
153     *
154     * The configured destination path is always relative to the
155     * web application path.<p>
156     *
157     * This set method will automatically set the destination path as well.<p>
158     *
159     * @param value the configured destination path
160     *
161     */
162    public void setConfiguredDestination(String value) {
163
164        m_configuredDestination = value;
165        m_destinationPath = null;
166    }
167
168    /**
169     * Dummy method to expose the destination path as bean property.<p>
170     *
171     * This is required by the {@link org.apache.commons.beanutils.BeanUtils} package in order to
172     * enable using this Object with the digester.<p>
173     *
174     * The method does not actually change the value of the destination path.
175     * Use the <code>{@link #setConfiguredDestination(String)}</code> method instead.
176     *
177     * @param value the destination path (will be ignored)
178     */
179    public void setDestinationPath(String value) {
180
181        if (value == null) {
182            // check required to avoid "unused parameter" warning
183        }
184    }
185
186    /**
187     * Sets the uri of the OpenCms VFS folder to write as export point.<p>
188     *
189     * @param value the uri to set
190     */
191    public void setUri(String value) {
192
193        m_uri = value;
194    }
195
196    /**
197     * @see java.lang.Object#toString()
198     */
199    @Override
200    public String toString() {
201
202        return "[" + getClass().getName() + ", uri: " + m_uri + ", destination: " + getDestinationPath() + "]";
203    }
204}