Index: site-manage-link-helper/src/java/org/sakaiproject/site/tool/LinkAction.java =================================================================== --- site-manage-link-helper/src/java/org/sakaiproject/site/tool/LinkAction.java (revision 0) +++ site-manage-link-helper/src/java/org/sakaiproject/site/tool/LinkAction.java (revision 66960) @@ -0,0 +1,319 @@ +/********************************************************************************** + * $URL$ + * $Id$ + *********************************************************************************** + * + * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008 The Sakai Foundation + * + * Licensed under the Educational Community License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.osedu.org/licenses/ECL-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + **********************************************************************************/ + +package org.sakaiproject.site.tool; + +import java.io.IOException; + +import java.util.Properties; +import java.util.Iterator; +import java.util.List; +import java.util.ArrayList; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.sakaiproject.authz.api.AuthzGroup; +import org.sakaiproject.authz.api.GroupNotDefinedException; +import org.sakaiproject.authz.api.Role; +import org.sakaiproject.authz.cover.AuthzGroupService; +import org.sakaiproject.cheftool.Context; +import org.sakaiproject.cheftool.JetspeedRunData; +import org.sakaiproject.cheftool.RunData; +import org.sakaiproject.cheftool.VelocityPortlet; +import org.sakaiproject.cheftool.VelocityPortletPaneledAction; +import org.sakaiproject.component.cover.ServerConfigurationService; +import org.sakaiproject.entity.api.Reference; +import org.sakaiproject.entity.cover.EntityManager; +import org.sakaiproject.entity.api.ResourcePropertiesEdit; +import org.sakaiproject.event.api.SessionState; +import org.sakaiproject.exception.IdUnusedException; +import org.sakaiproject.site.api.Site; +import org.sakaiproject.site.api.SitePage; +import org.sakaiproject.site.api.SiteService.SortType; +import org.sakaiproject.site.api.ToolConfiguration; +import org.sakaiproject.site.cover.SiteService; +import org.sakaiproject.tool.api.Tool; +import org.sakaiproject.tool.api.ToolException; +import org.sakaiproject.tool.api.ToolSession; +import org.sakaiproject.tool.api.Placement; +import org.sakaiproject.tool.api.Session; +import org.sakaiproject.tool.api.ToolSession; +import org.sakaiproject.tool.cover.SessionManager; +import org.sakaiproject.tool.cover.ToolManager; +import org.sakaiproject.util.ResourceLoader; +import org.sakaiproject.util.StringUtil; +import org.sakaiproject.util.ParameterParser; +import org.sakaiproject.user.api.User; +import org.sakaiproject.user.api.UserNotDefinedException; +import org.sakaiproject.user.cover.UserDirectoryService; + +/** + *
+ * LinkAction allows site owners to link a site to a parent. + *
+ */ +public class LinkAction extends VelocityPortletPaneledAction +{ + /** Resource bundle using current language locale */ + protected static ResourceLoader rb = new ResourceLoader("link"); + + private static final Log logger = LogFactory.getLog(LinkAction.class); + + private static final String LINK_MODE = "link_mode"; + private static final String MODE_DONE = "helper.done"; + + /** + * Get the current site page our current tool is placed on. + * + * @return The site page id on which our tool is placed. + */ + protected String getCurrentSitePageId() + { + ToolSession ts = SessionManager.getCurrentToolSession(); + if (ts != null) + { + ToolConfiguration tool = SiteService.findTool(ts.getPlacementId()); + if (tool != null) + { + return tool.getPageId(); + } + } + + return null; + } + + /** + * Get the current site id + * @throws SessionDataException + * @return Site id (GUID) + */ + private String getSiteId() throws SessionDataException + { + Placement placement = ToolManager.getCurrentPlacement(); + + if (placement == null) + { + throw new SessionDataException("No current tool placement"); + } + return placement.getContext(); + } + + /** + * Get a site property by name + * + * @param name Property name + * @throws IdUnusedException, SessionDataException + * @return The property value (null if none) + */ + private String getSiteProperty(String name) throws IdUnusedException, SessionDataException + { + Site site; + + site = SiteService.getSite(getSiteId()); + return site.getProperties().getProperty(name); + } + + /** + * Setup the velocity context and choose the template for the response. + */ + public String buildMainPanelContext(VelocityPortlet portlet, Context context, RunData rundata, SessionState state) + { + // set the resource bundle with our strings + context.put("tlang", rb); + + context.put("doSave", BUTTON + "doSave"); + context.put("doCancel", BUTTON + "doCancel"); + context.put("doRemove", BUTTON + "doRemove"); + try + { + Site site; + String siteId = getSiteId(); + + site = SiteService.getSite(siteId); + String parentId = site.getProperties().getProperty("sakai:parent-id"); + context.put("currentSite", site); + if ( parentId != null ) { + // Make sure parent site exists before we show it. + // If the parent site does not exist, clear the property + try { + Site parentSite = SiteService.getSite(parentId); + context.put("parentId", parentId); + context.put("parentTitle", parentSite.getTitle()); + return "sakai_link"; + } catch (Exception e) { + addAlert(state,rb.getString("alert.parent.removed")+" "+parentId); + ResourcePropertiesEdit rpe = site.getPropertiesEdit(); + rpe.removeProperty("sakai:parent-id"); + SiteService.save(site); + } + } + + // Give the user a list of sites to select as parent + ListCurrent Parent Site: $parentTitle ($parentId)
+ +#else +$tlang.getString('java.selectparent')
+ +#end +