offline-messages.jsp 10.3 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3
<%--
  -	$Revision$
  -	$Date$
Bill Lynch's avatar
Bill Lynch committed
4
  -
5
  - Copyright (C) 2004-2005 Jive Software. All rights reserved.
Bill Lynch's avatar
Bill Lynch committed
6 7 8
  -
  - This software is published under the terms of the GNU Public License (GPL),
  - a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
9 10 11
--%>

<%@ page import="org.jivesoftware.util.*,
12
                 org.jivesoftware.wildfire.*,
Matt Tucker's avatar
Matt Tucker committed
13
                 java.util.HashMap,
Derek DeMoro's avatar
Derek DeMoro committed
14
                 java.util.Map,
15
                 java.text.DecimalFormat"
Bill Lynch's avatar
Bill Lynch committed
16 17 18
    errorPage="error.jsp"
%>

19 20
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
Matt Tucker's avatar
Matt Tucker committed
21

22 23
<jsp:useBean id="webManager" class="org.jivesoftware.util.WebManager" scope="page" />
<% webManager.init(request, response, session, application, out ); %>
Derek DeMoro's avatar
Derek DeMoro committed
24

25 26 27 28 29 30 31
<html>
    <head>
        <title><fmt:message key="offline.messages.title"/></title>
        <meta name="pageID" content="server-offline-messages"/>
        <meta name="helpPage" content="manage_offline_messages.html"/>
    </head>
    <body>
Matt Tucker's avatar
Matt Tucker committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

<c:set var="success" />

<%! // Global vars and methods:

    // Strategy definitions:
    static final int BOUNCE = 1;
    static final int DROP = 2;
    static final int STORE = 3;
    static final int ALWAYS_STORE = 4;
    static final int STORE_AND_BOUNCE = 5;
    static final int STORE_AND_DROP = 6;
%>

<%  // Get parameters
    boolean update = request.getParameter("update") != null;
    int strategy = ParamUtils.getIntParameter(request,"strategy",-1);
    int storeStrategy = ParamUtils.getIntParameter(request,"storeStrategy",-1);
50
    double quota = ParamUtils.getIntParameter(request,"quota",0);
Matt Tucker's avatar
Matt Tucker committed
51
    DecimalFormat format = new DecimalFormat("#0.00");
Matt Tucker's avatar
Matt Tucker committed
52 53

    // Get the offline message manager
54
    OfflineMessageStrategy manager = webManager.getXMPPServer().getOfflineMessageStrategy();
Matt Tucker's avatar
Matt Tucker committed
55 56

    // Update the session kick policy if requested
57
    Map<String, String> errors = new HashMap<String, String>();
Matt Tucker's avatar
Matt Tucker committed
58 59 60 61 62 63 64 65 66 67 68
    if (update) {
        // Validate params
        if (strategy != BOUNCE && strategy != DROP && strategy != STORE) {
            errors.put("general","Please choose one of the 3 strategies below.");
        }
        else {
            // Validate the storage policy of store strat is chosen:
            if (strategy == STORE) {
                if (storeStrategy != ALWAYS_STORE && storeStrategy != STORE_AND_BOUNCE
                        && storeStrategy != STORE_AND_DROP)
                {
69
                    errors.put("general", LocaleUtils.getLocalizedString("offline.messages.choose_policy"));
Matt Tucker's avatar
Matt Tucker committed
70 71 72 73
                }
                else {
                    // Validate the store size limit:
                    if (quota <= 0) {
74
                        errors.put("quota", LocaleUtils.getLocalizedString("offline.messages.enter_store_size"));
Matt Tucker's avatar
Matt Tucker committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
                    }
                }
            }
        }
        // If no errors, continue:
        if (errors.size() == 0) {

            if (strategy == STORE) {
                manager.setType(OfflineMessageStrategy.Type.store);

                if (storeStrategy == STORE_AND_BOUNCE) {
                    manager.setType(OfflineMessageStrategy.Type.store_and_bounce);
                }
                else if (storeStrategy == STORE_AND_DROP) {
                    manager.setType(OfflineMessageStrategy.Type.store_and_drop);
                }
                else /* (storeStrategy == ALWAYS_STORE) */ {
                    manager.setType(OfflineMessageStrategy.Type.store);
                }
            }
            else {
                if (strategy == BOUNCE) {
                    manager.setType(OfflineMessageStrategy.Type.bounce);
                }
                else if (strategy == DROP) {
                    manager.setType(OfflineMessageStrategy.Type.drop);
                }
            }

104
            manager.setQuota((int)(quota*1024));
Matt Tucker's avatar
Matt Tucker committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
%>
<c:set var="success" value="true" />
<%
        }
    }

    // Update variable values

    if (errors.size() == 0) {
        if (manager.getType() == OfflineMessageStrategy.Type.store
                || manager.getType() == OfflineMessageStrategy.Type.store_and_bounce
                || manager.getType() == OfflineMessageStrategy.Type.store_and_drop)
        {
            strategy = STORE;

            if (manager.getType() == OfflineMessageStrategy.Type.store_and_bounce) {
                storeStrategy = STORE_AND_BOUNCE;
            }
            else if (manager.getType() == OfflineMessageStrategy.Type.store_and_drop) {
                storeStrategy = STORE_AND_DROP;
            }
            else /*(manager.getType() == OfflineMessageStrategy.STORE)*/ {
                storeStrategy = ALWAYS_STORE;
            }
        }
        else {
            if (manager.getType() == OfflineMessageStrategy.Type.bounce) {
                strategy = BOUNCE;
            }
            else if (manager.getType() == OfflineMessageStrategy.Type.drop) {
                strategy = DROP;
            }
        }

139
        quota = ((double)manager.getQuota()) / (1024);
Matt Tucker's avatar
Matt Tucker committed
140 141 142 143 144 145 146 147
        if (quota < 0) {
            quota = 0;
        }
    }
