view src/nabble/view/web/template/CacheNamespace.java @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
line wrap: on
line source

package nabble.view.web.template;

import nabble.model.Node;
import nabble.model.Site;
import nabble.naml.compiler.Command;
import nabble.naml.compiler.CommandSpec;
import nabble.naml.compiler.IPrintWriter;
import nabble.naml.compiler.Interpreter;
import nabble.naml.compiler.Namespace;
import nabble.naml.compiler.TemplateRuntimeException;
import nabble.view.lib.Cache;
import nabble.view.lib.Jtp;

import javax.servlet.http.HttpServletRequest;
import java.util.LinkedHashSet;
import java.util.Set;


@Namespace (
	name = "cache",
	global = false
)
public final class CacheNamespace {
	static final class DontCache extends TemplateRuntimeException {}

	final Set<String> events = new LinkedHashSet<String>();
	private final Site site;

	CacheNamespace() {
		this.site = NabbleNamespace.current().site();
		events.add( Cache.siteChangeEvent(site) );
	}

	public static final CommandSpec descendant_changes = CommandSpec.NO_OUTPUT()
		.dotParameter("node")
		.build()
	;

	@Command public void descendant_changes(IPrintWriter out,Interpreter interp) {
		Node node = site.getNode(interp.getArgAsLong("node"));
		if (node != null)
			events.add( Cache.descendantChangeEvent(node) );
	}

	public static final CommandSpec node_changes = CommandSpec.NO_OUTPUT()
		.dotParameter("node")
		.build()
	;

	@Command public void node_changes(IPrintWriter out,Interpreter interp) {
		Node node = site.getNode(interp.getArgAsLong("node"));
		if (node != null)
			events.add( Cache.nodeChangeEvent(node) );
	}

	public static final CommandSpec bread_crumb_changes = CommandSpec.NO_OUTPUT()
		.dotParameter("node")
		.build()
	;

	@Command public void bread_crumb_changes(IPrintWriter out,Interpreter interp) {
		Node node = site.getNode(interp.getArgAsLong("node"));
		if (node != null)
			Jtp.addBreadCrumbEvents(events, node);
	}

	public static final CommandSpec new_user = CommandSpec.NO_OUTPUT;

	@Command public void new_user(IPrintWriter out,Interpreter interp) {
		events.add( Cache.newUserEvent(site) );
	}

	public static final CommandSpec user_group_change = CommandSpec.NO_OUTPUT;

	@Command public void user_group_change(IPrintWriter out,Interpreter interp) {
		events.add( Cache.groupChangeEvent(site) );
	}

}