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;
029
030import org.opencms.main.OpenCms;
031import org.opencms.workplace.CmsWorkplaceMessages;
032
033import java.util.Locale;
034
035/**
036 * Bean representing a category for workplace apps.<p>
037 *
038 * App categories should have a unique id. Nesting of categories is defined by the parent category id of each category.
039 * A category whose parent category id is null will be displayed at the root level, and similarly, a workplace app whose
040 * category id is null will be displayed at the root level.
041 *
042 */
043public class CmsAppCategory implements I_CmsAppCategory {
044
045    /** Prefix for message bundle keys used to localize app categories. */
046    private static final String MESSAGE_PREFIX = "appcategory.";
047
048    /** Sort key for the category. */
049    private int m_order;
050
051    /** Category id. */
052    private String m_id;
053
054    /** Parent category id. */
055    private String m_parentId;
056
057    /** Priority number; categories with higher priorities can override those with lower priorities. */
058    private int m_priority;
059
060    /**
061     * Creates a new instance.<p>
062     *
063     * @param id the category id
064     * @param parentId the parent category id
065     * @param order the order
066     * @param priority the priority
067     */
068    public CmsAppCategory(String id, String parentId, int order, int priority) {
069
070        super();
071        m_id = id;
072        m_parentId = parentId;
073        m_order = order;
074        m_priority = priority;
075    }
076
077    /**
078     * @see org.opencms.ui.apps.I_CmsAppCategory#getId()
079     */
080    public String getId() {
081
082        return m_id;
083    }
084
085    /**
086     * @see org.opencms.ui.apps.I_CmsAppCategory#getName(java.util.Locale)
087     */
088    public String getName(Locale locale) {
089
090        CmsWorkplaceMessages messages = OpenCms.getWorkplaceManager().getMessages(locale);
091        String niceName = messages.keyDefault(MESSAGE_PREFIX + m_id, m_id);
092        return niceName;
093    }
094
095    /**
096     * @see org.opencms.ui.apps.I_CmsAppCategory#getOrder()
097     */
098    public int getOrder() {
099
100        return m_order;
101    }
102
103    /**
104     * @see org.opencms.ui.apps.I_CmsAppCategory#getParentId()
105     */
106    public String getParentId() {
107
108        return m_parentId;
109    }
110
111    /**
112     * @see org.opencms.ui.apps.I_CmsAppCategory#getPriority()
113     */
114    public int getPriority() {
115
116        return m_priority;
117    }
118}