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.ui.apps.dbmanager;
029
030import org.opencms.file.types.I_CmsResourceType;
031import org.opencms.main.OpenCms;
032import org.opencms.site.CmsSite;
033import org.opencms.ui.CmsVaadinUtils;
034import org.opencms.ui.apps.Messages;
035import org.opencms.workplace.explorer.CmsExplorerTypeSettings;
036
037/**
038 * Class for the result of a database statistic set.<p>
039 */
040public class CmsResourceTypeStatResult {
041
042    /**Count of resources.*/
043    private int m_count;
044
045    /**Site root.*/
046    private String m_siteRoot;
047
048    /**Time when the statistic was generated.*/
049    private long m_timestamp;
050
051    /**Type of resource.*/
052    private I_CmsResourceType m_type;
053
054    /**
055     * Public constructor.<p>
056     *
057     * @param type of resources
058     * @param siteRoot of site
059     * @param count of found resources
060     */
061    public CmsResourceTypeStatResult(I_CmsResourceType type, String siteRoot, int count) {
062        m_type = type;
063        m_count = count;
064        m_siteRoot = siteRoot;
065        m_timestamp = System.currentTimeMillis();
066    }
067
068    /**
069     * @see java.lang.Object#equals(java.lang.Object)
070     */
071    @Override
072    public boolean equals(Object o) {
073
074        if (!(o instanceof CmsResourceTypeStatResult)) {
075            return false;
076        }
077        CmsResourceTypeStatResult result = (CmsResourceTypeStatResult)o;
078
079        if (m_type != null) {
080            return m_type.equals(result.getType()) & m_siteRoot.equals(result.getSiteRoot());
081        }
082        return (result.getType() == null) & m_siteRoot.equals(result.getSiteRoot());
083    }
084
085    /**
086     * Gets the localized result message.<p>
087     *
088     * @return the result as string
089     */
090    public String getResult() {
091
092        String res;
093        CmsSite site = OpenCms.getSiteManager().getSiteForSiteRoot(m_siteRoot);
094        if (site == null) {
095            res = CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_STATS_RESULTS_ROOT_1, Integer.valueOf(m_count));
096        } else {
097            res = CmsVaadinUtils.getMessageText(
098                Messages.GUI_DATABASEAPP_STATS_RESULTS_2,
099                site.getTitle(),
100                Integer.valueOf(m_count));
101        }
102        return res;
103    }
104
105    /**
106     * Getter for site root.<p>
107     *
108     * @return site roor
109     */
110    public String getSiteRoot() {
111
112        return m_siteRoot;
113    }
114
115    /**
116     * Getter for timestamp.<p>
117     *
118     * @return the timestamp
119     */
120    public long getTimestamp() {
121
122        return m_timestamp;
123    }
124
125    /**
126     * Getter for resource type.<p>
127     *
128     * @return the resource type
129     */
130    public I_CmsResourceType getType() {
131
132        return m_type;
133    }
134
135    /**
136     * Gets the title of the resource type.<p>
137     *
138     * @return title of resource type
139     */
140    public String getTypeTitle() {
141
142        if (m_type == null) {
143            return CmsVaadinUtils.getMessageText(Messages.GUI_DATABASEAPP_STATS_ALL_RESOURCES_0);
144        }
145
146        String res = "";
147        CmsExplorerTypeSettings typeSetting = OpenCms.getWorkplaceManager().getExplorerTypeSetting(
148            m_type.getTypeName());
149        res = CmsVaadinUtils.getMessageText(typeSetting.getKey());
150        return res;
151    }
152
153    /**
154     * @see java.lang.Object#hashCode()
155     */
156    @Override
157    public int hashCode() {
158
159        return super.hashCode();
160    }
161}