info.kwarc.sally4.framing.factory.SallyFrameMenuFactory Maven / Gradle / Ivy
The newest version!
package info.kwarc.sally4.framing.factory;
import info.kwarc.sally4.components.TemplatingComponent;
import info.kwarc.sally4.docmanager.CallbackManager;
import info.kwarc.sally4.framing.impl.SallyFrameMenuImpl;
import info.kwarc.sally4.framing.impl.SallyFrameMenuImpl.MenuListWindow;
import info.kwarc.sally4.registration.SallyClient;
import info.kwarc.sally4.servlet.SallyServlet;
import info.kwarc.sally4.util.InstanceCreator;
import java.util.HashMap;
import org.apache.camel.CamelContext;
import org.apache.camel.Header;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.MissingHandlerException;
import org.apache.felix.ipojo.UnacceptableConfiguration;
import org.apache.felix.ipojo.annotations.Bind;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Invalidate;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Instantiate
@Component
public class SallyFrameMenuFactory extends RouteBuilder {
final public static String menuPath = "/frames/menu";
@Requires
SallyServlet servlet;
@Requires
CallbackManager callbacks;
@Requires(filter="(factory.name="+SallyFrameMenuImpl.factoryid+")")
Factory sallyFrameMenuFactory;
Logger log;
public SallyFrameMenuFactory() throws Exception {
log = LoggerFactory.getLogger(getClass());
}
@Validate
void start() throws Exception {
CamelContext context = new DefaultCamelContext();
context.addComponent("sallyservlet", servlet.getCamelComponent());
context.addComponent("freemarker", new TemplatingComponent("templates/", getClass().getClassLoader()));
// context.addComponent("freemarker", new FreemarkerComponent());
context.addRoutes(this);
context.start();
}
@Invalidate
void stop() throws Exception {
getContext().stop();
}
@Bind(aggregate=true)
void addDoc(SallyClient doc) throws UnacceptableConfiguration, MissingHandlerException, ConfigurationException {
if (doc.supports("frames")) {
InstanceCreator.init(sallyFrameMenuFactory)
.setInstanceName("Sally Frame Menu for "+doc.getDocQueue())
.setDynamicRequirement("clientInstance", "(docQueue="+doc.getDocQueue()+")")
.setDynamicRequirement("theoInstance", "(environmentid="+doc.getEnvironmentID()+")")
.create();
}
}
public HashMap processRequest(@Header("id") String id, @Header("choice") Integer choice) throws Exception {
HashMap result = new HashMap();
if (id == null)
return result;
MenuListWindow menuInfo = callbacks.get(id, MenuListWindow.class);
if (choice!=null) {
Integer index = choice;
menuInfo.getTheo().closeWindow(menuInfo.getWndid());
menuInfo.getItems().get(index).run();
}
result.put("items", menuInfo.getItems());
result.put("menuid", id);
return result;
}
@Override
public void configure() throws Exception {
from("sallyservlet://"+menuPath)
.bean(method(this, "processRequest"))
.to("freemarker:frames_menu.html");
// .to("freemarker:file:///home/cjucovschi/sally4/office-base/src/main/resources/templates/frames_menu.html");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy