mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Merged V1.4 to HEAD
svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@3987 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4133 . Removed LicenseComponent reference from projects\repository\source\java\org\alfresco\repo\descriptor\DescriptorServiceImpl.java git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4135 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -28,32 +28,32 @@ import org.alfresco.service.cmr.action.ParameterDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import org.mozilla.javascript.Wrapper;
|
||||
|
||||
/**
|
||||
* Scripted Action service for describing and executing actions against Nodes.
|
||||
*
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public final class Actions implements Scopeable
|
||||
{
|
||||
/** Repository Service Registry */
|
||||
private ServiceRegistry services;
|
||||
|
||||
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param services repository service registry
|
||||
* @param services
|
||||
* repository service registry
|
||||
*/
|
||||
public Actions(ServiceRegistry services)
|
||||
{
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
@@ -61,11 +61,11 @@ public final class Actions implements Scopeable
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the list of registered action names
|
||||
*
|
||||
* @return the registered action names
|
||||
* @return the registered action names
|
||||
*/
|
||||
public String[] getRegistered()
|
||||
{
|
||||
@@ -79,17 +79,18 @@ public final class Actions implements Scopeable
|
||||
}
|
||||
return registered;
|
||||
}
|
||||
|
||||
|
||||
public String[] jsGet_registered()
|
||||
{
|
||||
return getRegistered();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create an Action
|
||||
*
|
||||
* @param actionName the action name
|
||||
* @return the action
|
||||
* @param actionName
|
||||
* the action name
|
||||
* @return the action
|
||||
*/
|
||||
public ScriptAction create(String actionName)
|
||||
{
|
||||
@@ -104,8 +105,7 @@ public final class Actions implements Scopeable
|
||||
}
|
||||
return scriptAction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Scriptable Action
|
||||
*
|
||||
@@ -114,23 +114,25 @@ public final class Actions implements Scopeable
|
||||
public final class ScriptAction implements Serializable, Scopeable
|
||||
{
|
||||
private static final long serialVersionUID = 5794161358406531996L;
|
||||
|
||||
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
private Scriptable scope;
|
||||
|
||||
/** Converter with knowledge of action parameter values */
|
||||
private ActionValueConverter converter;
|
||||
|
||||
|
||||
/** Action state */
|
||||
private Action action;
|
||||
|
||||
private ActionDefinition actionDef;
|
||||
|
||||
private ScriptableParameterMap<String, Serializable> parameters = null;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*
|
||||
* @param action Alfresco action
|
||||
* @param action
|
||||
* Alfresco action
|
||||
*/
|
||||
public ScriptAction(Action action, ActionDefinition actionDef)
|
||||
{
|
||||
@@ -138,7 +140,7 @@ public final class Actions implements Scopeable
|
||||
this.actionDef = actionDef;
|
||||
this.converter = new ActionValueConverter();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
@@ -146,28 +148,25 @@ public final class Actions implements Scopeable
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the action name
|
||||
*
|
||||
* @return action name
|
||||
* @return action name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return this.actionDef.getName();
|
||||
}
|
||||
|
||||
|
||||
public String jsGet_name()
|
||||
{
|
||||
return getName();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return all the properties known about this node.
|
||||
*
|
||||
* The Map returned implements the Scriptable interface to allow access to the properties via
|
||||
* JavaScript associative array access. This means properties of a node can be access thus:
|
||||
* <code>node.properties["name"]</code>
|
||||
* Return all the properties known about this node. The Map returned implements the Scriptable interface to allow access to the properties via JavaScript associative array
|
||||
* access. This means properties of a node can be access thus: <code>node.properties["name"]</code>
|
||||
*
|
||||
* @return Map of properties for this Node.
|
||||
*/
|
||||
@@ -187,17 +186,18 @@ public final class Actions implements Scopeable
|
||||
this.parameters.setModified(false);
|
||||
}
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Map<String, Serializable> jsGet_parameters()
|
||||
{
|
||||
return getParameters();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute action
|
||||
*
|
||||
* @param node the node to execute action upon
|
||||
* @param node
|
||||
* the node to execute action upon
|
||||
*/
|
||||
@SuppressWarnings("synthetic-access")
|
||||
public void execute(Node node)
|
||||
@@ -206,7 +206,7 @@ public final class Actions implements Scopeable
|
||||
{
|
||||
Map<String, Serializable> actionParams = action.getParameterValues();
|
||||
actionParams.clear();
|
||||
|
||||
|
||||
for (Map.Entry<String, Serializable> entry : this.parameters.entrySet())
|
||||
{
|
||||
// perform the conversion from script wrapper object to repo serializable values
|
||||
@@ -217,7 +217,7 @@ public final class Actions implements Scopeable
|
||||
}
|
||||
services.getActionService().executeAction(action, node.getNodeRef());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Value converter with specific knowledge of action parameters
|
||||
*
|
||||
@@ -227,10 +227,12 @@ public final class Actions implements Scopeable
|
||||
{
|
||||
/**
|
||||
* Convert Action Parameter for Script usage
|
||||
*
|
||||
* @param paramName parameter name
|
||||
* @param value value to convert
|
||||
* @return converted value
|
||||
*
|
||||
* @param paramName
|
||||
* parameter name
|
||||
* @param value
|
||||
* value to convert
|
||||
* @return converted value
|
||||
*/
|
||||
@SuppressWarnings("synthetic-access")
|
||||
public Serializable convertActionParamForScript(String paramName, Serializable value)
|
||||
@@ -238,7 +240,7 @@ public final class Actions implements Scopeable
|
||||
ParameterDefinition paramDef = actionDef.getParameterDefintion(paramName);
|
||||
if (paramDef != null && paramDef.getType().equals(DataTypeDefinition.QNAME))
|
||||
{
|
||||
return ((QName)value).toPrefixString(services.getNamespaceService());
|
||||
return ((QName) value).toPrefixString(services.getNamespaceService());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -249,17 +251,45 @@ public final class Actions implements Scopeable
|
||||
/**
|
||||
* Convert Action Parameter for Java usage
|
||||
*
|
||||
* @param paramName parameter name
|
||||
* @param value value to convert
|
||||
* @return converted value
|
||||
* @param paramName
|
||||
* parameter name
|
||||
* @param value
|
||||
* value to convert
|
||||
* @return converted value
|
||||
*/
|
||||
@SuppressWarnings("synthetic-access")
|
||||
public Serializable convertActionParamForRepo(String paramName, Serializable value)
|
||||
{
|
||||
ParameterDefinition paramDef = actionDef.getParameterDefintion(paramName);
|
||||
|
||||
if (paramDef != null && paramDef.getType().equals(DataTypeDefinition.QNAME))
|
||||
{
|
||||
return QName.createQName((String)value, services.getNamespaceService());
|
||||
if (value instanceof Wrapper)
|
||||
{
|
||||
// unwrap a Java object from a JavaScript wrapper
|
||||
// recursively call this method to convert the unwrapped value
|
||||
return convertActionParamForRepo(paramName, (Serializable) ((Wrapper) value).unwrap());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value instanceof String)
|
||||
{
|
||||
String stringQName = (String) value;
|
||||
if (stringQName.startsWith("{"))
|
||||
{
|
||||
return QName.createQName(stringQName);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return QName.createQName(stringQName, services.getNamespaceService());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -269,39 +299,41 @@ public final class Actions implements Scopeable
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scripted Parameter map with modified flag.
|
||||
*
|
||||
*
|
||||
* @author davidc
|
||||
*/
|
||||
public static final class ScriptableParameterMap<K,V> extends ScriptableHashMap<K,V>
|
||||
public static final class ScriptableParameterMap<K, V> extends ScriptableHashMap<K, V>
|
||||
{
|
||||
private static final long serialVersionUID = 574661815973241554L;
|
||||
private boolean modified = false;
|
||||
|
||||
private boolean modified = false;
|
||||
|
||||
/**
|
||||
* Is this a modified parameter map?
|
||||
*
|
||||
* @return true => modified
|
||||
* @return true => modified
|
||||
*/
|
||||
/*package*/ boolean isModified()
|
||||
/* package */boolean isModified()
|
||||
{
|
||||
return modified;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set explicitly whether this map is modified
|
||||
*
|
||||
* @param modified true => modified, false => not modified
|
||||
* @param modified
|
||||
* true => modified, false => not modified
|
||||
*/
|
||||
/*package*/ void setModified(boolean modified)
|
||||
/* package */void setModified(boolean modified)
|
||||
{
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.mozilla.javascript.Scriptable#getClassName()
|
||||
*/
|
||||
@Override
|
||||
@@ -310,7 +342,9 @@ public final class Actions implements Scopeable
|
||||
return "ScriptableParameterMap";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.mozilla.javascript.Scriptable#delete(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
@@ -320,7 +354,9 @@ public final class Actions implements Scopeable
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.mozilla.javascript.Scriptable#put(java.lang.String, org.mozilla.javascript.Scriptable, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
@@ -330,5 +366,5 @@ public final class Actions implements Scopeable
|
||||
setModified(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
206
source/java/org/alfresco/repo/jscript/CategoryNode.java
Normal file
206
source/java/org/alfresco/repo/jscript/CategoryNode.java
Normal file
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.repo.jscript;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.search.CategoryService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Category Nodes from the classification helper have special support.
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public class CategoryNode extends Node
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param nodeRef
|
||||
* @param services
|
||||
* @param resolver
|
||||
*/
|
||||
public CategoryNode(NodeRef nodeRef, ServiceRegistry services, TemplateImageResolver resolver)
|
||||
{
|
||||
super(nodeRef, services, resolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param nodeRef
|
||||
* @param services
|
||||
* @param resolver
|
||||
* @param scope
|
||||
*/
|
||||
public CategoryNode(NodeRef nodeRef, ServiceRegistry services, TemplateImageResolver resolver, Scriptable scope)
|
||||
{
|
||||
super(nodeRef, services, resolver, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all the members of a category
|
||||
*/
|
||||
public Node[] getCategoryMembers()
|
||||
{
|
||||
return buildNodes(services.getCategoryService().getChildren(getNodeRef(), CategoryService.Mode.MEMBERS, CategoryService.Depth.ANY));
|
||||
}
|
||||
|
||||
public Node[] jsGet_categoryMembers()
|
||||
{
|
||||
return getCategoryMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all the subcategories of a category
|
||||
*/
|
||||
public CategoryNode[] getSubCategories()
|
||||
{
|
||||
return buildCategoryNodes(services.getCategoryService().getChildren(getNodeRef(), CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.ANY));
|
||||
}
|
||||
|
||||
public CategoryNode[] jsGet_subCategories()
|
||||
{
|
||||
return getSubCategories();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return members and subcategories of a category
|
||||
*/
|
||||
public Node[] getMembersAndSubCategories()
|
||||
{
|
||||
return buildMixedNodes(services.getCategoryService().getChildren(getNodeRef(), CategoryService.Mode.ALL, CategoryService.Depth.ANY));
|
||||
}
|
||||
|
||||
public Node[] jsGet_membersAndSubCategories()
|
||||
{
|
||||
return getMembersAndSubCategories();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all the immediate member of a category
|
||||
*/
|
||||
public Node[] getImmediateCategoryMembers()
|
||||
{
|
||||
return buildNodes(services.getCategoryService().getChildren(getNodeRef(), CategoryService.Mode.MEMBERS, CategoryService.Depth.IMMEDIATE));
|
||||
}
|
||||
|
||||
public Node[] jsGet_immediateCategoryMembers()
|
||||
{
|
||||
return getImmediateCategoryMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all the immediate subcategories of a category
|
||||
*/
|
||||
public CategoryNode[] getImmediateSubCategories()
|
||||
{
|
||||
return buildCategoryNodes(services.getCategoryService().getChildren(getNodeRef(), CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.IMMEDIATE));
|
||||
}
|
||||
|
||||
public CategoryNode[] jsGet_immediateSubCategories()
|
||||
{
|
||||
return getImmediateSubCategories();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return immediate members and subcategories of a category
|
||||
*/
|
||||
public Node[] getImmediateMembersAndSubCategories()
|
||||
{
|
||||
return buildMixedNodes(services.getCategoryService().getChildren(getNodeRef(), CategoryService.Mode.ALL, CategoryService.Depth.IMMEDIATE));
|
||||
}
|
||||
|
||||
public Node[] jsGet_immediateMembersAndSubCategories()
|
||||
{
|
||||
return getImmediateMembersAndSubCategories();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new subcategory
|
||||
*
|
||||
* @param name Of the category to create
|
||||
*
|
||||
* @return CategoryNode
|
||||
*/
|
||||
public CategoryNode createSubCategory(String name)
|
||||
{
|
||||
return new CategoryNode(services.getCategoryService().createCategory(getNodeRef(), name), this.services, this.imageResolver, this.scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove this category
|
||||
*/
|
||||
public void removeCategory()
|
||||
{
|
||||
services.getCategoryService().deleteCategory(getNodeRef());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCategory()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private CategoryNode[] buildCategoryNodes(Collection<ChildAssociationRef> cars)
|
||||
{
|
||||
CategoryNode[] categoryNodes = new CategoryNode[cars.size()];
|
||||
int i = 0;
|
||||
for (ChildAssociationRef car : cars)
|
||||
{
|
||||
categoryNodes[i++] = new CategoryNode(car.getChildRef(), this.services, this.imageResolver, this.scope);
|
||||
}
|
||||
return categoryNodes;
|
||||
}
|
||||
|
||||
private Node[] buildNodes(Collection<ChildAssociationRef> cars)
|
||||
{
|
||||
Node[] nodes = new Node[cars.size()];
|
||||
int i = 0;
|
||||
for (ChildAssociationRef car : cars)
|
||||
{
|
||||
nodes[i++] = new Node(car.getChildRef(), this.services, this.imageResolver, this.scope);
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
private Node[] buildMixedNodes(Collection<ChildAssociationRef> cars)
|
||||
{
|
||||
Node[] nodes = new Node[cars.size()];
|
||||
int i = 0;
|
||||
for (ChildAssociationRef car : cars)
|
||||
{
|
||||
QName type = services.getNodeService().getType(car.getChildRef());
|
||||
if (services.getDictionaryService().isSubClass(type, ContentModel.TYPE_CATEGORY))
|
||||
{
|
||||
nodes[i++] = new CategoryNode(car.getChildRef(), this.services, this.imageResolver, this.scope);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodes[i++] = new Node(car.getChildRef(), this.services, this.imageResolver, this.scope);
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
}
|
202
source/java/org/alfresco/repo/jscript/CategoryTemplateNode.java
Normal file
202
source/java/org/alfresco/repo/jscript/CategoryTemplateNode.java
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.repo.jscript;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.repository.TemplateNode;
|
||||
import org.alfresco.service.cmr.search.CategoryService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Category Nodes from the classification helper have special support.
|
||||
*/
|
||||
public class CategoryTemplateNode extends TemplateNode
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param nodeRef
|
||||
* @param services
|
||||
* @param resolver
|
||||
*/
|
||||
public CategoryTemplateNode(NodeRef nodeRef, ServiceRegistry services, TemplateImageResolver resolver)
|
||||
{
|
||||
super(nodeRef, services, resolver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getIsCategory()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all the member of a category
|
||||
*/
|
||||
public List<TemplateNode> getCategoryMembers()
|
||||
{
|
||||
if (getIsCategory())
|
||||
{
|
||||
return buildTemplateNodeList(services.getCategoryService().getChildren(getNodeRef(),
|
||||
CategoryService.Mode.MEMBERS, CategoryService.Depth.ANY));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.<TemplateNode>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all the subcategories of a category
|
||||
*/
|
||||
public List<CategoryTemplateNode> getSubCategories()
|
||||
{
|
||||
if (getIsCategory())
|
||||
{
|
||||
return buildCategoryNodeList(services.getCategoryService().getChildren(getNodeRef(),
|
||||
CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.ANY));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.<CategoryTemplateNode>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return members and subcategories of a category
|
||||
*/
|
||||
public List<TemplateNode> getMembersAndSubCategories()
|
||||
{
|
||||
if (getIsCategory())
|
||||
{
|
||||
|
||||
return buildMixedNodeList(services.getCategoryService().getChildren(getNodeRef(), CategoryService.Mode.ALL,
|
||||
CategoryService.Depth.ANY));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.<TemplateNode>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all the immediate member of a category
|
||||
*/
|
||||
public List<TemplateNode> getImmediateCategoryMembers()
|
||||
{
|
||||
if (getIsCategory())
|
||||
{
|
||||
return buildTemplateNodeList(services.getCategoryService().getChildren(getNodeRef(),
|
||||
CategoryService.Mode.MEMBERS, CategoryService.Depth.IMMEDIATE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.<TemplateNode>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all the immediate subcategories of a category
|
||||
*/
|
||||
public List<CategoryTemplateNode> getImmediateSubCategories()
|
||||
{
|
||||
if (getIsCategory())
|
||||
{
|
||||
return buildCategoryNodeList(services.getCategoryService().getChildren(getNodeRef(),
|
||||
CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.IMMEDIATE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.<CategoryTemplateNode>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return immediate members and subcategories of a category
|
||||
*/
|
||||
public List<TemplateNode> getImmediateMembersAndSubCategories()
|
||||
{
|
||||
if (getIsCategory())
|
||||
{
|
||||
return buildMixedNodeList(services.getCategoryService().getChildren(getNodeRef(),
|
||||
CategoryService.Mode.ALL, CategoryService.Depth.IMMEDIATE));
|
||||
}
|
||||
else
|
||||
{
|
||||
return Collections.<TemplateNode>emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Support to build node lists from category service API calls.
|
||||
*
|
||||
* @param childRefs
|
||||
*
|
||||
* @return List of TemplateNode
|
||||
*/
|
||||
private List<TemplateNode> buildTemplateNodeList(Collection<ChildAssociationRef> childRefs)
|
||||
{
|
||||
List<TemplateNode> answer = new ArrayList<TemplateNode>(childRefs.size());
|
||||
for (ChildAssociationRef ref : childRefs)
|
||||
{
|
||||
// create our Node representation from the NodeRef
|
||||
TemplateNode child = new TemplateNode(ref.getChildRef(), this.services, this.imageResolver);
|
||||
answer.add(child);
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
private List<CategoryTemplateNode> buildCategoryNodeList(Collection<ChildAssociationRef> childRefs)
|
||||
{
|
||||
List<CategoryTemplateNode> answer = new ArrayList<CategoryTemplateNode>(childRefs.size());
|
||||
for (ChildAssociationRef ref : childRefs)
|
||||
{
|
||||
// create our Node representation from the NodeRef
|
||||
CategoryTemplateNode child = new CategoryTemplateNode(ref.getChildRef(), this.services, this.imageResolver);
|
||||
answer.add(child);
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
private List<TemplateNode> buildMixedNodeList(Collection<ChildAssociationRef> cars)
|
||||
{
|
||||
List<TemplateNode> nodes = new ArrayList<TemplateNode>(cars.size());
|
||||
int i = 0;
|
||||
for (ChildAssociationRef car : cars)
|
||||
{
|
||||
QName type = services.getNodeService().getType(car.getChildRef());
|
||||
if (services.getDictionaryService().isSubClass(type, ContentModel.TYPE_CATEGORY))
|
||||
{
|
||||
nodes.add(new CategoryTemplateNode(car.getChildRef(), this.services, this.imageResolver));
|
||||
}
|
||||
else
|
||||
{
|
||||
nodes.add(new TemplateNode(car.getChildRef(), this.services, this.imageResolver));
|
||||
}
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
}
|
144
source/java/org/alfresco/repo/jscript/Classification.java
Normal file
144
source/java/org/alfresco/repo/jscript/Classification.java
Normal file
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.repo.jscript;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.cmr.search.CategoryService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Support class for finding categories, finding root nodes for categories and creating root categories.
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public final class Classification implements Scopeable
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
private Scriptable scope;
|
||||
|
||||
private ServiceRegistry services;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private TemplateImageResolver imageResolver;
|
||||
|
||||
private StoreRef storeRef;
|
||||
|
||||
public Classification(ServiceRegistry services, StoreRef storeRef, TemplateImageResolver imageResolver)
|
||||
{
|
||||
this.services = services;
|
||||
this.imageResolver = imageResolver;
|
||||
this.storeRef = storeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
public void setScope(Scriptable scope)
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all the category nodes in a given classification.
|
||||
*
|
||||
* @param aspect
|
||||
* @return
|
||||
*/
|
||||
public CategoryNode[] getAllCategoryNodes(String aspect)
|
||||
{
|
||||
return buildCategoryNodes(services.getCategoryService().getCategories(storeRef, createQName(aspect),
|
||||
CategoryService.Depth.ANY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the aspects that define a classification.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String[] getAllClassificationAspects()
|
||||
{
|
||||
Collection<QName> aspects = services.getCategoryService().getClassificationAspects();
|
||||
String[] answer = new String[aspects.size()];
|
||||
int i = 0;
|
||||
for (QName qname : aspects)
|
||||
{
|
||||
answer[i++] = qname.toPrefixString(this.services.getNamespaceService());
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
public String[] jsGet_allClassificationAspects()
|
||||
{
|
||||
return getAllClassificationAspects();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a root category in a classification.
|
||||
*
|
||||
* @param aspect
|
||||
* @param name
|
||||
*/
|
||||
public void createRootCategory(String aspect, String name)
|
||||
{
|
||||
services.getCategoryService().createRootCategory(storeRef, createQName(aspect), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root categories in a classification.
|
||||
*
|
||||
* @param aspect
|
||||
* @return
|
||||
*/
|
||||
public CategoryNode[] getRootCategories(String aspect)
|
||||
{
|
||||
return buildCategoryNodes(services.getCategoryService().getRootCategories(storeRef, createQName(aspect)));
|
||||
}
|
||||
|
||||
private CategoryNode[] buildCategoryNodes(Collection<ChildAssociationRef> cars)
|
||||
{
|
||||
CategoryNode[] categoryNodes = new CategoryNode[cars.size()];
|
||||
int i = 0;
|
||||
for (ChildAssociationRef car : cars)
|
||||
{
|
||||
categoryNodes[i++] = new CategoryNode(car.getChildRef(), this.services, this.imageResolver, this.scope);
|
||||
}
|
||||
return categoryNodes;
|
||||
}
|
||||
|
||||
private QName createQName(String s)
|
||||
{
|
||||
QName qname;
|
||||
if (s.indexOf(QName.NAMESPACE_BEGIN) != -1)
|
||||
{
|
||||
qname = QName.createQName(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
qname = QName.createQName(s, this.services.getNamespaceService());
|
||||
}
|
||||
return qname;
|
||||
}
|
||||
|
||||
}
|
@@ -92,7 +92,7 @@ public class Node implements Serializable, Scopeable
|
||||
private final static String FOLDER_BROWSE_URL = "/navigate/browse/{0}/{1}/{2}";
|
||||
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
protected Scriptable scope;
|
||||
|
||||
/** Node Value Converter */
|
||||
private NodeValueConverter converter = null;
|
||||
@@ -110,18 +110,17 @@ public class Node implements Serializable, Scopeable
|
||||
private Node[] children = null;
|
||||
/** The properties of this node */
|
||||
private ScriptableQNameMap<String, Serializable> properties = null;
|
||||
private ServiceRegistry services = null;
|
||||
protected ServiceRegistry services = null;
|
||||
private NodeService nodeService = null;
|
||||
private Boolean isDocument = null;
|
||||
private Boolean isContainer = null;
|
||||
private String displayPath = null;
|
||||
private TemplateImageResolver imageResolver = null;
|
||||
protected TemplateImageResolver imageResolver = null;
|
||||
private Node parent = null;
|
||||
private ChildAssociationRef primaryParentAssoc = null;
|
||||
// NOTE: see the reset() method when adding new cached members!
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Construction
|
||||
|
||||
@@ -464,6 +463,20 @@ public class Node implements Serializable, Scopeable
|
||||
return isDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the Node is a Category
|
||||
*/
|
||||
public boolean isCategory()
|
||||
{
|
||||
// this valid is overriden by the CategoryNode sub-class
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean jsGet_isCategory()
|
||||
{
|
||||
return isCategory();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The list of aspects applied to this node
|
||||
*/
|
||||
@@ -890,7 +903,8 @@ public class Node implements Serializable, Scopeable
|
||||
this.services.getPermissionService().deletePermission(this.nodeRef, authority, permission);
|
||||
}
|
||||
|
||||
// -------------
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Ownership API
|
||||
|
||||
/**
|
||||
@@ -1145,7 +1159,7 @@ public class Node implements Serializable, Scopeable
|
||||
{
|
||||
if (destination != null)
|
||||
{
|
||||
NodeRef copyRef = this.services.getCopyService().copy(
|
||||
NodeRef copyRef = this.services.getCopyService().copyAndRename(
|
||||
this.nodeRef,
|
||||
destination.getNodeRef(),
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
|
@@ -220,25 +220,24 @@ public class RhinoScriptService implements ScriptService
|
||||
// add useful util objects
|
||||
model.put("actions", new Actions(services));
|
||||
model.put("logger", new ScriptLogger());
|
||||
model.put("utils", new ScriptUtils());
|
||||
|
||||
// insert supplied object model into root of the default scope
|
||||
for (String key : model.keySet())
|
||||
{
|
||||
for (String key : model.keySet())
|
||||
// set the root scope on appropriate objects
|
||||
// this is used to allow native JS object creation etc.
|
||||
Object obj = model.get(key);
|
||||
if (obj instanceof Scopeable)
|
||||
{
|
||||
// set the root scope on appropriate objects
|
||||
// this is used to allow native JS object creation etc.
|
||||
Object obj = model.get(key);
|
||||
if (obj instanceof Scopeable)
|
||||
{
|
||||
((Scopeable)obj).setScope(scope);
|
||||
}
|
||||
|
||||
// convert/wrap each object to JavaScript compatible
|
||||
Object jsObject = Context.javaToJS(obj, scope);
|
||||
|
||||
// insert into the root scope ready for access by the script
|
||||
ScriptableObject.putProperty(scope, key, jsObject);
|
||||
((Scopeable)obj).setScope(scope);
|
||||
}
|
||||
|
||||
// convert/wrap each object to JavaScript compatible
|
||||
Object jsObject = Context.javaToJS(obj, scope);
|
||||
|
||||
// insert into the root scope ready for access by the script
|
||||
ScriptableObject.putProperty(scope, key, jsObject);
|
||||
}
|
||||
|
||||
// execute the script
|
||||
@@ -343,6 +342,10 @@ public class RhinoScriptService implements ScriptService
|
||||
|
||||
model.put("search", new Search(services, companyHome.getStoreRef(), resolver));
|
||||
|
||||
model.put("session", new Session(services, resolver));
|
||||
|
||||
model.put("classification", new Classification(services, companyHome.getStoreRef(), resolver));
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
56
source/java/org/alfresco/repo/jscript/ScriptUtils.java
Normal file
56
source/java/org/alfresco/repo/jscript/ScriptUtils.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.repo.jscript;
|
||||
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Place for general and miscellenous utility functions not already found in generic JavaScript.
|
||||
*
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class ScriptUtils implements Scopeable
|
||||
{
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
public void setScope(Scriptable scope)
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to pad a string with zero '0' characters to the required length
|
||||
*
|
||||
* @param s String to pad with leading zero '0' characters
|
||||
* @param len Length to pad to
|
||||
*
|
||||
* @return padded string or the original if already at >=len characters
|
||||
*/
|
||||
public String pad(String s, int len)
|
||||
{
|
||||
String result = s;
|
||||
for (int i=0; i<(len - s.length()); i++)
|
||||
{
|
||||
result = "0" + result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
79
source/java/org/alfresco/repo/jscript/Session.java
Normal file
79
source/java/org/alfresco/repo/jscript/Session.java
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.repo.jscript;
|
||||
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
/**
|
||||
* Support object for session level properties etc.
|
||||
* <p>
|
||||
* Provides access to the user's authentication ticket.
|
||||
*
|
||||
* @author Andy Hind
|
||||
*/
|
||||
public class Session implements Scopeable
|
||||
{
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static Log logger = LogFactory.getLog(Session.class);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Scriptable scope;
|
||||
|
||||
private ServiceRegistry services;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private TemplateImageResolver imageResolver;
|
||||
|
||||
public Session(ServiceRegistry services, TemplateImageResolver imageResolver)
|
||||
{
|
||||
this.services = services;
|
||||
this.imageResolver = imageResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
public void setScope(Scriptable scope)
|
||||
{
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's authentication ticket.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getTicket()
|
||||
{
|
||||
return services.getAuthenticationService().getCurrentTicket();
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose the user's authentication ticket as JavaScipt property.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String jsGet_ticket()
|
||||
{
|
||||
return getTicket();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user