KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > setup > forms > ClientRestrictionsForm


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.setup.forms;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.StringTokenizer JavaDoc;
26 import java.util.regex.Pattern JavaDoc;
27
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29
30 import org.apache.struts.Globals;
31 import org.apache.struts.action.ActionErrors;
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionMapping;
34 import org.apache.struts.action.ActionMessage;
35 import org.apache.struts.util.LabelValueBean;
36
37 import com.sslexplorer.setup.ClientRestrictionItem;
38
39 public class ClientRestrictionsForm
40     extends ActionForm {
41   
42   List JavaDoc clientRestrictionItems;
43   String JavaDoc action;
44   List JavaDoc osList;
45   String JavaDoc selectedOs = "Windows XP";
46   List JavaDoc selectedItems;
47
48   public ClientRestrictionsForm() {
49   }
50
51   public void reset(ActionMapping mapping,
52                     javax.servlet.http.HttpServletRequest JavaDoc request) {
53   }
54   
55   public void initialise(List JavaDoc clientRestrictionItems) {
56     this.clientRestrictionItems = clientRestrictionItems;
57     osList = new ArrayList JavaDoc();
58     osList.add(new LabelValueBean("All", "All"));
59     selectedItems = new ArrayList JavaDoc();
60     String JavaDoc lastOs = null;
61     for(Iterator JavaDoc i = clientRestrictionItems.iterator(); i.hasNext(); ) {
62       ClientRestrictionItem item = (ClientRestrictionItem)i.next();
63       if(!item.getClientRestriction().getOsName().equals(lastOs)) {
64         lastOs = item.getClientRestriction().getOsName();
65         osList.add(new LabelValueBean(lastOs, lastOs));
66       }
67     }
68     buildSelectedList();
69   }
70   
71   public String JavaDoc getSelectedOs() {
72     return selectedOs;
73   }
74   
75   public void setSelectedOs(String JavaDoc selectedOs) {
76     this.selectedOs =selectedOs;
77   }
78   
79   public List JavaDoc getClientRestrictionItems() {
80     return selectedItems;
81   }
82
83   public String JavaDoc getAction() {
84     return action;
85   }
86   
87   public void setAction(String JavaDoc action) {
88     this.action = action;
89   }
90   
91   public List JavaDoc getOsList() {
92     return osList;
93   }
94   
95   public void setClientRestrictionItems(List JavaDoc selectedItems) {
96     this.selectedItems = selectedItems;
97   }
98   
99   public void setClientRestrictionItem(int idx, ClientRestrictionItem item) {
100     selectedItems.set(idx, item);
101   }
102   
103   public ClientRestrictionItem getClientRestrictionItem(int idx) {
104     return (ClientRestrictionItem)selectedItems.get(idx);
105   }
106
107   public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
108     if("commit".equals(request.getParameter("action"))) {
109         ActionErrors msgs = new ActionErrors();
110         for(Iterator JavaDoc i = selectedItems.iterator(); i.hasNext(); ) {
111           ClientRestrictionItem item = (ClientRestrictionItem)i.next();
112           String JavaDoc exceptions = item.getClientRestriction().getExceptions();
113           StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(exceptions, "\r\n");
114           while(t.hasMoreTokens()) {
115             String JavaDoc pattern = t.nextToken();
116             try {
117               Pattern.compile(pattern);
118             }
119             catch(Exception JavaDoc e) {
120               msgs.add(Globals.MESSAGE_KEY, new ActionMessage("clientRestrictions.error.invalidExceptionPattern", e.getMessage(),
121                         item.getClientRestriction().getOsName(), item.getClientRestriction().getPropertyName()));
122             }
123           }
124         }
125         return msgs;
126     }
127     else {
128       return null;
129     }
130   }
131   
132   private void buildSelectedList() {
133     selectedItems.clear();
134     for(Iterator JavaDoc i = clientRestrictionItems.iterator(); i.hasNext(); ) {
135       ClientRestrictionItem item = (ClientRestrictionItem)i.next();
136       if("All".equals(selectedOs) || item.getClientRestriction().getOsName().equals(selectedOs)) {
137         selectedItems.add(item);
138       }
139     }
140   }
141 }
Popular Tags