New API for templates.

Provides access to AVM stores and nodes within those stores. The majority of the standard template Node API is available (such as properties, children, content, icons etc.) and some additional AVM specific methods. 

Root level helper object 'avm' provides lookup for AVM store object and AVM nodes objects by path in the OO style expected by template writers. Once retrieved, the store object provides store meta-data and access to the root Template AVM node for the store (or lookup of individual nodes by path) which exposes the standard template Node API.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5460 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2007-04-04 16:26:16 +00:00
parent 8760a86ff5
commit 98f2e85cc0
10 changed files with 924 additions and 178 deletions

View File

@@ -46,9 +46,9 @@ public final class AVM extends BaseScopableScriptImplementation
*/
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
this.services = serviceRegistry;
this.services = serviceRegistry;
}
/**
* Return an AVM Node representing the public store root folder.
*
@@ -61,16 +61,16 @@ public final class AVM extends BaseScopableScriptImplementation
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());
}
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.
*
@@ -91,13 +91,13 @@ public final class AVM extends BaseScopableScriptImplementation
}
return node;
}
public static String getWebappsFolderPath()
{
return '/' + JNDIConstants.DIR_DEFAULT_WWW + '/' +
JNDIConstants.DIR_DEFAULT_APPBASE;
return '/' + JNDIConstants.DIR_DEFAULT_WWW +
'/' + JNDIConstants.DIR_DEFAULT_APPBASE;
}
public static String jsGet_webappsFolderPath()
{
return getWebappsFolderPath();

View File

@@ -24,9 +24,12 @@
*/
package org.alfresco.repo.jscript;
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.alfresco.util.ParameterCheck;
import org.mozilla.javascript.Scriptable;
@@ -41,6 +44,9 @@ public class AVMNode extends Node
{
private String path;
private int version;
private boolean deleted;
private AVMNodeDescriptor avmRef;
private QName type;
/**
* Constructor
@@ -68,6 +74,13 @@ public class AVMNode extends Node
Pair<Integer, String> versionPath = AVMNodeConverter.ToAVMVersionPath(nodeRef);
this.path = versionPath.getSecond();
this.version = versionPath.getFirst();
AVMNodeDescriptor descriptor = this.services.getAVMService().lookup(this.version, this.path, true);
if (descriptor == null)
{
throw new IllegalArgumentException("Invalid node specified: " + nodeRef.toString());
}
this.avmRef = descriptor;
this.deleted = descriptor.isDeleted();
}
/**
@@ -111,6 +124,60 @@ public class AVMNode extends Node
return getVersion();
}
/**
* @return QName type of this node
*/
public QName 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;
}
public String jsGet_type()
{
return getType().toString();
}
public boolean isDirectory()
{
return this.avmRef.isDirectory() || this.avmRef.isDeletedDirectory();
}
public boolean jsGet_isDirectory()
{
return isDirectory();
}
public boolean isFile()
{
return this.avmRef.isFile() || this.avmRef.isDeletedFile();
}
public boolean jsGet_isFile()
{
return isFile();
}
/**
* @return Helper to return the 'name' property for the node
*/
@Override
public String getName()
{
return this.avmRef.getName();
}
/**
* Copy this Node into a new parent destination.
*
@@ -226,8 +293,15 @@ public class AVMNode extends Node
{
super.reset();
this.path = path;
this.nodeRef = AVMNodeConverter.ToNodeRef(version, 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();
}
@Override