Warning: Attempt to read property "date" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Warning: Attempt to read property "msg" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/www/websvn.26th.net/html/blame.php on line 247

Warning: Attempt to read property "date" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Warning: Attempt to read property "msg" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/www/websvn.26th.net/html/blame.php on line 247

Warning: Attempt to read property "date" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Warning: Attempt to read property "msg" on null in /home/www/websvn.26th.net/html/blame.php on line 247

Deprecated: preg_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/www/websvn.26th.net/html/blame.php on line 247
WebSVN – general – Blame – /hostadmiral/trunk/src/ak/hostadmiral/core/action/InetDomainAction.java/ – Rev 913

Subversion Repositories general

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
904 dev 1
package ak.hostcaptain.core.action;
899 dev 2
 
3
import java.util.List;
4
import java.util.Collections;
5
import java.util.ArrayList;
6
 
7
import javax.servlet.http.HttpServletRequest;
8
import javax.servlet.http.HttpServletResponse;
9
 
10
import org.apache.struts.action.Action;
11
import org.apache.struts.action.ActionMapping;
12
import org.apache.struts.action.ActionForm;
13
import org.apache.struts.action.DynaActionForm;
14
import org.apache.struts.action.ActionForward;
15
import org.apache.struts.action.ActionMessages;
16
import org.apache.struts.action.ActionErrors;
17
import org.apache.struts.action.ActionError;
18
 
19
import ak.strutsx.RequestUtilsX;
20
import ak.strutsx.ErrorHandlerX;
21
import ak.backpath.BackPath;
22
 
904 dev 23
import ak.hostcaptain.util.StringConverter;
24
import ak.hostcaptain.core.model.User;
25
import ak.hostcaptain.core.model.UserManager;
26
import ak.hostcaptain.core.model.InetDomain;
27
import ak.hostcaptain.core.model.InetDomainManager;
899 dev 28
 
29
public final class InetDomainAction
30
	extends Action
31
	implements ErrorHandlerX
32
{
33
	public void handleErrors(ActionMapping mapping, ActionForm form,
34
			 HttpServletRequest request, HttpServletResponse response)
35
		throws Exception
36
	{
37
		if("submit".equals(mapping.getParameter())) {
38
			initUserList(request);
39
		}
40
	}
41
 
42
	public ActionForward execute(ActionMapping mapping, ActionForm form,
43
			HttpServletRequest request, HttpServletResponse response)
44
		throws Exception
45
	{
46
		User user = (User)request.getSession().getAttribute("user");
47
 
48
		if("list".equals(mapping.getParameter())) {
49
			List list = new ArrayList(InetDomainManager.getInstance().listInetDomains());
50
			Collections.sort(list, InetDomainManager.NAME_COMPARATOR);
51
			request.setAttribute("domains", list);
52
 
53
			return mapping.findForward("default");
54
		}
55
		else if("edit".equals(mapping.getParameter())) {
56
			DynaActionForm theForm  = (DynaActionForm)form;
57
			Long           domainId = StringConverter.parseLong(theForm.get("id"));
58
			DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
904 dev 59
				this, request, "ak.hostcaptain.core.form.InetDomainEditForm");
899 dev 60
 
61
			if(domainId == null) {
913 dev 62
				showForm.set("enabled", new Boolean(true));
899 dev 63
			}
64
			else {
65
				InetDomain domain = InetDomainManager.getInstance().get(domainId);
66
            	showForm.set("name", domain.getName());
67
            	if(domain.getOwner() != null)
68
            		showForm.set("owner", StringConverter.toString(domain.getOwner().getId()));
913 dev 69
				showForm.set("enabled", domain.getEnabled());
70
				showForm.set("comment", domain.getComment());
899 dev 71
			}
72
 
73
			initUserList(request);
74
			return mapping.findForward("default");
75
		}
76
		else if("delete".equals(mapping.getParameter())) {
77
			DynaActionForm theForm  = (DynaActionForm)form;
78
			Long           domainId = StringConverter.parseLong(theForm.get("id"));
79
			InetDomain     domain   = InetDomainManager.getInstance().get(domainId);
80
 
81
			InetDomainManager.getInstance().delete(domain);
82
			response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
83
			return null;
84
		}
85
		else if("submit".equals(mapping.getParameter())) {
86
			DynaActionForm theForm  = (DynaActionForm)form;
87
			Long           domainId = StringConverter.parseLong(theForm.get("id"));
88
			InetDomain     domain;
89
 
90
			if(domainId == null) {
91
				domain = InetDomainManager.getInstance().create();
92
			}
93
			else {
94
				domain = InetDomainManager.getInstance().get(domainId);
95
			}
96
 
97
            domain.setName((String)theForm.get("name"));
98
            domain.setOwner(UserManager.getInstance().get(
99
            	StringConverter.parseLong(theForm.get("owner"))));
100
 
913 dev 101
			domain.setEnabled((Boolean)theForm.get("enabled"));
102
			domain.setComment((String)theForm.get("comment"));
103
 
899 dev 104
			InetDomainManager.getInstance().save(domain);
105
			response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
106
			return null;
107
		}
108
		else {
109
			throw new Exception("unknown mapping parameter");
110
		}
111
	}
112
 
113
	private void initUserList(HttpServletRequest request)
114
		throws Exception
115
	{
116
		List list = new ArrayList(UserManager.getInstance().listUsers());
117
		Collections.sort(list, UserManager.LOGIN_COMPARATOR);
118
		request.setAttribute("users", list);
119
	}
120
}