. First pass of the Alfresco JavaScript API wiki docs:

http://wiki.alfresco.com/wiki/JavaScript_API
 - JavaDoc and minor API updates that made sense as I was writing the documentation :)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2788 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-05-08 14:55:05 +00:00
parent f7b13bf0a0
commit ba9512439a
4 changed files with 108 additions and 31 deletions

View File

@@ -157,9 +157,9 @@ public final class Node implements Serializable
return this.nodeRef;
}
public NodeRef jsGet_nodeRef()
public String jsGet_nodeRef()
{
return getNodeRef();
return getNodeRef().toString();
}
/**
@@ -175,9 +175,9 @@ public final class Node implements Serializable
return type;
}
public QName jsGet_type()
public String jsGet_type()
{
return getType();
return getType().toString();
}
/**
@@ -443,9 +443,16 @@ public final class Node implements Serializable
return this.aspects;
}
public QName[] jsGet_aspects()
public String[] jsGet_aspects()
{
return getAspects().toArray(new QName[getAspects().size()]);
Set<QName> aspects = getAspects();
String[] result = new String[aspects.size()];
int count = 0;
for (QName qname : aspects)
{
result[count++] = qname.toString();
}
return result;
}
/**
@@ -928,13 +935,27 @@ public final class Node implements Serializable
}
/**
* Copy this Node to a new parent destination.
* Copy this Node to a new parent destination. Note that children of the source
* Node are not copied.
*
* @param destination Node
*
* @return The newly copied Node instance or null if failed to copy.
*/
public Node copy(Node destination)
{
return copy(destination, false);
}
/**
* Copy this Node and potentially all child nodes to a new parent destination.
*
* @param destination Node
* @param deepCopy True for a deep copy, false otherwise.
*
* @return The newly copied Node instance or null if failed to copy.
*/
public Node copy(Node destination, boolean deepCopy)
{
Node copy = null;
@@ -947,7 +968,7 @@ public final class Node implements Serializable
destination.getNodeRef(),
ContentModel.ASSOC_CONTAINS,
getPrimaryParentAssoc().getQName(),
false);
deepCopy);
copy = new Node(copyRef, this.services, this.imageResolver);
}
}

View File

@@ -33,6 +33,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.ScriptException;
import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.service.cmr.repository.TemplateImageResolver;
import org.alfresco.service.namespace.QName;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
@@ -244,24 +245,50 @@ public class RhinoScriptService implements ScriptService
*/
public static Map<String, Object> buildDefaultModel(ServiceRegistry services,
NodeRef person, NodeRef companyHome, NodeRef userHome, NodeRef document, NodeRef space)
{
return buildDefaultModel(services, person, companyHome, userHome, document, space, null);
}
/**
* Create the default data-model available to scripts as global scope level objects:
* <p>
* 'companyhome' - the Company Home node<br>
* 'userhome' - the current user home space node<br>
* 'person' - the node representing the current user Person<br>
* 'document' - document context node (may not be available)<br>
* 'space' - space context node (may not be available)
*
* @param services ServiceRegistry
* @param person The current user Person Node
* @param companyHome The CompanyHome ref
* @param userHome The User home space ref
* @param document Optional ref to a document Node
* @param space Optional ref to a space Node
* @param resolver Image resolver to resolve icon images etc.
*
* @return A Map of global scope scriptable Node objects
*/
public static Map<String, Object> buildDefaultModel(ServiceRegistry services,
NodeRef person, NodeRef companyHome, NodeRef userHome, NodeRef document, NodeRef space,
TemplateImageResolver resolver)
{
Map<String, Object> model = new HashMap<String, Object>();
// add the well known node wrapper objects
model.put("companyhome", new Node(companyHome, services, null));
model.put("userhome", new Node(userHome, services, null));
model.put("person", new Node(person, services, null));
model.put("companyhome", new Node(companyHome, services, resolver));
model.put("userhome", new Node(userHome, services, resolver));
model.put("person", new Node(person, services, resolver));
if (document != null)
{
model.put("document", new Node(document, services, null));
model.put("document", new Node(document, services, resolver));
}
if (space != null)
{
model.put("space", new Node(space, services, null));
model.put("space", new Node(space, services, resolver));
}
// add other useful util objects
model.put("search", new Search(services, companyHome.getStoreRef(), null));
model.put("search", new Search(services, companyHome.getStoreRef(), resolver));
return model;
}

View File

@@ -81,13 +81,20 @@ public final class Search
*/
public Node[] luceneSearch(String search)
{
return query(search);
if (search != null && search.length() != 0)
{
return query(search);
}
else
{
return new Node[0];
}
}
/**
* Execute a saved Lucene search
*
* @param savedSearch Node that contains the saved lucene search content
* @param savedSearch Node that contains the saved search XML content
*
* @return Node[] of results from the search - can be empty but not null
*/
@@ -98,19 +105,22 @@ public final class Search
// read the Saved Search XML on the specified node - and get the Lucene search from it
try
{
ContentReader content = this.services.getContentService().getReader(
savedSearch.getNodeRef(), ContentModel.PROP_CONTENT);
if (content != null && content.exists())
if (savedSearch != null)
{
// get the root element
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(content.getContentString()));
Element rootElement = document.getRootElement();
Element queryElement = rootElement.element("query");
if (queryElement != null)
ContentReader content = this.services.getContentService().getReader(
savedSearch.getNodeRef(), ContentModel.PROP_CONTENT);
if (content != null && content.exists())
{
search = queryElement.getText();
// get the root element
SAXReader reader = new SAXReader();
Document document = reader.read(new StringReader(content.getContentString()));
Element rootElement = document.getRootElement();
Element queryElement = rootElement.element("query");
if (queryElement != null)
{
search = queryElement.getText();
}
}
}
}
@@ -122,6 +132,25 @@ public final class Search
return search != null ? query(search) : new Node[0];
}
/**
* Execute a saved Lucene search
*
* @param searchRef NodeRef string that points to the node containing saved search XML content
*
* @return Node[] of results from the search - can be empty but not null
*/
public Node[] savedSearch(String searchRef)
{
if (searchRef != null)
{
return savedSearch(new Node(new NodeRef(searchRef), services, null));
}
else
{
return new Node[0];
}
}
private Node[] query(String search)
{
Node[] nodes = null;