com.talk2object.plum.view.web.WebPageView Maven / Gradle / Ivy
The newest version!
package com.talk2object.plum.view.web;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.talk2object.plum.view.component.Component;
import com.talk2object.plum.view.event.AbstractEventListener;
import com.talk2object.plum.view.event.EventListener;
import com.talk2object.plum.view.web.component.WebComponent;
import com.talk2object.plum.view.web.component.builder.WebViewBuilder;
import com.talk2object.plum.view.web.component.container.window.WebMainWindowTitlePanel;
import com.talk2object.plum.view.web.component.container.window.WebWindow;
import com.talk2object.plum.view.web.component.container.window.dialog.WebDialog;
import com.talk2object.plum.view.web.component.input.WebCheckBox;
public class WebPageView {
static final String START_JS = "_plum_start_js";
// index for all web components
private Map webComponentMap = new HashMap();
// index for all check boxes
private Map webCheckBoxMap = new HashMap();
private Map componentToWebComponentMap = new HashMap();
private Map nodeHashes = new HashMap();
private WebComponent rootContentWebComponent;
private Document doc;
private String sessionId;
Element head;
Element body;
Element formTemplate;
Element startJs;
private EventListener stateChangeEventListener;
public WebPageView(Document document, String pushTopic) {
this.doc = document;
this.sessionId = sessionId;
head = doc.getElementsByTag("head").get(0);
body = doc.getElementsByTag("body").get(0);
formTemplate = body.getElementsByTag("form").get(0);
startJs = body.getElementById(START_JS);
// body.empty();
// remove all except scripts
for (Element e : body.children()) {
if (!e.tagName().equalsIgnoreCase("script")
&& !e.attr("keep").equals("true"))
e.remove();
}
// replace JS code
String js = startJs.html().replaceAll("#topic#", pushTopic);
startJs.html(js);
}
public Map getWebComponentMap() {
return webComponentMap;
}
public Map getWebCheckBoxMap() {
return webCheckBoxMap;
}
public Map getComponentToWebComponentMap() {
return componentToWebComponentMap;
}
public Map getNodeHashes() {
return nodeHashes;
}
public void setRootContentWebComponent(WebComponent rootContentWebComponent, String title) {
this.rootContentWebComponent = rootContentWebComponent;
if (title != null)
doc.title(title);
Element form = formTemplate.clone();
body.prependChild(form);
form.prependChild(rootContentWebComponent.getHtmlOuterElement());
}
public void setStateChangeEventListener(
EventListener stateChangeEventListener) {
this.stateChangeEventListener = stateChangeEventListener;
}
public WebComponent getRootContentWebComponent() {
return rootContentWebComponent;
}
public Document getDoc() {
return doc;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy