mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Humongous merge. It is incomplete, however; faces-config-navigation.xml and ClientConfigElement
were both beyond me, and are just the raw conflict merge data. If Kev can't figure out how they should go together by tomorrow AM (for me) I'll dig back in. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4306 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -28,32 +28,31 @@ 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
|
||||
public final class Actions extends BaseScriptImplementation implements Scopeable
|
||||
{
|
||||
/** Repository Service Registry */
|
||||
private ServiceRegistry services;
|
||||
|
||||
|
||||
/** Root scope for this object */
|
||||
private Scriptable scope;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Set the service registry
|
||||
*
|
||||
* @param services repository service registry
|
||||
* @param serviceRegistry the service registry
|
||||
*/
|
||||
public Actions(ServiceRegistry services)
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.services = services;
|
||||
this.services = serviceRegistry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.jscript.Scopeable#setScope(org.mozilla.javascript.Scriptable)
|
||||
*/
|
||||
@@ -65,7 +64,7 @@ public final class Actions implements Scopeable
|
||||
/**
|
||||
* Gets the list of registered action names
|
||||
*
|
||||
* @return the registered action names
|
||||
* @return the registered action names
|
||||
*/
|
||||
public String[] getRegistered()
|
||||
{
|
||||
@@ -79,17 +78,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 +104,7 @@ public final class Actions implements Scopeable
|
||||
}
|
||||
return scriptAction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Scriptable Action
|
||||
*
|
||||
@@ -114,23 +113,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 +139,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 +147,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 +185,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 +205,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
|
||||
@@ -216,8 +215,11 @@ public final class Actions implements Scopeable
|
||||
}
|
||||
}
|
||||
services.getActionService().executeAction(action, node.getNodeRef());
|
||||
|
||||
// Reset the actioned upon node
|
||||
node.reset();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Value converter with specific knowledge of action parameters
|
||||
*
|
||||
@@ -227,10 +229,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 +242,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 +253,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 +301,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 +344,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 +356,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 +368,5 @@ public final class Actions implements Scopeable
|
||||
setModified(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.jscript;
|
||||
|
||||
import org.alfresco.service.cmr.repository.ScriptImplementation;
|
||||
import org.alfresco.service.cmr.repository.ScriptService;
|
||||
|
||||
/**
|
||||
* Abstract base class for a script implementation
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public abstract class BaseScriptImplementation implements ScriptImplementation
|
||||
{
|
||||
/** The script service */
|
||||
private ScriptService scriptService;
|
||||
|
||||
/** The name of the script */
|
||||
private String scriptName;
|
||||
|
||||
/**
|
||||
* Sets the script service
|
||||
*
|
||||
* @param scriptService the script service
|
||||
*/
|
||||
public void setScriptService(ScriptService scriptService)
|
||||
{
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers this script with the script service
|
||||
*/
|
||||
public void register()
|
||||
{
|
||||
this.scriptService.registerScript(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the script name
|
||||
*
|
||||
* @param scriptName the script name
|
||||
*/
|
||||
public void setScriptName(String scriptName)
|
||||
{
|
||||
this.scriptName = scriptName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.repository.ScriptImplementation#getScriptName()
|
||||
*/
|
||||
public String getScriptName()
|
||||
{
|
||||
return this.scriptName;
|
||||
}
|
||||
}
|
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 getIsCategory()
|
||||
{
|
||||
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
|
||||
|
||||
@@ -428,7 +427,7 @@ public class Node implements Serializable, Scopeable
|
||||
/**
|
||||
* @return true if this Node is a container (i.e. a folder)
|
||||
*/
|
||||
public boolean isContainer()
|
||||
public boolean getIsContainer()
|
||||
{
|
||||
if (isContainer == null)
|
||||
{
|
||||
@@ -442,13 +441,13 @@ public class Node implements Serializable, Scopeable
|
||||
|
||||
public boolean jsGet_isContainer()
|
||||
{
|
||||
return isContainer();
|
||||
return getIsContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this Node is a Document (i.e. with content)
|
||||
*/
|
||||
public boolean isDocument()
|
||||
public boolean getIsDocument()
|
||||
{
|
||||
if (isDocument == null)
|
||||
{
|
||||
@@ -461,7 +460,21 @@ public class Node implements Serializable, Scopeable
|
||||
|
||||
public boolean jsGet_isDocument()
|
||||
{
|
||||
return isDocument();
|
||||
return getIsDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the Node is a Category
|
||||
*/
|
||||
public boolean getIsCategory()
|
||||
{
|
||||
// this valid is overriden by the CategoryNode sub-class
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean jsGet_isCategory()
|
||||
{
|
||||
return getIsCategory();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -554,7 +567,7 @@ public class Node implements Serializable, Scopeable
|
||||
{
|
||||
if (this.imageResolver != null)
|
||||
{
|
||||
if (isDocument())
|
||||
if (getIsDocument())
|
||||
{
|
||||
return this.imageResolver.resolveImagePathForName(getName(), true);
|
||||
}
|
||||
@@ -581,7 +594,7 @@ public class Node implements Serializable, Scopeable
|
||||
{
|
||||
if (this.imageResolver != null)
|
||||
{
|
||||
if (isDocument())
|
||||
if (getIsDocument())
|
||||
{
|
||||
return this.imageResolver.resolveImagePathForName(getName(), false);
|
||||
}
|
||||
@@ -727,7 +740,7 @@ public class Node implements Serializable, Scopeable
|
||||
*/
|
||||
public String getUrl()
|
||||
{
|
||||
if (isDocument() == true)
|
||||
if (getIsDocument() == true)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -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,
|
||||
@@ -1632,7 +1646,7 @@ public class Node implements Serializable, Scopeable
|
||||
this.imageResolver);
|
||||
|
||||
// add the current node as either the document/space as appropriate
|
||||
if (this.isDocument())
|
||||
if (this.getIsDocument())
|
||||
{
|
||||
model.put("document", new TemplateNode(this.nodeRef, this.services, this.imageResolver));
|
||||
model.put("space", new TemplateNode(getPrimaryParentAssoc().getParentRef(), this.services, this.imageResolver));
|
||||
@@ -1724,7 +1738,7 @@ public class Node implements Serializable, Scopeable
|
||||
/**
|
||||
* Reset the Node cached state
|
||||
*/
|
||||
private void reset()
|
||||
public void reset()
|
||||
{
|
||||
this.name = null;
|
||||
this.type = null;
|
||||
|
@@ -21,7 +21,9 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
@@ -30,6 +32,7 @@ import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.ScriptException;
|
||||
import org.alfresco.service.cmr.repository.ScriptImplementation;
|
||||
import org.alfresco.service.cmr.repository.ScriptService;
|
||||
import org.alfresco.service.cmr.repository.TemplateImageResolver;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -51,6 +54,8 @@ public class RhinoScriptService implements ScriptService
|
||||
/** Repository Service Registry */
|
||||
private ServiceRegistry services;
|
||||
|
||||
/** List of global scripts */
|
||||
private List<ScriptImplementation> globalScripts = new ArrayList<ScriptImplementation>(5);
|
||||
|
||||
/**
|
||||
* Set the Service Registry
|
||||
@@ -62,6 +67,14 @@ public class RhinoScriptService implements ScriptService
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.repository.ScriptService#registerScript(java.lang.Object)
|
||||
*/
|
||||
public void registerScript(ScriptImplementation script)
|
||||
{
|
||||
this.globalScripts.add(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.service.cmr.repository.ScriptService#executeScript(java.lang.String, java.util.Map)
|
||||
*/
|
||||
@@ -217,28 +230,28 @@ public class RhinoScriptService implements ScriptService
|
||||
model = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
// add useful util objects
|
||||
model.put("actions", new Actions(services));
|
||||
model.put("logger", new ScriptLogger());
|
||||
// add the global scripts
|
||||
for (ScriptImplementation script : this.globalScripts)
|
||||
{
|
||||
model.put(script.getScriptName(), script);
|
||||
}
|
||||
|
||||
// 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 +356,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;
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ import org.apache.log4j.Logger;
|
||||
/**
|
||||
* @author Kevin Roast
|
||||
*/
|
||||
public final class ScriptLogger
|
||||
public final class ScriptLogger extends BaseScriptImplementation
|
||||
{
|
||||
private static final Logger logger = Logger.getLogger(ScriptLogger.class);
|
||||
|
||||
|
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 extends BaseScriptImplementation 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