Skip to content

Commit

Permalink
Passes sitemap to the renderers for proper display and makes adjustme…
Browse files Browse the repository at this point in the history
…nts to the proxy call

Signed-off-by: Brian Homeyer <bhomeyer@gmail.com>
  • Loading branch information
bigbasec committed Jan 28, 2021
1 parent d7a80f3 commit 2a8e15e
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 28 deletions.
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 @@ -32,6 +32,8 @@
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This is an implementation of the {@link WidgetRenderer} interface, which
Expand All @@ -46,6 +48,8 @@ public class ImageRenderer extends AbstractWidgetRenderer {

private static final String URL_NONE_ICON = "images/none.png";

private final Logger logger = LoggerFactory.getLogger(ImageRenderer.class);

@Activate
public ImageRenderer(final BundleContext bundleContext, final @Reference TranslationProvider i18nProvider,
final @Reference ItemUIRegistry itemUIRegistry, final @Reference LocaleProvider localeProvider) {
Expand All @@ -58,7 +62,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 +76,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 +98,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);

// logger.warn(snippet);
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 @@ -27,6 +27,8 @@
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This is an implementation of the {@link WidgetRenderer} interface, which
Expand All @@ -39,6 +41,8 @@
@NonNullByDefault
public class TextRenderer extends AbstractWidgetRenderer {

private final Logger logger = LoggerFactory.getLogger(TextRenderer.class);

@Activate
public TextRenderer(final BundleContext bundleContext, final @Reference TranslationProvider i18nProvider,
final @Reference ItemUIRegistry itemUIRegistry, final @Reference LocaleProvider localeProvider) {
Expand All @@ -51,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 {
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,12 @@ 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();
// 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
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

0 comments on commit 2a8e15e

Please sign in to comment.