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

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 914

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())) {
914 dev 49
			List list = new ArrayList(InetDomainManager.getInstance().listInetDomains(user));
899 dev 50
			Collections.sort(list, InetDomainManager.NAME_COMPARATOR);
51
			request.setAttribute("domains", list);
914 dev 52
			request.setAttribute("allowedToCreate",
53
				new Boolean(InetDomainManager.getInstance().allowedToCreate(user)));
899 dev 54
 
55
			return mapping.findForward("default");
56
		}
57
		else if("edit".equals(mapping.getParameter())) {
58
			DynaActionForm theForm  = (DynaActionForm)form;
59
			Long           domainId = StringConverter.parseLong(theForm.get("id"));
60
			DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
904 dev 61
				this, request, "ak.hostcaptain.core.form.InetDomainEditForm");
899 dev 62
 
63
			if(domainId == null) {
913 dev 64
				showForm.set("enabled", new Boolean(true));
899 dev 65
			}
66
			else {
914 dev 67
				InetDomain domain = InetDomainManager.getInstance().get(user, domainId);
899 dev 68
            	showForm.set("name", domain.getName());
69
            	if(domain.getOwner() != null)
70
            		showForm.set("owner", StringConverter.toString(domain.getOwner().getId()));
913 dev 71
				showForm.set("enabled", domain.getEnabled());
72
				showForm.set("comment", domain.getComment());
899 dev 73
			}
74
 
75
			initUserList(request);
76
			return mapping.findForward("default");
77
		}
78
		else if("delete".equals(mapping.getParameter())) {
79
			DynaActionForm theForm  = (DynaActionForm)form;
80
			Long           domainId = StringConverter.parseLong(theForm.get("id"));
914 dev 81
			InetDomain     domain   = InetDomainManager.getInstance().get(user, domainId);
899 dev 82
 
914 dev 83
			InetDomainManager.getInstance().delete(user, domain);
899 dev 84
			response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
85
			return null;
86
		}
87
		else if("submit".equals(mapping.getParameter())) {
88
			DynaActionForm theForm  = (DynaActionForm)form;
89
			Long           domainId = StringConverter.parseLong(theForm.get("id"));
90
			InetDomain     domain;
91
 
92
			if(domainId == null) {
914 dev 93
				domain = InetDomainManager.getInstance().create(user);
899 dev 94
			}
95
			else {
914 dev 96
				domain = InetDomainManager.getInstance().get(user, domainId);
899 dev 97
			}
98
 
99
            domain.setName((String)theForm.get("name"));
100
            domain.setOwner(UserManager.getInstance().get(
101
            	StringConverter.parseLong(theForm.get("owner"))));
102
 
913 dev 103
			domain.setEnabled((Boolean)theForm.get("enabled"));
104
			domain.setComment((String)theForm.get("comment"));
105
 
914 dev 106
			InetDomainManager.getInstance().save(user, domain);
899 dev 107
			response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
108
			return null;
109
		}
110
		else {
111
			throw new Exception("unknown mapping parameter");
112
		}
113
	}
114
 
115
	private void initUserList(HttpServletRequest request)
116
		throws Exception
117
	{
118
		List list = new ArrayList(UserManager.getInstance().listUsers());
119
		Collections.sort(list, UserManager.LOGIN_COMPARATOR);
120
		request.setAttribute("users", list);
121
	}
122
}