Search in sources :

Example 1 with Store

use of org.springframework.extensions.webscripts.Store in project alfresco-remote-api by Alfresco.

the class RepositoryScriptProcessor method init.

/**
 * Register script loader from each Web Script Store with Script Processor
 */
private void init() {
    List<ScriptLoader> loaders = new ArrayList<ScriptLoader>();
    for (Store apiStore : searchPath.getStores()) {
        ScriptLoader loader = apiStore.getScriptLoader();
        if (loader == null) {
            throw new WebScriptException("Unable to retrieve script loader for Web Script store " + apiStore.getBasePath());
        }
        loaders.add(loader);
    }
    scriptLoader = new MultiScriptLoader(loaders.toArray(new ScriptLoader[loaders.size()]));
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) MultiScriptLoader(org.springframework.extensions.webscripts.MultiScriptLoader) ArrayList(java.util.ArrayList) Store(org.springframework.extensions.webscripts.Store) ScriptLoader(org.springframework.extensions.webscripts.ScriptLoader) MultiScriptLoader(org.springframework.extensions.webscripts.MultiScriptLoader)

Example 2 with Store

use of org.springframework.extensions.webscripts.Store in project alfresco-remote-api by Alfresco.

the class RepositoryTemplateProcessor method initConfig.

/**
 * Initialise FreeMarker Configuration
 */
protected void initConfig() {
    Configuration config = new Configuration();
    // setup template cache
    config.setCacheStorage(new StrongCacheStorage());
    config.setTemplateUpdateDelay(updateDelay);
    // setup template loaders
    List<TemplateLoader> loaders = new ArrayList<TemplateLoader>();
    for (Store apiStore : searchPath.getStores()) {
        TemplateLoader loader = apiStore.getTemplateLoader();
        if (loader == null) {
            throw new WebScriptException("Unable to retrieve template loader for Web Script store " + apiStore.getBasePath());
        }
        loaders.add(loader);
    }
    MultiTemplateLoader loader = new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()]));
    config.setTemplateLoader(loader);
    // use our custom object wrapper that can deal with QNameMap objects directly
    config.setObjectWrapper(new QNameAwareObjectWrapper());
    // rethrow any exception so we can deal with them
    config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    // turn off locale sensitive lookup - to save numerous wasted calls to nodeservice.exists()
    config.setLocalizedLookup(false);
    // set template encoding
    if (defaultEncoding != null) {
        config.setDefaultEncoding(defaultEncoding);
    }
    // set output encoding
    config.setOutputEncoding("UTF-8");
    config.setIncompatibleImprovements(new Version(2, 3, 20));
    config.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
    templateConfig = config;
}
Also used : MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) Configuration(freemarker.template.Configuration) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) Version(freemarker.template.Version) TemplateLoader(freemarker.cache.TemplateLoader) MultiTemplateLoader(freemarker.cache.MultiTemplateLoader) ArrayList(java.util.ArrayList) Store(org.springframework.extensions.webscripts.Store) StrongCacheStorage(freemarker.cache.StrongCacheStorage) QNameAwareObjectWrapper(org.alfresco.repo.template.QNameAwareObjectWrapper)

Example 3 with Store

use of org.springframework.extensions.webscripts.Store in project alfresco-remote-api by Alfresco.

the class TemplatesWebScript method executeImpl.

/* (non-Javadoc)
     * @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.WebScriptResponse)
     */
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
    String path = "/";
    String templatePattern = "*.ftl";
    // process extension
    // optional
    String p = req.getExtensionPath();
    if ((p != null) && (p.length() > 0)) {
        int idx = p.lastIndexOf("/");
        if (idx != -1) {
            path = p.substring(0, idx);
            templatePattern = p.substring(idx + 1) + ".ftl";
        }
    }
    Set<String> templatePaths = new HashSet<String>();
    for (Store apiStore : searchPath.getStores()) {
        try {
            for (String templatePath : apiStore.getDocumentPaths(path, false, templatePattern)) {
                templatePaths.add(templatePath);
            }
        } catch (IOException e) {
            throw new WebScriptException("Failed to search for templates from store " + apiStore, e);
        }
    }
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("paths", templatePaths);
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap) Store(org.springframework.extensions.webscripts.Store) IOException(java.io.IOException) HashSet(java.util.HashSet)

Aggregations

Store (org.springframework.extensions.webscripts.Store)3 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 ArrayList (java.util.ArrayList)2 MultiTemplateLoader (freemarker.cache.MultiTemplateLoader)1 StrongCacheStorage (freemarker.cache.StrongCacheStorage)1 TemplateLoader (freemarker.cache.TemplateLoader)1 Configuration (freemarker.template.Configuration)1 Version (freemarker.template.Version)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 QNameAwareObjectWrapper (org.alfresco.repo.template.QNameAwareObjectWrapper)1 MultiScriptLoader (org.springframework.extensions.webscripts.MultiScriptLoader)1 ScriptLoader (org.springframework.extensions.webscripts.ScriptLoader)1