KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > security > forms > ShowAvailableIpRestrictionsForm


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.security.forms;
21
22 import javax.servlet.http.HttpSession JavaDoc;
23
24 import org.apache.struts.action.ActionMapping;
25
26 import com.sslexplorer.security.IpRestriction;
27 import com.sslexplorer.security.IpRestrictionItem;
28 import com.sslexplorer.security.IpRestrictionItemModel;
29 import com.sslexplorer.table.forms.AbstractPagerForm;
30
31 /**
32  * Implementation of a {@link com.sslexplorer.table.forms.AbstractPagerForm}
33  * that allows an administrator to create and delete <i>IP Restrictions</i>.
34  *
35  * @author P.J.King <a HREF="mailto:peter@3sp.com">&lt;peter@3sp.com&gt;</a>
36  * @see com.sslexplorer.security.IpRestrictionItem
37  *
38  */

39 public class ShowAvailableIpRestrictionsForm extends AbstractPagerForm {
40
41     // Private instance variables
42

43     private IpRestriction[] ipRestrictions;
44     private String JavaDoc action;
45
46     /**
47      * Constructor. Creates a new {@link IpRestrictionItemModel} object.
48      */

49     public ShowAvailableIpRestrictionsForm() {
50         super(new IpRestrictionItemModel());
51         getPager().setSorts(false);
52     }
53
54     /**
55      * Builds the ipRestrictions page model and initialises the super class.
56      *
57      * @param ipRestrictions list of IP Restriction objects
58      * @param session session
59      */

60     public void initialize(IpRestriction[] ipRestrictions, HttpSession JavaDoc session) {
61         super.initialize(session, "");
62         for (int i = 0; ipRestrictions != null && i < ipRestrictions.length; i++) {
63             getModel().addItem(new IpRestrictionItem(ipRestrictions[i], i > 1, i > 0 && i < ( ipRestrictions.length - 1 ),
64                 !ipRestrictions[i].isDefault()));
65         }
66         getPager().rebuild(getFilterText());
67     }
68
69     /**
70      * Get the IP Restrictions list.
71      *
72      * @return ipResrictions list of IP Restriction objects
73      */

74     public IpRestriction[] getIpRestrictions() {
75         return ipRestrictions;
76     }
77
78     /**
79      * Get if this IP Restriction is authorised.
80      *
81      * @return is authorised
82      */

83     public boolean isAuthorized() {
84         return action != null && action.equals("allow");
85     }
86
87     /**
88      * Get if this IP Restriction is displayable.
89      *
90      * @return is displayable
91      */

92     public boolean isDisplayable() {
93         return ipRestrictions.length > 0;
94     }
95
96     /* (non-Javadoc)
97      * @see com.sslexplorer.table.forms.AbstractPagerForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
98      */

99     public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest JavaDoc request) {
100         ipRestrictions = null;
101         action = "";
102     }
103 }
Popular Tags