/**
* Copyright (c) 2010-2014, openHAB.org and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.openhab.ui.webapp.internal.render;
import org.apache.commons.lang.StringUtils;
import org.eclipse.emf.common.util.EList;
import org.openhab.model.sitemap.Text;
import org.openhab.model.sitemap.Widget;
import org.openhab.ui.webapp.render.RenderException;
import org.openhab.ui.webapp.render.WidgetRenderer;
/**
* This is an implementation of the {@link WidgetRenderer} interface, which
* can produce HTML code for Text widgets.
*
* @author Kai Kreuzer
* @since 0.6.0
*
*/
public class TextRenderer extends AbstractWidgetRenderer {
/**
* {@inheritDoc}
*/
public boolean canRender(Widget w) {
return w instanceof Text;
}
/**
* {@inheritDoc}
*/
public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
Text text = (Text) w;
String snippet = (text.getChildren().size() > 0) ?
getSnippet("text_link") : getSnippet("text");
snippet = StringUtils.replace(snippet, "%id%", itemUIRegistry.getWidgetId(w));
snippet = StringUtils.replace(snippet, "%icon%", escapeURLPath(itemUIRegistry.getIcon(w)));
snippet = StringUtils.replace(snippet, "%label%", getLabel(w));
// Process the color tags
snippet = processColor(w, snippet);
sb.append(snippet);
return null;
}
}