mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-08-28 09:26:54 +00:00
UI: Use a single instance of Freemarker for the whole application
So we don't need to configure it separately in every resource class that uses HTML templates.
This commit is contained in:
@@ -27,6 +27,11 @@ import org.restlet.resource.ServerResource;
|
||||
* @author nlevitt
|
||||
*/
|
||||
public abstract class BaseResource extends ServerResource {
|
||||
@Override
|
||||
public EngineApplication getApplication() {
|
||||
return (EngineApplication) super.getApplication();
|
||||
}
|
||||
|
||||
protected String getStaticRef(String resource) {
|
||||
String rootRef = getRequest().getRootRef().toString();
|
||||
return rootRef + "/engine/static/" + resource;
|
||||
|
||||
@@ -63,8 +63,7 @@ import freemarker.template.TemplateException;
|
||||
*/
|
||||
public class BeanBrowseResource extends JobRelatedResource {
|
||||
protected PathSharingContext appCtx;
|
||||
protected String beanPath;
|
||||
private Configuration _templateConfiguration;
|
||||
protected String beanPath;
|
||||
|
||||
@Override
|
||||
public void init(Context ctx, Request req, Response res) throws ResourceException {
|
||||
@@ -82,17 +81,6 @@ public class BeanBrowseResource extends JobRelatedResource {
|
||||
} else {
|
||||
beanPath = "";
|
||||
}
|
||||
|
||||
Configuration tmpltCfg = new Configuration();
|
||||
tmpltCfg.setClassForTemplateLoading(this.getClass(),"");
|
||||
tmpltCfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
|
||||
setTemplateConfiguration(tmpltCfg);
|
||||
}
|
||||
public void setTemplateConfiguration(Configuration tmpltCfg) {
|
||||
_templateConfiguration=tmpltCfg;
|
||||
}
|
||||
public Configuration getTemplateConfiguration(){
|
||||
return _templateConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -225,7 +213,7 @@ public class BeanBrowseResource extends JobRelatedResource {
|
||||
if(!baseRef.endsWith("/")) {
|
||||
baseRef += "/";
|
||||
}
|
||||
Configuration tmpltCfg = getTemplateConfiguration();
|
||||
Configuration tmpltCfg = getApplication().getTemplateConfiguration();
|
||||
|
||||
ViewModel viewModel = new ViewModel();
|
||||
viewModel.setFlashes(Flash.getFlashes(getRequest()));
|
||||
|
||||
@@ -23,6 +23,8 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.ObjectWrapper;
|
||||
import org.archive.crawler.framework.Engine;
|
||||
import org.archive.util.TextUtils;
|
||||
import org.restlet.Application;
|
||||
@@ -48,12 +50,17 @@ import org.restlet.service.StatusService;
|
||||
* @author gojomo
|
||||
*/
|
||||
public class EngineApplication extends Application {
|
||||
protected Engine engine;
|
||||
protected Engine engine;
|
||||
private final Configuration templateConfiguration;
|
||||
|
||||
public EngineApplication(Engine engine) {
|
||||
this.engine = engine;
|
||||
getMetadataService().addExtension("log", MediaType.TEXT_PLAIN );
|
||||
getMetadataService().addExtension("cxml", MediaType.APPLICATION_XML );
|
||||
setStatusService(new EngineStatusService());
|
||||
templateConfiguration = new Configuration();
|
||||
templateConfiguration.setClassForTemplateLoading(getClass(), "");
|
||||
templateConfiguration.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -159,4 +166,7 @@ public class EngineApplication extends Application {
|
||||
|
||||
}
|
||||
|
||||
public Configuration getTemplateConfiguration() {
|
||||
return templateConfiguration;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,25 +58,11 @@ import static org.restlet.data.MediaType.APPLICATION_XML;
|
||||
*/
|
||||
public class EngineResource extends BaseResource {
|
||||
|
||||
private Configuration _templateConfiguration;
|
||||
|
||||
@Override
|
||||
public void init(Context ctx, Request req, Response res) {
|
||||
super.init(ctx, req, res);
|
||||
getVariants().add(new Variant(MediaType.TEXT_HTML));
|
||||
getVariants().add(new Variant(APPLICATION_XML));
|
||||
|
||||
Configuration tmpltCfg = new Configuration();
|
||||
tmpltCfg.setClassForTemplateLoading(this.getClass(),"");
|
||||
tmpltCfg.setObjectWrapper(new DefaultObjectWrapper());
|
||||
setTemplateConfiguration(tmpltCfg);
|
||||
}
|
||||
|
||||
public void setTemplateConfiguration(Configuration tmpltCfg) {
|
||||
_templateConfiguration=tmpltCfg;
|
||||
}
|
||||
public Configuration getTemplateConfiguration(){
|
||||
return _templateConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -233,7 +219,7 @@ public class EngineResource extends BaseResource {
|
||||
if(!baseRef.endsWith("/")) {
|
||||
baseRef += "/";
|
||||
}
|
||||
Configuration tmpltCfg = getTemplateConfiguration();
|
||||
Configuration tmpltCfg = getApplication().getTemplateConfiguration();
|
||||
|
||||
ViewModel viewModel = new ViewModel();
|
||||
viewModel.setFlashes(Flash.getFlashes(getRequest()));
|
||||
|
||||
@@ -61,7 +61,6 @@ import freemarker.template.TemplateException;
|
||||
public class JobResource extends BaseResource {
|
||||
public static final IOFileFilter EDIT_FILTER = FileUtils
|
||||
.getRegexFileFilter(".*\\.((c?xml)|(txt))$");
|
||||
private Configuration _templateConfiguration;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final Logger logger = Logger.getLogger(JobResource.class
|
||||
@@ -77,17 +76,6 @@ public class JobResource extends BaseResource {
|
||||
getVariants().add(new Variant(MediaType.APPLICATION_XML));
|
||||
cj = getEngine().getJob(
|
||||
TextUtils.urlUnescape((String) req.getAttributes().get("job")));
|
||||
|
||||
Configuration tmpltCfg = new Configuration();
|
||||
tmpltCfg.setClassForTemplateLoading(this.getClass(),"");
|
||||
tmpltCfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
|
||||
setTemplateConfiguration(tmpltCfg);
|
||||
}
|
||||
public void setTemplateConfiguration(Configuration tmpltCfg) {
|
||||
_templateConfiguration=tmpltCfg;
|
||||
}
|
||||
public Configuration getTemplateConfiguration(){
|
||||
return _templateConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,7 +127,7 @@ public class JobResource extends BaseResource {
|
||||
if(!baseRef.endsWith("/")) {
|
||||
baseRef += "/";
|
||||
}
|
||||
Configuration tmpltCfg = getTemplateConfiguration();
|
||||
Configuration tmpltCfg = getApplication().getTemplateConfiguration();
|
||||
|
||||
ViewModel viewModel = new ViewModel();
|
||||
viewModel.setFlashes(Flash.getFlashes(getRequest()));
|
||||
|
||||
@@ -80,28 +80,16 @@ public class ScriptResource extends JobRelatedResource {
|
||||
}
|
||||
|
||||
protected String chosenEngine = FACTORIES.isEmpty() ? "" : FACTORIES.getFirst().getNames().get(0);
|
||||
private Configuration _templateConfiguration;
|
||||
|
||||
@Override
|
||||
public void init(Context ctx, Request req, Response res) throws ResourceException {
|
||||
super.init(ctx, req, res);
|
||||
getVariants().add(new Variant(MediaType.TEXT_HTML));
|
||||
getVariants().add(new Variant(MediaType.APPLICATION_XML));
|
||||
|
||||
Configuration tmpltCfg = new Configuration();
|
||||
tmpltCfg.setClassForTemplateLoading(this.getClass(),"");
|
||||
tmpltCfg.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
|
||||
setTemplateConfiguration(tmpltCfg);
|
||||
|
||||
scriptingConsole = new ScriptingConsole(cj);
|
||||
}
|
||||
public void setTemplateConfiguration(Configuration tmpltCfg) {
|
||||
_templateConfiguration=tmpltCfg;
|
||||
}
|
||||
public Configuration getTemplateConfiguration(){
|
||||
return _templateConfiguration;
|
||||
}
|
||||
|
||||
|
||||
private ScriptingConsole scriptingConsole;
|
||||
|
||||
@Override
|
||||
@@ -184,7 +172,7 @@ public class ScriptResource extends JobRelatedResource {
|
||||
if(!baseRef.endsWith("/")) {
|
||||
baseRef += "/";
|
||||
}
|
||||
Configuration tmpltCfg = getTemplateConfiguration();
|
||||
Configuration tmpltCfg = getApplication().getTemplateConfiguration();
|
||||
|
||||
ViewModel viewModel = new ViewModel();
|
||||
viewModel.setFlashes(Flash.getFlashes(getRequest()));
|
||||
|
||||
Reference in New Issue
Block a user