001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.admin.action;
022:
023: import com.liferay.portal.CompanyMxException;
024: import com.liferay.portal.CompanyVirtualHostException;
025: import com.liferay.portal.CompanyWebIdException;
026: import com.liferay.portal.NoSuchCompanyException;
027: import com.liferay.portal.kernel.util.ParamUtil;
028: import com.liferay.portal.model.Company;
029: import com.liferay.portal.security.auth.PrincipalException;
030: import com.liferay.portal.service.CompanyServiceUtil;
031: import com.liferay.portal.struts.PortletAction;
032: import com.liferay.portal.util.PortalInstances;
033: import com.liferay.portal.util.WebKeys;
034: import com.liferay.util.servlet.SessionErrors;
035:
036: import javax.portlet.ActionRequest;
037: import javax.portlet.ActionResponse;
038: import javax.portlet.PortletConfig;
039: import javax.portlet.RenderRequest;
040: import javax.portlet.RenderResponse;
041:
042: import javax.servlet.ServletContext;
043:
044: import org.apache.struts.action.ActionForm;
045: import org.apache.struts.action.ActionForward;
046: import org.apache.struts.action.ActionMapping;
047:
048: /**
049: * <a href="EditInstanceAction.java.html"><b><i>View Source</i></b></a>
050: *
051: * @author Brian Wing Shun Chan
052: *
053: */
054: public class EditInstanceAction extends PortletAction {
055:
056: public void processAction(ActionMapping mapping, ActionForm form,
057: PortletConfig config, ActionRequest req, ActionResponse res)
058: throws Exception {
059:
060: try {
061: updateInstance(req);
062:
063: sendRedirect(req, res);
064: } catch (Exception e) {
065: if (e instanceof NoSuchCompanyException
066: || e instanceof PrincipalException) {
067:
068: SessionErrors.add(req, e.getClass().getName());
069:
070: setForward(req, "portlet.admin.error");
071: } else if (e instanceof CompanyMxException
072: || e instanceof CompanyVirtualHostException
073: || e instanceof CompanyWebIdException) {
074:
075: SessionErrors.add(req, e.getClass().getName());
076: } else {
077: throw e;
078: }
079: }
080: }
081:
082: public ActionForward render(ActionMapping mapping, ActionForm form,
083: PortletConfig config, RenderRequest req, RenderResponse res)
084: throws Exception {
085:
086: try {
087: ActionUtil.getInstance(req);
088: } catch (Exception e) {
089: if (e instanceof NoSuchCompanyException
090: || e instanceof PrincipalException) {
091:
092: SessionErrors.add(req, e.getClass().getName());
093:
094: return mapping.findForward("portlet.admin.error");
095: } else {
096: throw e;
097: }
098: }
099:
100: return mapping.findForward(getForward(req,
101: "portlet.admin.edit_instance"));
102: }
103:
104: protected void updateInstance(ActionRequest req) throws Exception {
105: long companyId = ParamUtil.getLong(req, "companyId");
106:
107: String webId = ParamUtil.getString(req, "webId");
108: String virtualHost = ParamUtil.getString(req, "virtualHost");
109: String mx = ParamUtil.getString(req, "mx");
110:
111: if (companyId <= 0) {
112:
113: // Add instance
114:
115: Company company = CompanyServiceUtil.addCompany(webId,
116: virtualHost, mx);
117:
118: ServletContext ctx = (ServletContext) req
119: .getAttribute(WebKeys.CTX);
120:
121: PortalInstances.initCompany(ctx, company.getWebId());
122: } else {
123:
124: // Update instance
125:
126: CompanyServiceUtil
127: .updateCompany(companyId, virtualHost, mx);
128: }
129: }
130:
131: }
|