mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
78403: Merged EOL (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 75700: ACE-2149: EOL AVM / WCM - Remove most of the AVM and WCM beans, scripts, classes, patches, etc - The Explorer client is very broken for compilation - TODO: Remove all WCM-related functionality, which I thought would be best left to a UI dev I've murdered many of the classes and beans but there's more to do - The repository compiles TODO: Get it running again - TODO: Check if we can wipe the 'deployment' project as well git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@82540 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,245 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.jscript;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.config.JNDIConstants;
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
|
||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||
import org.alfresco.wcm.asset.AssetInfo;
|
||||
import org.alfresco.wcm.sandbox.SandboxService;
|
||||
import org.alfresco.wcm.util.WCMUtil;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Helper to access AVM nodes from a script context.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class AVM extends BaseScopableProcessorExtension
|
||||
{
|
||||
/** Repository Service Registry */
|
||||
private ServiceRegistry services;
|
||||
|
||||
/**
|
||||
* Set the service registry
|
||||
*
|
||||
* @param serviceRegistry the service registry
|
||||
*/
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.services = serviceRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a array of all AVM stores in the system
|
||||
*/
|
||||
public Scriptable getStores()
|
||||
{
|
||||
List<AVMStoreDescriptor> stores = this.services.getAVMService().getStores();
|
||||
Object[] results = new Object[stores.size()];
|
||||
int i=0;
|
||||
for (AVMStoreDescriptor store : stores)
|
||||
{
|
||||
results[i++] = new AVMScriptStore(this.services, store, getScope());
|
||||
}
|
||||
return Context.getCurrentContext().newArray(getScope(), results);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AVM store object for the specified store name
|
||||
*
|
||||
* @param store Store name to lookup
|
||||
*
|
||||
* @return the AVM store object for the specified store or null if not found
|
||||
*/
|
||||
public AVMScriptStore lookupStore(String store)
|
||||
{
|
||||
ParameterCheck.mandatoryString("Store", store);
|
||||
AVMScriptStore avmStore = null;
|
||||
AVMStoreDescriptor descriptor = this.services.getAVMService().getStore(store);
|
||||
if (descriptor != null)
|
||||
{
|
||||
avmStore = new AVMScriptStore(this.services, descriptor, getScope());
|
||||
}
|
||||
return avmStore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AVM Node representing the public store root folder.
|
||||
*
|
||||
* @param store Store name to lookup root folder for
|
||||
*
|
||||
* @return AVM Node representing the public store root folder, or null if not found.
|
||||
*/
|
||||
public AVMNode lookupStoreRoot(String store)
|
||||
{
|
||||
AVMNode rootNode = null;
|
||||
if (store != null && store.length() != 0)
|
||||
{
|
||||
String rootPath = store + ':' + getWebappsFolderPath();
|
||||
AVMNodeDescriptor nodeDesc = this.services.getAVMService().lookup(-1, rootPath);
|
||||
if (nodeDesc != null)
|
||||
{
|
||||
rootNode = new AVMNode(AVMNodeConverter.ToNodeRef(-1, rootPath), this.services, getScope());
|
||||
}
|
||||
}
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AVM Node for the fully qualified path.
|
||||
*
|
||||
* @param path Fully qualified path to node to lookup
|
||||
*
|
||||
* @return AVM Node for the fully qualified path, or null if not found.
|
||||
*/
|
||||
public AVMNode lookupNode(String path)
|
||||
{
|
||||
AVMNode node = null;
|
||||
if (path != null && path.length() != 0)
|
||||
{
|
||||
AVMNodeDescriptor nodeDesc = this.services.getAVMService().lookup(-1, path);
|
||||
if (nodeDesc != null)
|
||||
{
|
||||
node = new AVMNode(AVMNodeConverter.ToNodeRef(-1, path), this.services, getScope());
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of modified items for the specified user sandbox against staging store id
|
||||
* for a specific webapp.
|
||||
*
|
||||
* @param storeId Root Store ID
|
||||
* @param username Username to get modified items for
|
||||
* @param webapp Webapp name to filter by
|
||||
*
|
||||
* @return List of AVMNode objects representing the modified items
|
||||
*/
|
||||
public List<AVMNode> getModifiedItems(String storeId, String username, String webapp)
|
||||
{
|
||||
ParameterCheck.mandatoryString("Store ID", storeId);
|
||||
ParameterCheck.mandatoryString("Username", username);
|
||||
ParameterCheck.mandatoryString("Webapp", webapp);
|
||||
|
||||
SandboxService sbService = this.services.getSandboxService();
|
||||
|
||||
String userStoreId = userSandboxStore(storeId, username);
|
||||
|
||||
// get modified items - not including deleted
|
||||
List<AssetInfo> assets = sbService.listChangedWebApp(userStoreId, webapp, false);
|
||||
|
||||
List<AVMNode> items = new ArrayList<AVMNode>(assets.size());
|
||||
|
||||
for (AssetInfo asset : assets)
|
||||
{
|
||||
// convert each diff/node record into an AVM Node wrapper
|
||||
items.add(new AVMNode(asset.getAvmPath(), -1, this.services, getScope()));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param storeId Store ID to build staging store name for
|
||||
*
|
||||
* @return the Staging Store name for the given store ID
|
||||
*/
|
||||
public static String stagingStore(String storeId)
|
||||
{
|
||||
return WCMUtil.buildStagingStoreName(storeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param storeId Store ID to build sandbox store name for
|
||||
* @param username Username of the sandbox user
|
||||
*
|
||||
* @return the Sandbox Store name for the given store ID and username
|
||||
*/
|
||||
public static String userSandboxStore(String storeId, String username)
|
||||
{
|
||||
return WCMUtil.buildUserMainStoreName(storeId, username);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param storeId Store ID to build preview URL for
|
||||
*
|
||||
* @return the preview URL to the staging store for the specified store ID
|
||||
*/
|
||||
public String websiteStagingUrl(String storeId)
|
||||
{
|
||||
return this.services.getPreviewURIService().getPreviewURI(storeId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param storeId Store ID to build preview URL for
|
||||
* @param username Username to build sandbox preview URL for
|
||||
*
|
||||
* @return the preview URL to the user sandbox for the specified store ID and username
|
||||
*/
|
||||
public String websiteUserSandboxUrl(String storeId, String username)
|
||||
{
|
||||
ParameterCheck.mandatoryString("Store ID", storeId);
|
||||
ParameterCheck.mandatoryString("Username", username);
|
||||
return websiteStagingUrl(userSandboxStore(storeId, username));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param store Store ID of the asset
|
||||
* @param assetPath Store relative path to the asset
|
||||
*
|
||||
* @return the preview URL to the specified store asset
|
||||
*/
|
||||
public String assetUrl(String storeId, String assetPath)
|
||||
{
|
||||
return this.services.getPreviewURIService().getPreviewURI(storeId, assetPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param avmPath Fully qualified AVM path of the asset
|
||||
*
|
||||
* @return the preview URL to the specified asset
|
||||
*/
|
||||
public String assetUrl(String avmPath)
|
||||
{
|
||||
ParameterCheck.mandatoryString("AVM Path", avmPath);
|
||||
String[] s = avmPath.split(":");
|
||||
if (s.length != 2)
|
||||
{
|
||||
throw new IllegalArgumentException("Expected exactly one ':' in " + avmPath);
|
||||
}
|
||||
return assetUrl(s[0], s[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the path to the webapps folder in a standard web store.
|
||||
*/
|
||||
public static String getWebappsFolderPath()
|
||||
{
|
||||
return JNDIConstants.DIR_DEFAULT_WWW_APPBASE;
|
||||
}
|
||||
}
|
@@ -1,366 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.jscript;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.model.WCMModel;
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||
|
||||
/**
|
||||
* Represents a AVM specific node in the Script context. Provides specific implementations
|
||||
* of AVM specific methods such as copy, move, rename etc.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class AVMNode extends ScriptNode
|
||||
{
|
||||
private String path;
|
||||
private int version;
|
||||
private boolean deleted;
|
||||
private AVMNodeDescriptor avmRef;
|
||||
private QName type;
|
||||
|
||||
|
||||
public AVMNode(NodeRef nodeRef, ServiceRegistry services)
|
||||
{
|
||||
this(nodeRef, services, null);
|
||||
}
|
||||
|
||||
public AVMNode(NodeRef nodeRef, ServiceRegistry services, Scriptable scope)
|
||||
{
|
||||
super(nodeRef, services, scope);
|
||||
|
||||
Pair<Integer, String> versionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
|
||||
init(versionPath.getSecond(), versionPath.getFirst());
|
||||
}
|
||||
|
||||
public AVMNode(String path, int version, ServiceRegistry services, Scriptable scope)
|
||||
{
|
||||
super(AVMNodeConverter.ToNodeRef(version, path), services, scope);
|
||||
|
||||
init(path, version);
|
||||
}
|
||||
|
||||
private void init(String path, int version)
|
||||
{
|
||||
this.path = path;
|
||||
this.version = version;
|
||||
AVMNodeDescriptor descriptor = this.services.getAVMService().lookup(version, path, true);
|
||||
if (descriptor == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid node specified: " + this.nodeRef.toString());
|
||||
}
|
||||
this.avmRef = descriptor;
|
||||
this.deleted = descriptor.isDeleted();
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory methods
|
||||
*/
|
||||
@Override
|
||||
public ScriptNode newInstance(NodeRef nodeRef, ServiceRegistry services, Scriptable scope)
|
||||
{
|
||||
return new AVMNode(nodeRef, services, scope);
|
||||
}
|
||||
|
||||
public ScriptNode newInstance(String path, int version, ServiceRegistry services, Scriptable scope)
|
||||
{
|
||||
return new AVMNode(AVMNodeConverter.ToNodeRef(version, path), services, scope);
|
||||
}
|
||||
|
||||
// TODO: changing the 'name' property (either directly using .name or with .properties.name)
|
||||
// invalidates the path and the base noderef instance!
|
||||
// AVMService has a specific rename method - use this and block name property changes?
|
||||
|
||||
/**
|
||||
* @return the full AVM Path to this node
|
||||
*/
|
||||
public String getPath()
|
||||
{
|
||||
return this.path;
|
||||
}
|
||||
|
||||
public int getVersion()
|
||||
{
|
||||
return this.version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AVM path to the parent node
|
||||
*/
|
||||
public String getParentPath()
|
||||
{
|
||||
return AVMNodeConverter.SplitBase(this.path)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return QName type of this node
|
||||
*/
|
||||
public String getType()
|
||||
{
|
||||
if (this.type == null)
|
||||
{
|
||||
if (this.deleted == false)
|
||||
{
|
||||
this.type = this.services.getNodeService().getType(this.nodeRef);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.type = avmRef.isDeletedDirectory() ? WCMModel.TYPE_AVM_FOLDER : WCMModel.TYPE_AVM_CONTENT;
|
||||
}
|
||||
}
|
||||
|
||||
return type.toString();
|
||||
}
|
||||
|
||||
public boolean isDirectory()
|
||||
{
|
||||
return this.avmRef.isDirectory() || this.avmRef.isDeletedDirectory();
|
||||
}
|
||||
|
||||
public boolean isFile()
|
||||
{
|
||||
return this.avmRef.isFile() || this.avmRef.isDeletedFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Helper to return the 'name' property for the node
|
||||
*/
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.avmRef.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the node is currently locked
|
||||
*/
|
||||
public boolean getIsLocked()
|
||||
{
|
||||
String lockOwner = this.services.getAVMLockingService().getLockOwner(
|
||||
getWebProject(), path.substring(path.indexOf("/")));
|
||||
return (lockOwner != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this node is locked and the current user is the lock owner
|
||||
*/
|
||||
public boolean isLockOwner()
|
||||
{
|
||||
String lockOwner = this.services.getAVMLockingService().getLockOwner(
|
||||
getWebProject(), path.substring(path.indexOf("/")));
|
||||
if (lockOwner != null)
|
||||
{
|
||||
return lockOwner.equals(this.services.getAuthenticationService().getCurrentUserName());
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this user can perform operations on the node when locked.
|
||||
* This is true if the item is either unlocked, or locked and the current user is the lock owner,
|
||||
* or locked and the current user has Content Manager role in the associated web project.
|
||||
*/
|
||||
public boolean hasLockAccess()
|
||||
{
|
||||
return this.services.getAVMLockingService().hasAccess(
|
||||
getWebProject(), path, this.services.getAuthenticationService().getCurrentUserName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy this Node into a new parent destination.
|
||||
*
|
||||
* @param destination Parent node for the copy
|
||||
*
|
||||
* @return the copy of this node
|
||||
*/
|
||||
@Override
|
||||
public ScriptNode copy(ScriptNode destination)
|
||||
{
|
||||
ParameterCheck.mandatory("Destination Node", destination);
|
||||
|
||||
return getCrossRepositoryCopyHelper().copy(this, destination, getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy this Node into a new parent destination.
|
||||
*
|
||||
* @param destination Parent path for the copy
|
||||
*
|
||||
* @return the copy of this node
|
||||
*/
|
||||
public ScriptNode copy(String destination)
|
||||
{
|
||||
ParameterCheck.mandatoryString("Destination Path", destination);
|
||||
|
||||
this.services.getAVMService().copy(this.version, this.path, destination, getName());
|
||||
return newInstance(
|
||||
AVMNodeConverter.ToNodeRef(-1, AVMNodeConverter.ExtendAVMPath(destination, getName())),
|
||||
this.services, this.scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move this Node to a new parent destination node.
|
||||
*
|
||||
* @param destination Node
|
||||
*
|
||||
* @return true on successful move, false on failure to move.
|
||||
*/
|
||||
@Override
|
||||
public boolean move(ScriptNode destination)
|
||||
{
|
||||
ParameterCheck.mandatory("Destination Node", destination);
|
||||
|
||||
boolean success = false;
|
||||
|
||||
if (destination instanceof AVMNode)
|
||||
{
|
||||
success = move(((AVMNode)destination).getPath());
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move this Node to a new parent destination path.
|
||||
*
|
||||
* @param destination Path
|
||||
*
|
||||
* @return true on successful move, false on failure to move.
|
||||
*/
|
||||
public boolean move(String destination)
|
||||
{
|
||||
ParameterCheck.mandatoryString("Destination Path", destination);
|
||||
|
||||
boolean success = false;
|
||||
|
||||
if (destination != null && destination.length() != 0)
|
||||
{
|
||||
AVMNode parent = (AVMNode)this.getParent();
|
||||
this.services.getAVMService().rename(
|
||||
parent.getPath(), getName(), destination, getName());
|
||||
|
||||
reset(AVMNodeConverter.ExtendAVMPath(destination, getName()));
|
||||
|
||||
success = true;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this node to the specified name
|
||||
*
|
||||
* @param name New name for the node
|
||||
*
|
||||
* @return true on success, false otherwise
|
||||
*/
|
||||
public boolean rename(String name)
|
||||
{
|
||||
ParameterCheck.mandatoryString("Destination name", name);
|
||||
|
||||
boolean success = false;
|
||||
|
||||
if (name != null && name.length() != 0)
|
||||
{
|
||||
String parentPath = ((AVMNode)this.getParent()).getPath();
|
||||
this.services.getAVMService().rename(
|
||||
parentPath, getName(), parentPath, name);
|
||||
|
||||
reset(AVMNodeConverter.ExtendAVMPath(parentPath, name));
|
||||
|
||||
success = true;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The list of aspects applied to this node
|
||||
*/
|
||||
@Override
|
||||
public Set<QName> getAspectsSet()
|
||||
{
|
||||
if (this.aspects == null)
|
||||
{
|
||||
this.aspects = this.services.getAVMService().getAspects(this.version, this.path);
|
||||
}
|
||||
|
||||
return this.aspects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the Node cached state
|
||||
*/
|
||||
private void reset(String path)
|
||||
{
|
||||
super.reset();
|
||||
this.path = path;
|
||||
this.nodeRef = AVMNodeConverter.ToNodeRef(this.version, path);
|
||||
this.id = nodeRef.getId();
|
||||
AVMNodeDescriptor descriptor = this.services.getAVMService().lookup(this.version, path, true);
|
||||
if (descriptor == null)
|
||||
{
|
||||
throw new IllegalArgumentException("Invalid node specified: " + nodeRef.toString());
|
||||
}
|
||||
this.avmRef = descriptor;
|
||||
this.deleted = descriptor.isDeleted();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the WebProject identifier for the current path
|
||||
*/
|
||||
private String getWebProject()
|
||||
{
|
||||
String webProject = this.path.substring(0, this.path.indexOf(':'));
|
||||
int index = webProject.indexOf("--");
|
||||
if (index != -1)
|
||||
{
|
||||
webProject = webProject.substring(0, index);
|
||||
}
|
||||
return webProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if (this.services.getAVMService().lookup(version, this.path) != null)
|
||||
{
|
||||
return "AVM Path: " + getPath() +
|
||||
"\nNode Type: " + getType() +
|
||||
"\nNode Properties: " + this.getProperties().size() +
|
||||
"\nNode Aspects: " + this.getAspectsSet().toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Node no longer exists: " + nodeRef;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.jscript;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.repo.template.AVM;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.ResultSetRow;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public class AVMScriptStore implements Serializable
|
||||
{
|
||||
private ServiceRegistry services;
|
||||
private AVMStoreDescriptor descriptor;
|
||||
private Scriptable scope;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param services
|
||||
* @param store Store descriptor this object represents
|
||||
* @param scope
|
||||
*/
|
||||
public AVMScriptStore(ServiceRegistry services, AVMStoreDescriptor store, Scriptable scope)
|
||||
{
|
||||
this.descriptor = store;
|
||||
this.services = services;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Store name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return this.descriptor.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Store name
|
||||
*/
|
||||
public String getId()
|
||||
{
|
||||
return this.descriptor.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User who created the store
|
||||
*/
|
||||
public String getCreator()
|
||||
{
|
||||
return this.descriptor.getCreator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Creation date of the store
|
||||
*/
|
||||
public Serializable getCreatedDate()
|
||||
{
|
||||
return new ValueConverter().convertValueForScript(
|
||||
this.services, this.scope, null, new Date(this.descriptor.getCreateDate()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the root node of all webapps in the store
|
||||
*/
|
||||
public AVMNode lookupRoot()
|
||||
{
|
||||
AVMNode rootNode = null;
|
||||
String rootPath = this.descriptor.getName() + ':' + AVM.getWebappsFolderPath();
|
||||
AVMNodeDescriptor nodeDesc = this.services.getAVMService().lookup(-1, rootPath);
|
||||
if (nodeDesc != null)
|
||||
{
|
||||
rootNode = new AVMNode(AVMNodeConverter.ToNodeRef(-1, rootPath), this.services, this.scope);
|
||||
}
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup a node in the store, the path is assumed to be related to the webapps folder root.
|
||||
* Therefore a valid path would be "/ROOT/WEB-INF/lib/web.xml".
|
||||
*
|
||||
* @param path Relative to the webapps folder root path for this store.
|
||||
*
|
||||
* @return node if found, null otherwise.
|
||||
*/
|
||||
public AVMNode lookupNode(String path)
|
||||
{
|
||||
AVMNode node = null;
|
||||
if (path != null && path.length() != 0)
|
||||
{
|
||||
if (path.charAt(0) != '/')
|
||||
{
|
||||
path = '/' + path;
|
||||
}
|
||||
path = this.descriptor.getName() + ':' + AVM.getWebappsFolderPath() + path;
|
||||
AVMNodeDescriptor nodeDesc = this.services.getAVMService().lookup(-1, path);
|
||||
if (nodeDesc != null)
|
||||
{
|
||||
node = new AVMNode(path, -1, this.services, this.scope);
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a lucene query against this store.
|
||||
*
|
||||
* @param query Lucene
|
||||
*
|
||||
* @return array of AVM node object results - empty array if no results found
|
||||
*/
|
||||
public Scriptable luceneSearch(String query)
|
||||
{
|
||||
Object[] nodes = null;
|
||||
|
||||
// perform the search against the repo
|
||||
ResultSet results = null;
|
||||
try
|
||||
{
|
||||
results = this.services.getSearchService().query(
|
||||
new StoreRef(StoreRef.PROTOCOL_AVM, this.descriptor.getName()),
|
||||
SearchService.LANGUAGE_LUCENE,
|
||||
query);
|
||||
|
||||
if (results.length() != 0)
|
||||
{
|
||||
nodes = new Object[results.length()];
|
||||
for (int i=0; i<results.length(); i++)
|
||||
{
|
||||
ResultSetRow row = results.getRow(i);
|
||||
nodes[i] = new AVMNode(row.getNodeRef(), this.services, this.scope);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable err)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Failed to execute search: " + query, err);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (results != null)
|
||||
{
|
||||
results.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (nodes != null)
|
||||
{
|
||||
return Context.getCurrentContext().newArray(this.scope, nodes);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Context.getCurrentContext().newArray(this.scope, 0);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.jscript;
|
||||
|
||||
import org.alfresco.repo.avm.AVMNodeConverter;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.springframework.extensions.surf.util.ParameterCheck;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Helper bean to access Cross Repository copy services from a script context.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class CrossRepositoryCopy extends BaseScopableProcessorExtension
|
||||
{
|
||||
public final static String BEAN_NAME = "crossCopyScript";
|
||||
|
||||
/** Service registry */
|
||||
private ServiceRegistry services;
|
||||
|
||||
/**
|
||||
* Set the service registry
|
||||
*
|
||||
* @param services the service registry
|
||||
*/
|
||||
public void setServiceRegistry(ServiceRegistry services)
|
||||
{
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a copy of a source node to the specified parent destination node. The name will
|
||||
* be applied to the destination node copy.
|
||||
* <p>
|
||||
* Inter-store copy operations between Workspace and AVM and visa-versa are supported.
|
||||
*
|
||||
* @param src Source node instance
|
||||
* @param dest Destination parent node instance
|
||||
* @param name Name of the node copy
|
||||
*
|
||||
* @return node representing the copy if successful, null on unsupported store type.
|
||||
*
|
||||
* @throws org.alfresco.error.AlfrescoRuntimeException on copy error
|
||||
*/
|
||||
public ScriptNode copy(ScriptNode src, ScriptNode dest, String name)
|
||||
{
|
||||
ParameterCheck.mandatory("Node source", src);
|
||||
ParameterCheck.mandatory("Node destination", dest);
|
||||
ParameterCheck.mandatory("Node destination name", name);
|
||||
|
||||
ScriptNode result = null;
|
||||
|
||||
// perform the copy operation using the repository service
|
||||
this.services.getCrossRepositoryCopyService().copy(src.getNodeRef(), dest.getNodeRef(), name);
|
||||
|
||||
// if we get here then copy succeeded - retrieve the new node reference
|
||||
if (dest.getNodeRef().getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_AVM))
|
||||
{
|
||||
Pair<Integer, String> versionPath = AVMNodeConverter.ToAVMVersionPath(dest.getNodeRef());
|
||||
String destPath = AVMNodeConverter.ExtendAVMPath(versionPath.getSecond(), name);
|
||||
AVMNodeDescriptor node = this.services.getAVMService().lookup(-1, destPath);
|
||||
if (node != null)
|
||||
{
|
||||
result = ((AVMNode)dest).newInstance(destPath, -1, this.services, getScope());
|
||||
}
|
||||
}
|
||||
else if (dest.getNodeRef().getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_WORKSPACE))
|
||||
{
|
||||
result = dest.childByNamePath(name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -85,7 +85,6 @@ import org.alfresco.service.cmr.repository.NoTransformerException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.Path;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter;
|
||||
@@ -2033,19 +2032,9 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider
|
||||
{
|
||||
ParameterCheck.mandatory("Destination Node", destination);
|
||||
|
||||
ScriptNode copy = null;
|
||||
|
||||
if (destination.getNodeRef().getStoreRef().getProtocol().equals(StoreRef.PROTOCOL_WORKSPACE))
|
||||
{
|
||||
NodeRef copyRef = this.services.getCopyService().copyAndRename(this.nodeRef, destination.getNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS, null, deepCopy);
|
||||
copy = newInstance(copyRef, this.services, this.scope);
|
||||
}
|
||||
else
|
||||
{
|
||||
// NOTE: the deepCopy flag is not respected for this copy mechanism
|
||||
copy = getCrossRepositoryCopyHelper().copy(this, destination, getName());
|
||||
}
|
||||
NodeRef copyRef = this.services.getCopyService().copyAndRename(this.nodeRef, destination.getNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS, null, deepCopy);
|
||||
ScriptNode copy = newInstance(copyRef, this.services, this.scope);
|
||||
|
||||
return copy;
|
||||
}
|
||||
@@ -3502,15 +3491,6 @@ public class ScriptNode implements Scopeable, NamespacePrefixResolverProvider
|
||||
this.siteNameResolved = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return helper object to perform cross repository copy of JavaScript Node objects
|
||||
*/
|
||||
protected CrossRepositoryCopy getCrossRepositoryCopyHelper()
|
||||
{
|
||||
return (CrossRepositoryCopy)this.services.getService(
|
||||
QName.createQName("", CrossRepositoryCopy.BEAN_NAME));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list or a single Node from executing an xpath against the parent Node.
|
||||
*
|
||||
|
Reference in New Issue
Block a user