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, 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.urlname;
029
030import org.opencms.util.CmsUUID;
031
032import java.util.Comparator;
033
034/**
035 * An URL name mapping entry.<p>
036 *
037 * @since 8.0.0
038 */
039public class CmsUrlNameMappingEntry {
040
041    /**
042     * Class for comparing URL name mapping entries by date.<p>
043     **/
044    public static class DateComparator implements Comparator<CmsUrlNameMappingEntry> {
045
046        /**
047         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
048         */
049        public int compare(CmsUrlNameMappingEntry o1, CmsUrlNameMappingEntry o2) {
050
051            long date1 = o1.m_dateChanged;
052            long date2 = o2.m_dateChanged;
053            if (date1 < date2) {
054                return -1;
055            } else if (date2 < date1) {
056                return +1;
057            } else {
058                return o1.m_name.compareTo(o2.m_name);
059            }
060        }
061
062    }
063
064    /** The state for mapping entries which have not been published. */
065    public static final int MAPPING_STATUS_NEW = 0;
066
067    /** The state for mapping entries which have been published. */
068    public static final int MAPPING_STATUS_PUBLISHED = 1;
069
070    /** State which indicates that all previous mappings should be replace on publish. */
071    public static final int MAPPING_STATUS_REPLACE_ON_PUBLISH = 2;
072
073    /** State which indicates that all previous mappings have been replaced on publish. */
074    public static final int MAPPING_STATUS_REPLACE_ON_PUBLISH_PUBLISHED = 3;
075
076    /** The date on which the mapping entry was last changed. */
077    protected long m_dateChanged;
078
079    /** The locale of the mapping. */
080    protected String m_locale;
081
082    /** The name to which the mapping entry belongs. */
083    protected String m_name;
084
085    /** The state of the mapping entry. */
086    protected int m_state;
087
088    /** The structure id to which the name is mapped. */
089    protected CmsUUID m_structureId;
090
091    /**
092     * Creates a new URL name mapping entry.<p>
093     *
094     * @param name the URL name
095     * @param structureId the id to which the name is mapped
096     * @param state the state of the entry
097     * @param dateChanged the date of the entry's last change
098     * @param locale the locale of the mapping
099     */
100    public CmsUrlNameMappingEntry(String name, CmsUUID structureId, int state, long dateChanged, String locale) {
101
102        m_name = name;
103        m_structureId = structureId;
104        m_state = state;
105        m_dateChanged = dateChanged;
106        m_locale = locale;
107
108    }
109
110    /**
111     * Returns the date at which the mapping was last changed as a long.<p>
112     *
113     * @return the date at which the mapping was last changed
114     *
115     */
116    public long getDateChanged() {
117
118        return m_dateChanged;
119    }
120
121    /**
122     * Returns the locale of the mapping entry.<p>
123     *
124     * @return the locale of the mapping entry
125     */
126    public String getLocale() {
127
128        return m_locale;
129    }
130
131    /**
132     * Returns the name to which the mapping belongs.<p>
133     *
134     * @return the name to which the mapping belongs
135     */
136    public String getName() {
137
138        return m_name;
139    }
140
141    /**
142     * Returns the state of the mapping entry.<p>
143     *
144     * @return the state of the mapping entry
145     */
146    public int getState() {
147
148        return m_state;
149    }
150
151    /**
152     * Returns the structure id which is mapped to the name.<p>
153     *
154     * @return the structure id which is mapped to the name
155     */
156    public CmsUUID getStructureId() {
157
158        return m_structureId;
159    }
160
161    /**
162     * @see java.lang.Object#toString()
163     */
164    @Override
165    public String toString() {
166
167        StringBuffer buf = new StringBuffer();
168        buf.append("[");
169        buf.append(CmsUrlNameMappingEntry.class.getSimpleName());
170        buf.append(": ");
171        buf.append(m_name);
172        buf.append(",  ");
173        buf.append(m_structureId.toString());
174        buf.append(", ");
175        buf.append(m_state);
176        buf.append(", ");
177        buf.append(m_dateChanged);
178        buf.append(", ");
179        buf.append(m_locale);
180        buf.append("]");
181        return buf.toString();
182    }
183
184}