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.workplace.tools.scheduler;
029
030import org.opencms.i18n.CmsMessageContainer;
031import org.opencms.main.CmsContextInfo;
032import org.opencms.workplace.list.I_CmsListFormatter;
033
034import java.util.HashMap;
035import java.util.Locale;
036import java.util.Map;
037
038/**
039 * This list item detail formatter creates a two column table to represent a context info object.<p>
040 *
041 * @since 6.0.0
042 */
043public class CmsContextInfoDetailsFormatter implements I_CmsListFormatter {
044
045    /** Cache for localized messages. */
046    private Map<Locale, Map<CmsMessageContainer, String>> m_cache = new HashMap<Locale, Map<CmsMessageContainer, String>>();
047    /** Encoding message header. */
048    private CmsMessageContainer m_encodingMessage;
049    /** Locale message header. */
050    private CmsMessageContainer m_localeMessage;
051    /** Project message header. */
052    private CmsMessageContainer m_projectMessage;
053    /** Remote message header. */
054    private CmsMessageContainer m_remoteAddrMessage;
055    /** Request message header. */
056    private CmsMessageContainer m_requestedURIMessage;
057    /** RootSite message header. */
058    private CmsMessageContainer m_rootSiteMessage;
059
060    /** User message header. */
061    private CmsMessageContainer m_userMessage;
062
063    /**
064     * Default constructor.<p>
065     */
066    public CmsContextInfoDetailsFormatter() {
067
068        //noop
069    }
070
071    /**
072     * @see org.opencms.workplace.list.I_CmsListFormatter#format(java.lang.Object, java.util.Locale)
073     */
074    public String format(Object data, Locale locale) {
075
076        Map<CmsMessageContainer, String> cache = m_cache.get(locale);
077        if (cache == null) {
078            cache = new HashMap<CmsMessageContainer, String>();
079            cache.put(m_userMessage, m_userMessage.key(locale));
080            cache.put(m_projectMessage, m_projectMessage.key(locale));
081            cache.put(m_localeMessage, m_localeMessage.key(locale));
082            cache.put(m_rootSiteMessage, m_rootSiteMessage.key(locale));
083            cache.put(m_requestedURIMessage, m_requestedURIMessage.key(locale));
084            cache.put(m_remoteAddrMessage, m_remoteAddrMessage.key(locale));
085            cache.put(m_encodingMessage, m_encodingMessage.key(locale));
086            m_cache.put(locale, cache);
087        }
088        String userMessage = cache.get(m_userMessage);
089        String projectMessage = cache.get(m_projectMessage);
090        String localeMessage = cache.get(m_localeMessage);
091        String rootSiteMessage = cache.get(m_rootSiteMessage);
092        String requestedURIMessage = cache.get(m_requestedURIMessage);
093        String remoteAddrMessage = cache.get(m_remoteAddrMessage);
094        String encodingMessage = cache.get(m_encodingMessage);
095        CmsContextInfo info = (CmsContextInfo)data;
096        StringBuffer html = new StringBuffer(512);
097        html.append("<table border='0' cellspacing='0' cellpadding='0'>\n");
098        html.append("\t<tr>\n");
099        html.append("\t\t<td width='150' align='right' class='listdetailhead'>\n");
100        html.append("\t\t\t");
101        html.append(userMessage);
102        html.append("&nbsp;:&nbsp;\n");
103        html.append("\t\t</td>\n");
104        html.append("\t\t<td class='listdetailitem'>\n");
105        html.append("\t\t\t");
106        html.append(info.getUserName());
107        html.append("\n");
108        html.append("\t\t</td>\n");
109        html.append("\t</tr>\n");
110        html.append("\t<tr>\n");
111        html.append("\t\t<td width='150' align='right' class='listdetailhead'>\n");
112        html.append("\t\t\t");
113        html.append(projectMessage);
114        html.append("&nbsp;:&nbsp;\n");
115        html.append("\t\t</td>\n");
116        html.append("\t\t<td class='listdetailitem'>\n");
117        html.append("\t\t\t");
118        html.append(info.getProjectName());
119        html.append("\n");
120        html.append("\t\t</td>\n");
121        html.append("\t</tr>\n");
122        html.append("\t<tr>\n");
123        html.append("\t\t<td width='150' align='right' class='listdetailhead'>\n");
124        html.append("\t\t\t");
125        html.append(localeMessage);
126        html.append("&nbsp;:&nbsp;\n");
127        html.append("\t\t</td>\n");
128        html.append("\t\t<td class='listdetailitem'>\n");
129        html.append("\t\t\t");
130        html.append(info.getLocaleName());
131        html.append("\n");
132        html.append("\t\t</td>\n");
133        html.append("\t</tr>\n");
134        html.append("\t<tr>\n");
135        html.append("\t\t<td width='150' align='right' class='listdetailhead'>\n");
136        html.append("\t\t\t");
137        html.append(rootSiteMessage);
138        html.append("&nbsp;:&nbsp;\n");
139        html.append("\t\t</td>\n");
140        html.append("\t\t<td class='listdetailitem'>\n");
141        html.append("\t\t\t");
142        html.append(info.getSiteRoot());
143        html.append("\n");
144        html.append("\t\t</td>\n");
145        html.append("\t</tr>\n");
146        html.append("\t<tr>\n");
147        html.append("\t\t<td width='150' align='right' class='listdetailhead'>\n");
148        html.append("\t\t\t");
149        html.append(requestedURIMessage);
150        html.append("&nbsp;:&nbsp;\n");
151        html.append("\t\t</td>\n");
152        html.append("\t\t<td class='listdetailitem'>\n");
153        html.append("\t\t\t");
154        html.append(info.getRequestedUri());
155        html.append("\n");
156        html.append("\t\t</td>\n");
157        html.append("\t</tr>\n");
158        html.append("\t<tr>\n");
159        html.append("\t\t<td width='150' align='right' class='listdetailhead'>\n");
160        html.append("\t\t\t");
161        html.append(remoteAddrMessage);
162        html.append("&nbsp;:&nbsp;\n");
163        html.append("\t\t</td>\n");
164        html.append("\t\t<td class='listdetailitem'>\n");
165        html.append("\t\t\t");
166        html.append(info.getRemoteAddr());
167        html.append("\n");
168        html.append("\t\t</td>\n");
169        html.append("\t</tr>\n");
170        html.append("\t<tr>\n");
171        html.append("\t\t<td width='150' align='right' class='listdetailhead'>\n");
172        html.append("\t\t\t");
173        html.append(encodingMessage);
174        html.append("&nbsp;:&nbsp;\n");
175        html.append("\t\t</td>\n");
176        html.append("\t\t<td class='listdetailitem'>\n");
177        html.append("\t\t\t");
178        html.append(info.getEncoding());
179        html.append("\n");
180        html.append("\t\t</td>\n");
181        html.append("\t</tr>\n");
182        html.append("</table>\n");
183        return html.toString();
184    }
185
186    /**
187     * Sets the encoding Message.<p>
188     *
189     * @param encodingMessage the encoding Message to set
190     */
191    public void setEncodingMessage(CmsMessageContainer encodingMessage) {
192
193        m_encodingMessage = encodingMessage;
194    }
195
196    /**
197     * Sets the locale Message.<p>
198     *
199     * @param localeMessage the locale Message to set
200     */
201    public void setLocaleMessage(CmsMessageContainer localeMessage) {
202
203        m_localeMessage = localeMessage;
204    }
205
206    /**
207     * Sets the project Message.<p>
208     *
209     * @param projectMessage the project Message to set
210     */
211    public void setProjectMessage(CmsMessageContainer projectMessage) {
212
213        m_projectMessage = projectMessage;
214    }
215
216    /**
217     * Sets the remote Address Message.<p>
218     *
219     * @param remoteAddrMessage the remote Address Message to set
220     */
221    public void setRemoteAddrMessage(CmsMessageContainer remoteAddrMessage) {
222
223        m_remoteAddrMessage = remoteAddrMessage;
224    }
225
226    /**
227     * Sets the requested URI Message.<p>
228     *
229     * @param requestedURIMessage the requested URI Message to set
230     */
231    public void setRequestedURIMessage(CmsMessageContainer requestedURIMessage) {
232
233        m_requestedURIMessage = requestedURIMessage;
234    }
235
236    /**
237     * Sets the rootSiteMessage.<p>
238     *
239     * @param rootSiteMessage the rootSiteMessage to set
240     */
241    public void setRootSiteMessage(CmsMessageContainer rootSiteMessage) {
242
243        m_rootSiteMessage = rootSiteMessage;
244    }
245
246    /**
247     * Sets the userMessage.<p>
248     *
249     * @param userMessage the userMessage to set
250     */
251    public void setUserMessage(CmsMessageContainer userMessage) {
252
253        m_userMessage = userMessage;
254    }
255}