Search in sources :

Example 1 with VirtualContext

use of org.alfresco.repo.virtual.VirtualContext in project alfresco-repository by Alfresco.

the class TemplateResourceProcessorTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    VirtualContext context = new VirtualContext(environment, virtualFolder1NodeRef);
    nodeService.setProperty(virtualFolder1NodeRef, ContentModel.PROP_DESCRIPTION, "AContextDescription");
    InputStream vanillaIS = getClass().getResourceAsStream(TEST_TEMPLATE_2_JSON_CLASSPATH);
    String vanillaJSON = IOUtils.toString(vanillaIS, StandardCharsets.UTF_8);
    context.setParameter(ApplyTemplateMethod.VANILLA_JSON_PARAM_NAME, vanillaJSON);
    TemplateResourceProcessor processor = new TemplateResourceProcessor(context);
    testTemplate2Definition = processor.process(new ClasspathResource(VANILLA_PROCESSOR_JS_CLASSPATH));
}
Also used : ClasspathResource(org.alfresco.repo.virtual.ref.ClasspathResource) InputStream(java.io.InputStream) VirtualContext(org.alfresco.repo.virtual.VirtualContext) Before(org.junit.Before)

Example 2 with VirtualContext

use of org.alfresco.repo.virtual.VirtualContext in project alfresco-repository by Alfresco.

the class ApplyTemplateMethod method execute.

@Override
public VirtualFolderDefinition execute(VanillaProtocol vanillaProtocol, Reference reference) throws ProtocolMethodException {
    InputStream vanillaIS = reference.execute(new GetVanillaScriptInputStreamMethod(environment));
    try {
        String vanillaJSON = IOUtils.toString(vanillaIS, StandardCharsets.UTF_8);
        VirtualContext context = createVirtualContext(reference);
        context.setParameter(VANILLA_JSON_PARAM_NAME, vanillaJSON);
        return execute(vanillaProtocol, reference, context);
    } catch (IOException e) {
        throw new ProtocolMethodException(e);
    } finally {
        try {
            if (vanillaIS != null)
                vanillaIS.close();
        } catch (IOException ioe) {
            logger.warn("Failed to close input stream : " + ioe);
        }
    }
}
Also used : ProtocolMethodException(org.alfresco.repo.virtual.ref.ProtocolMethodException) InputStream(java.io.InputStream) GetVanillaScriptInputStreamMethod(org.alfresco.repo.virtual.ref.GetVanillaScriptInputStreamMethod) IOException(java.io.IOException) VirtualContext(org.alfresco.repo.virtual.VirtualContext)

Aggregations

InputStream (java.io.InputStream)2 VirtualContext (org.alfresco.repo.virtual.VirtualContext)2 IOException (java.io.IOException)1 ClasspathResource (org.alfresco.repo.virtual.ref.ClasspathResource)1 GetVanillaScriptInputStreamMethod (org.alfresco.repo.virtual.ref.GetVanillaScriptInputStreamMethod)1 ProtocolMethodException (org.alfresco.repo.virtual.ref.ProtocolMethodException)1 Before (org.junit.Before)1