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.jsp.userdata;
029
030import org.opencms.configuration.CmsParameterConfiguration;
031import org.opencms.file.CmsObject;
032import org.opencms.file.CmsUser;
033import org.opencms.main.OpenCms;
034import org.opencms.ui.dialogs.Messages;
035import org.opencms.util.CmsStringUtil;
036import org.opencms.workplace.CmsWorkplaceMessages;
037
038import java.util.List;
039
040import org.jsoup.nodes.Element;
041
042/**
043 * User data domain that only matches users requesting their information via user name and password.
044 * <p>Produces HTML for standard OpenCms user information like name, description, address, institution etc.
045 */
046public class CmsDefaultUserDataDomain implements I_CmsUserDataDomain {
047
048    /** The configuration. */
049    private CmsParameterConfiguration m_config = new CmsParameterConfiguration();
050
051    /**
052     * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#addConfigurationParameter(java.lang.String, java.lang.String)
053     */
054    public void addConfigurationParameter(String paramName, String paramValue) {
055
056        m_config.put(paramName, paramValue);
057    }
058
059    /**
060     * @see org.opencms.jsp.userdata.I_CmsUserDataDomain#appendInfoHtml(org.opencms.file.CmsObject, org.opencms.jsp.userdata.CmsUserDataRequestType, java.util.List, org.jsoup.nodes.Element)
061     */
062    public void appendInfoHtml(CmsObject cms, CmsUserDataRequestType reqType, List<CmsUser> users, Element element) {
063
064        Element main = element.appendElement("div");
065        String headerText = org.opencms.jsp.userdata.Messages.get().getBundle(cms.getRequestContext().getLocale()).key(
066            org.opencms.jsp.userdata.Messages.GUI_DEFAULT_USERDATA_SECTION_0);
067        main.appendElement("h2").text(headerText);
068        Element ul = main.appendElement("ul");
069        for (CmsUser user : users) {
070            Element section = ul.appendElement("li").appendElement("dl");
071            Element dl = section.appendElement("dl");
072
073            addField(cms, dl, org.opencms.ui.apps.Messages.GUI_USERMANAGEMENT_USER_LOGIN_NAME_0, user.getSimpleName());
074            addField(
075                cms,
076                dl,
077                org.opencms.ui.apps.Messages.GUI_USERMANAGEMENT_USER_DESCRIPTION_0,
078                user.getDescription(cms.getRequestContext().getLocale()));
079            addField(
080                cms,
081                dl,
082                org.opencms.ui.apps.Messages.GUI_USERMANAGEMENT_USER_OU_0,
083                CmsStringUtil.joinPaths(user.getOuFqn(), "/"));
084            addField(cms, dl, Messages.GUI_USER_DATA_FIRSTNAME_0, user.getFirstname());
085            addField(cms, dl, Messages.GUI_USER_DATA_LASTNAME_0, user.getLastname());
086            addField(cms, dl, Messages.GUI_USER_DATA_ADDRESS_0, user.getAddress());
087            addField(cms, dl, Messages.GUI_USER_DATA_CITY_0, user.getCity());
088            addField(cms, dl, Messages.GUI_USER_DATA_COUNTRY_0, user.getCountry());
089            addField(cms, dl, Messages.GUI_USER_DATA_EMAIL_0, user.getEmail());
090            addField(cms, dl, Messages.GUI_USER_DATA_INSTITUTION_0, user.getInstitution());
091            addField(cms, dl, Messages.GUI_USER_DATA_ZIPCODE_0, user.getZipcode());
092        }
093    }
094
095    /**
096     * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#getConfiguration()
097     */
098    public CmsParameterConfiguration getConfiguration() {
099
100        return m_config;
101    }
102
103    /**
104     * @see org.opencms.configuration.I_CmsConfigurationParameterHandler#initConfiguration()
105     */
106    public void initConfiguration() {
107
108        // Not used
109    }
110
111    /**
112     * @see org.opencms.jsp.userdata.I_CmsUserDataDomain#initialize(org.opencms.file.CmsObject)
113     */
114    public void initialize(CmsObject cms) {
115
116        // does nothing
117    }
118
119    /**
120     * @see org.opencms.jsp.userdata.I_CmsUserDataDomain#matchesUser(org.opencms.file.CmsObject, org.opencms.jsp.userdata.CmsUserDataRequestType, org.opencms.file.CmsUser)
121     */
122    public boolean matchesUser(CmsObject cms, CmsUserDataRequestType reqType, CmsUser user) {
123
124        return true;
125    }
126
127    /**
128     * @see java.lang.Object#toString()
129     */
130    @Override
131    public String toString() {
132
133        return getClass().getName() + "[" + m_config + "]";
134    }
135
136    /**
137     * Adds dt/dt tags with a given field name and field value to a parent dl element.
138     *
139     * @param cms the CMS context
140     * @param dl the parent element
141     * @param key the key
142     * @param value the value
143     */
144    private boolean addField(CmsObject cms, Element dl, String key, String value) {
145
146        CmsWorkplaceMessages messages = OpenCms.getWorkplaceManager().getMessages(cms.getRequestContext().getLocale());
147        String keyText = messages.key(key);
148        if (!CmsStringUtil.isEmpty(value)) {
149            dl.appendElement("dt").text(keyText);
150            dl.appendElement("dd").text(value);
151            return true;
152        }
153        return false;
154    }
155}