Search in sources :

Example 1 with ScriptTemplate

use of com.manydesigns.portofino.resourceactions.annotations.ScriptTemplate in project Portofino by ManyDesigns.

the class ResourceActionLogic method getScriptTemplate.

public static String getScriptTemplate(Class<?> actionClass) {
    if (!ResourceAction.class.isAssignableFrom(actionClass)) {
        return null;
    }
    ScriptTemplate scriptTemplate = actionClass.getAnnotation(ScriptTemplate.class);
    if (scriptTemplate != null) {
        String templateLocation = scriptTemplate.value();
        try {
            return IOUtils.toString(actionClass.getResourceAsStream(templateLocation), StandardCharsets.UTF_8);
        } catch (Exception e) {
            logger.error("Can't load script template: " + templateLocation + " for class: " + actionClass.getName(), e);
        }
    } else {
        String template = getScriptTemplate(actionClass.getSuperclass());
        if (template != null) {
            return template;
        }
    }
    logger.debug("Falling back to default template for {}", actionClass);
    try {
        InputStream stream = ResourceActionLogic.class.getResourceAsStream("/com/manydesigns/portofino/resourceactions/default_script_template.txt");
        return IOUtils.toString(stream, StandardCharsets.UTF_8);
    } catch (Exception e) {
        throw new Error("Can't load script template", e);
    }
}
Also used : ScriptTemplate(com.manydesigns.portofino.resourceactions.annotations.ScriptTemplate) InputStream(java.io.InputStream)

Aggregations

ScriptTemplate (com.manydesigns.portofino.resourceactions.annotations.ScriptTemplate)1 InputStream (java.io.InputStream)1