%>


<c:if test="${success}" >
Bill Lynch's avatar
Bill Lynch committed
148 149 150 151 152
    <div class="jive-success">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0"></td>
        <td class="jive-icon-label">
153
        <fmt:message key="offline.messages.update" />
Bill Lynch's avatar
Bill Lynch committed
154 155 156 157
        </td></tr>
    </tbody>
    </table>
    </div><br>
Matt Tucker's avatar
Matt Tucker committed
158 159
</c:if>

Bill Lynch's avatar
Bill Lynch committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
<%  if (errors.containsKey("general") || errors.containsKey("quota")) { %>

    <div class="jive-error">
    <table cellpadding="0" cellspacing="0" border="0">
    <tbody>
        <tr><td class="jive-icon"><img src="images/error-16x16.gif" width="16" height="16" border="0"></td>
        <td class="jive-icon-label">
        <%  if (errors.containsKey("general")) { %>
            <%= errors.get("general") %>
        <%  } else if (errors.containsKey("quota")) { %>
            <%= errors.get("quota") %>
        <%  } %>
        </td></tr>
    </tbody>
    </table>
    </div><br>
Matt Tucker's avatar
Matt Tucker committed
176 177 178

<%  } %>

Bill Lynch's avatar
Bill Lynch committed
179
<p>
180
<fmt:message key="offline.messages.info" />
Bill Lynch's avatar
Bill Lynch committed
181
</p>
Matt Tucker's avatar
Matt Tucker committed
182

Matt Tucker's avatar
Matt Tucker committed
183
<p>
184
<fmt:message key="offline.messages.size" />
Matt Tucker's avatar
Matt Tucker committed
185 186 187
<b><%= format.format(OfflineMessageStore.getInstance().getSize()/1024.0/1024.0) %> MB</b>
</p>

Bill Lynch's avatar
Bill Lynch committed
188
<form action="offline-messages.jsp">
Matt Tucker's avatar
Matt Tucker committed
189

Bill Lynch's avatar
Bill Lynch committed
190
<fieldset>
191
    <legend><fmt:message key="offline.messages.policy" /></legend>
Bill Lynch's avatar
Bill Lynch committed
192 193 194
    <div>
    <table cellpadding="3" cellspacing="0" border="0" width="100%">
    <tbody>
Matt Tucker's avatar
Matt Tucker committed
195 196
        <tr valign="top">
            <td width="1%" nowrap>
Bill Lynch's avatar
Bill Lynch committed
197 198
                <input type="radio" name="strategy" value="<%= BOUNCE %>" id="rb01"
                 <%= ((strategy==BOUNCE) ? "checked" : "") %>>
Matt Tucker's avatar
Matt Tucker committed
199 200
            </td>
            <td width="99%">
201
                <label for="rb01"><b><fmt:message key="offline.messages.bounce_option" /></b></label> - <fmt:message key="offline.messages.never_back" />
Matt Tucker's avatar
Matt Tucker committed
202 203 204 205
            </td>
        </tr>
        <tr valign="top">
            <td width="1%" nowrap>
Bill Lynch's avatar
Bill Lynch committed
206 207
                <input type="radio" name="strategy" value="<%= DROP %>" id="rb02"
                 <%= ((strategy==DROP) ? "checked" : "") %>>
