001: /*
002: * (C) Copyright 2000 - 2006 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portlet.psiteadmin;
020:
021: import java.io.IOException;
022:
023: import javax.portlet.ActionRequest;
024: import javax.portlet.ActionResponse;
025: import javax.portlet.PortletException;
026: import javax.portlet.PortletSecurityException;
027:
028: import org.apache.commons.lang.StringUtils;
029:
030: import org.w3c.dom.Element;
031:
032: import com.nabhinc.core.Constants;
033: import com.nabhinc.portal.api.EntityLockedException;
034: import com.nabhinc.portal.api.OrphanException;
035: import com.nabhinc.portal.api.PortalInformationStore;
036: import com.nabhinc.portal.api.PortalInformationStoreLocator;
037: import com.nabhinc.portal.core.PortalConstants;
038: import com.nabhinc.portal.model.PortalApplication;
039: import com.nabhinc.portlet.mvcportlet.core.ActionConfig;
040: import com.nabhinc.portlet.mvcportlet.core.ActionProcessor;
041: import com.nabhinc.portlet.mvcportlet.core.BaseRequestProcessor;
042: import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
043: import com.nabhinc.spi.EntityExistsException;
044: import com.nabhinc.util.StringUtil;
045: import com.nabhinc.ws.core.WebServiceSecurityException;
046:
047: /**
048: *
049: *
050: * @author Padmanabh Dabke
051: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
052: */
053: public class SiteCreator extends BaseRequestProcessor implements
054: ActionProcessor {
055: public static final int[] DEFAULT_USER_ROLES = { Constants.USER_ROLE_ID };
056: private int scMaxSites = -1; //unlimited
057:
058: public void init(Element xmlConfig, ControllerPortletConfig config)
059: throws PortletException {
060: super .init(xmlConfig, config);
061: String maxSitesStr = xmlConfig.getAttribute("maxSites");
062: if (StringUtil.isNotNullOrEmpty(maxSitesStr))
063: scMaxSites = Integer.parseInt(maxSitesStr);
064: }
065:
066: @SuppressWarnings("unchecked")
067: public String process(ActionRequest request,
068: ActionResponse response, ActionConfig actionConfig)
069: throws PortletException, IOException {
070:
071: String userName = request.getRemoteUser();
072: if (userName == null)
073: return "not-logged-in";
074: String appName = request
075: .getParameter(PortalConstants.SITE_NAME_PARAM);
076:
077: if (StringUtil.isNullOrEmpty(appName))
078: return "empty-site-name";
079: if (!StringUtils.isAlpha(appName.substring(0, 1)))
080: return "name-not-alpha";
081: appName = appName.trim();
082: //if (appName.indexOf('/') != -1) return "name-contains-slash";
083: if (appName.indexOf(' ') != -1 || appName.indexOf('\t') != -1
084: || appName.indexOf('\n') != -1
085: || appName.indexOf('\r') != -1)
086: return "name-contains-space";
087: if (!appName.startsWith("/"))
088: appName = "/" + appName;
089: try {
090: PortalApplication[] apps = PortalInformationStoreLocator
091: .getPortalInformationStore()
092: .getUserPortalApplications();
093: if (scMaxSites > 0 && apps != null
094: && apps.length > scMaxSites)
095: return "max-sites";
096: PortalInformationStore store = PortalInformationStoreLocator
097: .getPortalInformationStore();
098: PortalApplication app = store.createPortalApplication(
099: appName.toLowerCase(), null);
100: store.savePortalApplication(app, false);
101: /*
102: PortalApplication adminApp = store.createPortalApplication(appPath + "/admin", "/templates" + scParentAppPath + "admin");
103: adminApp.setTitle(appTitle);
104: adminApp.setTagline(appTagline);
105: adminApp.setTheme(appTheme);
106: adminApp.setTimezone(appTimezone);
107: adminApp.setOwnerName("admin");
108: //adminApp.setAdminPermission(new OwnerCondition());
109: adminApp.setViewPermission(new AllowUsers(new String[] {userName}));
110: //adminApp.setEditPermission(new OwnerCondition());
111: store.savePortalApplication(adminApp, false);
112: */
113: } catch (EntityExistsException e) {
114: return "site-exists";
115: } catch (WebServiceSecurityException e) {
116: throw new PortletSecurityException(e);
117: } catch (OrphanException e) {
118: return "parent-not-exists";
119: // throw new PortletException("Parent Psite does not exist!");
120: } catch (EntityLockedException e) {
121: return "locked-site";
122: // throw new PortletException("Brand new site locked?");
123: }
124:
125: return "success";
126: }
127:
128: }
|