Aqui dejo el codigo de un webscript hecho con java que permite crear un espacio con otro subespacio dentro a modo de ejemplo (para ello solo hay que descomentar algunas lineas). Me he basado en el libro de Jeff Pots y un hilo encontrado en sheila's blogEl nombre de los espacios los recibe por parametro como name1 y name2un ejemplo de llamada podria ser:http://localhost:8080/alfresco/service/pruebas/prueba?name1=padre&name2=hijopackage org.alfresco.pruebas;
package org.alfresco.pruebas;
import java.io.IOException;
import java.rmi.RemoteException;
import javax.servlet.http.HttpServletRequest;
import org.alfresco.web.scripts.AbstractWebScript;
import org.alfresco.web.scripts.WebScriptRequest;
import org.alfresco.web.scripts.WebScriptResponse;
import org.alfresco.web.scripts.servlet.WebScriptServletRequest;
import org.alfresco.webservice.authentication.AuthenticationFault;
import org.alfresco.webservice.repository.RepositoryFault;
import org.alfresco.webservice.repository.UpdateResult;
import org.alfresco.webservice.types.CML;
import org.alfresco.webservice.types.CMLCreate;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.ParentReference;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.Utils;
import org.alfresco.webservice.util.WebServiceFactory;
public class PruebaWebScript extends AbstractWebScript
{
private String name1;
//private String name2;
public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
{
HttpServletRequest httpReq = ((WebScriptServletRequest)req).getHttpServletRequest();
// locate the root path
name1 = (String) httpReq.getParameter("name1");
//name2 = (String) httpReq.getParameter("name2");
System.out.println(name1);
//System.out.println(name2);
this.validarUsuario();
String dir = "/app:company_home/app:guest_home";
//String dir2 = "/app:company_home/app:guest_home/cm:"+name1;
this.crearEspacio(dir,name1);
//this.crearEspacio(dir2,name2);
this.terminarSesion();
}
private boolean iniciarSesion(){
try {
AuthenticationUtils.startSession("admin", "admin");
return true;
} catch (AuthenticationFault e) {
e.printStackTrace();
return false;
}
}
private boolean terminarSesion(){
AuthenticationUtils.endSession();
return true;
}
private boolean crearEspacio(String dir, String name){
System.out.println("Voy a crear un directorio en: " + dir);
// The default workspace store is SpacesStore
Store storeReference = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
// We want to create a new folder or workspace called child in the parent folder under guest home
ParentReference parentReference = new ParentReference(storeReference, null, dir ,
Constants.ASSOC_CONTAINS, Constants.createQNameString(Constants.NAMESPACE_CONTENT_MODEL, name));
NamedValue[] properties = new NamedValue[] { Utils.createNamedValue(Constants.PROP_NAME, name) };
CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_FOLDER, properties);
// Create the child folder, ATENCION: preparado para el prototipo "Especialidad"
CML cml = new CML();
cml.setCreate(new CMLCreate[] { create });
// inicializamos para que no de errores el try/catch
UpdateResult[] results = null;
try {
results = WebServiceFactory.getRepositoryService().update(cml);
} catch (RepositoryFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Obtnenemos la referencia al nuevo espacio y se imprime por consola
String childReference = results[0].getDestination().getUuid();
System.out.println("Created a new workspace, node is:" + childReference);
return true; // por añadir alguna linea de validación.
}
}
el codigo del pruebas.get.desc.xml:
<webscript>
<shortname>The World's Simplest Webscript</shortname>
<description>Crea un directorio padre con un directorio hijo</description>
<url>/pruebas/prueba</url>
<authentication>none</authentication>
<format default="">argument</format>
</webscript>
y el bean en el web-services-aplication-context.xml
<bean id="webscript.org.alfresco.pruebas.pruebas.get"
class="org.alfresco.pruebas.PruebaWebScript"
parent="webscript">
</bean>