sirius.web.templates.rythm.SiriusResourceLoader Maven / Gradle / Ivy
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/
package sirius.web.templates.rythm;
import org.rythmengine.resource.ITemplateResource;
import org.rythmengine.resource.ResourceLoaderBase;
import sirius.kernel.commons.Strings;
import sirius.kernel.di.std.Part;
import sirius.web.templates.Resources;
import java.util.regex.Pattern;
/**
* Adapter to use {@link Resources} as resource loader.
*/
class SiriusResourceLoader extends ResourceLoaderBase {
@Part
private static Resources resources;
@Override
public String getResourceLoaderRoot() {
return "";
}
private static final Pattern QUALIFIED_TEMPLATE_URI = Pattern.compile("/?(view|help)(\\.|/).*");
@Override
public ITemplateResource load(String path) {
if (path.contains("://")) {
path = Strings.split(path, "://").getSecond();
}
if (!QUALIFIED_TEMPLATE_URI.matcher(path).matches()) {
if (path.startsWith("/")) {
path = "/view/parts" + path;
} else {
path = "/view/parts/" + path;
}
}
return resources.resolve(path).map(URLTemplateResource::new).orElse(null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy