mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Initial version of a "copy to web project" action
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5387 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -111,7 +111,12 @@ public class RunActionWizard extends BaseActionWizard
|
||||
this.actions = new ArrayList<SelectItem>();
|
||||
for (ActionDefinition ruleActionDef : ruleActions)
|
||||
{
|
||||
this.actions.add(new SelectItem(ruleActionDef.getName(), ruleActionDef.getTitle()));
|
||||
String title = ruleActionDef.getTitle();
|
||||
if (title == null || title.length() == 0)
|
||||
{
|
||||
title = ruleActionDef.getName();
|
||||
}
|
||||
this.actions.add(new SelectItem(ruleActionDef.getName(), title));
|
||||
}
|
||||
|
||||
// make sure the list is sorted by the label
|
||||
|
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2007 Alfresco Software Limited.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
* As a special exception to the terms and conditions of version 2.0 of
|
||||
* the GPL, you may redistribute this Program in connection with Free/Libre
|
||||
* and Open Source Software ("FLOSS") applications as described in Alfresco's
|
||||
* FLOSS exception. You should have recieved a copy of the text describing
|
||||
* the FLOSS exception, and it is also available here:
|
||||
* http://www.alfresco.com/legal/licensing"
|
||||
*/
|
||||
package org.alfresco.web.bean.actions.handlers;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.faces.context.FacesContext;
|
||||
|
||||
import org.alfresco.repo.action.executer.CopyToWebProjectActionExecuter;
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.bean.wcm.AVMConstants;
|
||||
import org.alfresco.web.bean.wcm.WebProject;
|
||||
import org.alfresco.web.bean.wizard.IWizardBean;
|
||||
|
||||
/**
|
||||
* Action handler implementation for the "copy-to-web-project" action.
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class CopyToWebProjectHandler extends BaseActionHandler
|
||||
{
|
||||
public String getJSPPath()
|
||||
{
|
||||
return getJSPPath(CopyToWebProjectActionExecuter.NAME);
|
||||
}
|
||||
|
||||
public void prepareForSave(Map<String, Serializable> actionProps,
|
||||
Map<String, Serializable> repoProps)
|
||||
{
|
||||
// get the destination selected by the user
|
||||
NodeRef destNodeRef = (NodeRef)actionProps.get(PROP_DESTINATION);
|
||||
|
||||
// if the destination is a workspace node the use the root of the
|
||||
// webapp for the web project
|
||||
if (destNodeRef.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_WORKSPACE))
|
||||
{
|
||||
WebProject webProject = new WebProject(destNodeRef);
|
||||
String storeName = AVMConstants.buildUserMainStoreName(webProject.getStoreId(),
|
||||
Application.getCurrentUser(FacesContext.getCurrentInstance()).getUserName());
|
||||
|
||||
String rootPath = AVMConstants.buildStoreWebappPath(storeName, AVMConstants.DIR_ROOT);
|
||||
destNodeRef = AVMNodeConverter.ToNodeRef(-1, rootPath);
|
||||
}
|
||||
|
||||
// setup the destination parameter
|
||||
repoProps.put(CopyToWebProjectActionExecuter.PARAM_DESTINATION_FOLDER, destNodeRef);
|
||||
}
|
||||
|
||||
public void prepareForEdit(Map<String, Serializable> actionProps,
|
||||
Map<String, Serializable> repoProps)
|
||||
{
|
||||
NodeRef destNodeRef = (NodeRef)repoProps.get(CopyToWebProjectActionExecuter.PARAM_DESTINATION_FOLDER);
|
||||
actionProps.put(PROP_DESTINATION, destNodeRef);
|
||||
}
|
||||
|
||||
public String generateSummary(FacesContext context, IWizardBean wizard,
|
||||
Map<String, Serializable> actionProps)
|
||||
{
|
||||
NodeRef dest = (NodeRef)actionProps.get(PROP_DESTINATION);
|
||||
|
||||
String folder = "/";
|
||||
String webProject = "?";
|
||||
|
||||
if (dest.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM))
|
||||
{
|
||||
// get the destination path
|
||||
Pair<Integer, String> avmNode = AVMNodeConverter.ToAVMVersionPath(dest);
|
||||
String avmPath = avmNode.getSecond();
|
||||
folder = avmPath.substring(avmPath.indexOf(AVMConstants.DIR_ROOT)+4);
|
||||
|
||||
// get the destination web project name
|
||||
NodeRef webProjectNode = AVMConstants.getWebProjectNode(avmPath);
|
||||
webProject = Repository.getNameForNode(
|
||||
Repository.getServiceRegistry(context).getNodeService(), webProjectNode);
|
||||
}
|
||||
else if (dest.getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM))
|
||||
{
|
||||
// get the destination web project name
|
||||
webProject = Repository.getNameForNode(
|
||||
Repository.getServiceRegistry(context).getNodeService(), dest);
|
||||
}
|
||||
|
||||
return MessageFormat.format(Application.getMessage(context, "action_copy_to_web_project_folder"),
|
||||
new Object[] {folder, webProject});
|
||||
}
|
||||
|
||||
}
|
@@ -25,6 +25,7 @@
|
||||
package org.alfresco.web.bean.wcm;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -38,6 +39,11 @@ import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.repo.domain.PropertyValue;
|
||||
import org.alfresco.service.cmr.avm.AVMNotFoundException;
|
||||
import org.alfresco.service.cmr.avm.AVMService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.util.VirtServerUtils;
|
||||
@@ -224,8 +230,8 @@ public final class AVMConstants
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the corresponding path in the preview store name if this is a path in
|
||||
* a main store.
|
||||
* Returns the corresponding path in the main store name if this is a path in
|
||||
* a preview store.
|
||||
*
|
||||
* @param avmPath an avm path within the main store.
|
||||
*
|
||||
@@ -625,6 +631,51 @@ public final class AVMConstants
|
||||
final Matcher m = SANDBOX_RELATIVE_PATH_PATTERN.matcher(absoluteAVMPath);
|
||||
return m.matches() && m.group(1).length() != 0 ? m.group(1) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the NodeRef that represents the given avm path
|
||||
*
|
||||
* @param absoluteAVMPath The path from which to determine the Web Project
|
||||
* @return The NodeRef representing the Web Project the path is from or null
|
||||
* if it could not be determined
|
||||
*/
|
||||
public static NodeRef getWebProjectNode(final String absoluteAVMPath)
|
||||
{
|
||||
// get services
|
||||
FacesContext fc = FacesContext.getCurrentInstance();
|
||||
SearchService searchService = Repository.getServiceRegistry(fc).getSearchService();
|
||||
|
||||
// get the store name
|
||||
String storeName = AVMConstants.getStoreName(absoluteAVMPath);
|
||||
String storeId = AVMConstants.getStoreId(storeName);
|
||||
|
||||
// construct the query
|
||||
String path = Application.getRootPath(fc) + "/" + Application.getWebsitesFolderName(fc) + "/*";
|
||||
String query = "PATH:\"/" + path + "\" AND @wca\\:avmstore:\"" + storeId + "\"";
|
||||
|
||||
NodeRef webProjectNode = null;
|
||||
ResultSet results = null;
|
||||
try
|
||||
{
|
||||
// execute the query
|
||||
results = searchService.query(Repository.getStoreRef(),
|
||||
SearchService.LANGUAGE_LUCENE, query);
|
||||
|
||||
if (results.length() == 1)
|
||||
{
|
||||
webProjectNode = results.getNodeRef(0);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (results != null)
|
||||
{
|
||||
results.close();
|
||||
}
|
||||
}
|
||||
|
||||
return webProjectNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates all directories for a path if they do not already exist.
|
||||
|
Reference in New Issue
Block a user