Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Basic UI] Fix proxy calls for sitemaps created through the UI #860

Merged
merged 5 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Chart chart = (Chart) w;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Colorpicker cp = (Colorpicker) w;

String snippet = getSnippet("colorpicker");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
String snippet = getSnippet("frame");
String label = StringEscapeUtils.escapeHtml(itemUIRegistry.getLabel(w));
List<String> frameClassList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
String snippet = getSnippet("group");

snippet = preprocessSnippet(snippet, w);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Image image = (Image) w;
String snippet = (image.getChildren().size() > 0) ? getSnippet("image_link") : getSnippet("image");

Expand All @@ -72,10 +72,6 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
snippet = StringUtils.replace(snippet, "%id%", widgetId);
snippet = preprocessSnippet(snippet, w);

String sitemap = null;
if (w.eResource() != null) {
sitemap = w.eResource().getURI().path();
}
boolean validUrl = isValidURL(image.getUrl());
String proxiedUrl = "../proxy?sitemap=" + sitemap + "&amp;widgetId=" + widgetId;
State state = itemUIRegistry.getState(w);
Expand All @@ -98,7 +94,7 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
snippet = StringUtils.replace(snippet, "%proxied_url%", proxiedUrl);
snippet = StringUtils.replace(snippet, "%ignore_refresh%", ignoreRefresh ? "true" : "false");
snippet = StringUtils.replace(snippet, "%url%", url);

sb.append(snippet);
return ECollections.emptyEList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
String snippet = getSnippet("list");
snippet = snippet.replaceAll("%label%", getLabel(w));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Mapview mapview = (Mapview) w;
String snippet = getSnippet("mapview");
snippet = preprocessSnippet(snippet, mapview);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ public StringBuilder processPage(String id, String sitemap, String label, EList<
StringBuilder postChildren = new StringBuilder(parts[1]);

if (parts.length == 2) {
processChildren(preChildren, postChildren, children);
processChildren(preChildren, postChildren, children, sitemap);
} else if (parts.length > 2) {
logger.error("Snippet '{}' contains multiple %children% sections, but only one is allowed!",
async ? "layer" : "main");
}
return preChildren.append(postChildren);
}

private void processChildren(StringBuilder sb_pre, StringBuilder sb_post, EList<Widget> children)
private void processChildren(StringBuilder sb_pre, StringBuilder sb_post, EList<Widget> children, String sitemap)
throws RenderException {
// put a single frame around all children widgets, if there are no explicit frames
if (!children.isEmpty()) {
Expand Down Expand Up @@ -158,7 +158,7 @@ private void processChildren(StringBuilder sb_pre, StringBuilder sb_post, EList<
StringBuilder newPre = new StringBuilder();
StringBuilder newPost = new StringBuilder();
StringBuilder widgetSB = new StringBuilder();
EList<Widget> nextChildren = renderWidget(w, widgetSB);
EList<Widget> nextChildren = renderWidget(w, widgetSB, sitemap);
if (!nextChildren.isEmpty()) {
String[] parts = widgetSB.toString().split("%children%");
// no %children% placeholder found or at the end
Expand All @@ -179,7 +179,7 @@ private void processChildren(StringBuilder sb_pre, StringBuilder sb_post, EList<
"Snippet for widget '{}' contains multiple %children% sections, but only one is allowed!",
widgetType);
}
processChildren(newPre, newPost, nextChildren);
processChildren(newPre, newPost, nextChildren, sitemap);
sb_pre.append(newPre);
sb_pre.append(newPost);
} else {
Expand All @@ -189,10 +189,10 @@ private void processChildren(StringBuilder sb_pre, StringBuilder sb_post, EList<
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
for (WidgetRenderer renderer : widgetRenderers) {
if (renderer.canRender(w)) {
return renderer.renderWidget(w, sb);
return renderer.renderWidget(w, sb, sitemap);
}
}
return ECollections.emptyEList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
String snippet = getSnippet("selection");

snippet = preprocessSnippet(snippet, w);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Setpoint sp = (Setpoint) w;

// set defaults for min, max and step
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Slider s = (Slider) w;

String snippetName = "slider";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Switch s = (Switch) w;

String snippetName = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Text text = (Text) w;
String snippet = (text.getChildren().size() > 0) ? getSnippet("text_link") : getSnippet("text");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Video videoWidget = (Video) w;
String snippet = null;

String widgetId = itemUIRegistry.getWidgetId(w);
String sitemap = w.eResource().getURI().path();

// we handle mjpeg streams as an html image as browser can usually handle this
String snippetName = (videoWidget.getEncoding() != null
Expand Down Expand Up @@ -100,7 +99,6 @@ public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderExcep
snippet = StringUtils.replace(snippet, "%url%", url);
snippet = StringUtils.replace(snippet, "%media_type%", mediaType);
}

sb.append(snippet);
return ECollections.emptyEList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public boolean canRender(Widget w) {
}

@Override
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException {
Webview webview = (Webview) w;
String snippet = getSnippet("webview");
snippet = preprocessSnippet(snippet, webview);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ protected void service(@NonNullByDefault({}) HttpServletRequest req, @NonNullByD
return;
}

logger.debug("reading sitemap {}", sitemap.getName());
if (widgetId == null || widgetId.isEmpty() || widgetId.equals(sitemapName)) {
// we are at the homepage, so we render the children of the sitemap root node
if (subscriptionId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public interface WidgetRenderer {
* a "%children%" placeholder for them.
* @throws RenderException if an error occurs during rendering
*/
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException;
public EList<Widget> renderWidget(Widget w, StringBuilder sb, String sitemap) throws RenderException;

/**
* Applies a servlet configuration to the renderer
Expand Down