Files
alfresco-community-repo/source/java/org/alfresco/repo/virtual/ref/VanillaProtocol.java
Raluca Munteanu 8674e2bfc8 Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
125603 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2)
      125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125781 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
2016-04-26 12:48:49 +00:00

92 lines
3.2 KiB
Java

package org.alfresco.repo.virtual.ref;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* A {@link VirtualProtocol} extension that uses a scripted processor virtual
* template in order to process a so-called vanilla JSON static template
* definition on template execution.<br>
* Vanilla references store have an extra {@link ResourceParameter} for the
* vanilla-JSON template.
*
* @author Bogdan Horje
*/
public class VanillaProtocol extends VirtualProtocol
{
/**
*
*/
private static final long serialVersionUID = -7192024582935232081L;
public static final int VANILLA_TEMPLATE_PARAM_INDEX = 2;
public VanillaProtocol()
{
super("vanilla");
}
@Override
public <R> R dispatch(ProtocolMethod<R> method, Reference reference) throws ProtocolMethodException
{
return method.execute(this,
reference);
}
public Reference newReference(String vanillaProcessorClasspath, String templatePath, NodeRef actualNodeRef,
NodeRef templateRef)
{
return this
.newReference(new ClasspathResource(vanillaProcessorClasspath),
templatePath,
actualNodeRef,
Arrays
.<Parameter> asList(new ResourceParameter(new RepositoryResource(new RepositoryNodeRef(templateRef)))));
}
public Reference newReference(Encoding encoding, Resource virtualTemplateResource, String templatePath,
Resource actualResource, Resource vanillTemplateResource, List<Parameter> extraParameters)
{
List<Parameter> parameters = new ArrayList<>(2);
parameters.add(new ResourceParameter(vanillTemplateResource));
parameters.addAll(extraParameters);
return this.newReference(encoding,
virtualTemplateResource,
templatePath,
actualResource,
parameters);
}
public Resource getVanillaTemplateResource(Reference reference)
{
ResourceParameter vanillaTemplateParamter = (ResourceParameter) reference
.getParameters()
.get(VANILLA_TEMPLATE_PARAM_INDEX);
Resource resource = vanillaTemplateParamter.getValue();
return resource;
}
public Reference newReference(String vanillaProcessorClasspath, String templatePath, NodeRef actualNodeRef,
String templateSysPath) throws ProtocolMethodException
{
Resource templateResource = createSystemPathResource(templateSysPath);
if (templateResource != null)
{
return this.newReference(new ClasspathResource(vanillaProcessorClasspath),
templatePath,
actualNodeRef,
Arrays.<Parameter> asList(new ResourceParameter(templateResource)));
}
else
{
throw new ProtocolMethodException("Invalid template system path : " + templatePath);
}
}
}