Matt Tucker's avatar
Matt Tucker committed
208 209
            </td>
            <td width="99%">
210
                <label for="rb02"><b><fmt:message key="offline.messages.drop_option" /></b></label> - <fmt:message key="offline.messages.never_store" />
Matt Tucker's avatar
Matt Tucker committed
211 212
            </td>
        </tr>
Bill Lynch's avatar
Bill Lynch committed
213
        <tr valign="top" class="">
Matt Tucker's avatar
Matt Tucker committed
214
            <td width="1%" nowrap>
Bill Lynch's avatar
Bill Lynch committed
215 216
                <input type="radio" name="strategy" value="<%= STORE %>" id="rb03"
                 <%= ((strategy==STORE) ? "checked" : "") %>>
Matt Tucker's avatar
Matt Tucker committed
217 218
            </td>
            <td width="99%">
219
                <label for="rb03"><b><fmt:message key="offline.messages.store_option" /></b></label> - <fmt:message key="offline.messages.storage_wildfire" />
Matt Tucker's avatar
Matt Tucker committed
220 221
            </td>
        </tr>
Bill Lynch's avatar
Bill Lynch committed
222 223 224 225 226
        <tr valign="top">
            <td width="1%" nowrap>
                &nbsp;
            </td>
            <td width="99%">
Matt Tucker's avatar
Matt Tucker committed
227

Bill Lynch's avatar
Bill Lynch committed
228 229 230 231 232 233 234 235
                <table cellpadding="4" cellspacing="0" border="0" width="100%">
                <tr valign="top">
                    <td width="1%" nowrap>
                        <input type="radio" name="storeStrategy" value="<%= ALWAYS_STORE %>" id="rb05"
                         onclick="this.form.strategy[2].checked=true;"
                         <%= ((storeStrategy==ALWAYS_STORE) ? "checked" : "") %>>
                    </td>
                    <td width="99%">
236
                        <label for="rb05"><b><fmt:message key="offline.messages.always_store" /></b></label> - <fmt:message key="offline.messages.always_store_info" />
Bill Lynch's avatar
Bill Lynch committed
237 238 239 240 241 242 243 244 245
                    </td>
                </tr>
                <tr valign="top">
                    <td width="1%" nowrap>
                        <input type="radio" name="storeStrategy" value="<%= STORE_AND_BOUNCE%>" id="rb06"
                         onclick="this.form.strategy[2].checked=true;"
                         <%= ((storeStrategy==STORE_AND_BOUNCE) ? "checked" : "") %>>
                    </td>
                    <td width="99%">
246
                        <label for="rb06"><b><fmt:message key="offline.messages.bounce" /></b></label> - <fmt:message key="offline.messages.bounce_info" />
Bill Lynch's avatar
Bill Lynch committed
247 248 249 250 251 252 253 254 255
                    </td>
                </tr>
                <tr valign="top">
                    <td width="1%" nowrap>
                        <input type="radio" name="storeStrategy" value="<%= STORE_AND_DROP %>" id="rb07"
                         onclick="this.form.strategy[2].checked=true;"
                         <%= ((storeStrategy==STORE_AND_DROP) ? "checked" : "") %>>
                    </td>
                    <td width="99%">
256
                        <label for="rb07"><b><fmt:message key="offline.messages.drop" /></b></label> - <fmt:message key="offline.messages.drop_info" />
Bill Lynch's avatar
Bill Lynch committed
257 258 259 260
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
261
                        <fmt:message key="offline.messages.storage_limit" />
Bill Lynch's avatar
Bill Lynch committed
262
                        <input type="text" size="5" maxlength="12" name="quota"
263
                         value="<%= (quota>0 ? ""+format.format(quota) : "") %>"
Bill Lynch's avatar
Bill Lynch committed
264
                         onclick="this.form.strategy[2].checked=true;">
265
                        KB
Bill Lynch's avatar
Bill Lynch committed
266 267 268 269 270 271 272 273 274
                    </td>
                </tr>
                </table>
            </td>
        </tr>
    </tbody>
    </table>
    </div>
</fieldset>
Matt Tucker's avatar
Matt Tucker committed
275

Bill Lynch's avatar
Bill Lynch committed
276
<br><br>
Matt Tucker's avatar
Matt Tucker committed
277

278
<input type="submit" name="update" value="<fmt:message key="global.save_settings" />">
Matt Tucker's avatar
Matt Tucker committed
279 280 281

</form>

282 283
    </body>
</html>