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 923

Subversion Repositories general

Rev

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

Rev Author Line No. Line
919 dev 1
package ak.hostcaptain.core.action;
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
 
23
import ak.hostcaptain.util.StringConverter;
923 dev 24
import ak.hostcaptain.util.UserException;
25
import ak.hostcaptain.core.CoreResources;
919 dev 26
import ak.hostcaptain.core.model.User;
27
import ak.hostcaptain.core.model.UserManager;
28
import ak.hostcaptain.core.model.InetDomain;
29
import ak.hostcaptain.core.model.InetDomainManager;
30
 
31
public final class InetDomainAction
32
	extends Action
33
	implements ErrorHandlerX
34
{
35
	public void handleErrors(ActionMapping mapping, ActionForm form,
36
			 HttpServletRequest request, HttpServletResponse response)
37
		throws Exception
38
	{
39
		if("submit".equals(mapping.getParameter())) {
40
			User user = (User)request.getSession().getAttribute("user");
41
			initUserList(request, user);
42
		}
43
	}
44
 
45
	public ActionForward execute(ActionMapping mapping, ActionForm form,
46
			HttpServletRequest request, HttpServletResponse response)
47
		throws Exception
48
	{
49
		User user = (User)request.getSession().getAttribute("user");
50
 
51
		if("list".equals(mapping.getParameter())) {
52
			List list = new ArrayList(InetDomainManager.getInstance().listInetDomains(user));
53
			Collections.sort(list, InetDomainManager.NAME_COMPARATOR);
54
			request.setAttribute("domains", list);
55
			request.setAttribute("allowedToCreate",
56
				new Boolean(InetDomainManager.getInstance().allowedToCreate(user)));
57
 
58
			return mapping.findForward("default");
59
		}
60
		else if("edit".equals(mapping.getParameter())) {
61
			DynaActionForm theForm  = (DynaActionForm)form;
62
			Long           domainId = StringConverter.parseLong(theForm.get("id"));
923 dev 63
			InetDomain     domain;
919 dev 64
			DynaActionForm showForm = (DynaActionForm)RequestUtilsX.populateActionForm(
65
				this, request, "ak.hostcaptain.core.form.InetDomainEditForm");
66
 
67
			if(domainId == null) {
923 dev 68
				domain = InetDomainManager.getInstance().create(user);
919 dev 69
				showForm.set("enabled", new Boolean(true));
70
			}
71
			else {
923 dev 72
				domain = InetDomainManager.getInstance().get(user, domainId);
919 dev 73
            	showForm.set("name", domain.getName());
74
            	if(domain.getOwner() != null)
75
            		showForm.set("owner", StringConverter.toString(domain.getOwner().getId()));
76
				showForm.set("enabled", domain.getEnabled());
77
				showForm.set("comment", domain.getComment());
78
			}
79
 
80
			initUserList(request, user);
923 dev 81
			request.setAttribute("domain", domain);
82
			if(domain.editableBy(user))
83
				return mapping.findForward("default");
84
			else
85
				return mapping.findForward("view");
919 dev 86
		}
87
		else if("delete".equals(mapping.getParameter())) {
88
			DynaActionForm theForm  = (DynaActionForm)form;
89
			Long           domainId = StringConverter.parseLong(theForm.get("id"));
90
			InetDomain     domain   = InetDomainManager.getInstance().get(user, domainId);
91
 
92
			InetDomainManager.getInstance().delete(user, domain);
93
			response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
94
			return null;
95
		}
96
		else if("submit".equals(mapping.getParameter())) {
97
			DynaActionForm theForm  = (DynaActionForm)form;
98
			Long           domainId = StringConverter.parseLong(theForm.get("id"));
99
			InetDomain     domain;
100
 
101
			if(domainId == null) {
102
				domain = InetDomainManager.getInstance().create(user);
103
			}
104
			else {
105
				domain = InetDomainManager.getInstance().get(user, domainId);
106
			}
107
 
923 dev 108
            String name = (String)theForm.get("name");
109
            if(InetDomainManager.getInstance().nameExists(user, domain, name)) {
110
				handleErrors(mapping, form, request, response);
111
            	throw new UserException(CoreResources.NONUNIQUE_DOMAIN_NAME);
112
            }
113
            domain.setName(user, name);
114
 
921 dev 115
            domain.setOwner(user, UserManager.getInstance().get(user,
919 dev 116
            	StringConverter.parseLong(theForm.get("owner"))));
117
 
921 dev 118
			domain.setEnabled(user, (Boolean)theForm.get("enabled"));
119
			domain.setComment(user, (String)theForm.get("comment"));
919 dev 120
 
121
			InetDomainManager.getInstance().save(user, domain);
122
			response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl());
123
			return null;
124
		}
125
		else {
126
			throw new Exception("unknown mapping parameter");
127
		}
128
	}
129
 
130
	private void initUserList(HttpServletRequest request, User user)
131
		throws Exception
132
	{
133
		List list = new ArrayList(UserManager.getInstance().listUsers(user));
134
		Collections.sort(list, UserManager.LOGIN_COMPARATOR);
135
		request.setAttribute("users", list);
136
	}
137
}