001: /**
002: *
003: */package clime.messadmin.providers.userdata;
004:
005: import java.text.NumberFormat;
006: import java.util.ArrayList;
007: import java.util.Iterator;
008: import java.util.List;
009:
010: import javax.servlet.http.HttpSession;
011:
012: import clime.messadmin.clickstream.HttpRequestInfo;
013: import clime.messadmin.clickstream.Utils;
014: import clime.messadmin.i18n.I18NSupport;
015: import clime.messadmin.model.Server;
016: import clime.messadmin.model.Session;
017: import clime.messadmin.providers.spi.SessionDataProvider;
018: import clime.messadmin.providers.spi.SizeOfProvider;
019: import clime.messadmin.utils.BytesFormat;
020: import clime.messadmin.utils.DateUtils;
021:
022: /**
023: * @author Cédrik LIME
024: */
025: public class ClickStreamDisplayer implements SessionDataProvider {
026: private static final String BUNDLE_NAME = ClickStreamDisplayer.class
027: .getName();
028:
029: /**
030: *
031: */
032: public ClickStreamDisplayer() {
033: super ();
034: }
035:
036: /**
037: * {@inheritDoc}
038: */
039: public int getPriority() {
040: return 10;
041: }
042:
043: /**
044: * Convenience method for i18n
045: */
046: protected ClassLoader getClassLoader(final HttpSession session) {
047: return Server.getInstance().getApplication(
048: session.getServletContext()).getApplicationInfo()
049: .getClassLoader();
050: }
051:
052: /**
053: * {@inheritDoc}
054: */
055: public String getSessionDataTitle(HttpSession httpSession) {
056: NumberFormat numberFormatter = NumberFormat
057: .getNumberInstance(I18NSupport.getAdminLocale());
058: NumberFormat bytesFormatter = BytesFormat.getBytesInstance(
059: I18NSupport.getAdminLocale(), " ");//$NON-NLS-1$
060: Session session = Server.getInstance().getApplication(
061: httpSession.getServletContext()).getSession(
062: httpSession.getId());
063: List data = new ArrayList(Utils.getPluginData(session));
064: ClassLoader cl = Server.getInstance().getApplication(
065: httpSession.getServletContext()).getApplicationInfo()
066: .getClassLoader();
067: long currentItemSize = SizeOfProvider.Util.getObjectSize(data,
068: cl);
069: String result = I18NSupport.getLocalizedMessage(BUNDLE_NAME,
070: getClassLoader(httpSession), "title",//$NON-NLS-1$
071: new Object[] { bytesFormatter.format(currentItemSize),
072: numberFormatter.format(data.size()) });
073: return result;
074: }
075:
076: /**
077: * {@inheritDoc}
078: */
079: public String getXHTMLSessionData(HttpSession httpSession) {
080: Session session = Server.getInstance().getApplication(
081: httpSession.getServletContext()).getSession(
082: httpSession.getId());
083: final List data = new ArrayList(Utils.getPluginData(session));
084: StringBuffer buffer = new StringBuffer(16 + data.size() * 120);
085: int hiddenRequests = session.getSessionInfo().getHits()
086: - data.size();
087: // 'ol' 'start' attribute is deprecated in HTML4, but not anymore in HTML5
088: buffer
089: .append("<ol start=\"").append(Math.max(1, hiddenRequests + 1)).append("\">\n");//$NON-NLS-1$//$NON-NLS-2$
090: // for (int i=0; i < hiddenRequests; ++i) {
091: // buffer.append("<li style=\"display: hidden; list-style-type: none;\"></li>\n");//$NON-NLS-1$
092: // }
093: NumberFormat numberFormatter = NumberFormat
094: .getNumberInstance(I18NSupport.getAdminLocale());
095: Iterator iter = data.iterator();
096: while (iter.hasNext()) {
097: HttpRequestInfo request = (HttpRequestInfo) iter.next();
098: boolean error = (request.getError() != null);
099: buffer.append("<li title=\"");//$NON-NLS-1$
100: buffer
101: .append(
102: numberFormatter.format(request
103: .getUsedTime())).append(" ms");//$NON-NLS-1$
104: buffer.append("\">");//$NON-NLS-1$
105: if (error) {
106: buffer
107: .append("<span style=\"color: red; font-weight: bolder;\">");//$NON-NLS-1$
108: }
109: buffer
110: .append(
111: DateUtils.dateToFormattedDateTimeString(
112: request.getRequestDate().getTime(),
113: "yyyy-MM-dd HH:mm:ss")).append(" ");//$NON-NLS-1$//$NON-NLS-2$
114: buffer.append(request.getURL());
115: if (error) {
116: buffer.append("</span>");//$NON-NLS-1$
117: }
118: buffer.append("</li>\n");//$NON-NLS-1$
119: }
120: buffer.append("</ol>\n");//$NON-NLS-1$
121:
122: return buffer.toString();
123: }
124:
125: }
|