04-13-2010 07:18 AM
<webscript>
<shortname>Images API</shortname>
<description>Images API</description>
<url>/teste/{getImages}</url>
<format default="xml">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
<cache>
<never>true</never>
</cache>
</webscript>
// globals
var REPO_ROOT = "Company Home/ClientContent";
var IMAGES_FOLDER_NAME = "Images";
//
// Returns a list of images
function listImages() {
logger.log( "listImages()" );
var photosFolder = getRepoRoot(IMAGES_FOLDER_NAME);
var searchResult = photosFolder.children;
var photos = new Array();
for( var i=0; i<searchResult.length; i++ ) {
logger.log( "listImages() searchResult[i]=" + searchResult[i].name + ", mimetype=" + searchResult[i].mimetype );
if( searchResult[i].mimetype == "image/gif"
|| searchResult[i].mimetype == "image/jpeg"
|| searchResult[i].mimetype == "image/png" ) {
photos.push( searchResult[i] );
}
}
return photos;
}
//
// return the node that points to the data repository folder in which to store nodes.
// optional path parameter will be treated as a directory path relative to the
// root and the node pointed to by the path will be returned rather than the root itself.
// if the path does not exist it will be created.
//
function getRepoRoot( path ) {
if( null == path ) {
path = "";
}
var rootNodePath = REPO_ROOT + "/" + path;
rootNodePath = rootNodePath.replace( "\\\\/+", "/" );
logger.log( "getRepoRoot() look for path: " + rootNodePath );
var paths = rootNodePath.split( "/" );
logger.log( "getRepoRoot() paths.length=" + paths.length );
if( paths.length>0 && ""==paths[0] ) {
paths.shift();
}
var node = companyhome;
for( var i=0; i< paths.length; i++ ) {
if( 0==i && "Company Home" == paths[i] ) { continue; }
if( !paths[i] ) { continue; }
logger.log( "getRepoRoot() paths[i]=" + paths[i] );
var childNode = node.childByNamePath( paths[i] );
logger.log( "getRepoRoot() childNode=" + childNode.name );
/*if( !childNode ) {
childNode = node.createFolder( paths[i] );
logger.log( "getRepoRoot() createFolder childNode=" + childNode.name );
}*/
node = childNode;
}
return node;
}
////////////////////
try {
if( "getImages" == url.extension ) {
model.resultset = listImages();
} else {
throw( "method " + url.extension + " not implemented" );
}
} catch( apiError ) {
logger.log( "ERROR processing API call " + url.full + " Error message: " + apiError );
status.message = "ERROR processing API call " + url.full + " Error message: " + apiError;
status.code = 400;
status.redirect = true;
}
<?xml version="1.0" encoding="UTF-8"?>
<images>
<#list resultset as node>
<image>
<fileName>${node.name}</fileName>
<filePath>http://10.0.20.5:8080/alfresco/alf_data/contentstore/2010/4/12/11/30/${node.id}/${node.name}</filePath>
</image>
</#list>
</images>
<response>
−
<status>
400
<name>Bad Request</name>
−
<description>
Request sent by the client was syntactically incorrect.
</description>
</status>
−
<message>
ERROR processing API call /alfresco/service/teste/{getImages} Error message: method {getImages} not implemented
</message>
<exception/>
<callstack>
</callstack>
<server>Alfresco Community v3.2.0 (r 2384) schema 3.003</server>
<time>13/Abr/2010 12:12:47</time>
</response>
04-13-2010 10:08 AM
04-13-2010 10:22 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.