[analysis]重构模块,移除ChartPlugin、DashboardWidget等的RenderContext类型参数设计,简化概念和结构

This commit is contained in:
datagear 2020-06-03 20:25:36 +08:00
parent 54e705388a
commit 605d37cdd6
62 changed files with 1581 additions and 1922 deletions

View File

@ -16,7 +16,7 @@ package org.datagear.analysis;
*/
public class Chart extends ChartDefinition
{
private ChartPlugin<?> plugin;
private ChartPlugin plugin;
private RenderContext renderContext;
@ -25,15 +25,14 @@ public class Chart extends ChartDefinition
super();
}
public Chart(String id, String name, ChartDataSet[] chartDataSets, ChartPlugin<?> plugin,
RenderContext renderContext)
public Chart(String id, String name, ChartDataSet[] chartDataSets, ChartPlugin plugin, RenderContext renderContext)
{
super(id, name, chartDataSets);
this.plugin = plugin;
this.renderContext = renderContext;
}
public Chart(ChartDefinition chartDefinition, ChartPlugin<?> plugin, RenderContext renderContext)
public Chart(ChartDefinition chartDefinition, ChartPlugin plugin, RenderContext renderContext)
{
super(chartDefinition.getId(), chartDefinition.getName(), chartDefinition.getChartDataSets());
setParamValues(chartDefinition.getParamValues());
@ -53,12 +52,12 @@ public class Chart extends ChartDefinition
this.renderContext = renderContext;
}
public ChartPlugin<?> getPlugin()
public ChartPlugin getPlugin()
{
return plugin;
}
public void setPlugin(ChartPlugin<?> plugin)
public void setPlugin(ChartPlugin plugin)
{
this.plugin = plugin;
}

View File

@ -19,9 +19,8 @@ import org.datagear.util.i18n.Labeled;
*
* @author datagear@163.com
*
* @param <T>
*/
public interface ChartPlugin<T extends RenderContext> extends Identifiable, Labeled
public interface ChartPlugin extends Identifiable, Labeled
{
String PROPERTY_ID = "id";
String PROPERTY_NAME_LABEL = Labeled.PROPERTY_NAME_LABEL;
@ -117,8 +116,7 @@ public interface ChartPlugin<T extends RenderContext> extends Identifiable, Labe
* @return
* @throws RenderException
*/
Chart renderChart(T renderContext, ChartDefinition chartDefinition)
throws RenderException;
Chart renderChart(RenderContext renderContext, ChartDefinition chartDefinition) throws RenderException;
/**
* 获取版本号

View File

@ -19,7 +19,7 @@ public interface ChartPluginManager
*
* @param chartPlugin
*/
void register(ChartPlugin<?> chartPlugin);
void register(ChartPlugin chartPlugin);
/**
* 移除指定ID的{@linkplain ChartPlugin}
@ -27,7 +27,7 @@ public interface ChartPluginManager
* @param ids
* @return 被移除的{@linkplain ChartPlugin}或者{@code null}
*/
ChartPlugin<?>[] remove(String... ids);
ChartPlugin[] remove(String... ids);
/**
* 获取指定ID的{@linkplain ChartPlugin}
@ -35,18 +35,18 @@ public interface ChartPluginManager
* @param id
* @return
*/
<T extends RenderContext> ChartPlugin<T> get(String id);
ChartPlugin get(String id);
/**
* 获取支持指定类型{@linkplain RenderContext}的所有{@linkplain ChartPlugin}
* 获取指定类型的所有{@linkplain ChartPlugin}
* <p>
* 返回结果将根据{@linkplain ChartPlugin#getOrder()}进行排序越小越靠前
* </p>
*
* @param renderContextType
* @param chartPluginType
* @return
*/
<T extends RenderContext> List<ChartPlugin<T>> getAll(Class<? extends T> renderContextType);
<T extends ChartPlugin> List<T> getAll(Class<? super T> chartPluginType);
/**
* 获取所有{@linkplain ChartPlugin}
@ -56,5 +56,5 @@ public interface ChartPluginManager
*
* @return
*/
List<ChartPlugin<?>> getAll();
List<ChartPlugin> getAll();
}

View File

@ -28,7 +28,7 @@ public class Dashboard extends AbstractIdentifiable
private RenderContext renderContext;
private DashboardWidget<?> widget;
private DashboardWidget widget;
private List<Chart> charts;
@ -37,7 +37,7 @@ public class Dashboard extends AbstractIdentifiable
super();
}
public Dashboard(String id, RenderContext renderContext, DashboardWidget<?> widget)
public Dashboard(String id, RenderContext renderContext, DashboardWidget widget)
{
super(id);
this.renderContext = renderContext;
@ -54,12 +54,12 @@ public class Dashboard extends AbstractIdentifiable
this.renderContext = renderContext;
}
public DashboardWidget<?> getWidget()
public DashboardWidget getWidget()
{
return widget;
}
public void setWidget(DashboardWidget<?> widget)
public void setWidget(DashboardWidget widget)
{
this.widget = widget;
}

View File

@ -13,7 +13,7 @@ package org.datagear.analysis;
* @author datagear@163.com
*
*/
public interface DashboardWidget<T extends RenderContext> extends Identifiable
public interface DashboardWidget extends Identifiable
{
/**
* 渲染{@linkplain Dashboard}
@ -22,5 +22,5 @@ public interface DashboardWidget<T extends RenderContext> extends Identifiable
* @return
* @throws RenderException
*/
Dashboard render(T renderContext) throws RenderException;
Dashboard render(RenderContext renderContext) throws RenderException;
}

View File

@ -16,7 +16,7 @@ public class TemplateDashboard extends Dashboard
super();
}
public TemplateDashboard(String id, String template, RenderContext renderContext, TemplateDashboardWidget<?> widget)
public TemplateDashboard(String id, String template, RenderContext renderContext, TemplateDashboardWidget widget)
{
super(id, renderContext, widget);
this.template = template;
@ -33,15 +33,15 @@ public class TemplateDashboard extends Dashboard
}
@Override
public TemplateDashboardWidget<?> getWidget()
public TemplateDashboardWidget getWidget()
{
return (TemplateDashboardWidget<?>) super.getWidget();
return (TemplateDashboardWidget) super.getWidget();
}
@Override
public void setWidget(DashboardWidget<?> widget)
public void setWidget(DashboardWidget widget)
{
if (widget != null && !(widget instanceof TemplateDashboardWidget<?>))
if (widget != null && !(widget instanceof TemplateDashboardWidget))
throw new IllegalArgumentException();
super.setWidget(widget);

View File

@ -20,8 +20,7 @@ import org.datagear.util.StringUtil;
* @author datagear@163.com
*
*/
public abstract class TemplateDashboardWidget<T extends RenderContext> extends AbstractIdentifiable
implements DashboardWidget<T>
public abstract class TemplateDashboardWidget extends AbstractIdentifiable implements DashboardWidget
{
public static final String DEFAULT_TEMPLATE_ENCODING = "UTF-8";
@ -113,7 +112,7 @@ public abstract class TemplateDashboardWidget<T extends RenderContext> extends A
if (this.templates == null || this.templates.length == 0)
return;
List<String> list = new ArrayList<String>(this.templates.length);
List<String> list = new ArrayList<>(this.templates.length);
for (String t : this.templates)
{
@ -125,7 +124,7 @@ public abstract class TemplateDashboardWidget<T extends RenderContext> extends A
}
@Override
public TemplateDashboard render(T renderContext) throws RenderException
public TemplateDashboard render(RenderContext renderContext) throws RenderException
{
String template = getFirstTemplate();
@ -145,7 +144,8 @@ public abstract class TemplateDashboardWidget<T extends RenderContext> extends A
* @throws IllegalArgumentException
* {@code template}不是模板时
*/
public TemplateDashboard render(T renderContext, String template) throws RenderException, IllegalArgumentException
public TemplateDashboard render(RenderContext renderContext, String template)
throws RenderException, IllegalArgumentException
{
if (!isTemplate(template))
throw new IllegalArgumentException("[" + template + "] is not template");
@ -161,5 +161,6 @@ public abstract class TemplateDashboardWidget<T extends RenderContext> extends A
* @return
* @throws RenderException
*/
protected abstract TemplateDashboard renderTemplate(T renderContext, String template) throws RenderException;
protected abstract TemplateDashboard renderTemplate(RenderContext renderContext, String template)
throws RenderException;
}

View File

@ -34,7 +34,7 @@ public interface TemplateDashboardWidgetResManager
* @return
* @throws IOException
*/
Reader getTemplateReader(TemplateDashboardWidget<?> widget, String template) throws IOException;
Reader getTemplateReader(TemplateDashboardWidget widget, String template) throws IOException;
/**
* 获取指定模板的输出流
@ -44,14 +44,17 @@ public interface TemplateDashboardWidgetResManager
* @return
* @throws IOException
*/
Writer getTemplateWriter(TemplateDashboardWidget<?> widget, String template) throws IOException;
Writer getTemplateWriter(TemplateDashboardWidget widget, String template) throws IOException;
/**
* 获取指定名称资源的输入流
*
* @param id {@linkplain TemplateDashboardWidget#getId()}
* @param name 资源名称
* @param encoding 资源编码{@code null}或空则使用默认编码
* @param id
* {@linkplain TemplateDashboardWidget#getId()}
* @param name
* 资源名称
* @param encoding
* 资源编码{@code null}或空则使用默认编码
* @return
* @throws IOException
*/
@ -60,9 +63,12 @@ public interface TemplateDashboardWidgetResManager
/**
* 获取指定名称资源的输出流
*
* @param id {@linkplain TemplateDashboardWidget#getId()}
* @param name 资源名称
* @param encoding 资源编码{@code null}或空则使用默认编码
* @param id
* {@linkplain TemplateDashboardWidget#getId()}
* @param name
* 资源名称
* @param encoding
* 资源编码{@code null}或空则使用默认编码
* @return
* @throws IOException
*/
@ -71,8 +77,10 @@ public interface TemplateDashboardWidgetResManager
/**
* 获取指定名称资源的输入流
*
* @param id {@linkplain TemplateDashboardWidget#getId()}
* @param name 资源名称
* @param id
* {@linkplain TemplateDashboardWidget#getId()}
* @param name
* 资源名称
* @return
* @throws IOException
*/
@ -81,8 +89,10 @@ public interface TemplateDashboardWidgetResManager
/**
* 获取指定名称资源的输出流
*
* @param id {@linkplain TemplateDashboardWidget#getId()}
* @param name 资源名称
* @param id
* {@linkplain TemplateDashboardWidget#getId()}
* @param name
* 资源名称
* @return
* @throws IOException
*/
@ -94,7 +104,8 @@ public interface TemplateDashboardWidgetResManager
* 拷入后目录下所有子文件的相对路径名比如<code>some-file.txt</code><code>some-directory/some-file.png</code>即可作为此类的资源名称使用
* </p>
*
* @param id {@linkplain Dashboard#getId()}
* @param id
* {@linkplain Dashboard#getId()}
* @param directory
* @throws IOException
*/
@ -103,8 +114,10 @@ public interface TemplateDashboardWidgetResManager
/**
* 是否包含指定名称的资源
*
* @param id {@linkplain Dashboard#getId()}
* @param name 资源名称
* @param id
* {@linkplain Dashboard#getId()}
* @param name
* 资源名称
* @return
*/
boolean containsResource(String id, String name);

View File

@ -16,7 +16,6 @@ import org.datagear.analysis.ChartParam;
import org.datagear.analysis.ChartPlugin;
import org.datagear.analysis.DataSign;
import org.datagear.analysis.Icon;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderStyle;
import org.datagear.util.i18n.Label;
@ -26,8 +25,7 @@ import org.datagear.util.i18n.Label;
* @author datagear@163.com
*
*/
public abstract class AbstractChartPlugin<T extends RenderContext> extends AbstractIdentifiable
implements ChartPlugin<T>
public abstract class AbstractChartPlugin extends AbstractIdentifiable implements ChartPlugin
{
private Label nameLabel;

View File

@ -16,10 +16,8 @@ import java.util.Map;
import org.datagear.analysis.ChartPlugin;
import org.datagear.analysis.ChartPluginManager;
import org.datagear.analysis.RenderContext;
import org.datagear.util.StringUtil;
import org.datagear.util.version.Version;
import org.springframework.core.GenericTypeResolver;
/**
* 抽象{@linkplain ChartPluginManager}
@ -29,34 +27,21 @@ import org.springframework.core.GenericTypeResolver;
*/
public abstract class AbstractChartPluginManager implements ChartPluginManager
{
private Map<String, ChartPlugin<?>> chartPluginMap = new HashMap<String, ChartPlugin<?>>();
private Map<String, Class<?>> renderContextTypeMap = new HashMap<String, Class<?>>();
private Map<String, ChartPlugin> chartPluginMap = new HashMap<>();
public AbstractChartPluginManager()
{
super();
}
protected Map<String, ? extends ChartPlugin<?>> getChartPluginMap()
protected Map<String, ChartPlugin> getChartPluginMap()
{
return chartPluginMap;
}
@SuppressWarnings("unchecked")
protected void setChartPluginMap(Map<String, ? extends ChartPlugin<?>> chartPluginMap)
protected void setChartPluginMap(Map<String, ChartPlugin> chartPluginMap)
{
this.chartPluginMap = (Map<String, ChartPlugin<?>>) chartPluginMap;
}
protected Map<String, Class<?>> getRenderContextTypeMap()
{
return renderContextTypeMap;
}
protected void setRenderContextTypeMap(Map<String, Class<?>> renderContextTypeMap)
{
this.renderContextTypeMap = renderContextTypeMap;
this.chartPluginMap = chartPluginMap;
}
/**
@ -68,22 +53,18 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
* @param chartPlugin
* @return
*/
protected boolean registerChartPlugin(ChartPlugin<?> chartPlugin)
protected boolean registerChartPlugin(ChartPlugin chartPlugin)
{
checkLegalChartPlugin(chartPlugin);
boolean put = true;
ChartPlugin<?> prev = this.chartPluginMap.get(chartPlugin.getId());
ChartPlugin prev = this.chartPluginMap.get(chartPlugin.getId());
if (prev != null)
put = canReplaceForSameId(chartPlugin, prev);
if (put)
{
this.chartPluginMap.put(chartPlugin.getId(), chartPlugin);
this.renderContextTypeMap.put(chartPlugin.getId(),
resolveChartPluginRenderContextType(chartPlugin.getClass()));
}
return put;
}
@ -93,9 +74,9 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
*
* @param id
*/
protected ChartPlugin<?>[] removeChartPlugins(String[] ids)
protected ChartPlugin[] removeChartPlugins(String[] ids)
{
ChartPlugin<?>[] removed = new ChartPlugin<?>[ids.length];
ChartPlugin[] removed = new ChartPlugin[ids.length];
for (int i = 0; i < ids.length; i++)
removed[i] = removeChartPlugin(ids[i]);
@ -108,9 +89,8 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
*
* @param id
*/
protected ChartPlugin<?> removeChartPlugin(String id)
protected ChartPlugin removeChartPlugin(String id)
{
this.renderContextTypeMap.remove(id);
return this.chartPluginMap.remove(id);
}
@ -120,7 +100,6 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
protected void removeAllChartPlugins()
{
this.chartPluginMap.clear();
this.renderContextTypeMap.clear();
}
/**
@ -129,30 +108,31 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
* @param id
* @return
*/
@SuppressWarnings("unchecked")
protected <T extends RenderContext> ChartPlugin<T> getChartPlugin(String id)
protected ChartPlugin getChartPlugin(String id)
{
return (ChartPlugin<T>) this.chartPluginMap.get(id);
return this.chartPluginMap.get(id);
}
/**
* 查找支持指定类型{@linkplain RenderContext}的所有{@linkplain ChartPlugin}
* 查找指定类型的所有{@linkplain ChartPlugin}
* <p>
* 返回列表已使用{@linkplain #sortChartPlugins(List)}排序
* </p>
*
* @param renderContextType
* @param chartPluginType
* @return
*/
@SuppressWarnings("unchecked")
protected <T extends RenderContext> List<ChartPlugin<T>> findChartPlugins(Class<? extends T> renderContextType)
protected <T extends ChartPlugin> List<T> findChartPlugins(Class<? super T> chartPluginType)
{
List<ChartPlugin<T>> reChartPlugins = new ArrayList<ChartPlugin<T>>();
List<T> reChartPlugins = new ArrayList<>();
for (Map.Entry<String, Class<?>> entry : this.renderContextTypeMap.entrySet())
for (Map.Entry<String, ChartPlugin> entry : this.chartPluginMap.entrySet())
{
if (entry.getValue().isAssignableFrom(renderContextType))
reChartPlugins.add((ChartPlugin<T>) this.chartPluginMap.get(entry.getKey()));
ChartPlugin plugin = entry.getValue();
if (chartPluginType.isAssignableFrom(plugin.getClass()))
reChartPlugins.add((T) plugin);
}
sortChartPlugins(reChartPlugins);
@ -168,9 +148,9 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
*
* @return
*/
protected List<ChartPlugin<?>> getAllChartPlugins()
protected List<ChartPlugin> getAllChartPlugins()
{
List<ChartPlugin<?>> reChartPlugins = new ArrayList<ChartPlugin<?>>();
List<ChartPlugin> reChartPlugins = new ArrayList<>();
reChartPlugins.addAll(this.chartPluginMap.values());
@ -179,48 +159,7 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
return reChartPlugins;
}
/**
* 解析{@linkplain ChartPlugin}可支持的{@linkplain RenderContext}类型列表
*
* @param chartPlugins
* @return
*/
protected List<Class<? extends RenderContext>> resolveChartPluginRenderContextTypes(
List<? extends ChartPlugin<?>> chartPlugins)
{
List<Class<? extends RenderContext>> renderContextTypes = new ArrayList<Class<? extends RenderContext>>(
chartPlugins.size());
for (ChartPlugin<?> chartPlugin : chartPlugins)
{
Class<? extends RenderContext> renderContextType = resolveChartPluginRenderContextType(
chartPlugin.getClass());
renderContextTypes.add(renderContextType);
}
return renderContextTypes;
}
/**
* 解析指定{@linkplain ChartPlugin}类所支持的{@linkplain RenderContext}类型
*
* @param chartPluginType
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Class<? extends RenderContext> resolveChartPluginRenderContextType(
Class<? extends ChartPlugin> chartPluginType)
{
Class<?> renderContextType = GenericTypeResolver.resolveTypeArgument(chartPluginType, ChartPlugin.class);
if (renderContextType == null)
renderContextType = RenderContext.class;
return (Class<? extends RenderContext>) renderContextType;
}
protected void sortChartPlugins(List<? extends ChartPlugin<?>> chartPlugins)
protected void sortChartPlugins(List<? extends ChartPlugin> chartPlugins)
{
sort(chartPlugins);
}
@ -230,12 +169,12 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
*
* @param chartPlugins
*/
public static void sort(List<? extends ChartPlugin<?>> chartPlugins)
public static void sort(List<? extends ChartPlugin> chartPlugins)
{
Collections.sort(chartPlugins, new Comparator<ChartPlugin<?>>()
Collections.sort(chartPlugins, new Comparator<ChartPlugin>()
{
@Override
public int compare(ChartPlugin<?> o1, ChartPlugin<?> o2)
public int compare(ChartPlugin o1, ChartPlugin o2)
{
return Integer.valueOf(o1.getOrder()).compareTo(o2.getOrder());
}
@ -250,7 +189,7 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
* 允许为{@code null}
* @return
*/
protected boolean canReplaceForSameId(ChartPlugin<?> my, ChartPlugin<?> old)
protected boolean canReplaceForSameId(ChartPlugin my, ChartPlugin old)
{
if (old == null)
return true;
@ -296,7 +235,7 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
* @param oldVersion
* @return
*/
protected boolean canReplaceForSameId(ChartPlugin<?> my, Version myVersion, ChartPlugin<?> old, Version oldVersion)
protected boolean canReplaceForSameId(ChartPlugin my, Version myVersion, ChartPlugin old, Version oldVersion)
{
boolean replace = false;
@ -319,7 +258,7 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
* @param chartPlugin
* @throws IllegalArgumentException
*/
protected void checkLegalChartPlugin(ChartPlugin<?> chartPlugin) throws IllegalArgumentException
protected void checkLegalChartPlugin(ChartPlugin chartPlugin) throws IllegalArgumentException
{
if (!isLegalChartPlugin(chartPlugin))
throw new IllegalArgumentException("[" + chartPlugin + "] is illegal");
@ -331,7 +270,7 @@ public abstract class AbstractChartPluginManager implements ChartPluginManager
* @param chartPlugin
* @return
*/
protected boolean isLegalChartPlugin(ChartPlugin<?> chartPlugin)
protected boolean isLegalChartPlugin(ChartPlugin chartPlugin)
{
if (chartPlugin == null)
return false;

View File

@ -49,7 +49,7 @@ public abstract class AbstractTemplateDashboardWidgetResManager implements Templ
return IOUtil.getWriter(out, encoding);
}
protected String getTemplateEncodingWithDefault(TemplateDashboardWidget<?> widget)
protected String getTemplateEncodingWithDefault(TemplateDashboardWidget widget)
{
String encoding = widget.getTemplateEncoding();

View File

@ -35,12 +35,12 @@ public class CategorizationResolver
* @param chartPlugins
* @return 最后一个元素包含所有未分组的{@linkplain ChartPlugin}
*/
public List<Categorization> resolve(List<? extends ChartPlugin<?>> chartPlugins)
public List<Categorization> resolve(List<? extends ChartPlugin> chartPlugins)
{
List<Categorization> categorizations = new ArrayList<Categorization>();
List<ChartPlugin<?>> uncategorizeds = new ArrayList<ChartPlugin<?>>();
List<Categorization> categorizations = new ArrayList<>();
List<ChartPlugin> uncategorizeds = new ArrayList<>();
for (ChartPlugin<?> chartPlugin : chartPlugins)
for (ChartPlugin chartPlugin : chartPlugins)
{
Category category = chartPlugin.getCategory();
@ -102,7 +102,7 @@ public class CategorizationResolver
{
private Category category;
private List<ChartPlugin<?>> chartPlugins = new ArrayList<ChartPlugin<?>>(5);
private List<ChartPlugin> chartPlugins = new ArrayList<>(5);
public Categorization()
{
@ -125,17 +125,17 @@ public class CategorizationResolver
this.category = category;
}
public List<ChartPlugin<?>> getChartPlugins()
public List<ChartPlugin> getChartPlugins()
{
return chartPlugins;
}
public void setChartPlugins(List<ChartPlugin<?>> chartPlugins)
public void setChartPlugins(List<ChartPlugin> chartPlugins)
{
this.chartPlugins = chartPlugins;
}
public void addChartPlugin(ChartPlugin<?> chartPlugin)
public void addChartPlugin(ChartPlugin chartPlugin)
{
this.chartPlugins.add(chartPlugin);
}

View File

@ -22,27 +22,27 @@ import org.datagear.util.IDUtil;
* @author datagear@163.com
*
*/
public class ChartWidget<T extends RenderContext> extends ChartDefinition
public class ChartWidget extends ChartDefinition
{
private ChartPlugin<T> plugin;
private ChartPlugin plugin;
public ChartWidget()
{
super();
}
public ChartWidget(String id, String name, ChartDataSet[] chartDataSets, ChartPlugin<T> plugin)
public ChartWidget(String id, String name, ChartDataSet[] chartDataSets, ChartPlugin plugin)
{
super(id, name, chartDataSets);
this.plugin = plugin;
}
public ChartPlugin<T> getPlugin()
public ChartPlugin getPlugin()
{
return plugin;
}
public void setPlugin(ChartPlugin<T> plugin)
public void setPlugin(ChartPlugin plugin)
{
this.plugin = plugin;
}
@ -56,7 +56,7 @@ public class ChartWidget<T extends RenderContext> extends ChartDefinition
*/
public void setPlugin(ChartPluginManager chartPluginManager, String chartPluginId)
{
ChartPlugin<T> chartPlugin = chartPluginManager.get(chartPluginId);
ChartPlugin chartPlugin = chartPluginManager.get(chartPluginId);
setPlugin(chartPlugin);
}
@ -67,12 +67,12 @@ public class ChartWidget<T extends RenderContext> extends ChartDefinition
* @return
* @throws RenderException
*/
public Chart render(T renderContext) throws RenderException
public Chart render(RenderContext renderContext) throws RenderException
{
return this.plugin.renderChart(renderContext, buildChartDefinition(renderContext));
}
protected ChartDefinition buildChartDefinition(T renderContext) throws RenderException
protected ChartDefinition buildChartDefinition(RenderContext renderContext) throws RenderException
{
ChartDefinition chartDefinition = new ChartDefinition();
ChartDefinition.copy(this, chartDefinition);
@ -87,7 +87,7 @@ public class ChartWidget<T extends RenderContext> extends ChartDefinition
* @return
* @throws RenderException
*/
protected String generateChartId(T renderContext) throws RenderException
protected String generateChartId(RenderContext renderContext) throws RenderException
{
return IDUtil.uuid();
}

View File

@ -4,8 +4,6 @@
package org.datagear.analysis.support;
import org.datagear.analysis.RenderContext;
/**
* {@linkplain ChartWidget}
*
@ -21,5 +19,5 @@ public interface ChartWidgetSource
* @return
* @throws Throwable
*/
<T extends RenderContext> ChartWidget<T> getChartWidget(String id) throws Throwable;
ChartWidget getChartWidget(String id) throws Throwable;
}

View File

@ -14,7 +14,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import org.datagear.analysis.ChartPlugin;
import org.datagear.analysis.ChartPluginManager;
import org.datagear.analysis.RenderContext;
/**
* 并发{@linkplain ChartPluginManager}
@ -35,7 +34,7 @@ public class ConcurrentChartPluginManager extends AbstractChartPluginManager
}
@Override
public void register(ChartPlugin<?> chartPlugin)
public void register(ChartPlugin chartPlugin)
{
WriteLock writeLock = this.lock.writeLock();
@ -52,7 +51,7 @@ public class ConcurrentChartPluginManager extends AbstractChartPluginManager
}
@Override
public ChartPlugin<?>[] remove(String... ids)
public ChartPlugin[] remove(String... ids)
{
WriteLock writeLock = this.lock.writeLock();
@ -69,7 +68,7 @@ public class ConcurrentChartPluginManager extends AbstractChartPluginManager
}
@Override
public <T extends RenderContext> ChartPlugin<T> get(String id)
public ChartPlugin get(String id)
{
ReadLock readLock = this.lock.readLock();
@ -86,7 +85,7 @@ public class ConcurrentChartPluginManager extends AbstractChartPluginManager
}
@Override
public <T extends RenderContext> List<ChartPlugin<T>> getAll(Class<? extends T> renderContextType)
public <T extends ChartPlugin> List<T> getAll(Class<? super T> chartPluginType)
{
ReadLock readLock = this.lock.readLock();
@ -94,7 +93,7 @@ public class ConcurrentChartPluginManager extends AbstractChartPluginManager
{
readLock.lock();
return findChartPlugins(renderContextType);
return findChartPlugins(chartPluginType);
}
finally
{
@ -103,7 +102,7 @@ public class ConcurrentChartPluginManager extends AbstractChartPluginManager
}
@Override
public List<ChartPlugin<?>> getAll()
public List<ChartPlugin> getAll()
{
ReadLock readLock = this.lock.readLock();

View File

@ -15,21 +15,28 @@ import org.datagear.analysis.RenderContext;
* @author datagear@163.com
*
*/
public abstract class AbstractRenderContext implements RenderContext
public class DefaultRenderContext implements RenderContext
{
private Map<String, Object> attributes;
private Map<String, Object> attributes = new HashMap<>();
public AbstractRenderContext()
public DefaultRenderContext()
{
super();
this.attributes = new HashMap<String, Object>();
}
@SuppressWarnings("unchecked")
public AbstractRenderContext(Map<String, ?> attributes)
public DefaultRenderContext(Map<String, ?> attributes)
{
super();
this.attributes = (Map<String, Object>) attributes;
this.attributes.putAll(attributes);
}
public DefaultRenderContext(RenderContext renderContext)
{
super();
Map<String, ?> attributes = renderContext.getAttributes();
if (attributes != null)
this.attributes.putAll(attributes);
}
public void setAttributes(Map<String, Object> attributes)
@ -47,7 +54,7 @@ public abstract class AbstractRenderContext implements RenderContext
@Override
public <T> T getAttribute(String name)
{
return (T) (this.attributes == null ? null : this.attributes.get(name));
return (T) this.attributes.get(name);
}
@Override

View File

@ -94,7 +94,7 @@ public class FileTemplateDashboardWidgetResManager extends AbstractTemplateDashb
}
@Override
public Reader getTemplateReader(TemplateDashboardWidget<?> widget, String template) throws IOException
public Reader getTemplateReader(TemplateDashboardWidget widget, String template) throws IOException
{
if (this.templateAsContent)
{
@ -112,7 +112,7 @@ public class FileTemplateDashboardWidgetResManager extends AbstractTemplateDashb
}
@Override
public Writer getTemplateWriter(TemplateDashboardWidget<?> widget, String template) throws IOException
public Writer getTemplateWriter(TemplateDashboardWidget widget, String template) throws IOException
{
if (this.templateAsContent)
throw new UnsupportedOperationException();
@ -168,12 +168,12 @@ public class FileTemplateDashboardWidgetResManager extends AbstractTemplateDashb
File directory = FileUtil.getDirectory(this.rootDirectory, id, false);
if (!directory.exists())
return new ArrayList<String>(0);
return new ArrayList<>(0);
List<File> files = new ArrayList<File>();
List<File> files = new ArrayList<>();
listAllDescendentFiles(directory, files);
List<String> resources = new ArrayList<String>(files.size());
List<String> resources = new ArrayList<>(files.size());
for (File file : files)
{
@ -235,7 +235,7 @@ public class FileTemplateDashboardWidgetResManager extends AbstractTemplateDashb
* @param template
* @return
*/
protected String getResourceNameForTemplate(TemplateDashboardWidget<?> widget, String template)
protected String getResourceNameForTemplate(TemplateDashboardWidget widget, String template)
{
return template;
}

View File

@ -76,7 +76,7 @@ public class JsonChartPluginPropertiesResolver
* @param chartPlugin
* @param properties
*/
public void resolveChartPluginProperties(AbstractChartPlugin<?> chartPlugin, Map<String, ?> properties)
public void resolveChartPluginProperties(AbstractChartPlugin chartPlugin, Map<String, ?> properties)
{
chartPlugin.setId((String) properties.get(ChartPlugin.PROPERTY_ID));
chartPlugin.setNameLabel(convertToLabel(properties.get(ChartPlugin.PROPERTY_NAME_LABEL)));
@ -97,7 +97,7 @@ public class JsonChartPluginPropertiesResolver
* @param json
* @throws IOException
*/
public void resolveChartPluginProperties(AbstractChartPlugin<?> chartPlugin, String json) throws IOException
public void resolveChartPluginProperties(AbstractChartPlugin chartPlugin, String json) throws IOException
{
@SuppressWarnings("unchecked")
Map<String, Object> properties = JsonSupport.parseNonStardand(json, Map.class);
@ -111,7 +111,7 @@ public class JsonChartPluginPropertiesResolver
* @param jsonReader
* @throws IOException
*/
public void resolveChartPluginProperties(AbstractChartPlugin<?> chartPlugin, Reader jsonReader) throws IOException
public void resolveChartPluginProperties(AbstractChartPlugin chartPlugin, Reader jsonReader) throws IOException
{
String json = null;
@ -139,7 +139,7 @@ public class JsonChartPluginPropertiesResolver
* @param encoding
* @throws IOException
*/
public void resolveChartPluginProperties(AbstractChartPlugin<?> chartPlugin, InputStream in, String encoding)
public void resolveChartPluginProperties(AbstractChartPlugin chartPlugin, InputStream in, String encoding)
throws IOException
{
Reader reader = IOUtil.getReader(in, encoding);

View File

@ -11,7 +11,6 @@ import java.util.List;
import org.datagear.analysis.ChartPlugin;
import org.datagear.analysis.ChartPluginManager;
import org.datagear.analysis.RenderContext;
/**
* 简单{@linkplain ChartPluginManager}
@ -30,31 +29,31 @@ public class SimpleChartPluginManager extends AbstractChartPluginManager
}
@Override
public void register(ChartPlugin<?> chartPlugin)
public void register(ChartPlugin chartPlugin)
{
registerChartPlugin(chartPlugin);
}
@Override
public ChartPlugin<?>[] remove(String... ids)
public ChartPlugin[] remove(String... ids)
{
return removeChartPlugins(ids);
}
@Override
public <T extends RenderContext> ChartPlugin<T> get(String id)
public ChartPlugin get(String id)
{
return getChartPlugin(id);
}
@Override
public <T extends RenderContext> List<ChartPlugin<T>> getAll(Class<? extends T> renderContextType)
public <T extends ChartPlugin> List<T> getAll(Class<? super T> chartPluginType)
{
return findChartPlugins(renderContextType);
return findChartPlugins(chartPluginType);
}
@Override
public List<ChartPlugin<?>> getAll()
public List<ChartPlugin> getAll()
{
return getAllChartPlugins();
}

View File

@ -11,45 +11,44 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.datagear.analysis.RenderContext;
/**
* 简单{@linkplain ChartWidgetSource}
*
* @author datagear@163.com
*
*/
public class SimpleChartWidgetSource implements ChartWidgetSource
{
private Set<ChartWidget<?>> chartWidgets = new HashSet<ChartWidget<?>>();
private Set<ChartWidget> chartWidgets = new HashSet<>();
public SimpleChartWidgetSource()
{
super();
}
public SimpleChartWidgetSource(ChartWidget<?>... chartWidgets)
public SimpleChartWidgetSource(ChartWidget... chartWidgets)
{
super();
this.chartWidgets.addAll(Arrays.asList(chartWidgets));
}
public Set<ChartWidget<?>> getChartWidgets()
public Set<ChartWidget> getChartWidgets()
{
return chartWidgets;
}
public void setChartWidgets(Set<ChartWidget<?>> chartWidgets)
public void setChartWidgets(Set<ChartWidget> chartWidgets)
{
this.chartWidgets = chartWidgets;
}
@SuppressWarnings("unchecked")
@Override
public <T extends RenderContext> ChartWidget<T> getChartWidget(String id)
public ChartWidget getChartWidget(String id)
{
for (ChartWidget<?> chartWidget : this.chartWidgets)
for (ChartWidget chartWidget : this.chartWidgets)
{
if (chartWidget.getId().equals(id))
return (ChartWidget<T>) chartWidget;
return chartWidget;
}
return null;

View File

@ -8,6 +8,7 @@ import java.io.IOException;
import java.io.Writer;
import java.util.Map;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.support.JsonSupport;
import com.fasterxml.jackson.core.JsonGenerator;
@ -38,7 +39,7 @@ public abstract class AbstractHtmlScriptObjectWriter
JsonSupport.disableAutoCloseTargetFeature(objectMapper);
SimpleModule module = new SimpleModule(RefObjectSerializer.class.getSimpleName());
module.addSerializer(RefHtmlRenderContext.class, new RefObjectSerializer());
module.addSerializer(RefRenderContext.class, new RefObjectSerializer());
module.addSerializer(RefHtmlChartPlugin.class, new RefObjectSerializer());
this.objectMapper.registerModule(module);
}
@ -117,11 +118,11 @@ public abstract class AbstractHtmlScriptObjectWriter
}
}
protected static class RefHtmlRenderContext implements HtmlRenderContext, JsonRefObject
protected static class RefRenderContext implements RenderContext, JsonRefObject
{
private String refName;
public RefHtmlRenderContext(String refName)
public RefRenderContext(String refName)
{
super();
this.refName = refName;
@ -162,27 +163,9 @@ public abstract class AbstractHtmlScriptObjectWriter
{
return null;
}
@Override
public WebContext getWebContext()
{
return null;
}
@Override
public Writer getWriter()
{
return null;
}
@Override
public int nextSequence()
{
return 0;
}
}
protected static class RefHtmlChartPlugin extends HtmlChartPlugin<HtmlRenderContext> implements JsonRefObject
protected static class RefHtmlChartPlugin extends HtmlChartPlugin implements JsonRefObject
{
private String refName;

View File

@ -1,67 +0,0 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis.support.html;
import java.io.Writer;
import org.datagear.analysis.support.AbstractRenderContext;
/**
* 默认{@linkplain HtmlRenderContext}
*
* @author datagear@163.com
*
*/
public class DefaultHtmlRenderContext extends AbstractRenderContext implements HtmlRenderContext
{
private WebContext webContext;
private Writer writer;
private int sequence = 1;
public DefaultHtmlRenderContext()
{
super();
}
public DefaultHtmlRenderContext(WebContext webContext, Writer writer)
{
super();
this.webContext = webContext;
this.writer = writer;
}
@Override
public WebContext getWebContext()
{
return webContext;
}
public void setWebContext(WebContext webContext)
{
this.webContext = webContext;
}
@Override
public Writer getWriter()
{
return this.writer;
}
public void setWriter(Writer writer)
{
this.writer = writer;
}
@Override
public int nextSequence()
{
return this.sequence++;
}
}

View File

@ -16,7 +16,6 @@ import java.util.zip.ZipOutputStream;
import org.datagear.analysis.Category;
import org.datagear.analysis.ChartPlugin;
import org.datagear.analysis.ChartPluginManager;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.support.ConcurrentChartPluginManager;
import org.datagear.util.FileUtil;
import org.datagear.util.IOUtil;
@ -46,9 +45,9 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
private long readCheckForReloadTimeThreashold = (LOGGER.isDebugEnabled() ? 0 : 5 * 60 * 1000);
private Map<String, String> pluginIdFileNameMap = new HashMap<String, String>();
private Map<String, String> pluginIdFileNameMap = new HashMap<>();
private Map<String, FileCheckTime> fileNameCheckTimeMap = new HashMap<String, FileCheckTime>();
private Map<String, FileCheckTime> fileNameCheckTimeMap = new HashMap<>();
private volatile long _prevReadCheckForReloadTime = 0;
@ -141,7 +140,7 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
}
@Override
public <T extends RenderContext> ChartPlugin<T> get(String id)
public ChartPlugin get(String id)
{
readCheckForReload();
@ -149,7 +148,7 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
}
@Override
public <T extends RenderContext> List<ChartPlugin<T>> getAll(Class<? extends T> renderContextType)
public <T extends ChartPlugin> List<T> getAll(Class<? super T> renderContextType)
{
readCheckForReload();
@ -157,7 +156,7 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
}
@Override
public List<ChartPlugin<?>> getAll()
public List<ChartPlugin> getAll()
{
readCheckForReload();
@ -175,9 +174,9 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
* @return
* @throws IOException
*/
public Set<HtmlChartPlugin<?>> upload(File file) throws IOException
public Set<HtmlChartPlugin> upload(File file) throws IOException
{
Set<HtmlChartPlugin<?>> ids = new HashSet<HtmlChartPlugin<?>>();
Set<HtmlChartPlugin> ids = new HashSet<>();
WriteLock writeLock = lock.writeLock();
@ -228,14 +227,14 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
}
}
protected void upload(File file, Set<HtmlChartPlugin<?>> plugins, int depth) throws IOException
protected void upload(File file, Set<HtmlChartPlugin> plugins, int depth) throws IOException
{
if (depth > 1 || !file.exists())
return;
if (file.isDirectory())
{
HtmlChartPlugin<?> myPlugin = this.htmlChartPluginLoader.load(file);
HtmlChartPlugin myPlugin = this.htmlChartPluginLoader.load(file);
inflateCagetory(myPlugin);
if (myPlugin != null)
@ -256,7 +255,7 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
}
else if (this.htmlChartPluginLoader.isHtmlChartPluginZip(file))
{
HtmlChartPlugin<?> myPlugin = this.htmlChartPluginLoader.loadZip(file);
HtmlChartPlugin myPlugin = this.htmlChartPluginLoader.loadZip(file);
inflateCagetory(myPlugin);
if (myPlugin != null)
@ -283,8 +282,7 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
}
}
protected HtmlChartPlugin<?> registerForUpload(HtmlChartPlugin<?> uploadPlugin, File uploadPluginFile)
throws IOException
protected HtmlChartPlugin registerForUpload(HtmlChartPlugin uploadPlugin, File uploadPluginFile) throws IOException
{
if (!isLegalChartPlugin(uploadPlugin))
return null;
@ -302,7 +300,7 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
else
{
String loadedPluginId = getFilePluginId(pluginFileName);
ChartPlugin<?> loadedPlugin = (loadedPluginId == null ? null : getChartPlugin(loadedPluginId));
ChartPlugin loadedPlugin = (loadedPluginId == null ? null : getChartPlugin(loadedPluginId));
// 同名文件不是插件则删除它并拷入新文件
if (loadedPlugin == null)
@ -338,9 +336,9 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
}
@Override
protected ChartPlugin<?> removeChartPlugin(String id)
protected ChartPlugin removeChartPlugin(String id)
{
ChartPlugin<?> plugin = super.removeChartPlugin(id);
ChartPlugin plugin = super.removeChartPlugin(id);
deletePluginFile(id);
return plugin;
@ -413,7 +411,7 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
*/
protected void checkForReload()
{
List<FileCheckTime> reloads = new ArrayList<FileCheckTime>();
List<FileCheckTime> reloads = new ArrayList<>();
// 是否有删除插件文件如果有删除那么全部重新加载
boolean hasDelete = false;
@ -503,11 +501,11 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
* {@linkplain #directory}目录下的一个文件
* @return
*/
protected HtmlChartPlugin<?> loadAndRegisterHtmlChartPlugin(File file)
protected HtmlChartPlugin loadAndRegisterHtmlChartPlugin(File file)
{
try
{
HtmlChartPlugin<?> plugin = this.htmlChartPluginLoader.loadFile(file);
HtmlChartPlugin plugin = this.htmlChartPluginLoader.loadFile(file);
inflateCagetory(plugin);
return registerHtmlChartPlugin(plugin, file);
}
@ -530,7 +528,7 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
* {@linkplain #directory}目录下的一个文件
* @return
*/
protected HtmlChartPlugin<?> registerHtmlChartPlugin(HtmlChartPlugin<?> plugin, File file)
protected HtmlChartPlugin registerHtmlChartPlugin(HtmlChartPlugin plugin, File file)
{
String fileName = file.getName();
@ -550,7 +548,7 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
}
@Override
protected boolean canReplaceForSameId(ChartPlugin<?> my, Version myVersion, ChartPlugin<?> old, Version oldVersion)
protected boolean canReplaceForSameId(ChartPlugin my, Version myVersion, ChartPlugin old, Version oldVersion)
{
// 调试模式下总替换
if (LOGGER.isDebugEnabled())
@ -559,7 +557,7 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
return super.canReplaceForSameId(my, myVersion, old, oldVersion);
}
protected boolean inflateCagetory(HtmlChartPlugin<?> plugin)
protected boolean inflateCagetory(HtmlChartPlugin plugin)
{
if (plugin == null)
return false;
@ -572,14 +570,14 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
if (category.hasNameLabel())
return false;
Map<String, ? extends ChartPlugin<?>> map = getChartPluginMap();
Map<String, ChartPlugin> map = getChartPluginMap();
for (ChartPlugin<?> chartPlugin : map.values())
for (ChartPlugin chartPlugin : map.values())
{
Category myCategory = chartPlugin.getCategory();
if (myCategory != null && myCategory.hasNameLabel()
&& myCategory.getName() != null && myCategory.getName().equals(category.getName()))
if (myCategory != null && myCategory.hasNameLabel() && myCategory.getName() != null
&& myCategory.getName().equals(category.getName()))
{
plugin.setCategory(myCategory);
return true;
@ -626,15 +624,15 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
}
@Override
protected boolean isLegalChartPlugin(ChartPlugin<?> chartPlugin)
protected boolean isLegalChartPlugin(ChartPlugin chartPlugin)
{
boolean legal = super.isLegalChartPlugin(chartPlugin);
if (legal)
{
if (chartPlugin instanceof HtmlChartPlugin<?>)
if (chartPlugin instanceof HtmlChartPlugin)
{
HtmlChartPlugin<?> htmlChartPlugin = (HtmlChartPlugin<?>) chartPlugin;
HtmlChartPlugin htmlChartPlugin = (HtmlChartPlugin) chartPlugin;
if (htmlChartPlugin.getChartRenderer() == null)
legal = false;

View File

@ -30,7 +30,7 @@ public class HtmlChart extends Chart
super();
}
public HtmlChart(String id, String name, ChartDataSet[] chartDataSets, ChartPlugin<?> plugin,
public HtmlChart(String id, String name, ChartDataSet[] chartDataSets, ChartPlugin plugin,
RenderContext renderContext, String elementId, String varName)
{
super(id, name, chartDataSets, plugin, renderContext);
@ -38,8 +38,8 @@ public class HtmlChart extends Chart
this.varName = varName;
}
public HtmlChart(ChartDefinition chartDefinition, ChartPlugin<?> plugin, RenderContext renderContext,
String elementId, String varName)
public HtmlChart(ChartDefinition chartDefinition, ChartPlugin plugin, RenderContext renderContext, String elementId,
String varName)
{
super(chartDefinition, plugin, renderContext);
this.elementId = elementId;
@ -47,30 +47,15 @@ public class HtmlChart extends Chart
}
@Override
public HtmlRenderContext getRenderContext()
public HtmlChartPlugin getPlugin()
{
return (HtmlRenderContext) super.getRenderContext();
return (HtmlChartPlugin) super.getPlugin();
}
@Override
public void setRenderContext(RenderContext renderContext)
public void setPlugin(ChartPlugin plugin)
{
if (renderContext != null && !(renderContext instanceof HtmlRenderContext))
throw new IllegalArgumentException();
super.setRenderContext(renderContext);
}
@Override
public HtmlChartPlugin<?> getPlugin()
{
return (HtmlChartPlugin<?>) super.getPlugin();
}
@Override
public void setPlugin(ChartPlugin<?> plugin)
{
if (plugin != null && !(plugin instanceof HtmlChartPlugin<?>))
if (plugin != null && !(plugin instanceof HtmlChartPlugin))
throw new IllegalArgumentException();
super.setPlugin(plugin);

View File

@ -9,18 +9,20 @@ package org.datagear.analysis.support.html;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.Collection;
import org.datagear.analysis.Chart;
import org.datagear.analysis.ChartDefinition;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderException;
import org.datagear.analysis.support.AbstractChartPlugin;
import org.datagear.util.StringUtil;
import org.datagear.analysis.support.html.HtmlChartRenderAttr.HtmlChartRenderOption;
import org.datagear.util.i18n.Label;
/**
* HTML图表插件
* <p>
* 此类将图表代码HTMLJavaScript输出至{@linkplain HtmlRenderContext#getWriter()}
* 此类将图表代码HTMLJavaScript输出至{@linkplain HtmlRenderAttr#getHtmlWriter(RenderContext)}
* </p>
* <p>
* 输出格式为
@ -45,13 +47,16 @@ import org.datagear.util.i18n.Label;
* </pre>
* </code>
* <p>
* {@linkplain HtmlChartPluginRenderOption}可自定义上述输出内容
* {@linkplain HtmlChartRenderAttr#getRenderOption(RenderContext)}可自定义上述输出内容
* </p>
* <p>
* 注意此类{@linkplain #renderChart(RenderContext, ChartDefinition)}{@linkplain RenderContext}必须符合{@linkplain HtmlChartRenderAttr#inflate(RenderContext, Writer, HtmlChartRenderOption)}规范
* </p>
*
* @author datagear@163.com
*
*/
public class HtmlChartPlugin<T extends HtmlRenderContext> extends AbstractChartPlugin<T>
public class HtmlChartPlugin extends AbstractChartPlugin
{
public static final String PROPERTY_CHART_RENDERER = "chartRenderer";
@ -131,16 +136,18 @@ public class HtmlChartPlugin<T extends HtmlRenderContext> extends AbstractChartP
}
@Override
public Chart renderChart(T renderContext, ChartDefinition chartDefinition) throws RenderException
public HtmlChart renderChart(RenderContext renderContext, ChartDefinition chartDefinition) throws RenderException
{
HtmlChartPluginRenderOption option = getOptionInitialized(renderContext);
HtmlChartRenderAttr renderAttr = getHtmlChartRenderAttrNonNull(renderContext);
Writer out = renderAttr.getHtmlWriterNonNull(renderContext);
HtmlChartRenderOption option = renderAttr.getRenderOptionNonNull(renderContext);
HtmlChart chart = createHtmlChart(renderContext, chartDefinition, option);
try
{
writeChartElement(renderContext, option);
writeScript(renderContext, chart, option);
writeChartElement(renderContext, renderAttr, out, option);
writeScript(renderContext, renderAttr, out, chart, option);
}
catch (IOException e)
{
@ -150,80 +157,81 @@ public class HtmlChartPlugin<T extends HtmlRenderContext> extends AbstractChartP
return chart;
}
protected HtmlChart createHtmlChart(T renderContext, ChartDefinition chartDefinition,
HtmlChartPluginRenderOption option)
protected HtmlChart createHtmlChart(RenderContext renderContext, ChartDefinition chartDefinition,
HtmlChartRenderOption option)
{
return new HtmlChart(chartDefinition, this, renderContext,
option.getChartElementId(), option.getChartVarName());
return new HtmlChart(chartDefinition, this, renderContext, option.getChartElementId(),
option.getChartVarName());
}
protected boolean writeChartElement(T renderContext, HtmlChartPluginRenderOption option) throws IOException
protected boolean writeChartElement(RenderContext renderContext, HtmlChartRenderAttr renderAttr, Writer out,
HtmlChartRenderOption option) throws IOException
{
if (option.isNotWriteChartElement())
return false;
Writer writer = renderContext.getWriter();
writer.write("<" + this.elementTagName + " id=\"" + option.getChartElementId() + "\">");
writer.write("</" + this.elementTagName + ">");
writeNewLine(writer);
out.write("<" + this.elementTagName + " id=\"" + option.getChartElementId() + "\">");
out.write("</" + this.elementTagName + ">");
writeNewLine(out);
return true;
}
protected void writeScript(T renderContext, HtmlChart chart, HtmlChartPluginRenderOption optionInitialized)
throws IOException
protected void writeScript(RenderContext renderContext, HtmlChartRenderAttr renderAttr, Writer out, HtmlChart chart,
HtmlChartRenderOption optionInitialized) throws IOException
{
Writer out = renderContext.getWriter();
if (!optionInitialized.isNotWriteScriptTag())
{
writeScriptStartTag(renderContext);
writeScriptStartTag(renderContext, out);
writeNewLine(out);
}
writePluginJsObject(renderContext, chart, optionInitialized);
writeRenderContextJsObject(renderContext, chart, optionInitialized);
writeChartJsObject(renderContext, chart, optionInitialized);
writePluginJsObject(renderContext, renderAttr, out, chart, optionInitialized);
writeRenderContextJsObject(renderContext, renderAttr, out, chart, optionInitialized);
writeChartJsObject(renderContext, renderAttr, out, chart, optionInitialized);
if (!optionInitialized.isNotWriteScriptTag())
{
writeScriptEndTag(renderContext);
writeScriptEndTag(renderContext, out);
writeNewLine(out);
}
}
protected boolean writePluginJsObject(T renderContext, HtmlChart chart,
HtmlChartPluginRenderOption optionInitialized) throws IOException
protected boolean writePluginJsObject(RenderContext renderContext, HtmlChartRenderAttr renderAttr, Writer out,
HtmlChart chart, HtmlChartRenderOption optionInitialized) throws IOException
{
if (optionInitialized.isNotWritePluginObject())
return false;
Writer out = renderContext.getWriter();
HtmlChartPlugin<?> plugin = chart.getPlugin();
HtmlChartPlugin plugin = chart.getPlugin();
getHtmlChartPluginScriptObjectWriter().write(out, plugin, optionInitialized.getPluginVarName());
return true;
}
protected boolean writeRenderContextJsObject(T renderContext, HtmlChart chart,
HtmlChartPluginRenderOption optionInitialized) throws IOException
protected boolean writeRenderContextJsObject(RenderContext renderContext, HtmlChartRenderAttr renderAttr,
Writer out, HtmlChart chart, HtmlChartRenderOption optionInitialized) throws IOException
{
if (optionInitialized.isNotWriteRenderContextObject())
return false;
Writer out = renderContext.getWriter();
getHtmlRenderContextScriptObjectWriter().write(out, renderContext, optionInitialized.getRenderContextVarName());
getHtmlRenderContextScriptObjectWriter().write(out, renderContext, optionInitialized.getRenderContextVarName(),
getHtmlRenderContextIgnoreAttrs(renderContext, renderAttr, out, chart));
return true;
}
protected void writeChartJsObject(T renderContext, HtmlChart chart, HtmlChartPluginRenderOption optionInitialized)
throws IOException
protected Collection<String> getHtmlRenderContextIgnoreAttrs(RenderContext renderContext,
HtmlChartRenderAttr renderAttr, Writer out, HtmlChart chart)
{
Writer out = renderContext.getWriter();
Collection<String> ignores = renderAttr.getIgnoreRenderAttrs(renderContext);
return (ignores != null ? ignores : Arrays.asList(renderAttr.getHtmlWriterName()));
}
protected void writeChartJsObject(RenderContext renderContext, HtmlChartRenderAttr renderAttr, Writer out,
HtmlChart chart, HtmlChartRenderOption optionInitialized) throws IOException
{
if (optionInitialized.isWriteChartJson())
getHtmlChartScriptObjectWriter().writeJson(out, chart, optionInitialized.getRenderContextVarName(),
optionInitialized.getPluginVarName());
@ -254,98 +262,23 @@ public class HtmlChartPlugin<T extends HtmlRenderContext> extends AbstractChartP
return HTML_CHART_SCRIPT_OBJECT_WRITER;
}
/**
* 写脚本开始标签
*
* @param renderContext
* @throws IOException
*/
protected void writeScriptStartTag(T renderContext) throws IOException
protected void writeScriptStartTag(RenderContext renderContext, Writer out) throws IOException
{
renderContext.getWriter().write("<script type=\"text/javascript\">");
out.write("<script type=\"text/javascript\">");
}
/**
* 写脚本结束标签
*
* @param renderContext
* @throws IOException
*/
protected void writeScriptEndTag(T renderContext) throws IOException
protected void writeScriptEndTag(RenderContext renderContext, Writer out) throws IOException
{
renderContext.getWriter().write("</script>");
out.write("</script>");
}
/**
* 写换行符
*
* @param out
* @throws IOException
*/
protected void writeNewLine(Writer out) throws IOException
{
out.write(getNewLine());
}
/**
* 获取已初始化的{@linkplain HtmlChartPluginRenderOption}
* <p>
* 它的{@linkplain HtmlChartPluginRenderOption#getChartElementId()}
* {@linkplain HtmlChartPluginRenderOption#getPluginVarName()}
* {@linkplain HtmlChartPluginRenderOption#getRenderContextVarName()}
* {@linkplain HtmlChartPluginRenderOption#getChartVarName()}都是已初始化的
* </p>
*
* @param renderContext
* @return
*/
protected HtmlChartPluginRenderOption getOptionInitialized(T renderContext)
protected HtmlChartRenderAttr getHtmlChartRenderAttrNonNull(RenderContext renderContext)
{
HtmlChartPluginRenderOption option = HtmlChartPluginRenderOption.getOption(renderContext);
if (option == null)
{
option = new HtmlChartPluginRenderOption();
option.setNotWriteChartElement(false);
option.setNotWritePluginObject(false);
option.setNotWriteRenderContextObject(false);
option.setNotWriteScriptTag(false);
option.setNotWriteInvoke(false);
option.setWriteChartJson(false);
}
String chartElementId = option.getChartElementId();
String pluginVarName = option.getPluginVarName();
String renderContextVarName = option.getRenderContextVarName();
String chartVarName = option.getChartVarName();
if (option.isNotWriteChartElement() && StringUtil.isEmpty(chartElementId))
throw new RenderException(
"[" + HtmlChartPluginRenderOption.class.getSimpleName() + ".elementId] must be set");
if (StringUtil.isEmpty(chartElementId))
{
chartElementId = HtmlRenderAttributes.generateChartElementId(renderContext);
option.setChartElementId(chartElementId);
}
if (StringUtil.isEmpty(pluginVarName))
{
pluginVarName = HtmlRenderAttributes.generateChartPluginVarName(renderContext);
option.setPluginVarName(pluginVarName);
}
if (StringUtil.isEmpty(renderContextVarName))
{
renderContextVarName = HtmlRenderAttributes.generateRenderContextVarName(renderContext);
option.setRenderContextVarName(renderContextVarName);
}
if (StringUtil.isEmpty(chartVarName))
{
chartVarName = HtmlRenderAttributes.generateChartVarName(renderContext);
option.setChartVarName(chartVarName);
}
return option;
return HtmlChartRenderAttr.getNonNull(renderContext);
}
}

View File

@ -209,7 +209,7 @@ public class HtmlChartPluginLoader
* @return
* @throws HtmlChartPluginLoadException
*/
public HtmlChartPlugin<?> load(File directory) throws HtmlChartPluginLoadException
public HtmlChartPlugin load(File directory) throws HtmlChartPluginLoadException
{
return loadSingleForDirectory(directory);
}
@ -221,7 +221,7 @@ public class HtmlChartPluginLoader
* @return
* @throws HtmlChartPluginLoadException
*/
public HtmlChartPlugin<?> loadZip(File zip) throws HtmlChartPluginLoadException
public HtmlChartPlugin loadZip(File zip) throws HtmlChartPluginLoadException
{
return loadSingleForZip(zip);
}
@ -233,7 +233,7 @@ public class HtmlChartPluginLoader
* @return
* @throws HtmlChartPluginLoadException
*/
public HtmlChartPlugin<?> loadZip(ZipInputStream in) throws HtmlChartPluginLoadException
public HtmlChartPlugin loadZip(ZipInputStream in) throws HtmlChartPluginLoadException
{
return loadSingleForZip(in);
}
@ -245,9 +245,9 @@ public class HtmlChartPluginLoader
* @return
* @throws HtmlChartPluginLoadException
*/
public HtmlChartPlugin<?> loadFile(File file) throws HtmlChartPluginLoadException
public HtmlChartPlugin loadFile(File file) throws HtmlChartPluginLoadException
{
HtmlChartPlugin<?> plugin = null;
HtmlChartPlugin plugin = null;
if (file.isDirectory())
plugin = loadSingleForDirectory(file);
@ -269,15 +269,15 @@ public class HtmlChartPluginLoader
* @return
* @throws HtmlChartPluginLoadException
*/
public Set<HtmlChartPlugin<?>> loads(File file) throws HtmlChartPluginLoadException
public Set<HtmlChartPlugin> loads(File file) throws HtmlChartPluginLoadException
{
Set<HtmlChartPlugin<?>> plugins = new HashSet<HtmlChartPlugin<?>>();
Set<HtmlChartPlugin> plugins = new HashSet<>();
if (file.isDirectory())
{
if (isHtmlChartPluginDirectory(file))
{
HtmlChartPlugin<?> plugin = load(file);
HtmlChartPlugin plugin = load(file);
if (plugin != null)
plugins.add(plugin);
@ -288,7 +288,7 @@ public class HtmlChartPluginLoader
for (File child : children)
{
HtmlChartPlugin<?> plugin = loadFile(child);
HtmlChartPlugin plugin = loadFile(child);
if (plugin != null)
plugins.add(plugin);
@ -299,7 +299,7 @@ public class HtmlChartPluginLoader
{
if (isHtmlChartPluginZip(file))
{
HtmlChartPlugin<?> plugin = loadZip(file);
HtmlChartPlugin plugin = loadZip(file);
if (plugin != null)
plugins.add(plugin);
@ -327,7 +327,7 @@ public class HtmlChartPluginLoader
for (File child : children)
{
HtmlChartPlugin<?> plugin = loadFile(child);
HtmlChartPlugin plugin = loadFile(child);
if (plugin != null)
plugins.add(plugin);
@ -340,12 +340,12 @@ public class HtmlChartPluginLoader
return plugins;
}
protected HtmlChartPlugin<?> loadFileExt(File file) throws HtmlChartPluginLoadException
protected HtmlChartPlugin loadFileExt(File file) throws HtmlChartPluginLoadException
{
return null;
}
protected HtmlChartPlugin<?> loadSingleForZip(File zip) throws HtmlChartPluginLoadException
protected HtmlChartPlugin loadSingleForZip(File zip) throws HtmlChartPluginLoadException
{
ZipInputStream in = null;
@ -370,7 +370,7 @@ public class HtmlChartPluginLoader
}
}
protected HtmlChartPlugin<?> loadSingleForZip(ZipInputStream in) throws HtmlChartPluginLoadException
protected HtmlChartPlugin loadSingleForZip(ZipInputStream in) throws HtmlChartPluginLoadException
{
try
{
@ -378,7 +378,7 @@ public class HtmlChartPluginLoader
IOUtil.unzip(in, tmpDirectory);
HtmlChartPlugin<?> chartPlugin = loadSingleForDirectory(tmpDirectory);
HtmlChartPlugin chartPlugin = loadSingleForDirectory(tmpDirectory);
FileUtil.deleteFile(tmpDirectory);
@ -397,32 +397,33 @@ public class HtmlChartPluginLoader
* @return
* @throws HtmlChartPluginLoadException
*/
protected HtmlChartPlugin<?> loadSingleForDirectory(File directory) throws HtmlChartPluginLoadException
protected HtmlChartPlugin loadSingleForDirectory(File directory) throws HtmlChartPluginLoadException
{
File chartFile = new File(directory, FILE_NAME_PLUGIN);
if (!chartFile.exists())
return null;
HtmlChartPlugin<?> plugin = null;
HtmlChartPlugin plugin = null;
Reader chartIn = null;
try
{
chartIn = IOUtil.getReader(chartFile, this.encoding);
JsDefContent jsDefContent = this.htmlChartPluginJsDefResolver.resolve(chartIn);
if (!StringUtil.isEmpty(jsDefContent.getPluginJson())
&& !StringUtil.isEmpty(jsDefContent.getPluginChartRenderer()))
{
plugin = createHtmlChartPlugin();
this.jsonChartPluginPropertiesResolver.resolveChartPluginProperties(plugin, jsDefContent.getPluginJson());
this.jsonChartPluginPropertiesResolver.resolveChartPluginProperties(plugin,
jsDefContent.getPluginJson());
plugin.setChartRenderer(new StringJsChartRenderer(jsDefContent.getPluginChartRenderer()));
plugin.setIcons(toBytesIconsInDirectory(directory, plugin.getIcons()));
if (StringUtil.isEmpty(plugin.getId()) || StringUtil.isEmpty(plugin.getNameLabel()))
plugin = null;
}
@ -439,7 +440,7 @@ public class HtmlChartPluginLoader
// 设置为加载时间而不取文件上次修改时间因为文件上次修改时间可能错乱
if (plugin != null)
plugin.setLastModified(System.currentTimeMillis());
return plugin;
}
@ -449,7 +450,7 @@ public class HtmlChartPluginLoader
if (icons == null || icons.isEmpty())
return icons;
Map<RenderStyle, Icon> bytesIcons = new HashMap<RenderStyle, Icon>();
Map<RenderStyle, Icon> bytesIcons = new HashMap<>();
for (Map.Entry<RenderStyle, Icon> entry : icons.entrySet())
{
@ -521,8 +522,8 @@ public class HtmlChartPluginLoader
return FileUtil.isExtension(file, "zip");
}
protected HtmlChartPlugin<?> createHtmlChartPlugin()
protected HtmlChartPlugin createHtmlChartPlugin()
{
return new HtmlChartPlugin<HtmlRenderContext>();
return new HtmlChartPlugin();
}
}

View File

@ -1,281 +0,0 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis.support.html;
import java.io.Serializable;
import org.datagear.analysis.RenderContext;
/**
* {@linkplain HtmlChartPlugin}渲染设置项
*
* @author datagear@163.com
*
*/
public class HtmlChartPluginRenderOption implements Serializable
{
private static final long serialVersionUID = 1L;
/** 图表的HTML元素ID */
private String chartElementId;
/** 是否不输出图表HTML元素 */
private boolean notWriteChartElement = false;
/** 插件变量名 */
private String pluginVarName;
/** 是否不输出插件JS对象 */
private boolean notWritePluginObject = false;
/** 图表变量名 */
private String chartVarName;
/** 渲染上下文变量名 */
private String renderContextVarName;
/** 是否不输出渲染上下文JS对象 */
private boolean notWriteRenderContextObject = false;
/** 是否不输出{@code <script>}标签 */
private boolean notWriteScriptTag = false;
/** 是否不输出调用渲染函数 */
private boolean notWriteInvoke = false;
/** 写入图表JSON对象而非JS对象 */
private boolean writeChartJson = false;
public HtmlChartPluginRenderOption()
{
super();
}
public boolean hasChartElementId()
{
return (this.chartElementId != null && !this.chartElementId.isEmpty());
}
public String getChartElementId()
{
return chartElementId;
}
/**
* 自定义图表HTML元素的ID属性值
*
* @param chartElementId
*/
public void setChartElementId(String chartElementId)
{
this.chartElementId = chartElementId;
}
public boolean isNotWriteChartElement()
{
return notWriteChartElement;
}
/**
* 自定义是否不输出图表HTML元素
* <p>
* 如果设置为{@code true}那么必须设置{@linkplain #setChartElementId(String)}
* </p>
*
* @param notWriteChartElement
*/
public void setNotWriteChartElement(boolean notWriteChartElement)
{
this.notWriteChartElement = notWriteChartElement;
}
public boolean hasPluginVarName()
{
return (this.pluginVarName != null && !this.pluginVarName.isEmpty());
}
public String getPluginVarName()
{
return pluginVarName;
}
/**
* 自定义{@linkplain HtmlChartPlugin} JS变量名
*
* @param pluginVarName
*/
public void setPluginVarName(String pluginVarName)
{
this.pluginVarName = pluginVarName;
}
public boolean isNotWritePluginObject()
{
return notWritePluginObject;
}
/**
* 设置是否不输出{@linkplain HtmlChartPlugin} JS对象
* <p>
* 如果设置为{@code true}那么必须设置{@linkplain #setPluginVarName(String)}
* </p>
*
* @param notWritePluginObject
*/
public void setNotWritePluginObject(boolean notWritePluginObject)
{
this.notWritePluginObject = notWritePluginObject;
}
public boolean hasChartVarName()
{
return (this.chartVarName != null && !this.chartVarName.isEmpty());
}
public String getChartVarName()
{
return chartVarName;
}
/**
* 自定义{@linkplain HtmlChart} JS变量名
*
* @param pluginVarName
*/
public void setChartVarName(String chartVarName)
{
this.chartVarName = chartVarName;
}
public boolean hasRenderContextVarName()
{
return (this.renderContextVarName != null && !this.renderContextVarName.isEmpty());
}
public String getRenderContextVarName()
{
return renderContextVarName;
}
/**
* 自定义{@linkplain HtmlRenderContext} JS变量名
*
* @param renderContextVarName
*/
public void setRenderContextVarName(String renderContextVarName)
{
this.renderContextVarName = renderContextVarName;
}
public boolean isNotWriteRenderContextObject()
{
return notWriteRenderContextObject;
}
/**
* 设置是否不输出{@linkplain HtmlRenderContext} JS对象
* <p>
* 如果设置为{@code true}那么必须设置{@linkplain #setRenderContextVarName(String)}
* </p>
*
* @param notWriteRenderContextObject
*/
public void setNotWriteRenderContextObject(boolean notWriteRenderContextObject)
{
this.notWriteRenderContextObject = notWriteRenderContextObject;
}
public boolean isNotWriteScriptTag()
{
return notWriteScriptTag;
}
/**
* 自定义是否不输出<code>&lt;script&gt;</code>标签
*
* @param notWriteScriptTag
*/
public void setNotWriteScriptTag(boolean notWriteScriptTag)
{
this.notWriteScriptTag = notWriteScriptTag;
}
public boolean isNotWriteInvoke()
{
return notWriteInvoke;
}
/**
* 自定义是否不输出调用渲染图表的函数类似<code>chartPlugin.render(chart);</code>
*
* @param notWriteInvoke
*/
public void setNotWriteInvoke(boolean notWriteInvoke)
{
this.notWriteInvoke = notWriteInvoke;
}
public boolean isWriteChartJson()
{
return writeChartJson;
}
/**
* 设置写入图表JSON对象而非JS对象
*
* @param writeChartJson
*/
public void setWriteChartJson(boolean writeChartJson)
{
this.writeChartJson = writeChartJson;
}
@Override
public String toString()
{
return getClass().getSimpleName() + " [chartElementId=" + chartElementId + ", notWriteChartElement="
+ notWriteChartElement + ", pluginVarName=" + pluginVarName + ", notWritePluginObject="
+ notWritePluginObject + ", chartVarName=" + chartVarName + ", renderContextVarName="
+ renderContextVarName + ", notWriteRenderContextObject=" + notWriteRenderContextObject
+ ", notWriteScriptTag=" + notWriteScriptTag + ", notWriteInvoke=" + notWriteInvoke
+ ", writeChartJson=" + writeChartJson + "]";
}
/**
* 设置{@linkplain HtmlChartPluginRenderOption}对象
*
* @param renderContext
* @param option
*/
public static void setOption(RenderContext renderContext, HtmlChartPluginRenderOption option)
{
renderContext.setAttribute(ATTR_NAME, option);
}
/**
* 获取{@linkplain HtmlChartPluginRenderOption}对象
*
* @param renderContext
*/
public static HtmlChartPluginRenderOption getOption(RenderContext renderContext)
{
return renderContext.getAttribute(ATTR_NAME);
}
/**
* 移除{@linkplain HtmlChartPluginRenderOption}对象
*
* @param renderContext
*/
public static HtmlChartPluginRenderOption removeOption(RenderContext renderContext)
{
return renderContext.removeAttribute(ATTR_NAME);
}
public static final String ATTR_NAME = HtmlChartPluginRenderOption.class.getName();
}

View File

@ -51,7 +51,7 @@ public class HtmlChartPluginScriptObjectWriter extends AbstractHtmlScriptObjectW
* @param varName
* @throws IOException
*/
public void write(Writer out, HtmlChartPlugin<?> plugin, String varName) throws IOException
public void write(Writer out, HtmlChartPlugin plugin, String varName) throws IOException
{
JsonChartPlugin jsonPlugin = new JsonChartPlugin(plugin);
@ -70,7 +70,7 @@ public class HtmlChartPluginScriptObjectWriter extends AbstractHtmlScriptObjectW
* @param chart
* @throws IOException
*/
protected void writeHtmlChartRenderer(Writer out, HtmlChartPlugin<?> plugin, String varName) throws IOException
protected void writeHtmlChartRenderer(Writer out, HtmlChartPlugin plugin, String varName) throws IOException
{
out.write(varName + "." + HtmlChartPlugin.PROPERTY_CHART_RENDERER + "=");
writeNewLine(out);
@ -98,9 +98,9 @@ public class HtmlChartPluginScriptObjectWriter extends AbstractHtmlScriptObjectW
* @author datagear@163.com
*
*/
public static class JsonChartPlugin extends AbstractChartPlugin<RenderContext>
public static class JsonChartPlugin extends AbstractChartPlugin
{
public JsonChartPlugin(HtmlChartPlugin<?> plugin)
public JsonChartPlugin(HtmlChartPlugin plugin)
{
super(plugin.getId(), plugin.getNameLabel());
setDescLabel(plugin.getDescLabel());

View File

@ -4,9 +4,12 @@
package org.datagear.analysis.support.html;
import java.io.Serializable;
import java.io.Writer;
import org.datagear.analysis.ChartDefinition;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderException;
/**
* {@linkplain HtmlChart}渲染上下文属性定义类
@ -21,7 +24,113 @@ public class HtmlChartRenderAttr extends HtmlRenderAttr
/**
* {@linkplain HtmlChartRenderAttr}的渲染上下文属性名
*/
public static final String NAME = HtmlChartRenderAttr.class.getName();
public static final String ATTR_NAME = HtmlChartRenderAttr.class.getName();
/** 属性名:渲染选项 */
private String renderOptionName = "renderOption";
public HtmlChartRenderAttr()
{
super();
}
public String getRenderOptionName()
{
return renderOptionName;
}
public void setRenderOptionName(String renderOptionName)
{
this.renderOptionName = renderOptionName;
}
/**
* 获取{@linkplain HtmlChartRenderOption}
*
* @param renderContext
* @return
*/
public HtmlChartRenderOption getRenderOptionNonNull(RenderContext renderContext)
{
HtmlChartRenderOption renderOption = renderContext.getAttribute(this.renderOptionName);
if (renderOption == null)
throw new RenderException("The [" + this.renderOptionName + "] attribute must be set");
return renderOption;
}
/**
* 获取{@linkplain HtmlChartRenderOption}没有则返回{@code null}
*
* @param renderContext
* @return
*/
public HtmlChartRenderOption getRenderOption(RenderContext renderContext)
{
return renderContext.getAttribute(this.renderOptionName);
}
/**
* 设置{@linkplain HtmlChartRenderOption}
*
* @param renderContext
* @param renderOption
*/
public void setRenderOption(RenderContext renderContext, HtmlChartRenderOption renderOption)
{
renderContext.setAttribute(this.renderOptionName, renderOption);
}
/**
* 移除{@linkplain HtmlChartRenderOption}
*
* @param renderContext
* @return 移除对象
*/
public HtmlChartRenderOption removeRenderOption(RenderContext renderContext)
{
return renderContext.removeAttribute(this.renderOptionName);
}
/**
* 设置{@linkplain HtmlChartPlugin#renderChart(RenderContext, ChartDefinition)}必须的上下文属性值
*
* @param renderContext
* @param htmlWriter
* @param renderOption
*/
public void inflate(RenderContext renderContext, Writer htmlWriter, HtmlChartRenderOption renderOption)
{
HtmlChartRenderAttr.set(renderContext, this);
setHtmlWriter(renderContext, htmlWriter);
setRenderOption(renderContext, renderOption);
}
/**
* 获取{@linkplain HtmlChartRenderAttr}对象
*
* @param renderContext
*/
public static HtmlChartRenderAttr getNonNull(RenderContext renderContext)
{
HtmlChartRenderAttr renderAttr = get(renderContext);
if (renderAttr == null)
throw new RenderException("The [" + ATTR_NAME + "] attribute must be set");
return renderAttr;
}
/**
* 获取{@linkplain HtmlChartRenderAttr}对象没有则返回{@code null}
*
* @param renderContext
*/
public static HtmlChartRenderAttr get(RenderContext renderContext)
{
return renderContext.getAttribute(ATTR_NAME);
}
/**
* 设置{@linkplain HtmlChartRenderAttr}对象
@ -31,17 +140,7 @@ public class HtmlChartRenderAttr extends HtmlRenderAttr
*/
public static void set(RenderContext renderContext, HtmlChartRenderAttr renderAttr)
{
renderContext.setAttribute(NAME, renderAttr);
}
/**
* 获取{@linkplain HtmlChartRenderAttr}对象
*
* @param renderContext
*/
public static HtmlTplDashboardRenderAttr get(RenderContext renderContext)
{
return renderContext.getAttribute(NAME);
renderContext.setAttribute(ATTR_NAME, renderAttr);
}
/**
@ -51,19 +150,229 @@ public class HtmlChartRenderAttr extends HtmlRenderAttr
*/
public static HtmlChartRenderAttr remove(RenderContext renderContext)
{
return renderContext.removeAttribute(NAME);
return renderContext.removeAttribute(ATTR_NAME);
}
/**
* 设置{@linkplain HtmlChartWidget#render(HtmlRenderContext)}必须的上下文属性值
* {@linkplain HtmlChart}渲染选项
*
* @param renderContext
* @param renderAttr
* @param htmlWriter
* @author datagear@163.com
*
*/
public static void inflate(RenderContext renderContext, HtmlChartRenderAttr renderAttr, Writer htmlWriter)
public static class HtmlChartRenderOption implements Serializable
{
HtmlChartRenderAttr.set(renderContext, renderAttr);
renderAttr.setHtmlWriter(renderContext, htmlWriter);
private static final long serialVersionUID = 1L;
/** 图表的HTML元素ID */
private String chartElementId;
/** 是否不输出图表HTML元素 */
private boolean notWriteChartElement = false;
/** 插件变量名 */
private String pluginVarName;
/** 是否不输出插件JS对象 */
private boolean notWritePluginObject = false;
/** 图表变量名 */
private String chartVarName;
/** 渲染上下文变量名 */
private String renderContextVarName;
/** 是否不输出渲染上下文JS对象 */
private boolean notWriteRenderContextObject = false;
/** 是否不输出{@code <script>}标签 */
private boolean notWriteScriptTag = false;
/** 是否不输出调用渲染函数 */
private boolean notWriteInvoke = false;
/** 写入图表JSON对象而非JS对象 */
private boolean writeChartJson = false;
public HtmlChartRenderOption()
{
super();
}
public HtmlChartRenderOption(HtmlRenderAttr renderAttr)
{
this(renderAttr.genChartElementId(), renderAttr.genChartPluginVarName(), renderAttr.genChartVarName(),
renderAttr.genRenderContextVarName());
}
public HtmlChartRenderOption(String chartElementId, String pluginVarName, String chartVarName,
String renderContextVarName)
{
super();
this.chartElementId = chartElementId;
this.pluginVarName = pluginVarName;
this.chartVarName = chartVarName;
this.renderContextVarName = renderContextVarName;
}
public String getChartElementId()
{
return chartElementId;
}
/**
* 自定义图表HTML元素的ID属性值
*
* @param chartElementId
*/
public void setChartElementId(String chartElementId)
{
this.chartElementId = chartElementId;
}
public boolean isNotWriteChartElement()
{
return notWriteChartElement;
}
/**
* 自定义是否不输出图表HTML元素
*
* @param notWriteChartElement
*/
public void setNotWriteChartElement(boolean notWriteChartElement)
{
this.notWriteChartElement = notWriteChartElement;
}
public String getPluginVarName()
{
return pluginVarName;
}
/**
* 自定义{@linkplain HtmlChartPlugin} JS变量名
*
* @param pluginVarName
*/
public void setPluginVarName(String pluginVarName)
{
this.pluginVarName = pluginVarName;
}
public boolean isNotWritePluginObject()
{
return notWritePluginObject;
}
/**
* 设置是否不输出{@linkplain HtmlChartPlugin} JS对象
*
* @param notWritePluginObject
*/
public void setNotWritePluginObject(boolean notWritePluginObject)
{
this.notWritePluginObject = notWritePluginObject;
}
public String getChartVarName()
{
return chartVarName;
}
/**
* 自定义{@linkplain HtmlChart} JS变量名
*
* @param pluginVarName
*/
public void setChartVarName(String chartVarName)
{
this.chartVarName = chartVarName;
}
public String getRenderContextVarName()
{
return renderContextVarName;
}
/**
* 自定义{@linkplain RenderContext} JS变量名
*
* @param renderContextVarName
*/
public void setRenderContextVarName(String renderContextVarName)
{
this.renderContextVarName = renderContextVarName;
}
public boolean isNotWriteRenderContextObject()
{
return notWriteRenderContextObject;
}
/**
* 设置是否不输出{@linkplain RenderContext} JS对象
*
* @param notWriteRenderContextObject
*/
public void setNotWriteRenderContextObject(boolean notWriteRenderContextObject)
{
this.notWriteRenderContextObject = notWriteRenderContextObject;
}
public boolean isNotWriteScriptTag()
{
return notWriteScriptTag;
}
/**
* 自定义是否不输出<code>&lt;script&gt;</code>标签
*
* @param notWriteScriptTag
*/
public void setNotWriteScriptTag(boolean notWriteScriptTag)
{
this.notWriteScriptTag = notWriteScriptTag;
}
public boolean isNotWriteInvoke()
{
return notWriteInvoke;
}
/**
* 自定义是否不输出调用渲染图表的函数
*
* @param notWriteInvoke
*/
public void setNotWriteInvoke(boolean notWriteInvoke)
{
this.notWriteInvoke = notWriteInvoke;
}
public boolean isWriteChartJson()
{
return writeChartJson;
}
/**
* 设置写入图表JSON对象而非JS对象
*
* @param writeChartJson
*/
public void setWriteChartJson(boolean writeChartJson)
{
this.writeChartJson = writeChartJson;
}
@Override
public String toString()
{
return getClass().getSimpleName() + " [chartElementId=" + chartElementId + ", notWriteChartElement="
+ notWriteChartElement + ", pluginVarName=" + pluginVarName + ", notWritePluginObject="
+ notWritePluginObject + ", chartVarName=" + chartVarName + ", renderContextVarName="
+ renderContextVarName + ", notWriteRenderContextObject=" + notWriteRenderContextObject
+ ", notWriteScriptTag=" + notWriteScriptTag + ", notWriteInvoke=" + notWriteInvoke
+ ", writeChartJson=" + writeChartJson + "]";
}
}
}

View File

@ -111,7 +111,7 @@ public class HtmlChartScriptObjectWriter extends AbstractHtmlScriptObjectWriter
ChartDefinition.copy(htmlChart, this);
setChartDataSets(JsonChartDataSet.valuesOf(htmlChart.getChartDataSets()));
setPlugin(new RefHtmlChartPlugin(pluginVarName));
setRenderContext(new RefHtmlRenderContext(renderContextVarName));
setRenderContext(new RefRenderContext(renderContextVarName));
setElementId(htmlChart.getElementId());
setVarName(htmlChart.getVarName());
}

View File

@ -7,46 +7,53 @@
*/
package org.datagear.analysis.support.html;
import java.io.Writer;
import org.datagear.analysis.ChartDataSet;
import org.datagear.analysis.ChartPlugin;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderException;
import org.datagear.analysis.support.ChartWidget;
import org.datagear.analysis.support.html.HtmlChartRenderAttr.HtmlChartRenderOption;
/**
* HTML {@linkplain ChartWidget}
* <p>
* 注意此类{@linkplain #render(RenderContext)}{@linkplain RenderContext}必须符合{@linkplain HtmlChartRenderAttr#inflate(RenderContext, Writer, HtmlChartRenderOption)}规范
* </p>
*
* @author datagear@163.com
*
*/
public class HtmlChartWidget<T extends HtmlRenderContext> extends ChartWidget<T>
public class HtmlChartWidget extends ChartWidget
{
public HtmlChartWidget()
{
super();
}
public HtmlChartWidget(String id, String name, ChartDataSet[] chartDataSets, HtmlChartPlugin<T> plugin)
public HtmlChartWidget(String id, String name, ChartDataSet[] chartDataSets, HtmlChartPlugin plugin)
{
super(id, name, chartDataSets, plugin);
}
@Override
public HtmlChartPlugin<T> getPlugin()
public HtmlChartPlugin getPlugin()
{
return (HtmlChartPlugin<T>) super.getPlugin();
return (HtmlChartPlugin) super.getPlugin();
}
@Override
public void setPlugin(ChartPlugin<T> plugin)
public void setPlugin(ChartPlugin plugin)
{
if (plugin != null && !(plugin instanceof HtmlChartPlugin<?>))
if (plugin != null && !(plugin instanceof HtmlChartPlugin))
throw new IllegalArgumentException();
super.setPlugin(plugin);
}
@Override
public HtmlChart render(T renderContext) throws RenderException
public HtmlChart render(RenderContext renderContext) throws RenderException
{
HtmlChart chart = (HtmlChart) super.render(renderContext);

View File

@ -6,9 +6,13 @@ package org.datagear.analysis.support.html;
import java.io.Serializable;
import java.io.Writer;
import java.util.Collection;
import java.util.Locale;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderException;
import org.datagear.util.Global;
import org.datagear.util.StringUtil;
/**
* HTML渲染上下文属性定义类
@ -26,6 +30,9 @@ public abstract class HtmlRenderAttr implements Serializable
/** 属性名:地区 */
private String localeName = "locale";
/** 属性名:忽略输出的属性集名 */
private String ignoreRenderAttrsName = "ignoreRenderAttrs";
public HtmlRenderAttr()
{
super();
@ -51,6 +58,32 @@ public abstract class HtmlRenderAttr implements Serializable
this.localeName = localeName;
}
public String getIgnoreRenderAttrsName()
{
return ignoreRenderAttrsName;
}
public void setIgnoreRenderAttrsName(String ignoreRenderAttrsName)
{
this.ignoreRenderAttrsName = ignoreRenderAttrsName;
}
/**
* 获取HTML输出流没有则返回{@code null}
*
* @param renderContext
* @return
*/
public Writer getHtmlWriterNonNull(RenderContext renderContext)
{
Writer out = renderContext.getAttribute(this.htmlWriterName);
if (out == null)
throw new RenderException("The [" + this.htmlWriterName + "] attribute must be set");
return out;
}
/**
* 获取HTML输出流没有则返回{@code null}
*
@ -116,4 +149,162 @@ public abstract class HtmlRenderAttr implements Serializable
{
return renderContext.removeAttribute(this.localeName);
}
/**
* 获取忽略渲染的{@linkplain RenderContext#getAttribute(String)}集合没有则返回{@code null}
*
* @param renderContext
* @return
*/
public Collection<String> getIgnoreRenderAttrs(RenderContext renderContext)
{
return renderContext.getAttribute(this.ignoreRenderAttrsName);
}
/**
* 设置忽略渲染的{@linkplain RenderContext#getAttribute(String)}集合
*
* @param renderContext
* @param ignoreRenderAttrs
*/
public void setIgnoreRenderAttrs(RenderContext renderContext, Collection<String> ignoreRenderAttrs)
{
renderContext.setAttribute(this.ignoreRenderAttrsName, ignoreRenderAttrs);
}
/**
* 移除忽略渲染的{@linkplain RenderContext#getAttribute(String)}集合
*
* @param renderContext
* @return 移除对象
*/
public Collection<String> removeIgnoreRenderAttrs(RenderContext renderContext)
{
return renderContext.removeAttribute(this.ignoreRenderAttrsName);
}
/**
* 生成默认{@linkplain RenderContext}变量名
*
* @param suffix
* @return
*/
public String genRenderContextVarName()
{
return genRenderContextVarName(null);
}
/**
* 生成{@linkplain RenderContext}变量名
*
* @param suffix
* @return
*/
public String genRenderContextVarName(String suffix)
{
if (suffix == null)
suffix = "";
return StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "RenderContext" + suffix;
}
/**
* 生成默认图表插件变量名
*
* @return
*/
public String genChartPluginVarName()
{
return genChartPluginVarName(null);
}
/**
* 生成图表插件变量名
*
* @param suffix
* 允许为{@code null}
* @return
*/
public String genChartPluginVarName(String suffix)
{
if (suffix == null)
suffix = "";
return StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "ChartPlugin" + suffix;
}
/**
* 生成默认图表HTML元素ID
*
* @return
*/
public String genChartElementId()
{
return genChartElementId(null);
}
/**
* 生成图表HTML元素ID
*
* @param suffix
* 允许为{@code null}
* @return
*/
public String genChartElementId(String suffix)
{
if (suffix == null)
suffix = "";
return StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "ChartElement" + suffix;
}
/**
* 生成默认图表变量名
*
* @return
*/
public String genChartVarName()
{
return genChartVarName(null);
}
/**
* 生成图表变量名
*
* @param suffix
* 允许为{@code null}
* @return
*/
public String genChartVarName(String suffix)
{
if (suffix == null)
suffix = "";
return StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "Chart" + suffix;
}
/**
* 生成默认看板变量名
*
* @return
*/
public String genDashboardVarName()
{
return genDashboardVarName(null);
}
/**
* 生成看板变量名
*
* @param suffix
* 允许为{@code null}
* @return
*/
public String genDashboardVarName(String suffix)
{
if (suffix == null)
suffix = "";
return StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "Dashboard" + suffix;
}
}

View File

@ -1,307 +0,0 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis.support.html;
import java.util.Locale;
import org.datagear.analysis.ChartTheme;
import org.datagear.analysis.DashboardTheme;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderStyle;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetRenderer.HtmlTitleHandler;
import org.datagear.util.Global;
import org.datagear.util.StringUtil;
/**
* HTML渲染属性常量
*
* @author datagear@163.com
*
*/
public class HtmlRenderAttributes
{
public static final String RENDER_STYPE = "renderStyle";
public static final String DASHBOARD_THEME = "dashboardTheme";
public static final String CHART_THEME = "chartTheme";
public static final String LOCALE = "locale";
public static final String HTML_TITLE_HANDLER = HtmlTitleHandler.class.getName();
/**
* 获取{@linkplain RenderStyle}没有则返回{@code null}
*
* @param renderContext
* @return
*/
public static RenderStyle getRenderStyle(RenderContext renderContext)
{
return renderContext.getAttribute(RENDER_STYPE);
}
/**
* 设置{@linkplain RenderStyle}
*
* @param renderContext
* @param renderStyle
*/
public static void setRenderStyle(RenderContext renderContext, RenderStyle renderStyle)
{
renderContext.setAttribute(RENDER_STYPE, renderStyle);
}
/**
* 移除{@linkplain RenderStyle}
*
* @param renderContext
*/
public static void removeRenderStyle(RenderContext renderContext)
{
renderContext.removeAttribute(RENDER_STYPE);
}
/**
* 获取{@linkplain DashboardTheme}没有则返回{@code null}
*
* @param renderContext
* @return
*/
public static DashboardTheme getDashboardTheme(RenderContext renderContext)
{
return renderContext.getAttribute(DASHBOARD_THEME);
}
/**
* 设置{@linkplain DashboardTheme}
*
* @param renderContext
* @param dashboardTheme
*/
public static void setDashboardTheme(RenderContext renderContext, DashboardTheme dashboardTheme)
{
renderContext.setAttribute(DASHBOARD_THEME, dashboardTheme);
}
/**
* 移除{@linkplain DashboardTheme}
*
* @param renderContext
*/
public static void removeDashboardTheme(RenderContext renderContext)
{
renderContext.removeAttribute(DASHBOARD_THEME);
}
/**
* 获取{@linkplain ChartTheme}没有则返回{@code null}
*
* @param renderContext
* @return
*/
public static ChartTheme getChartTheme(RenderContext renderContext)
{
return renderContext.getAttribute(CHART_THEME);
}
/**
* 设置{@linkplain ChartTheme}
*
* @param renderContext
* @param chartTheme
*/
public static void setChartTheme(RenderContext renderContext, ChartTheme chartTheme)
{
renderContext.setAttribute(CHART_THEME, chartTheme);
}
/**
* 移除{@linkplain ChartTheme}
*
* @param renderContext
*/
public static ChartTheme removeChartTheme(RenderContext renderContext)
{
return renderContext.removeAttribute(CHART_THEME);
}
/**
* 获取{@linkplain Locale}没有则返回{@code null}
*
* @param renderContext
* @return
*/
public static Locale getLocale(RenderContext renderContext)
{
return renderContext.getAttribute(LOCALE);
}
/**
* 设置{@linkplain Locale}
*
* @param renderContext
* @param locale
*/
public static void setLocale(RenderContext renderContext, Locale locale)
{
renderContext.setAttribute(LOCALE, locale);
}
/**
* 移除{@linkplain Locale}
*
* @param renderContext
*/
public static Locale removeLocale(RenderContext renderContext)
{
return renderContext.removeAttribute(LOCALE);
}
/**
* 获取{@linkplain HtmlTitleHandler}没有则返回{@code null}
*
* @param renderContext
* @return
*/
public static HtmlTitleHandler getHtmlTitleHandler(RenderContext renderContext)
{
return renderContext.getAttribute(HTML_TITLE_HANDLER);
}
/**
* 设置{@linkplain HtmlTitleHandler}
*
* @param renderContext
* @param htmlTitleHandler
*/
public static void setHtmlTitleHandler(RenderContext renderContext, HtmlTitleHandler htmlTitleHandler)
{
renderContext.setAttribute(HTML_TITLE_HANDLER, htmlTitleHandler);
}
/**
* 移除{@linkplain HtmlTitleHandler}
*
* @param renderContext
*/
public static HtmlTitleHandler removeHtmlTitleHandler(RenderContext renderContext)
{
return renderContext.removeAttribute(HTML_TITLE_HANDLER);
}
/**
* 生成图表HTML元素ID
*
* @param renderContext
* @return
*/
public static String generateChartElementId(HtmlRenderContext renderContext)
{
return generateChartElementId(Integer.toString(renderContext.nextSequence()));
}
/**
* 生成图表HTML元素ID
*
* @param suffix
* @return
*/
public static String generateChartElementId(String suffix)
{
return StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "ChartElement" + suffix;
}
/**
* 生成图表插件变量名
*
* @param renderContext
* @return
*/
public static String generateChartPluginVarName(HtmlRenderContext renderContext)
{
return generateChartPluginVarName(Integer.toString(renderContext.nextSequence()));
}
/**
* 生成图表插件变量名
*
* @param suffix
* @return
*/
public static String generateChartPluginVarName(String suffix)
{
return StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "ChartPlugin" + suffix;
}
/**
* 生成图表变量名
*
* @param renderContext
* @return
*/
public static String generateChartVarName(HtmlRenderContext renderContext)
{
return generateChartVarName(Integer.toString(renderContext.nextSequence()));
}
/**
* 生成图表变量名
*
* @param suffix
* @return
*/
public static String generateChartVarName(String suffix)
{
return StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "Chart" + suffix;
}
/**
* 生成看板变量名
*
* @param renderContext
* @return
*/
public static String generateDashboardVarName(HtmlRenderContext renderContext)
{
return generateDashboardVarName(Integer.toString(renderContext.nextSequence()));
}
/**
* 生成看板变量名
*
* @param suffix
* @return
*/
public static String generateDashboardVarName(String suffix)
{
return StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "Dashboard" + suffix;
}
/**
* 生成{@linkplain RenderContext}变量名
*
* @param renderContext
* @return
*/
public static String generateRenderContextVarName(HtmlRenderContext renderContext)
{
return generateRenderContextVarName(Integer.toString(renderContext.nextSequence()));
}
/**
* 生成{@linkplain RenderContext}变量名
*
* @param suffix
* @return
*/
public static String generateRenderContextVarName(String suffix)
{
return StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "RenderContext" + suffix;
}
}

View File

@ -1,139 +0,0 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
package org.datagear.analysis.support.html;
import java.io.Writer;
import org.datagear.analysis.RenderContext;
/**
* HTML渲染上下文
*
* @author datagear@163.com
*
*/
public interface HtmlRenderContext extends RenderContext
{
/**
* 获取{@linkplain WebContext}
*
* @return
*/
WebContext getWebContext();
/**
* 获取渲染输出流
*
* @return
*/
Writer getWriter();
/**
* 生成下一个序号
* <p>
* 此方法为生成HTML页面元素ID变量名提供支持
* </p>
*
* @return
*/
int nextSequence();
/**
* Web上下文信息
* <p>
* 这些信息可以输出值客户端提供看板交互支持
* </p>
*
* @author datagear@163.com
*
*/
class WebContext
{
/** 上下文路径 */
private String contextPath;
/** 更新看板数据的URL */
private String updateDashboardURL;
/** 更新看板数据的的看板ID参数名 */
private String dashboardIdParam = "dashboardId";
/** 更新看板数据的图表集参数名 */
private String chartIdsParam = "chartsId";
/** 更新看板数据的图表集参数值的参数名 */
private String chartsParamValuesParam = "chartsParamValues";
public WebContext()
{
super();
}
public WebContext(String contextPath, String updateDashboardURL)
{
super();
this.contextPath = contextPath;
this.updateDashboardURL = updateDashboardURL;
}
public String getContextPath()
{
return contextPath;
}
public void setContextPath(String contextPath)
{
this.contextPath = contextPath;
}
public String getUpdateDashboardURL()
{
return updateDashboardURL;
}
public void setUpdateDashboardURL(String updateDashboardURL)
{
this.updateDashboardURL = updateDashboardURL;
}
public String getDashboardIdParam()
{
return dashboardIdParam;
}
public void setDashboardIdParam(String dashboardIdParam)
{
this.dashboardIdParam = dashboardIdParam;
}
public String getChartIdsParam()
{
return chartIdsParam;
}
public void setChartIdsParam(String chartIdsParam)
{
this.chartIdsParam = chartIdsParam;
}
public String getChartsParamValuesParam()
{
return chartsParamValuesParam;
}
public void setChartsParamValuesParam(String chartsParamValuesParam)
{
this.chartsParamValuesParam = chartsParamValuesParam;
}
@Override
public String toString()
{
return getClass().getSimpleName() + " [contextPath=" + contextPath + ", updateDashboardURL="
+ updateDashboardURL + ", dashboardIdParam=" + dashboardIdParam + ", chartIdsParam=" + chartIdsParam
+ ", chartsParamValuesParam=" + chartsParamValuesParam + "]";
}
}
}

View File

@ -9,13 +9,14 @@ package org.datagear.analysis.support.html;
import java.io.IOException;
import java.io.Writer;
import java.util.Collection;
import java.util.Map;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.support.AbstractRenderContext;
import org.datagear.analysis.support.DefaultRenderContext;
/**
* {@linkplain HtmlRenderContext} JS脚本对象输出流
* HTML {@linkplain RenderContext} JS脚本对象输出流
*
* @author datagear@163.com
*
@ -28,68 +29,7 @@ public class HtmlRenderContextScriptObjectWriter extends AbstractHtmlScriptObjec
}
/**
* {@linkplain HtmlRenderContext}的JS脚本对象写入输出流
* <p>
* 格式为
* </p>
* <code>
* <pre>
* var [varName]=
* {
* webContext : {...},
* attributes : {...}
* };
* <pre>
* </code>
*
* @param out
* @param renderContext
* @param varName
* @throws IOException
*/
public void write(Writer out, HtmlRenderContext renderContext, String varName) throws IOException
{
JsonHtmlRenderContext jsonRenderContext = new JsonHtmlRenderContext(renderContext);
out.write("var " + varName + "=");
writeNewLine(out);
writeJsonObject(out, jsonRenderContext);
out.write(";");
writeNewLine(out);
}
/**
* {@linkplain HtmlRenderContext}的JS脚本对象写入输出流并且忽略{@linkplain RenderContext#getAttributes()}属性
* <p>
* 格式为
* </p>
* <code>
* <pre>
* var [varName]=
* {
* webContext : {...}
* };
* <pre>
* </code>
*
* @param out
* @param renderContext
* @param varName
* @throws IOException
*/
public void writeNoAttributes(Writer out, HtmlRenderContext renderContext, String varName) throws IOException
{
JsonNoAttributesHtmlRenderContext jsonRenderContext = new JsonNoAttributesHtmlRenderContext(renderContext);
out.write("var " + varName + "=");
writeNewLine(out);
writeJsonObject(out, jsonRenderContext);
out.write(";");
writeNewLine(out);
}
/**
* {@linkplain HtmlRenderContext}的JS脚本对象写入输出流并且仅输出{@linkplain RenderContext#getAttributes()}属性
* {@linkplain RenderContext}的JS脚本对象写入输出流
* <p>
* 格式为
* </p>
@ -107,9 +47,36 @@ public class HtmlRenderContextScriptObjectWriter extends AbstractHtmlScriptObjec
* @param varName
* @throws IOException
*/
public void writeOnlyAttributes(Writer out, HtmlRenderContext renderContext, String varName) throws IOException
public void write(Writer out, RenderContext renderContext, String varName) throws IOException
{
JsonOnlyAttributesHtmlRenderContext jsonRenderContext = new JsonOnlyAttributesHtmlRenderContext(renderContext);
write(out, renderContext, varName, null);
}
/**
* {@linkplain RenderContext}的JS脚本对象写入输出流并忽略某些属性
* <p>
* 格式为
* </p>
* <code>
* <pre>
* var [varName]=
* {
* attributes : {...}
* };
* <pre>
* </code>
*
* @param out
* @param renderContext
* @param varName
* @param ignoreAttrs
* 忽略属性允许为{@code null}
* @throws IOException
*/
public void write(Writer out, RenderContext renderContext, String varName, Collection<String> ignoreAttrs)
throws IOException
{
JsonRenderContext jsonRenderContext = new JsonRenderContext(renderContext, ignoreAttrs);
out.write("var " + varName + "=");
writeNewLine(out);
@ -119,48 +86,70 @@ public class HtmlRenderContextScriptObjectWriter extends AbstractHtmlScriptObjec
}
/**
* 可输出为JSON的{@linkplain HtmlRenderContext}
* {@linkplain RenderContext}的JS脚本对象写入输出流并且忽略{@linkplain RenderContext#getAttributes()}属性
* <p>
* 格式为
* </p>
* <code>
* <pre>
* var [varName]= {};
* <pre>
* </code>
*
* @param out
* @param renderContext
* @param varName
* @throws IOException
*/
public void writeNoAttributes(Writer out, RenderContext renderContext, String varName) throws IOException
{
JsonNoAttributesRenderContext jsonRenderContext = new JsonNoAttributesRenderContext(renderContext);
out.write("var " + varName + "=");
writeJsonObject(out, jsonRenderContext);
out.write(";");
writeNewLine(out);
}
/**
* 可输出为JSON的{@linkplain RenderContext}
*
* @author datagear@163.com
*
*/
public static class JsonHtmlRenderContext extends DefaultHtmlRenderContext
protected static class JsonRenderContext extends DefaultRenderContext
{
public JsonRenderContext(RenderContext renderContext)
{
this(renderContext, null);
}
@SuppressWarnings("unchecked")
public JsonHtmlRenderContext(HtmlRenderContext renderContext)
public JsonRenderContext(RenderContext renderContext, Collection<String> ignoreAttrs)
{
super();
setWebContext(renderContext.getWebContext());
setAttributes((Map<String, Object>) renderContext.getAttributes());
if (ignoreAttrs != null)
{
for (String attr : ignoreAttrs)
removeAttribute(attr);
}
}
}
/**
* 可输出为JSON且{@linkplain HtmlRenderContext#getAttributes()}为空的{@linkplain HtmlRenderContext}
* 可输出为JSON且{@linkplain RenderContext#getAttributes()}为空的{@linkplain RenderContext}
*
* @author datagear@163.com
*
*/
public static class JsonNoAttributesHtmlRenderContext extends AbstractRenderContext implements HtmlRenderContext
protected static class JsonNoAttributesRenderContext extends DefaultRenderContext
{
private WebContext webContext;
public JsonNoAttributesHtmlRenderContext(HtmlRenderContext renderContext)
public JsonNoAttributesRenderContext(RenderContext renderContext)
{
super();
super.setAttributes(null);
this.webContext = renderContext.getWebContext();
}
@Override
public WebContext getWebContext()
{
return webContext;
}
public void setWebContext(WebContext webContext)
{
this.webContext = webContext;
}
@Override
@ -186,39 +175,21 @@ public class HtmlRenderContextScriptObjectWriter extends AbstractHtmlScriptObjec
{
throw new UnsupportedOperationException();
}
@Override
public Writer getWriter()
{
return null;
}
@Override
public int nextSequence()
{
return 0;
}
}
/**
* 可输出为JSON且仅带有{@linkplain RenderContext#getAttributes()}{@linkplain HtmlRenderContext}
* 可输出为JSON且仅带有{@linkplain RenderContext#getAttributes()}{@linkplain RenderContext}
*
* @author datagear@163.com
*
*/
public static class JsonOnlyAttributesHtmlRenderContext extends AbstractRenderContext implements HtmlRenderContext
protected static class JsonOnlyAttributesRenderContext extends DefaultRenderContext
{
public JsonOnlyAttributesHtmlRenderContext(RenderContext renderContext)
public JsonOnlyAttributesRenderContext(RenderContext renderContext)
{
super(renderContext.getAttributes());
}
@Override
public WebContext getWebContext()
{
return null;
}
@Override
public <T> T getAttribute(String name)
{
@ -242,17 +213,5 @@ public class HtmlRenderContextScriptObjectWriter extends AbstractHtmlScriptObjec
{
throw new UnsupportedOperationException();
}
@Override
public Writer getWriter()
{
return null;
}
@Override
public int nextSequence()
{
return 0;
}
}
}

View File

@ -7,9 +7,9 @@
*/
package org.datagear.analysis.support.html;
import org.datagear.analysis.DashboardWidget;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.TemplateDashboard;
import org.datagear.analysis.TemplateDashboardWidget;
/**
* HTML模板看板
@ -26,26 +26,26 @@ public class HtmlTplDashboard extends TemplateDashboard
super();
}
public HtmlTplDashboard(String id, String template, HtmlRenderContext renderContext,
TemplateDashboardWidget<?> dashboardWidget, String varName)
public HtmlTplDashboard(String id, String template, RenderContext renderContext,
HtmlTplDashboardWidget dashboardWidget, String varName)
{
super(id, template, renderContext, dashboardWidget);
this.varName = varName;
}
@Override
public HtmlRenderContext getRenderContext()
public HtmlTplDashboardWidget getWidget()
{
return (HtmlRenderContext) super.getRenderContext();
return (HtmlTplDashboardWidget) super.getWidget();
}
@Override
public void setRenderContext(RenderContext renderContext)
public void setWidget(DashboardWidget widget)
{
if (renderContext != null && !(renderContext instanceof HtmlRenderContext))
if (widget != null && !(widget instanceof HtmlTplDashboardWidget))
throw new IllegalArgumentException();
super.setRenderContext(renderContext);
super.setWidget(widget);
}
public String getVarName()

View File

@ -8,6 +8,7 @@ import java.io.Writer;
import org.datagear.analysis.DashboardTheme;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderException;
import org.datagear.analysis.RenderStyle;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetRenderer.HtmlTitleHandler;
@ -24,7 +25,10 @@ public class HtmlTplDashboardRenderAttr extends HtmlRenderAttr
/**
* {@linkplain HtmlTplDashboardRenderAttr}的渲染上下文属性名
*/
public static final String NAME = HtmlTplDashboardRenderAttr.class.getName();
public static final String ATTR_NAME = HtmlTplDashboardRenderAttr.class.getName();
/** 属性名Web上下文 */
private String webContextName = "webContext";
/** 属性名:渲染风格 */
private String renderStyleName = "renderStyle";
@ -40,6 +44,16 @@ public class HtmlTplDashboardRenderAttr extends HtmlRenderAttr
super();
}
public String getWebContextName()
{
return webContextName;
}
public void setWebContextName(String webContextName)
{
this.webContextName = webContextName;
}
public String getRenderStyleName()
{
return renderStyleName;
@ -70,6 +84,55 @@ public class HtmlTplDashboardRenderAttr extends HtmlRenderAttr
this.htmlTitleHandlerName = htmlTitleHandlerName;
}
/**
* 获取{@linkplain WebContext}
*
* @param renderContext
* @return
*/
public WebContext getWebContextNonNull(RenderContext renderContext)
{
WebContext webContext = getWebContext(renderContext);
if (webContext == null)
throw new RenderException("The [" + this.webContextName + "] attribute must be set");
return webContext;
}
/**
* 获取{@linkplain WebContext}没有则返回{@code null}
*
* @param renderContext
* @return
*/
public WebContext getWebContext(RenderContext renderContext)
{
return renderContext.getAttribute(this.webContextName);
}
/**
* 设置{@linkplain WebContext}
*
* @param renderContext
* @param renderStyle
*/
public void setWebContext(RenderContext renderContext, WebContext webContext)
{
renderContext.setAttribute(this.webContextName, webContext);
}
/**
* 移除{@linkplain WebContext}
*
* @param renderContext
* @return 移除对象
*/
public WebContext removeWebContext(RenderContext renderContext)
{
return renderContext.removeAttribute(this.webContextName);
}
/**
* 获取{@linkplain RenderStyle}没有则返回{@code null}
*
@ -170,14 +233,17 @@ public class HtmlTplDashboardRenderAttr extends HtmlRenderAttr
}
/**
* 设置{@linkplain HtmlTplDashboardRenderAttr}对象
* 设置{@linkplain HtmlTplDashboardWidget#render(RenderContext)}必须的上下文属性值
*
* @param renderContext
* @param renderAttr
* @param htmlWriter
* @param webContext
*/
public static void set(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr)
public void inflate(RenderContext renderContext, Writer htmlWriter, WebContext webContext)
{
renderContext.setAttribute(NAME, renderAttr);
HtmlTplDashboardRenderAttr.set(renderContext, this);
setHtmlWriter(renderContext, htmlWriter);
setWebContext(renderContext, webContext);
}
/**
@ -185,9 +251,35 @@ public class HtmlTplDashboardRenderAttr extends HtmlRenderAttr
*
* @param renderContext
*/
public static HtmlTplDashboardRenderAttr getNonNull(RenderContext renderContext)
{
HtmlTplDashboardRenderAttr renderAttr = get(renderContext);
if (renderAttr == null)
throw new RenderException("The [" + ATTR_NAME + "] attribute must be set");
return renderAttr;
}
/**
* 获取{@linkplain HtmlTplDashboardRenderAttr}对象没有则返回{@code null}
*
* @param renderContext
*/
public static HtmlTplDashboardRenderAttr get(RenderContext renderContext)
{
return renderContext.getAttribute(NAME);
return renderContext.getAttribute(ATTR_NAME);
}
/**
* 设置{@linkplain HtmlTplDashboardRenderAttr}对象
*
* @param renderContext
* @param renderAttr
*/
public static void set(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr)
{
renderContext.setAttribute(ATTR_NAME, renderAttr);
}
/**
@ -197,19 +289,103 @@ public class HtmlTplDashboardRenderAttr extends HtmlRenderAttr
*/
public static HtmlTplDashboardRenderAttr remove(RenderContext renderContext)
{
return renderContext.removeAttribute(NAME);
return renderContext.removeAttribute(ATTR_NAME);
}
/**
* 设置{@linkplain HtmlTplDashboardWidget#render(HtmlRenderContext)}必须的上下文属性值
* Web上下文信息
* <p>
* 这些信息可以输出值客户端提供看板交互支持
* </p>
*
* @param renderContext
* @param renderAttr
* @param htmlWriter
* @author datagear@163.com
*
*/
public static void inflate(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr, Writer htmlWriter)
public static class WebContext
{
HtmlTplDashboardRenderAttr.set(renderContext, renderAttr);
renderAttr.setHtmlWriter(renderContext, htmlWriter);
/** 上下文路径 */
private String contextPath;
/** 更新看板数据的URL */
private String updateDashboardURL;
/** 更新看板数据的的看板ID参数名 */
private String dashboardIdParam = "dashboardId";
/** 更新看板数据的图表集参数名 */
private String chartIdsParam = "chartsId";
/** 更新看板数据的图表集参数值的参数名 */
private String chartsParamValuesParam = "chartsParamValues";
public WebContext()
{
super();
}
public WebContext(String contextPath, String updateDashboardURL)
{
super();
this.contextPath = contextPath;
this.updateDashboardURL = updateDashboardURL;
}
public String getContextPath()
{
return contextPath;
}
public void setContextPath(String contextPath)
{
this.contextPath = contextPath;
}
public String getUpdateDashboardURL()
{
return updateDashboardURL;
}
public void setUpdateDashboardURL(String updateDashboardURL)
{
this.updateDashboardURL = updateDashboardURL;
}
public String getDashboardIdParam()
{
return dashboardIdParam;
}
public void setDashboardIdParam(String dashboardIdParam)
{
this.dashboardIdParam = dashboardIdParam;
}
public String getChartIdsParam()
{
return chartIdsParam;
}
public void setChartIdsParam(String chartIdsParam)
{
this.chartIdsParam = chartIdsParam;
}
public String getChartsParamValuesParam()
{
return chartsParamValuesParam;
}
public void setChartsParamValuesParam(String chartsParamValuesParam)
{
this.chartsParamValuesParam = chartsParamValuesParam;
}
@Override
public String toString()
{
return getClass().getSimpleName() + " [contextPath=" + contextPath + ", updateDashboardURL="
+ updateDashboardURL + ", dashboardIdParam=" + dashboardIdParam + ", chartIdsParam=" + chartIdsParam
+ ", chartsParamValuesParam=" + chartsParamValuesParam + "]";
}
}
}

View File

@ -16,8 +16,6 @@ import org.datagear.analysis.DataSetException;
import org.datagear.analysis.DataSetResult;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderException;
import org.datagear.analysis.TemplateDashboard;
import org.datagear.analysis.TemplateDashboardWidget;
import com.fasterxml.jackson.annotation.JsonIgnore;
@ -79,7 +77,7 @@ public class HtmlTplDashboardScriptObjectWriter extends AbstractHtmlScriptObject
@SuppressWarnings("unchecked")
public JsonHtmlTplDashboard(HtmlTplDashboard dashboard, String renderContextVarName)
{
super(dashboard.getId(), dashboard.getTemplate(), new RefHtmlRenderContext(renderContextVarName),
super(dashboard.getId(), dashboard.getTemplate(), new RefRenderContext(renderContextVarName),
new JsonTemplateDashboardWidget(dashboard.getWidget()), dashboard.getVarName());
setCharts(Collections.EMPTY_LIST);
@ -94,11 +92,11 @@ public class HtmlTplDashboardScriptObjectWriter extends AbstractHtmlScriptObject
}
protected static class JsonTemplateDashboardWidget extends TemplateDashboardWidget<RenderContext>
protected static class JsonTemplateDashboardWidget extends HtmlTplDashboardWidget
{
public JsonTemplateDashboardWidget(TemplateDashboardWidget<?> dashboardWidget)
public JsonTemplateDashboardWidget(HtmlTplDashboardWidget dashboardWidget)
{
super(dashboardWidget.getId(), dashboardWidget.getTemplates());
super(dashboardWidget.getId(), dashboardWidget.getTemplates(), null);
}
@JsonIgnore
@ -116,7 +114,7 @@ public class HtmlTplDashboardScriptObjectWriter extends AbstractHtmlScriptObject
}
@Override
protected TemplateDashboard renderTemplate(RenderContext renderContext, String template) throws RenderException
protected HtmlTplDashboard renderTemplate(RenderContext renderContext, String template) throws RenderException
{
throw new UnsupportedOperationException();
}

View File

@ -4,63 +4,71 @@
package org.datagear.analysis.support.html;
import java.io.Writer;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderException;
import org.datagear.analysis.TemplateDashboardWidget;
import org.datagear.analysis.support.html.HtmlTplDashboardRenderAttr.WebContext;
/**
* HTML {@linkplain TemplateDashboardWidget}
* <p>
* 此类将看板代码HTMLJavaScript输出至{@linkplain HtmlRenderContext#getWriter()}
* 此类将看板代码HTMLJavaScript输出至{@linkplain HtmlTplDashboardRenderAttr#getHtmlWriter(RenderContext)}
* </p>
* <p>
* 注意此类{@linkplain #render(RenderContext)}{@linkplain #render(RenderContext, String)}{@linkplain RenderContext}必须符合{@linkplain HtmlTplDashboardRenderAttr#inflate(RenderContext, Writer, WebContext)}规范
* </p>
*
* @author datagear@163.com
*
*/
public class HtmlTplDashboardWidget<T extends HtmlRenderContext> extends TemplateDashboardWidget<T>
public class HtmlTplDashboardWidget extends TemplateDashboardWidget
{
private HtmlTplDashboardWidgetRenderer<T> renderer;
private HtmlTplDashboardWidgetRenderer renderer;
public HtmlTplDashboardWidget()
{
super();
}
public HtmlTplDashboardWidget(String id, String template, HtmlTplDashboardWidgetRenderer<T> renderer)
public HtmlTplDashboardWidget(String id, String template, HtmlTplDashboardWidgetRenderer renderer)
{
super(id, template);
this.renderer = renderer;
}
public HtmlTplDashboardWidget(String id, String[] templates, HtmlTplDashboardWidgetRenderer<T> renderer)
public HtmlTplDashboardWidget(String id, String[] templates, HtmlTplDashboardWidgetRenderer renderer)
{
super(id, templates);
this.renderer = renderer;
}
public HtmlTplDashboardWidgetRenderer<T> getRenderer()
public HtmlTplDashboardWidgetRenderer getRenderer()
{
return renderer;
}
public void setRenderer(HtmlTplDashboardWidgetRenderer<T> renderer)
public void setRenderer(HtmlTplDashboardWidgetRenderer renderer)
{
this.renderer = renderer;
}
@Override
public HtmlTplDashboard render(T renderContext) throws RenderException
public HtmlTplDashboard render(RenderContext renderContext) throws RenderException
{
return (HtmlTplDashboard) super.render(renderContext);
}
@Override
public HtmlTplDashboard render(T renderContext, String template) throws RenderException, IllegalArgumentException
public HtmlTplDashboard render(RenderContext renderContext, String template)
throws RenderException, IllegalArgumentException
{
return (HtmlTplDashboard) super.render(renderContext, template);
}
@Override
protected HtmlTplDashboard renderTemplate(T renderContext, String template) throws RenderException
protected HtmlTplDashboard renderTemplate(RenderContext renderContext, String template) throws RenderException
{
return this.renderer.render(renderContext, this, template);
}

View File

@ -14,8 +14,11 @@ import java.util.ArrayList;
import java.util.List;
import org.datagear.analysis.Chart;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.TemplateDashboardWidgetResManager;
import org.datagear.analysis.support.ChartWidgetSource;
import org.datagear.analysis.support.DefaultRenderContext;
import org.datagear.analysis.support.html.HtmlChartRenderAttr.HtmlChartRenderOption;
import org.datagear.util.IOUtil;
import org.datagear.util.StringUtil;
@ -64,7 +67,7 @@ import org.datagear.util.StringUtil;
*
* @param <T>
*/
public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> extends HtmlTplDashboardWidgetRenderer<T>
public class HtmlTplDashboardWidgetHtmlRenderer extends HtmlTplDashboardWidgetRenderer
{
public static final String DEFAULT_DASHBOARD_SET_TAG_NAME = "html";
@ -226,14 +229,14 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
}
@Override
protected void renderHtmlTplDashboard(T renderContext, HtmlTplDashboard dashboard) throws Throwable
protected void renderHtmlTplDashboard(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr,
HtmlTplDashboard dashboard) throws Throwable
{
HtmlTplDashboardWidget<?> dashboardWidget = (HtmlTplDashboardWidget<?>) dashboard.getWidget();
Reader in = getTemplateReaderNotNull(dashboardWidget, dashboard.getTemplate());
Reader in = getTemplateReaderNotNull(dashboard.getWidget(), dashboard.getTemplate());
try
{
renderHtmlTplDashboard(renderContext, dashboard, in);
renderHtmlTplDashboard(renderContext, renderAttr, dashboard, in);
}
finally
{
@ -241,21 +244,12 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
}
}
/**
* 渲染{@linkplain HtmlTplDashboard}
*
* @param renderContext
* @param dashboard
* @param in
* @return
* @throws Exception
*/
protected DashboardInfo renderHtmlTplDashboard(T renderContext, HtmlTplDashboard dashboard, Reader in)
throws Exception
protected DashboardInfo renderHtmlTplDashboard(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr,
HtmlTplDashboard dashboard, Reader in) throws Exception
{
Writer out = renderContext.getWriter();
Writer out = renderAttr.getHtmlWriterNonNull(renderContext);
HtmlTitleHandler htmlTitleHandler = HtmlRenderAttributes.removeHtmlTitleHandler(renderContext);
HtmlTitleHandler htmlTitleHandler = renderAttr.getHtmlTitleHandler(renderContext);
boolean resolvedDashboardInfo = false;
boolean wroteDashboardImport = false;
@ -309,7 +303,7 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
readToTagEnd(in, out);
if (!wroteDashboardImport)
writeDashboardImport(renderContext, dashboard, dashboardInfo);
writeDashboardImport(renderContext, renderAttr, out, dashboard, dashboardInfo);
}
// <title
else if (inHeadTag && "title".equalsIgnoreCase(tagName))
@ -370,8 +364,8 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
clear(valueCache);
clear(tagContentCache);
last = resolveDashboardChartInfo(renderContext, dashboard, in, last, tagContentCache, nameCache,
valueCache, dashboardInfo);
last = resolveDashboardChartInfo(renderContext, renderAttr, dashboard, in, last,
tagContentCache, nameCache, valueCache, dashboardInfo);
append(out, tagContentCache);
}
@ -381,7 +375,7 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
{
if (!wroteDashboardScript)
{
writeHtmlTplDashboardScript(renderContext, dashboard, dashboardInfo);
writeHtmlTplDashboardScript(renderContext, renderAttr, out, dashboard, dashboardInfo);
wroteDashboardScript = true;
}
@ -407,64 +401,46 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
out.write(c);
}
HtmlRenderAttributes.setHtmlTitleHandler(renderContext, htmlTitleHandler);
return dashboardInfo;
}
/**
* 写看板导入项
*
* @param renderContext
* @param dashboard
* @param dashboardInfo
* @throws IOException
*/
protected void writeDashboardImport(T renderContext, HtmlTplDashboard dashboard, DashboardInfo dashboardInfo)
throws IOException
protected void writeDashboardImport(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr, Writer out,
HtmlTplDashboard dashboard, DashboardInfo dashboardInfo) throws IOException
{
writeDashboardImport(renderContext, dashboard, dashboardInfo.getImportExclude());
writeDashboardImport(renderContext, renderAttr, out, dashboard, dashboardInfo.getImportExclude());
}
/**
* 写HTML看板脚本
*
* @param renderContext
* @param dashboard
* @param dashboardInfo
* @throws IOException
*/
protected void writeHtmlTplDashboardScript(T renderContext, HtmlTplDashboard dashboard, DashboardInfo dashboardInfo)
throws IOException
protected void writeHtmlTplDashboardScript(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr,
Writer out, HtmlTplDashboard dashboard, DashboardInfo dashboardInfo) throws IOException
{
String globalDashboardVar = dashboardInfo.getDashboardVar();
if (StringUtil.isEmpty(globalDashboardVar))
globalDashboardVar = getDefaultDashboardVar();
String tmpRenderContextVarName = HtmlRenderAttributes.generateRenderContextVarName(renderContext);
String localDashboardVarName = HtmlRenderAttributes.generateDashboardVarName(renderContext);
String tmp0RenderContextVarName = renderAttr.genRenderContextVarName("Tmp0");
String tmp1RenderContextVarName = renderAttr.genRenderContextVarName("Tmp1");
String localDashboardVarName = renderAttr.genDashboardVarName("Tmp");
dashboard.setVarName(localDashboardVarName);
Writer out = renderContext.getWriter();
writeScriptStartTag(out);
writeNewLine(out);
out.write("(function(){");
writeNewLine(out);
writeHtmlTplDashboardJSVar(renderContext, out, dashboard, tmpRenderContextVarName);
writeHtmlTplDashboardJSVar(renderContext, renderAttr, out, dashboard, tmp0RenderContextVarName);
writeHtmlChartScripts(renderContext, dashboard, dashboardInfo);
writeHtmlTplDashboardJSInit(out, dashboard);
writeHtmlTplDashboardJSFactoryInit(out, dashboard, dashboardInfo.getDashboardFactoryVar());
writeHtmlChartScripts(renderContext, renderAttr, out, dashboard, dashboardInfo);
writeHtmlTplDashboardJSInit(renderContext, renderAttr, out, dashboard, tmp1RenderContextVarName);
writeHtmlTplDashboardJSFactoryInit(renderContext, renderAttr, out, dashboard,
dashboardInfo.getDashboardFactoryVar());
out.write("window." + globalDashboardVar + "=" + localDashboardVarName + ";");
writeNewLine(out);
writeNewLine(out);
writeHtmlTplDashboardJSRender(out, dashboard);
writeHtmlTplDashboardJSRender(renderContext, renderAttr, out, dashboard);
out.write("})();");
writeNewLine(out);
@ -473,8 +449,8 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
writeNewLine(out);
}
protected void writeHtmlChartScripts(T renderContext, HtmlTplDashboard dashboard, DashboardInfo dashboardInfo)
throws IOException
protected void writeHtmlChartScripts(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr, Writer out,
HtmlTplDashboard dashboard, DashboardInfo dashboardInfo) throws IOException
{
List<Chart> charts = dashboard.getCharts();
if (charts == null)
@ -486,44 +462,41 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
List<ChartInfo> chartInfos = dashboardInfo.getChartInfos();
if (chartInfos != null)
{
List<HtmlChartWidget<HtmlRenderContext>> chartWidgets = getHtmlChartWidgets(renderContext, chartInfos);
List<String> chartPluginVarNames = writeHtmlChartPluginScriptsResolveImport(renderContext, chartWidgets);
List<HtmlChartWidget> chartWidgets = getHtmlChartWidgets(renderContext, chartInfos);
List<String> chartPluginVarNames = writeHtmlChartPluginScriptsResolveImport(renderContext, renderAttr, out,
chartWidgets);
HtmlChartPluginRenderOption option = new HtmlChartPluginRenderOption();
option.setNotWriteChartElement(true);
option.setNotWriteScriptTag(true);
option.setNotWriteInvoke(true);
option.setNotWritePluginObject(true);
option.setNotWriteRenderContextObject(true);
option.setRenderContextVarName(dashboard.getVarName() + ".renderContext");
RenderContext chartRenderContext = new DefaultRenderContext(renderContext);
HtmlChartRenderAttr chartRenderAttr = new HtmlChartRenderAttr();
HtmlChartPluginRenderOption.setOption(renderContext, option);
HtmlChartRenderOption chartRenderOption = new HtmlChartRenderOption(chartRenderAttr);
chartRenderOption.setNotWriteChartElement(true);
chartRenderOption.setNotWriteScriptTag(true);
chartRenderOption.setNotWriteInvoke(true);
chartRenderOption.setNotWritePluginObject(true);
chartRenderOption.setNotWriteRenderContextObject(true);
chartRenderOption.setRenderContextVarName(dashboard.getVarName() + ".renderContext");
chartRenderAttr.inflate(chartRenderContext, out, chartRenderOption);
for (int i = 0; i < chartInfos.size(); i++)
{
ChartInfo chartInfo = chartInfos.get(i);
HtmlChartWidget<HtmlRenderContext> chartWidget = chartWidgets.get(i);
HtmlChartWidget chartWidget = chartWidgets.get(i);
option.setChartElementId(chartInfo.getElementId());
chartRenderOption.setChartElementId(chartInfo.getElementId());
chartRenderOption.setPluginVarName(chartPluginVarNames.get(i));
chartRenderOption.setChartVarName(chartRenderAttr.genChartVarName(Integer.toString(i)));
String chartVarName = HtmlRenderAttributes.generateChartVarName(renderContext);
option.setPluginVarName(chartPluginVarNames.get(i));
option.setChartVarName(chartVarName);
HtmlChart chart = writeHtmlChart(chartWidget, renderContext);
HtmlChart chart = writeHtmlChart(chartRenderContext, chartWidget);
charts.add(chart);
}
// 移除内部设置的属性
HtmlChartPluginRenderOption.removeOption(renderContext);
}
}
protected List<HtmlChartWidget<HtmlRenderContext>> getHtmlChartWidgets(HtmlRenderContext renderContext,
List<ChartInfo> chartInfos)
protected List<HtmlChartWidget> getHtmlChartWidgets(RenderContext renderContext, List<ChartInfo> chartInfos)
{
List<HtmlChartWidget<HtmlRenderContext>> list = new ArrayList<>();
List<HtmlChartWidget> list = new ArrayList<>();
if (chartInfos == null)
return list;
@ -582,23 +555,9 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
return c;
}
/**
* 解析{@linkplain DashboardInfo#getChartInfos()}
*
* @param renderContext
* @param dashboard
* @param in
* @param last
* @param cache
* @param attrName
* @param attrValue
* @param dashboardInfo
* @return
* @throws IOException
*/
protected int resolveDashboardChartInfo(T renderContext, HtmlTplDashboard dashboard, Reader in, int last,
StringBuilder cache, StringBuilder attrName, StringBuilder attrValue, DashboardInfo dashboardInfo)
throws IOException
protected int resolveDashboardChartInfo(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr,
HtmlTplDashboard dashboard, Reader in, int last, StringBuilder cache, StringBuilder attrName,
StringBuilder attrValue, DashboardInfo dashboardInfo) throws IOException
{
ChartInfo chartInfo = null;
@ -636,7 +595,8 @@ public class HtmlTplDashboardWidgetHtmlRenderer<T extends HtmlRenderContext> ext
// 元素没有定义id属性
if (chartInfo != null && StringUtil.isEmpty(chartInfo.getElementId()))
{
String elementId = HtmlRenderAttributes.generateChartElementId(renderContext);
int chartIndex = dashboardInfo.getChartInfos().size();
String elementId = renderAttr.genChartElementId(Integer.toString(chartIndex));
chartInfo.setElementId(elementId);

View File

@ -12,13 +12,14 @@ import java.io.InputStream;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.datagear.analysis.Chart;
import org.datagear.analysis.ChartDefinition;
import org.datagear.analysis.ChartTheme;
import org.datagear.analysis.Dashboard;
import org.datagear.analysis.DashboardTheme;
import org.datagear.analysis.DashboardThemeSource;
@ -30,6 +31,7 @@ import org.datagear.analysis.Theme;
import org.datagear.analysis.support.ChartWidget;
import org.datagear.analysis.support.ChartWidgetSource;
import org.datagear.analysis.support.SimpleDashboardThemeSource;
import org.datagear.analysis.support.html.HtmlTplDashboardRenderAttr.WebContext;
import org.datagear.util.Global;
import org.datagear.util.IDUtil;
import org.datagear.util.IOUtil;
@ -38,6 +40,9 @@ import org.datagear.util.StringUtil;
/**
* 抽象{@linkplain HtmlTplDashboardWidget}渲染器
* <p>
* 注意此类{@linkplain #render(RenderContext, HtmlTplDashboardWidget, String)}{@linkplain RenderContext}必须符合{@linkplain HtmlTplDashboardRenderAttr#inflate(RenderContext, Writer, WebContext)}规范
* </p>
* <p>
* 此类的{@linkplain #writeHtmlTplDashboardJSFactoryInit(Writer, HtmlTplDashboard, String)}方法的JS看板渲染逻辑为
* </p>
* <code>
@ -64,7 +69,7 @@ import org.datagear.util.StringUtil;
* </p>
* <p>
* 此类的{@linkplain #getHtmlTplDashboardImports()}{@linkplain HtmlTplDashboardImport#getContent()}可以包含{@linkplain #getContextPathPlaceholder()}占位符
* 在渲染时占位符会被替换为实际的{@linkplain HtmlRenderContext#getContextPath()}
* 在渲染时占位符会被替换为{@linkplain HtmlTplDashboardRenderAttr#getWebContext(RenderContext)}{@linkplain WebContext#getContextPath()}
* </p>
* <p>
* 此类的{@linkplain #getHtmlTplDashboardImports()}{@linkplain HtmlTplDashboardImport#getContent()}可以包含{@linkplain #getVersionPlaceholder()}占位符
@ -79,7 +84,7 @@ import org.datagear.util.StringUtil;
*
* @param <T>
*/
public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext> extends TextParserSupport
public abstract class HtmlTplDashboardWidgetRenderer extends TextParserSupport
{
public static final String DEFAULT_CONTEXT_PATH_PLACE_HOLDER = "$CONTEXTPATH";
@ -109,7 +114,7 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
private HtmlTplDashboardScriptObjectWriter htmlTplDashboardScriptObjectWriter = new HtmlTplDashboardScriptObjectWriter();
private ParamValueHtmlChartPlugin<HtmlRenderContext> htmlChartPluginForGetWidgetException = new ParamValueHtmlChartPlugin<>(
private ParamValueHtmlChartPlugin htmlChartPluginForGetWidgetException = new ParamValueHtmlChartPlugin(
StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "HtmlChartPluginForGetWidgetException",
StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "HtmlChartPluginForGetWidgetExceptionMsg");
@ -231,13 +236,12 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
this.htmlTplDashboardScriptObjectWriter = htmlTplDashboardScriptObjectWriter;
}
public ParamValueHtmlChartPlugin<HtmlRenderContext> getHtmlChartPluginForGetWidgetException()
public ParamValueHtmlChartPlugin getHtmlChartPluginForGetWidgetException()
{
return htmlChartPluginForGetWidgetException;
}
public void setHtmlChartPluginForGetWidgetException(
ParamValueHtmlChartPlugin<HtmlRenderContext> htmlChartPluginForGetWidgetException)
public void setHtmlChartPluginForGetWidgetException(ParamValueHtmlChartPlugin htmlChartPluginForGetWidgetException)
{
this.htmlChartPluginForGetWidgetException = htmlChartPluginForGetWidgetException;
}
@ -486,6 +490,45 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
return charset;
}
/**
* 渲染{@linkplain Dashboard}
*
* @param renderContext
* @param dashboardWidget
* @param template
* @return
* @throws RenderException
*/
public HtmlTplDashboard render(RenderContext renderContext, HtmlTplDashboardWidget dashboardWidget, String template)
throws RenderException
{
HtmlTplDashboardRenderAttr renderAttr = getHtmlTplDashboardRenderAttrNonNull(renderContext);
RenderStyle renderStyle = inflateRenderStyle(renderContext, renderAttr);
inflateDashboardTheme(renderContext, renderAttr, renderStyle);
HtmlTplDashboard dashboard = createHtmlTplDashboard(renderContext, dashboardWidget, template);
try
{
renderHtmlTplDashboard(renderContext, renderAttr, dashboard);
}
catch (RenderException e)
{
throw e;
}
catch (Throwable t)
{
throw new RenderException(t);
}
return dashboard;
}
protected HtmlTplDashboardRenderAttr getHtmlTplDashboardRenderAttrNonNull(RenderContext renderContext)
{
return HtmlTplDashboardRenderAttr.getNonNull(renderContext);
}
/**
* 设置必要的{@linkplain RenderStyle}
* <p>
@ -495,14 +538,14 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* @param renderContext
* @return
*/
public RenderStyle inflateRenderStyle(HtmlRenderContext renderContext)
public RenderStyle inflateRenderStyle(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr)
{
RenderStyle renderStyle = HtmlRenderAttributes.getRenderStyle(renderContext);
RenderStyle renderStyle = renderAttr.getRenderStyle(renderContext);
if (renderStyle == null)
{
renderStyle = RenderStyle.LIGHT;
HtmlRenderAttributes.setRenderStyle(renderContext, renderStyle);
renderAttr.setRenderStyle(renderContext, renderStyle);
}
return renderStyle;
@ -517,54 +560,20 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* @param renderContext
* @param renderStyle
*/
public DashboardTheme inflateDashboardTheme(HtmlRenderContext renderContext, RenderStyle renderStyle)
public DashboardTheme inflateDashboardTheme(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr,
RenderStyle renderStyle)
{
DashboardTheme dashboardTheme = HtmlRenderAttributes.getDashboardTheme(renderContext);
DashboardTheme dashboardTheme = renderAttr.getDashboardTheme(renderContext);
if (dashboardTheme == null)
{
dashboardTheme = getDashboardTheme(renderStyle);
HtmlRenderAttributes.setDashboardTheme(renderContext, dashboardTheme);
renderAttr.setDashboardTheme(renderContext, dashboardTheme);
}
HtmlRenderAttributes.setChartTheme(renderContext, dashboardTheme.getChartTheme());
return dashboardTheme;
}
/**
* 渲染{@linkplain Dashboard}
*
* @param renderContext
* @param dashboardWidget
* @param template
* @return
* @throws RenderException
*/
public HtmlTplDashboard render(T renderContext, HtmlTplDashboardWidget<T> dashboardWidget, String template)
throws RenderException
{
RenderStyle renderStyle = inflateRenderStyle(renderContext);
inflateDashboardTheme(renderContext, renderStyle);
HtmlTplDashboard dashboard = createHtmlTplDashboard(renderContext, dashboardWidget, template);
try
{
renderHtmlTplDashboard(renderContext, dashboard);
}
catch (RenderException e)
{
throw e;
}
catch (Throwable t)
{
throw new RenderException(t);
}
return dashboard;
}
/**
* 读取指定{@linkplain HtmlTplDashboardWidget}的模板内容
*
@ -573,7 +582,7 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* @return
* @throws IOException
*/
public String readTemplateContent(HtmlTplDashboardWidget<T> dashboardWidget, String template) throws IOException
public String readTemplateContent(HtmlTplDashboardWidget dashboardWidget, String template) throws IOException
{
Reader reader = getTemplateReaderNotNull(dashboardWidget, template);
@ -588,7 +597,7 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* @param templateContent
* @throws IOException
*/
public void saveTemplateContent(HtmlTplDashboardWidget<T> dashboardWidget, String template, String templateContent)
public void saveTemplateContent(HtmlTplDashboardWidget dashboardWidget, String template, String templateContent)
throws IOException
{
Writer writer = null;
@ -614,37 +623,23 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
public abstract String simpleTemplateContent(String htmlCharset, String... chartWidgetId);
/**
* 渲染{@linkplain Dashboard}
* 渲染{@linkplain HtmlTplDashboard}
*
* @param renderContext
* @param renderAttr
* @param dashboard
* @throws Throwable
*/
protected abstract void renderHtmlTplDashboard(T renderContext, HtmlTplDashboard dashboard) throws Throwable;
protected abstract void renderHtmlTplDashboard(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr,
HtmlTplDashboard dashboard) throws Throwable;
/**
* 获取{@linkplain HtmlTplDashboardWidget}的模板输入流
*
* @param dashboardWidget
* @param template
* @return
* @throws IOException
*/
protected Reader getTemplateReaderNotNull(HtmlTplDashboardWidget<?> dashboardWidget, String template)
protected Reader getTemplateReaderNotNull(HtmlTplDashboardWidget dashboardWidget, String template)
throws IOException
{
return getTemplateDashboardWidgetResManager().getTemplateReader(dashboardWidget, template);
}
/**
* 获取{@linkplain HtmlTplDashboardWidget}的模板输入流
*
* @param dashboardWidget
* @param template
* @return
* @throws IOException
*/
protected Writer getTemplateWriter(HtmlTplDashboardWidget<?> dashboardWidget, String template) throws IOException
protected Writer getTemplateWriter(HtmlTplDashboardWidget dashboardWidget, String template) throws IOException
{
return getTemplateDashboardWidgetResManager().getTemplateWriter(dashboardWidget, template);
}
@ -679,8 +674,7 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* @param id
* @return
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected HtmlChartWidget<HtmlRenderContext> getHtmlChartWidgetForRender(HtmlRenderContext renderContext, String id)
protected HtmlChartWidget getHtmlChartWidgetForRender(RenderContext renderContext, String id)
{
ChartWidget chartWidget = null;
@ -702,15 +696,13 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
if (chartWidget.getPlugin() == null)
chartWidget = createHtmlChartWidgetForPluginNull(chartWidget);
return (HtmlChartWidget<HtmlRenderContext>) chartWidget;
return (HtmlChartWidget) chartWidget;
}
protected HtmlChartWidget<HtmlRenderContext> createHtmlChartWidgetForGetException(String exceptionWidgetId,
Throwable t)
protected HtmlChartWidget createHtmlChartWidgetForGetException(String exceptionWidgetId, Throwable t)
{
HtmlChartWidget<HtmlRenderContext> widget = new HtmlChartWidget<>(IDUtil.uuid(),
"HtmlChartWidgetForWidgetGetException", ChartDefinition.EMPTY_CHART_DATA_SET,
this.htmlChartPluginForGetWidgetException);
HtmlChartWidget widget = new HtmlChartWidget(IDUtil.uuid(), "HtmlChartWidgetForWidgetGetException",
ChartDefinition.EMPTY_CHART_DATA_SET, this.htmlChartPluginForGetWidgetException);
Map<String, Object> paramValues = new HashMap<>();
paramValues.put(this.htmlChartPluginForGetWidgetException.getChartParamName(),
@ -721,11 +713,10 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
return widget;
}
protected HtmlChartWidget<HtmlRenderContext> createHtmlChartWidgetForNotFound(String notFoundWidgetId)
protected HtmlChartWidget createHtmlChartWidgetForNotFound(String notFoundWidgetId)
{
HtmlChartWidget<HtmlRenderContext> widget = new HtmlChartWidget<>(IDUtil.uuid(),
"HtmlChartWidgetForWidgetNotFound", ChartDefinition.EMPTY_CHART_DATA_SET,
this.htmlChartPluginForGetWidgetException);
HtmlChartWidget widget = new HtmlChartWidget(IDUtil.uuid(), "HtmlChartWidgetForWidgetNotFound",
ChartDefinition.EMPTY_CHART_DATA_SET, this.htmlChartPluginForGetWidgetException);
Map<String, Object> paramValues = new HashMap<>();
paramValues.put(this.htmlChartPluginForGetWidgetException.getChartParamName(),
@ -736,11 +727,10 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
return widget;
}
protected HtmlChartWidget<HtmlRenderContext> createHtmlChartWidgetForPluginNull(ChartWidget<?> chartWidget)
protected HtmlChartWidget createHtmlChartWidgetForPluginNull(ChartWidget chartWidget)
{
HtmlChartWidget<HtmlRenderContext> widget = new HtmlChartWidget<>(IDUtil.uuid(),
"HtmlChartWidgetForWidgetPluginNull", ChartDefinition.EMPTY_CHART_DATA_SET,
this.htmlChartPluginForGetWidgetException);
HtmlChartWidget widget = new HtmlChartWidget(IDUtil.uuid(), "HtmlChartWidgetForWidgetPluginNull",
ChartDefinition.EMPTY_CHART_DATA_SET, this.htmlChartPluginForGetWidgetException);
Map<String, Object> paramValues = new HashMap<>();
paramValues.put(this.htmlChartPluginForGetWidgetException.getChartParamName(),
@ -756,21 +746,21 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* <p>
* <code>
* <pre>
* var [tmpRenderContextVarName] = {...};
* var [dashboardVarName] = {...};
* var [tmpRenderContextVarName] = {};
* var [dashboardVarName] = {..., renderContext: [tmpRenderContextVarName], ...};
* </pre>
* </code>
* </p>
*
* @param renderContext
* @param renderAttr
* @param out
* @param dashboard
* @param tmpRenderContextVarName
* @throws IOException
*/
protected void writeHtmlTplDashboardJSVar(HtmlRenderContext renderContext, Writer out, HtmlTplDashboard dashboard,
String tmpRenderContextVarName)
throws IOException
protected void writeHtmlTplDashboardJSVar(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr,
Writer out, HtmlTplDashboard dashboard, String tmpRenderContextVarName) throws IOException
{
if (StringUtil.isEmpty(dashboard.getVarName()))
throw new IllegalArgumentException();
@ -784,8 +774,8 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* <p>
* <code>
* <pre>
* var tmpRenderContext = {...};
* dashboard.renderContext.attributes = renderContext.attributes;
* var [tmpRenderContext] = { attributes: {...} };
* dashboard.renderContext.attributes = [tmpRenderContext].attributes;
* ...
* dashboard.charts.push(...);
* ...
@ -794,34 +784,26 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* </code>
* </p>
*
* @param renderContext
* @param renderAttr
* @param out
* @param dashboard
* @param tmpRenderContextVarName
* @throws IOException
*/
protected void writeHtmlTplDashboardJSInit(Writer out, HtmlTplDashboard dashboard) throws IOException
protected void writeHtmlTplDashboardJSInit(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr,
Writer out, HtmlTplDashboard dashboard, String tmpRenderContextVarName) throws IOException
{
String varName = dashboard.getVarName();
if (StringUtil.isEmpty(varName))
throw new IllegalArgumentException();
HtmlRenderContext renderContext = dashboard.getRenderContext();
String tmpRenderContextVar = HtmlRenderAttributes.generateRenderContextVarName(renderContext);
ChartTheme chartTheme = HtmlRenderAttributes.removeChartTheme(renderContext);
getHtmlRenderContextScriptObjectWriter().writeOnlyAttributes(out, renderContext, tmpRenderContextVar);
getHtmlRenderContextScriptObjectWriter().write(out, renderContext, tmpRenderContextVarName,
getHtmlRenderContextIgnoreAttrs(renderContext, renderAttr, out, dashboard));
out.write(varName + "." + Dashboard.PROPERTY_RENDER_CONTEXT + "." + RenderContext.PROPERTY_ATTRIBUTES + " = "
+ tmpRenderContextVar + "." + RenderContext.PROPERTY_ATTRIBUTES + ";");
+ tmpRenderContextVarName + "." + RenderContext.PROPERTY_ATTRIBUTES + ";");
writeNewLine(out);
out.write(varName + "." + Dashboard.PROPERTY_RENDER_CONTEXT + "." + RenderContext.PROPERTY_ATTRIBUTES + "."
+ HtmlRenderAttributes.CHART_THEME + " = " + tmpRenderContextVar + "."
+ RenderContext.PROPERTY_ATTRIBUTES + "." + HtmlRenderAttributes.DASHBOARD_THEME + "."
+ DashboardTheme.PROPERTY_CHART_THEME + ";");
writeNewLine(out);
HtmlRenderAttributes.setChartTheme(renderContext, chartTheme);
List<Chart> charts = dashboard.getCharts();
if (charts != null)
@ -844,6 +826,13 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
}
}
protected Collection<String> getHtmlRenderContextIgnoreAttrs(RenderContext renderContext,
HtmlTplDashboardRenderAttr renderAttr, Writer out, HtmlTplDashboard dashboard)
{
Collection<String> ignores = renderAttr.getIgnoreRenderAttrs(renderContext);
return (ignores != null ? ignores : Arrays.asList(renderAttr.getHtmlWriterName()));
}
/**
* {@linkplain HtmlTplDashboard} JS工厂初始化代码
* <p>
@ -854,14 +843,17 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* </code>
* </p>
*
* @param renderContext
* @param renderAttr
* @param out
* @param dashboard
* @param dashboardFactoryVar
* 如果为{@code null}则使用{@linkplain #getDefaultDashboardFactoryVar()}
* @throws IOException
*/
protected void writeHtmlTplDashboardJSFactoryInit(Writer out, HtmlTplDashboard dashboard,
String dashboardFactoryVar) throws IOException
protected void writeHtmlTplDashboardJSFactoryInit(RenderContext renderContext,
HtmlTplDashboardRenderAttr renderAttr, Writer out, HtmlTplDashboard dashboard, String dashboardFactoryVar)
throws IOException
{
String varName = dashboard.getVarName();
@ -890,11 +882,14 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* </code>
* </p>
*
* @param renderContext
* @param renderAttr
* @param out
* @param dashboard
* @throws IOException
*/
protected void writeHtmlTplDashboardJSRender(Writer out, HtmlTplDashboard dashboard) throws IOException
protected void writeHtmlTplDashboardJSRender(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr,
Writer out, HtmlTplDashboard dashboard) throws IOException
{
String varName = dashboard.getVarName();
@ -921,14 +916,16 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* 写看板导入项
*
* @param renderContext
* @param renderAttr
* @param out
* @param dashboard
* @param importExclude
* @throws IOException
*/
protected void writeDashboardImport(HtmlRenderContext renderContext, HtmlTplDashboard dashboard,
String importExclude) throws IOException
protected void writeDashboardImport(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr, Writer out,
HtmlTplDashboard dashboard, String importExclude) throws IOException
{
Writer out = renderContext.getWriter();
WebContext webContext = renderAttr.getWebContext(renderContext);
List<String> excludes = StringUtil.splitWithTrim(importExclude, ",");
@ -941,8 +938,7 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
if (excludes.contains(name))
continue;
String content = replaceContextPathPlaceholder(impt.getContent(),
renderContext.getWebContext().getContextPath());
String content = replaceContextPathPlaceholder(impt.getContent(), webContext.getContextPath());
content = replaceVersionPlaceholder(content, Global.VERSION);
@ -954,7 +950,8 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
if (!excludes.contains(this.themeImportName))
{
writeNewLine(out);
writeDashboardThemeStyle(renderContext, dashboard, out);
writeDashboardThemeStyle(renderContext, renderAttr, out, dashboard,
renderAttr.getDashboardTheme(renderContext));
}
}
@ -966,24 +963,27 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* </p>
*
* @param renderContext
* @param renderAttr
* @param out
* @param htmlChartWidgets
* @return
* @throws IOException
*/
protected List<String> writeHtmlChartPluginScriptsResolveImport(T renderContext,
List<HtmlChartWidget<HtmlRenderContext>> htmlChartWidgets) throws IOException
protected List<String> writeHtmlChartPluginScriptsResolveImport(RenderContext renderContext,
HtmlTplDashboardRenderAttr renderAttr, Writer out, List<HtmlChartWidget> htmlChartWidgets)
throws IOException
{
if(this.importHtmlChartPluginVarNameResolver == null)
return writeHtmlChartPluginScripts(renderContext, htmlChartWidgets);
if (this.importHtmlChartPluginVarNameResolver == null)
return writeHtmlChartPluginScripts(renderContext, renderAttr, out, htmlChartWidgets);
List<String> pluginVarNames = new ArrayList<>(htmlChartWidgets.size());
for (HtmlChartWidget<?> widget : htmlChartWidgets)
for (HtmlChartWidget widget : htmlChartWidgets)
{
String importVarName = this.importHtmlChartPluginVarNameResolver.resolve(widget);
pluginVarNames.add(importVarName);
}
return pluginVarNames;
}
@ -991,12 +991,15 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* {@linkplain HtmlChartPlugin} JS脚本并返回对应的变量名列表
*
* @param renderContext
* @param renderAttr
* @param out
* @param htmlChartWidgets
* @return
* @throws IOException
*/
protected List<String> writeHtmlChartPluginScripts(T renderContext,
List<HtmlChartWidget<HtmlRenderContext>> htmlChartWidgets) throws IOException
protected List<String> writeHtmlChartPluginScripts(RenderContext renderContext,
HtmlTplDashboardRenderAttr renderAttr, Writer out, List<HtmlChartWidget> htmlChartWidgets)
throws IOException
{
List<String> pluginVarNames = new ArrayList<>(htmlChartWidgets.size());
@ -1004,13 +1007,13 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
{
String pluginVarName = null;
HtmlChartWidget<HtmlRenderContext> widget = htmlChartWidgets.get(i);
HtmlChartPlugin<HtmlRenderContext> plugin = widget.getPlugin();
HtmlChartWidget widget = htmlChartWidgets.get(i);
HtmlChartPlugin plugin = widget.getPlugin();
for (int j = 0; j < i; j++)
{
HtmlChartWidget<HtmlRenderContext> myWidget = htmlChartWidgets.get(j);
HtmlChartPlugin<HtmlRenderContext> myPlugin = myWidget.getPlugin();
HtmlChartWidget myWidget = htmlChartWidgets.get(j);
HtmlChartPlugin myPlugin = myWidget.getPlugin();
if (myPlugin.getId().equals(plugin.getId()))
{
@ -1021,8 +1024,8 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
if (pluginVarName == null)
{
pluginVarName = HtmlRenderAttributes.generateChartPluginVarName(renderContext);
getHtmlChartPluginScriptObjectWriter().write(renderContext.getWriter(), plugin, pluginVarName);
pluginVarName = renderAttr.genChartPluginVarName(Integer.toString(i));
getHtmlChartPluginScriptObjectWriter().write(out, plugin, pluginVarName);
}
pluginVarNames.add(pluginVarName);
@ -1033,13 +1036,12 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
/**
* {@linkplain HtmlChart}
*
* @param chartWidget
*
* @param renderContext
* @param chartWidget
* @return
*/
protected HtmlChart writeHtmlChart(HtmlChartWidget<HtmlRenderContext> chartWidget, HtmlRenderContext renderContext)
throws RenderException
protected HtmlChart writeHtmlChart(RenderContext renderContext, HtmlChartWidget chartWidget) throws RenderException
{
return chartWidget.render(renderContext);
}
@ -1048,16 +1050,16 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* 写看板主题样式
*
* @param renderContext
* @param dashboard
* @param out
* @param dashboard
* @param dashboardTheme
* {@code null}则什么也不写
* @return
* @throws IOException
*/
protected boolean writeDashboardThemeStyle(HtmlRenderContext renderContext, HtmlTplDashboard dashboard, Writer out)
throws IOException
protected boolean writeDashboardThemeStyle(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr,
Writer out, HtmlTplDashboard dashboard, DashboardTheme dashboardTheme) throws IOException
{
DashboardTheme dashboardTheme = HtmlRenderAttributes.getDashboardTheme(renderContext);
if (dashboardTheme == null)
return false;
@ -1430,8 +1432,8 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* @param template
* @return
*/
protected HtmlTplDashboard createHtmlTplDashboard(T renderContext, HtmlTplDashboardWidget<T> dashboardWidget,
String template)
protected HtmlTplDashboard createHtmlTplDashboard(RenderContext renderContext,
HtmlTplDashboardWidget dashboardWidget, String template)
{
HtmlTplDashboard dashboard = new HtmlTplDashboard();
@ -1525,7 +1527,7 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
* @param chartWidget
* @return
*/
String resolve(HtmlChartWidget<?> chartWidget);
String resolve(HtmlChartWidget chartWidget);
}
public static class TemplateImportHtmlChartPluginVarNameResolver implements ImportHtmlChartPluginVarNameResolver
@ -1556,7 +1558,7 @@ public abstract class HtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext
}
@Override
public String resolve(HtmlChartWidget<?> chartWidget)
public String resolve(HtmlChartWidget chartWidget)
{
String chartPluginId = chartWidget.getPlugin().getId();
return this.template.replace(PLACEHOLDER_CHART_PLUGIN_ID, chartPluginId);

View File

@ -87,13 +87,13 @@ public class LoadHtmlChartPluginBean
/**
* 加载
*/
public Set<HtmlChartPlugin<?>> load()
public Set<HtmlChartPlugin> load()
{
Set<HtmlChartPlugin<?>> plugins = this.htmlChartPluginLoader.loads(this.directory);
Set<HtmlChartPlugin> plugins = this.htmlChartPluginLoader.loads(this.directory);
if (plugins != null)
{
for (HtmlChartPlugin<?> plugin : plugins)
for (HtmlChartPlugin plugin : plugins)
this.chartPluginManager.register(plugin);
}

View File

@ -20,7 +20,7 @@ import org.datagear.util.i18n.Label;
* @author datagear@163.com
*
*/
public class ParamValueHtmlChartPlugin<T extends HtmlRenderContext> extends HtmlChartPlugin<T>
public class ParamValueHtmlChartPlugin extends HtmlChartPlugin
{
private String chartParamName;

View File

@ -161,7 +161,7 @@ public class JsonChartPluginPropertiesResolverTest
}
}
private static class TestChartPlugin extends AbstractChartPlugin<RenderContext>
private static class TestChartPlugin extends AbstractChartPlugin
{
public TestChartPlugin()
{

View File

@ -29,7 +29,6 @@ public class DirectoryHtmlChartPluginManagerTest
{
super();
}
@Test
@ -60,22 +59,22 @@ public class DirectoryHtmlChartPluginManagerTest
directoryHtmlChartPluginManager.init();
ChartPlugin<?> plugin = directoryHtmlChartPluginManager.get("test");
ChartPlugin plugin = directoryHtmlChartPluginManager.get("test");
assertNotNull(plugin);
assertEquals("0.1.0", plugin.getVersion());
{
Set<HtmlChartPlugin<?>> uploaded = directoryHtmlChartPluginManager.upload(uploadDirectory);
Set<HtmlChartPlugin> uploaded = directoryHtmlChartPluginManager.upload(uploadDirectory);
plugin = directoryHtmlChartPluginManager.get("test");
assertEquals(1, uploaded.size());
assertNotNull(plugin);
assertEquals("0.1.1", plugin.getVersion());
}
{
Set<HtmlChartPlugin<?>> uploaded = directoryHtmlChartPluginManager.upload(uploadDirectory);
Set<HtmlChartPlugin> uploaded = directoryHtmlChartPluginManager.upload(uploadDirectory);
plugin = directoryHtmlChartPluginManager.get("test");
assertEquals(0, uploaded.size());

View File

@ -35,7 +35,7 @@ public class HtmlChartPluginLoaderTest
File directory = new File(
"src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin01");
HtmlChartPlugin<?> plugin = this.htmlChartPluginLoader.load(directory);
HtmlChartPlugin plugin = this.htmlChartPluginLoader.load(directory);
Assert.assertEquals("plugin01", plugin.getId());
}
@ -45,7 +45,7 @@ public class HtmlChartPluginLoaderTest
File file = new File(
"src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin03.zip");
HtmlChartPlugin<?> plugin = this.htmlChartPluginLoader.loadZip(file);
HtmlChartPlugin plugin = this.htmlChartPluginLoader.loadZip(file);
Assert.assertEquals("plugin03", plugin.getId());
}
@ -54,9 +54,9 @@ public class HtmlChartPluginLoaderTest
{
File directory = new File("src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders");
Set<HtmlChartPlugin<?>> plugins = this.htmlChartPluginLoader.loads(directory);
Set<HtmlChartPlugin> plugins = this.htmlChartPluginLoader.loads(directory);
List<HtmlChartPlugin<?>> list = new ArrayList<HtmlChartPlugin<?>>();
List<HtmlChartPlugin> list = new ArrayList<>();
list.addAll(plugins);
AbstractChartPluginManager.sort(list);
@ -64,7 +64,7 @@ public class HtmlChartPluginLoaderTest
Assert.assertEquals(4, list.size());
{
HtmlChartPlugin<?> plugin = list.get(0);
HtmlChartPlugin plugin = list.get(0);
Assert.assertEquals("plugin04", plugin.getId());
Map<RenderStyle, Icon> icons = plugin.getIcons();
@ -73,7 +73,7 @@ public class HtmlChartPluginLoaderTest
}
{
HtmlChartPlugin<?> plugin = list.get(1);
HtmlChartPlugin plugin = list.get(1);
Assert.assertEquals("plugin03", plugin.getId());
Map<RenderStyle, Icon> icons = plugin.getIcons();
@ -82,7 +82,7 @@ public class HtmlChartPluginLoaderTest
}
{
HtmlChartPlugin<?> plugin = list.get(2);
HtmlChartPlugin plugin = list.get(2);
Assert.assertEquals("plugin02", plugin.getId());
Map<RenderStyle, Icon> icons = plugin.getIcons();
@ -91,7 +91,7 @@ public class HtmlChartPluginLoaderTest
}
{
HtmlChartPlugin<?> plugin = list.get(3);
HtmlChartPlugin plugin = list.get(3);
Assert.assertEquals("plugin01", plugin.getId());
Map<RenderStyle, Icon> icons = plugin.getIcons();

View File

@ -9,12 +9,10 @@ package org.datagear.analysis.support.html;
import java.io.File;
import java.io.StringWriter;
import java.util.Locale;
import org.datagear.analysis.ChartDefinition;
import org.datagear.analysis.RenderStyle;
import org.datagear.analysis.support.SimpleDashboardThemeSource;
import org.datagear.analysis.support.html.HtmlRenderContext.WebContext;
import org.datagear.analysis.support.DefaultRenderContext;
import org.datagear.analysis.support.html.HtmlChartRenderAttr.HtmlChartRenderOption;
import org.junit.Assert;
import org.junit.Test;
@ -32,33 +30,33 @@ public class HtmlChartPluginTest
@Test
public void renderChartTest() throws Throwable
{
HtmlChartPlugin<HtmlRenderContext> htmlChartPlugin = createHtmlChartPlugin();
HtmlChartPlugin htmlChartPlugin = createHtmlChartPlugin();
DefaultRenderContext renderContext = new DefaultRenderContext();
HtmlChartRenderAttr renderAttr = new HtmlChartRenderAttr();
StringWriter stringWriter = new StringWriter();
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(new WebContext("", ""), stringWriter);
HtmlRenderAttributes.setRenderStyle(renderContext, RenderStyle.DARK);
HtmlRenderAttributes.setChartTheme(renderContext, SimpleDashboardThemeSource.THEME_LIGHT.getChartTheme());
HtmlRenderAttributes.setLocale(renderContext, Locale.getDefault());
HtmlChartRenderOption renderOption = new HtmlChartRenderOption(renderAttr);
renderAttr.inflate(renderContext, stringWriter, renderOption);
htmlChartPlugin.renderChart(renderContext, new ChartDefinition());
String html = getHtmlWithPrint(stringWriter);
Assert.assertTrue(html.contains("<div id=\"" + HtmlRenderAttributes.generateChartElementId("1") + "\"></div>"));
Assert.assertTrue(html.contains("(" + HtmlRenderAttributes.generateChartVarName("4") + ");"));
Assert.assertTrue(html.contains("<div id=\"" + renderOption.getChartElementId() + "\"></div>"));
Assert.assertTrue(html.contains("(" + renderOption.getChartVarName() + ");"));
}
@Test
public void renderChartTest_setChartRenderContextVarName() throws Throwable
{
HtmlChartPlugin<HtmlRenderContext> htmlChartPlugin = createHtmlChartPlugin();
HtmlChartPlugin htmlChartPlugin = createHtmlChartPlugin();
DefaultRenderContext renderContext = new DefaultRenderContext();
HtmlChartRenderAttr renderAttr = new HtmlChartRenderAttr();
StringWriter stringWriter = new StringWriter();
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(new WebContext("", ""), stringWriter);
HtmlChartPluginRenderOption option = new HtmlChartPluginRenderOption();
option.setRenderContextVarName("chartRenderContext");
HtmlChartPluginRenderOption.setOption(renderContext, option);
HtmlChartRenderOption renderOption = new HtmlChartRenderOption(renderAttr);
renderOption.setRenderContextVarName("chartRenderContext");
renderAttr.inflate(renderContext, stringWriter, renderOption);
htmlChartPlugin.renderChart(renderContext, new ChartDefinition());
@ -67,13 +65,11 @@ public class HtmlChartPluginTest
Assert.assertTrue(html.contains("\"renderContext\":chartRenderContext"));
}
public static HtmlChartPlugin<HtmlRenderContext> createHtmlChartPlugin() throws Exception
public static HtmlChartPlugin createHtmlChartPlugin() throws Exception
{
File directory = new File("src/test/resources/org/datagear/analysis/support/html/HtmlChartPluginTest");
@SuppressWarnings("unchecked")
HtmlChartPlugin<HtmlRenderContext> htmlChartPlugin = (HtmlChartPlugin<HtmlRenderContext>) new HtmlChartPluginLoader()
.load(directory);
HtmlChartPlugin htmlChartPlugin = new HtmlChartPluginLoader().load(directory);
return htmlChartPlugin;
}

View File

@ -12,11 +12,12 @@ import java.util.ArrayList;
import java.util.List;
import org.datagear.analysis.ChartDefinition;
import org.datagear.analysis.RenderStyle;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.TemplateDashboardWidgetResManager;
import org.datagear.analysis.support.DefaultRenderContext;
import org.datagear.analysis.support.FileTemplateDashboardWidgetResManager;
import org.datagear.analysis.support.SimpleChartWidgetSource;
import org.datagear.analysis.support.html.HtmlRenderContext.WebContext;
import org.datagear.analysis.support.html.HtmlTplDashboardRenderAttr.WebContext;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetHtmlRenderer.ChartInfo;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetHtmlRenderer.DashboardInfo;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetRenderer.AddPrefixHtmlTitleHandler;
@ -32,7 +33,7 @@ import org.junit.Test;
*/
public class HtmlTplDashboardWidgetHtmlRendererTest
{
private HtmlTplDashboardWidgetHtmlRenderer<HtmlRenderContext> renderer;
private HtmlTplDashboardWidgetHtmlRenderer renderer;
protected static final String IMPORT_CONTENT_JQUERY = "<script type=\"text/javascript\" src=\"jquery.js\"></script>";
@ -46,34 +47,36 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
{
super();
HtmlChartPlugin<HtmlRenderContext> chartPlugin = HtmlChartPluginTest.createHtmlChartPlugin();
HtmlChartPlugin chartPlugin = HtmlChartPluginTest.createHtmlChartPlugin();
HtmlChartWidget<HtmlRenderContext> htmlChartWidget = new HtmlChartWidget<HtmlRenderContext>("chart-widget-01",
"chart-widget-01", ChartDefinition.EMPTY_CHART_DATA_SET, chartPlugin);
HtmlChartWidget htmlChartWidget = new HtmlChartWidget("chart-widget-01", "chart-widget-01",
ChartDefinition.EMPTY_CHART_DATA_SET, chartPlugin);
TemplateDashboardWidgetResManager resManager = new FileTemplateDashboardWidgetResManager(
"src/test/resources/org/datagear/analysis/support/html/htmlTplDashboardWidgets/html");
SimpleChartWidgetSource chartWidgetSource = new SimpleChartWidgetSource(htmlChartWidget);
List<HtmlTplDashboardImport> dashboardImports = new ArrayList<HtmlTplDashboardImport>();
List<HtmlTplDashboardImport> dashboardImports = new ArrayList<>();
dashboardImports.add(new HtmlTplDashboardImport("jquery", IMPORT_CONTENT_JQUERY));
dashboardImports.add(new HtmlTplDashboardImport("util", IMPORT_CONTENT_UTIL));
dashboardImports.add(new HtmlTplDashboardImport("theme", IMPORT_CONTENT_THEME));
dashboardImports.add(new HtmlTplDashboardImport("style", IMPORT_CONTENT_STYLE));
this.renderer = new HtmlTplDashboardWidgetHtmlRenderer<HtmlRenderContext>(resManager, chartWidgetSource);
this.renderer = new HtmlTplDashboardWidgetHtmlRenderer(resManager, chartWidgetSource);
this.renderer.setDashboardImports(dashboardImports);
}
@Test
public void renderTest() throws Exception
{
HtmlTplDashboardWidget<HtmlRenderContext> dashboardWidget = createHtmlTplDashboardWidget();
HtmlTplDashboardWidget dashboardWidget = createHtmlTplDashboardWidget();
RenderContext renderContext = new DefaultRenderContext();
HtmlTplDashboardRenderAttr renderAttr = new HtmlTplDashboardRenderAttr();
StringWriter out = new StringWriter();
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(new WebContext("", ""), out);
HtmlRenderAttributes.setRenderStyle(renderContext, RenderStyle.DARK);
renderAttr.inflate(renderContext, out, new WebContext("", ""));
HtmlTplDashboard dashboard = dashboardWidget.render(renderContext);
getHtmlWithPrint(out);
@ -84,19 +87,21 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
@Test
public void renderHtmlTplDashboardTest() throws Exception
{
HtmlTplDashboardWidget<HtmlRenderContext> dashboardWidget = createHtmlTplDashboardWidget();
HtmlTplDashboardWidget dashboardWidget = createHtmlTplDashboardWidget();
// 看板属性双引号
{
String template = "<html dg-dashboard-var=\"myDashboard\" dg-dashboard-factory=\"myDashboardFactory\" "
+ " dg-dashboard-import-exclude=\"jquery\"><head></head><body></body></html>";
RenderContext renderContext = new DefaultRenderContext();
HtmlTplDashboardRenderAttr renderAttr = new HtmlTplDashboardRenderAttr();
StringWriter out = new StringWriter();
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(new WebContext("", ""), out);
renderAttr.inflate(renderContext, out, new WebContext("", ""));
HtmlTplDashboard dashboard = this.renderer.createHtmlTplDashboard(renderContext, dashboardWidget, template);
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, dashboard,
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, renderAttr, dashboard,
IOUtil.getReader(template));
String html = getHtmlWithPrint(out);
@ -108,9 +113,9 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
Assert.assertTrue(html.contains(IMPORT_CONTENT_UTIL));
Assert.assertTrue(html.contains(IMPORT_CONTENT_THEME));
Assert.assertTrue(html.contains(IMPORT_CONTENT_STYLE));
Assert.assertTrue(html.contains("var dataGearDashboard2"));
Assert.assertTrue(html.contains("myDashboardFactory.init(dataGearDashboard2);"));
Assert.assertTrue(html.contains("window.myDashboard=dataGearDashboard2;"));
Assert.assertTrue(html.contains("var dataGearDashboardTmp"));
Assert.assertTrue(html.contains("myDashboardFactory.init(dataGearDashboardTmp);"));
Assert.assertTrue(html.contains("window.myDashboard=dataGearDashboardTmp;"));
}
// 看板属性无引号
@ -118,12 +123,14 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
String template = "<html dg-dashboard-var=myDashboard dg-dashboard-factory=myDashboardFactory "
+ " dg-dashboard-import-exclude=jquery><head></head><body></body></html>";
RenderContext renderContext = new DefaultRenderContext();
HtmlTplDashboardRenderAttr renderAttr = new HtmlTplDashboardRenderAttr();
StringWriter out = new StringWriter();
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(new WebContext("", ""), out);
renderAttr.inflate(renderContext, out, new WebContext("", ""));
HtmlTplDashboard dashboard = this.renderer.createHtmlTplDashboard(renderContext, dashboardWidget, template);
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, dashboard,
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, renderAttr, dashboard,
IOUtil.getReader(template));
String html = getHtmlWithPrint(out);
@ -135,9 +142,9 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
Assert.assertTrue(html.contains(IMPORT_CONTENT_UTIL));
Assert.assertTrue(html.contains(IMPORT_CONTENT_THEME));
Assert.assertTrue(html.contains(IMPORT_CONTENT_STYLE));
Assert.assertTrue(html.contains("var dataGearDashboard2"));
Assert.assertTrue(html.contains("myDashboardFactory.init(dataGearDashboard2);"));
Assert.assertTrue(html.contains("window.myDashboard=dataGearDashboard2;"));
Assert.assertTrue(html.contains("var dataGearDashboardTmp"));
Assert.assertTrue(html.contains("myDashboardFactory.init(dataGearDashboardTmp);"));
Assert.assertTrue(html.contains("window.myDashboard=dataGearDashboardTmp;"));
}
// 看板属性单引号
@ -145,12 +152,14 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
String template = "<html dg-dashboard-var='myDashboard' dg-dashboard-factory='myDashboardFactory' "
+ " dg-dashboard-import-exclude='jquery'><head></head><body></body></html>";
RenderContext renderContext = new DefaultRenderContext();
HtmlTplDashboardRenderAttr renderAttr = new HtmlTplDashboardRenderAttr();
StringWriter out = new StringWriter();
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(new WebContext("", ""), out);
renderAttr.inflate(renderContext, out, new WebContext("", ""));
HtmlTplDashboard dashboard = this.renderer.createHtmlTplDashboard(renderContext, dashboardWidget, template);
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, dashboard,
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, renderAttr, dashboard,
IOUtil.getReader(template));
String html = getHtmlWithPrint(out);
@ -162,9 +171,9 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
Assert.assertTrue(html.contains(IMPORT_CONTENT_UTIL));
Assert.assertTrue(html.contains(IMPORT_CONTENT_THEME));
Assert.assertTrue(html.contains(IMPORT_CONTENT_STYLE));
Assert.assertTrue(html.contains("var dataGearDashboard2"));
Assert.assertTrue(html.contains("myDashboardFactory.init(dataGearDashboard2);"));
Assert.assertTrue(html.contains("window.myDashboard=dataGearDashboard2;"));
Assert.assertTrue(html.contains("var dataGearDashboardTmp"));
Assert.assertTrue(html.contains("myDashboardFactory.init(dataGearDashboardTmp);"));
Assert.assertTrue(html.contains("window.myDashboard=dataGearDashboardTmp;"));
}
// 看板属性多个导入排除值
@ -172,12 +181,14 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
String template = "<html dg-dashboard-var='myDashboard' dg-dashboard-factory='myDashboardFactory' "
+ " dg-dashboard-import-exclude='jquery,theme, style'><head></head><body></body></html>";
RenderContext renderContext = new DefaultRenderContext();
HtmlTplDashboardRenderAttr renderAttr = new HtmlTplDashboardRenderAttr();
StringWriter out = new StringWriter();
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(new WebContext("", ""), out);
renderAttr.inflate(renderContext, out, new WebContext("", ""));
HtmlTplDashboard dashboard = this.renderer.createHtmlTplDashboard(renderContext, dashboardWidget, template);
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, dashboard,
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, renderAttr, dashboard,
IOUtil.getReader(template));
String html = getHtmlWithPrint(out);
@ -189,21 +200,23 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
Assert.assertTrue(html.contains(IMPORT_CONTENT_UTIL));
Assert.assertFalse(html.contains(IMPORT_CONTENT_THEME));
Assert.assertFalse(html.contains(IMPORT_CONTENT_STYLE));
Assert.assertTrue(html.contains("var dataGearDashboard2"));
Assert.assertTrue(html.contains("myDashboardFactory.init(dataGearDashboard2);"));
Assert.assertTrue(html.contains("window.myDashboard=dataGearDashboard2;"));
Assert.assertTrue(html.contains("var dataGearDashboardTmp"));
Assert.assertTrue(html.contains("myDashboardFactory.init(dataGearDashboardTmp);"));
Assert.assertTrue(html.contains("window.myDashboard=dataGearDashboardTmp;"));
}
// 看板属性默认
{
String template = "<html><head></head><body></body></html>";
RenderContext renderContext = new DefaultRenderContext();
HtmlTplDashboardRenderAttr renderAttr = new HtmlTplDashboardRenderAttr();
StringWriter out = new StringWriter();
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(new WebContext("", ""), out);
renderAttr.inflate(renderContext, out, new WebContext("", ""));
HtmlTplDashboard dashboard = this.renderer.createHtmlTplDashboard(renderContext, dashboardWidget, template);
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, dashboard,
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, renderAttr, dashboard,
IOUtil.getReader(template));
String html = getHtmlWithPrint(out);
@ -215,9 +228,9 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
Assert.assertTrue(html.contains(IMPORT_CONTENT_UTIL));
Assert.assertTrue(html.contains(IMPORT_CONTENT_THEME));
Assert.assertTrue(html.contains(IMPORT_CONTENT_STYLE));
Assert.assertTrue(html.contains("var dataGearDashboard2"));
Assert.assertTrue(html.contains("dashboardFactory.init(dataGearDashboard2);"));
Assert.assertTrue(html.contains("window.dashboard=dataGearDashboard2;"));
Assert.assertTrue(html.contains("var dataGearDashboardTmp"));
Assert.assertTrue(html.contains("dashboardFactory.init(dataGearDashboardTmp);"));
Assert.assertTrue(html.contains("window.dashboard=dataGearDashboardTmp;"));
}
// 图表属性
@ -242,12 +255,14 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
//
+ HtmlChartPlugin.HTML_NEW_LINE + "</body></html>";
RenderContext renderContext = new DefaultRenderContext();
HtmlTplDashboardRenderAttr renderAttr = new HtmlTplDashboardRenderAttr();
StringWriter out = new StringWriter();
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(new WebContext("", ""), out);
renderAttr.inflate(renderContext, out, new WebContext("", ""));
HtmlTplDashboard dashboard = this.renderer.createHtmlTplDashboard(renderContext, dashboardWidget, template);
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, dashboard,
DashboardInfo dashboardInfo = this.renderer.renderHtmlTplDashboard(renderContext, renderAttr, dashboard,
IOUtil.getReader(template));
String html = getHtmlWithPrint(out);
@ -273,8 +288,8 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
Assert.assertTrue(html.contains("<div id=element_6 dg-chart-widget=chartwidget_6 />"));
Assert.assertTrue(html.contains("<div id=element_7 dg-chart-widget=chartwidget_7 / >"));
Assert.assertTrue(
html.contains("<div dg-chart-widget=chartwidget_8 id=\"dataGearChartElement1\" / >"));
Assert.assertTrue(html.contains("<div dg-chart-widget=chartwidget_9 id=\"dataGearChartElement2\" />"));
html.contains("<div dg-chart-widget=chartwidget_8 id=\"dataGearChartElement7\" / >"));
Assert.assertTrue(html.contains("<div dg-chart-widget=chartwidget_9 id=\"dataGearChartElement8\" />"));
Assert.assertTrue(html.contains("<div dg-chart-widget='' />"));
Assert.assertTrue(html.contains("<div dg-chart-widget=\"\" />"));
Assert.assertTrue(html.contains("</body></html>"));
@ -284,28 +299,35 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
{
String template = "<html><head></head><body></body></html>";
RenderContext renderContext = new DefaultRenderContext();
HtmlTplDashboardRenderAttr renderAttr = new HtmlTplDashboardRenderAttr();
StringWriter out = new StringWriter();
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(new WebContext("", ""), out);
renderAttr.inflate(renderContext, out, new WebContext("", ""));
AddPrefixHtmlTitleHandler htmlTitleHandler = new AddPrefixHtmlTitleHandler("prefix-");
HtmlRenderAttributes.setHtmlTitleHandler(renderContext, htmlTitleHandler);
renderAttr.setHtmlTitleHandler(renderContext, htmlTitleHandler);
HtmlTplDashboard dashboard = this.renderer.createHtmlTplDashboard(renderContext, dashboardWidget, template);
this.renderer.renderHtmlTplDashboard(renderContext, dashboard, IOUtil.getReader(template));
this.renderer.renderHtmlTplDashboard(renderContext, renderAttr, dashboard, IOUtil.getReader(template));
String html = getHtmlWithPrint(out);
Assert.assertTrue(html.contains("<title>prefix-</title></head>"));
}
{
String template = "<html><head><title>abc</title></head><body><title>sdf</title></body></html>";
RenderContext renderContext = new DefaultRenderContext();
HtmlTplDashboardRenderAttr renderAttr = new HtmlTplDashboardRenderAttr();
StringWriter out = new StringWriter();
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(new WebContext("", ""), out);
renderAttr.inflate(renderContext, out, new WebContext("", ""));
AddPrefixHtmlTitleHandler htmlTitleHandler = new AddPrefixHtmlTitleHandler("prefix-");
HtmlRenderAttributes.setHtmlTitleHandler(renderContext, htmlTitleHandler);
renderAttr.setHtmlTitleHandler(renderContext, htmlTitleHandler);
HtmlTplDashboard dashboard = this.renderer.createHtmlTplDashboard(renderContext, dashboardWidget, template);
this.renderer.renderHtmlTplDashboard(renderContext, dashboard, IOUtil.getReader(template));
this.renderer.renderHtmlTplDashboard(renderContext, renderAttr, dashboard, IOUtil.getReader(template));
String html = getHtmlWithPrint(out);
@ -314,10 +336,9 @@ public class HtmlTplDashboardWidgetHtmlRendererTest
}
}
protected HtmlTplDashboardWidget<HtmlRenderContext> createHtmlTplDashboardWidget()
protected HtmlTplDashboardWidget createHtmlTplDashboardWidget()
{
HtmlTplDashboardWidget<HtmlRenderContext> dashboardWidget = new HtmlTplDashboardWidget<HtmlRenderContext>(
"widget01", "index.html", this.renderer);
HtmlTplDashboardWidget dashboardWidget = new HtmlTplDashboardWidget("widget01", "index.html", this.renderer);
return dashboardWidget;
}

View File

@ -9,6 +9,7 @@ package org.datagear.analysis.support.html;
import java.io.StringReader;
import org.datagear.analysis.RenderContext;
import org.junit.Assert;
import org.junit.Test;
@ -20,7 +21,7 @@ import org.junit.Test;
*/
public class HtmlTplDashboardWidgetRendererTest
{
private HtmlTplDashboardWidgetRenderer<HtmlRenderContext> renderer = new TestHtmlTplDashboardWidgetRenderer<HtmlRenderContext>();
private HtmlTplDashboardWidgetRenderer renderer = new TestHtmlTplDashboardWidgetRenderer();
@Test
public void resolveCharsetTest() throws Exception
@ -96,7 +97,7 @@ public class HtmlTplDashboardWidgetRendererTest
}
}
private class TestHtmlTplDashboardWidgetRenderer<T extends HtmlRenderContext> extends HtmlTplDashboardWidgetRenderer<T>
private class TestHtmlTplDashboardWidgetRenderer extends HtmlTplDashboardWidgetRenderer
{
@Override
public String simpleTemplateContent(String htmlCharset, String... chartWidgetId)
@ -105,7 +106,8 @@ public class HtmlTplDashboardWidgetRendererTest
}
@Override
protected void renderHtmlTplDashboard(T renderContext, HtmlTplDashboard dashboard) throws Throwable
protected void renderHtmlTplDashboard(RenderContext renderContext, HtmlTplDashboardRenderAttr renderAttr,
HtmlTplDashboard dashboard) throws Throwable
{
}
}

View File

@ -15,7 +15,6 @@ import org.datagear.analysis.DataSetResult;
import org.datagear.analysis.support.ChartWidget;
import org.datagear.analysis.support.html.HtmlChartPlugin;
import org.datagear.analysis.support.html.HtmlChartWidget;
import org.datagear.analysis.support.html.HtmlRenderContext;
import org.datagear.util.i18n.Label;
import com.fasterxml.jackson.annotation.JsonIgnore;
@ -26,7 +25,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
* @author datagear@163.com
*
*/
public class HtmlChartWidgetEntity extends HtmlChartWidget<HtmlRenderContext>
public class HtmlChartWidgetEntity extends HtmlChartWidget
implements CreateUserEntity<String>, DataPermissionEntity<String>
{
private static final long serialVersionUID = 1L;
@ -55,8 +54,8 @@ public class HtmlChartWidgetEntity extends HtmlChartWidget<HtmlRenderContext>
this.createTime = new Date();
}
public HtmlChartWidgetEntity(String id, String name, ChartDataSetVO[] chartDataSets,
HtmlChartPlugin<HtmlRenderContext> chartPlugin, User createUser)
public HtmlChartWidgetEntity(String id, String name, ChartDataSetVO[] chartDataSets, HtmlChartPlugin chartPlugin,
User createUser)
{
super(id, name, chartDataSets, chartPlugin);
super.setChartDataSets(EMPTY_CHART_DATA_VO_SET);
@ -74,12 +73,12 @@ public class HtmlChartWidgetEntity extends HtmlChartWidget<HtmlRenderContext>
super.setChartDataSets(chartDataSetVOs);
}
public HtmlChartPlugin<HtmlRenderContext> getHtmlChartPlugin()
public HtmlChartPlugin getHtmlChartPlugin()
{
return getPlugin();
}
public void setHtmlChartPlugin(HtmlChartPlugin<HtmlRenderContext> htmlChartPlugin)
public void setHtmlChartPlugin(HtmlChartPlugin htmlChartPlugin)
{
setPlugin(htmlChartPlugin);
}
@ -138,7 +137,7 @@ public class HtmlChartWidgetEntity extends HtmlChartWidget<HtmlRenderContext>
public void updateChartPluginName(Locale locale)
{
String name = null;
HtmlChartPlugin<HtmlRenderContext> plugin = getHtmlChartPlugin();
HtmlChartPlugin plugin = getHtmlChartPlugin();
if (plugin != null)
{

View File

@ -11,7 +11,6 @@ import java.util.Collection;
import java.util.Date;
import org.datagear.analysis.support.JsonSupport;
import org.datagear.analysis.support.html.HtmlRenderContext;
import org.datagear.analysis.support.html.HtmlTplDashboardWidget;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetHtmlRenderer;
import org.datagear.util.StringUtil;
@ -22,7 +21,7 @@ import org.datagear.util.StringUtil;
* @author datagear@163.com
*
*/
public class HtmlTplDashboardWidgetEntity extends HtmlTplDashboardWidget<HtmlRenderContext>
public class HtmlTplDashboardWidgetEntity extends HtmlTplDashboardWidget
implements CreateUserEntity<String>, DataPermissionEntity<String>
{
private static final long serialVersionUID = 1L;
@ -52,8 +51,8 @@ public class HtmlTplDashboardWidgetEntity extends HtmlTplDashboardWidget<HtmlRen
this.createTime = new Date();
}
public HtmlTplDashboardWidgetEntity(String id, String template,
HtmlTplDashboardWidgetHtmlRenderer<HtmlRenderContext> renderer, String name, User createUser)
public HtmlTplDashboardWidgetEntity(String id, String template, HtmlTplDashboardWidgetHtmlRenderer renderer,
String name, User createUser)
{
super(id, template, renderer);
this.name = name;

View File

@ -7,7 +7,6 @@
*/
package org.datagear.management.service;
import org.datagear.analysis.support.html.HtmlRenderContext;
import org.datagear.analysis.support.html.HtmlTplDashboardWidget;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetRenderer;
import org.datagear.management.domain.HtmlTplDashboardWidgetEntity;
@ -27,7 +26,7 @@ public interface HtmlTplDashboardWidgetEntityService
*
* @return
*/
HtmlTplDashboardWidgetRenderer<HtmlRenderContext> getHtmlTplDashboardWidgetRenderer();
HtmlTplDashboardWidgetRenderer getHtmlTplDashboardWidgetRenderer();
/**
* 获取可用于执行分析的{@linkplain HtmlTplDashboardWidget}

View File

@ -18,14 +18,11 @@ import java.util.Set;
import org.apache.ibatis.session.SqlSessionFactory;
import org.datagear.analysis.ChartDataSet;
import org.datagear.analysis.ChartPlugin;
import org.datagear.analysis.ChartPluginManager;
import org.datagear.analysis.DataSet;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.support.ChartWidget;
import org.datagear.analysis.support.JsonSupport;
import org.datagear.analysis.support.html.HtmlChartPlugin;
import org.datagear.analysis.support.html.HtmlRenderContext;
import org.datagear.management.domain.ChartDataSetVO;
import org.datagear.management.domain.HtmlChartWidgetEntity;
import org.datagear.management.domain.User;
@ -108,9 +105,8 @@ public class HtmlChartWidgetEntityServiceImpl
this.authorizationService = authorizationService;
}
@SuppressWarnings("unchecked")
@Override
public <T extends RenderContext> ChartWidget<T> getChartWidget(String id) throws Throwable
public ChartWidget getChartWidget(String id) throws Throwable
{
ChartWidgetSourceContext context = ChartWidgetSourceContext.get();
@ -127,7 +123,7 @@ public class HtmlChartWidgetEntityServiceImpl
setHtmlChartPlugin(entity, true);
setChartDataSets(entity, true);
return (ChartWidget<T>) entity;
return entity;
}
@Override
@ -223,11 +219,11 @@ public class HtmlChartWidgetEntityServiceImpl
protected void setHtmlChartPlugin(HtmlChartWidgetEntity obj, boolean forAnalysis)
{
HtmlChartPlugin<HtmlRenderContext> htmlChartPlugin = obj.getHtmlChartPlugin();
HtmlChartPlugin htmlChartPlugin = obj.getHtmlChartPlugin();
if (htmlChartPlugin != null)
{
HtmlChartPlugin<HtmlRenderContext> full = getHtmlChartPlugin(htmlChartPlugin.getId());
HtmlChartPlugin full = getHtmlChartPlugin(htmlChartPlugin.getId());
if (forAnalysis)
obj.setHtmlChartPlugin(full);
@ -339,10 +335,9 @@ public class HtmlChartWidgetEntityServiceImpl
return paramValues;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
protected HtmlChartPlugin<HtmlRenderContext> getHtmlChartPlugin(String id)
protected HtmlChartPlugin getHtmlChartPlugin(String id)
{
return (HtmlChartPlugin<HtmlRenderContext>) (ChartPlugin) this.chartPluginManager.get(id);
return (HtmlChartPlugin) this.chartPluginManager.get(id);
}
protected List<WidgetDataSetRelation> getWidgetDataSetRelations(HtmlChartWidgetEntity obj)

View File

@ -11,8 +11,6 @@ import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.SqlSessionFactory;
import org.datagear.analysis.support.html.HtmlRenderContext;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetHtmlRenderer;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetRenderer;
import org.datagear.management.domain.HtmlTplDashboardWidgetEntity;
import org.datagear.management.domain.User;
@ -33,7 +31,7 @@ public class HtmlTplDashboardWidgetEntityServiceImpl
{
protected static final String SQL_NAMESPACE = HtmlTplDashboardWidgetEntity.class.getName();
private HtmlTplDashboardWidgetRenderer<HtmlRenderContext> htmlTplDashboardWidgetRenderer;
private HtmlTplDashboardWidgetRenderer htmlTplDashboardWidgetRenderer;
private AuthorizationService authorizationService;
@ -42,34 +40,29 @@ public class HtmlTplDashboardWidgetEntityServiceImpl
super();
}
@SuppressWarnings("unchecked")
public HtmlTplDashboardWidgetEntityServiceImpl(SqlSessionFactory sqlSessionFactory,
HtmlTplDashboardWidgetRenderer<? extends HtmlRenderContext> htmlTplDashboardWidgetRenderer,
AuthorizationService authorizationService)
HtmlTplDashboardWidgetRenderer htmlTplDashboardWidgetRenderer, AuthorizationService authorizationService)
{
super(sqlSessionFactory);
this.htmlTplDashboardWidgetRenderer = (HtmlTplDashboardWidgetHtmlRenderer<HtmlRenderContext>) htmlTplDashboardWidgetRenderer;
this.htmlTplDashboardWidgetRenderer = htmlTplDashboardWidgetRenderer;
this.authorizationService = authorizationService;
}
@SuppressWarnings("unchecked")
public HtmlTplDashboardWidgetEntityServiceImpl(SqlSessionTemplate sqlSessionTemplate,
HtmlTplDashboardWidgetRenderer<? extends HtmlRenderContext> htmlTplDashboardWidgetRenderer,
AuthorizationService authorizationService)
HtmlTplDashboardWidgetRenderer htmlTplDashboardWidgetRenderer, AuthorizationService authorizationService)
{
super(sqlSessionTemplate);
this.htmlTplDashboardWidgetRenderer = (HtmlTplDashboardWidgetHtmlRenderer<HtmlRenderContext>) htmlTplDashboardWidgetRenderer;
this.htmlTplDashboardWidgetRenderer = htmlTplDashboardWidgetRenderer;
this.authorizationService = authorizationService;
}
@Override
public HtmlTplDashboardWidgetRenderer<HtmlRenderContext> getHtmlTplDashboardWidgetRenderer()
public HtmlTplDashboardWidgetRenderer getHtmlTplDashboardWidgetRenderer()
{
return htmlTplDashboardWidgetRenderer;
}
public void setHtmlTplDashboardWidgetRenderer(
HtmlTplDashboardWidgetRenderer<HtmlRenderContext> htmlTplDashboardWidgetRenderer)
public void setHtmlTplDashboardWidgetRenderer(HtmlTplDashboardWidgetRenderer htmlTplDashboardWidgetRenderer)
{
this.htmlTplDashboardWidgetRenderer = htmlTplDashboardWidgetRenderer;
}

View File

@ -17,9 +17,9 @@ import javax.servlet.http.HttpServletRequest;
import org.datagear.analysis.Category;
import org.datagear.analysis.Chart;
import org.datagear.analysis.ChartDefinition;
import org.datagear.analysis.ChartPlugin;
import org.datagear.analysis.DataSign;
import org.datagear.analysis.Icon;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderException;
import org.datagear.analysis.RenderStyle;
import org.datagear.analysis.support.AbstractChartPlugin;
@ -27,7 +27,6 @@ import org.datagear.analysis.support.CategorizationResolver;
import org.datagear.analysis.support.CategorizationResolver.Categorization;
import org.datagear.analysis.support.html.DirectoryHtmlChartPluginManager;
import org.datagear.analysis.support.html.HtmlChartPlugin;
import org.datagear.analysis.support.html.HtmlRenderContext;
import org.datagear.util.i18n.Label;
import org.datagear.web.util.KeywordMatcher;
import org.datagear.web.util.WebUtils;
@ -85,23 +84,18 @@ public class AbstractChartPluginAwareController extends AbstractDataAnalysisCont
*/
protected HtmlChartPluginVO getHtmlChartPluginVO(HttpServletRequest request, String id)
{
List<ChartPlugin<HtmlRenderContext>> plugins = getDirectoryHtmlChartPluginManager()
.getAll(HtmlRenderContext.class);
List<HtmlChartPlugin> plugins = getDirectoryHtmlChartPluginManager().getAll(HtmlChartPlugin.class);
if (plugins == null)
return null;
for (ChartPlugin<HtmlRenderContext> plugin : plugins)
for (HtmlChartPlugin plugin : plugins)
{
if (plugin instanceof HtmlChartPlugin<?>)
if (plugin.getId().equals(id))
{
HtmlChartPlugin<HtmlRenderContext> htmlChartPlugin = (HtmlChartPlugin<HtmlRenderContext>) plugin;
if (htmlChartPlugin.getId().equals(id))
{
Locale locale = WebUtils.getLocale(request);
RenderStyle renderStyle = resolveRenderStyle(request);
return toHtmlChartPluginVO(htmlChartPlugin, renderStyle, locale);
}
Locale locale = WebUtils.getLocale(request);
RenderStyle renderStyle = resolveRenderStyle(request);
return toHtmlChartPluginVO(plugin, renderStyle, locale);
}
}
@ -117,24 +111,17 @@ public class AbstractChartPluginAwareController extends AbstractDataAnalysisCont
*/
protected List<HtmlChartPluginVO> findHtmlChartPluginVOs(HttpServletRequest request, String keyword)
{
List<HtmlChartPluginVO> pluginViews = new ArrayList<HtmlChartPluginVO>();
List<HtmlChartPluginVO> pluginViews = new ArrayList<>();
List<ChartPlugin<HtmlRenderContext>> plugins = getDirectoryHtmlChartPluginManager()
.getAll(HtmlRenderContext.class);
List<HtmlChartPlugin> plugins = getDirectoryHtmlChartPluginManager().getAll(HtmlChartPlugin.class);
if (plugins != null)
{
Locale locale = WebUtils.getLocale(request);
RenderStyle renderStyle = resolveRenderStyle(request);
for (ChartPlugin<HtmlRenderContext> plugin : plugins)
{
if (plugin instanceof HtmlChartPlugin<?>)
{
HtmlChartPlugin<HtmlRenderContext> htmlChartPlugin = (HtmlChartPlugin<HtmlRenderContext>) plugin;
pluginViews.add(toHtmlChartPluginVO(htmlChartPlugin, renderStyle, locale));
}
}
for (HtmlChartPlugin plugin : plugins)
pluginViews.add(toHtmlChartPluginVO(plugin, renderStyle, locale));
}
return KeywordMatcher.<HtmlChartPluginVO> match(pluginViews, keyword,
@ -149,7 +136,7 @@ public class AbstractChartPluginAwareController extends AbstractDataAnalysisCont
});
}
protected HtmlChartPluginVO toHtmlChartPluginVO(HttpServletRequest request, HtmlChartPlugin<?> chartPlugin)
protected HtmlChartPluginVO toHtmlChartPluginVO(HttpServletRequest request, HtmlChartPlugin chartPlugin)
{
Locale locale = WebUtils.getLocale(request);
RenderStyle renderStyle = resolveRenderStyle(request);
@ -157,8 +144,7 @@ public class AbstractChartPluginAwareController extends AbstractDataAnalysisCont
return toHtmlChartPluginVO(chartPlugin, renderStyle, locale);
}
protected HtmlChartPluginVO toHtmlChartPluginVO(HtmlChartPlugin<?> chartPlugin, RenderStyle renderStyle,
Locale locale)
protected HtmlChartPluginVO toHtmlChartPluginVO(HtmlChartPlugin chartPlugin, RenderStyle renderStyle, Locale locale)
{
HtmlChartPluginVO pluginVO = new HtmlChartPluginVO();
@ -176,11 +162,10 @@ public class AbstractChartPluginAwareController extends AbstractDataAnalysisCont
List<DataSign> dataSigns = chartPlugin.getDataSigns();
if (dataSigns != null)
{
List<DataSign> dataSignVOs = new ArrayList<DataSign>(dataSigns.size());
List<DataSign> dataSignVOs = new ArrayList<>(dataSigns.size());
for (DataSign dataSign : dataSigns)
{
DataSign view = new DataSign(dataSign.getName(), dataSign.isRequired(),
dataSign.isMultiple());
DataSign view = new DataSign(dataSign.getName(), dataSign.isRequired(), dataSign.isMultiple());
view.setNameLabel(toConcreteLabel(dataSign.getNameLabel(), locale));
view.setDescLabel(toConcreteLabel(dataSign.getDescLabel(), locale));
@ -218,7 +203,7 @@ public class AbstractChartPluginAwareController extends AbstractDataAnalysisCont
return new Label(value);
}
protected String resolveIconUrl(HtmlChartPlugin<?> plugin)
protected String resolveIconUrl(HtmlChartPlugin plugin)
{
return "/analysis/chartPlugin/icon/" + plugin.getId();
}
@ -229,7 +214,7 @@ public class AbstractChartPluginAwareController extends AbstractDataAnalysisCont
* @author datagear@163.com
*
*/
public static class HtmlChartPluginVO extends AbstractChartPlugin<HtmlRenderContext> implements Serializable
public static class HtmlChartPluginVO extends AbstractChartPlugin implements Serializable
{
private static final long serialVersionUID = 1L;
@ -268,8 +253,7 @@ public class AbstractChartPluginAwareController extends AbstractDataAnalysisCont
}
@Override
public Chart renderChart(HtmlRenderContext renderContext, ChartDefinition chartDefinition)
throws RenderException
public Chart renderChart(RenderContext renderContext, ChartDefinition chartDefinition) throws RenderException
{
throw new UnsupportedOperationException();
}

View File

@ -10,6 +10,7 @@ package org.datagear.web.controller;
import java.io.Serializable;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
@ -29,13 +30,13 @@ import org.datagear.analysis.Dashboard;
import org.datagear.analysis.DashboardTheme;
import org.datagear.analysis.DataSetParam;
import org.datagear.analysis.DataSetResult;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderStyle;
import org.datagear.analysis.support.DataSetParamValueConverter;
import org.datagear.analysis.support.html.DefaultHtmlRenderContext;
import org.datagear.analysis.support.html.HtmlRenderAttributes;
import org.datagear.analysis.support.html.HtmlRenderContext;
import org.datagear.analysis.support.html.HtmlRenderContext.WebContext;
import org.datagear.analysis.support.DefaultRenderContext;
import org.datagear.analysis.support.html.HtmlTplDashboard;
import org.datagear.analysis.support.html.HtmlTplDashboardRenderAttr;
import org.datagear.analysis.support.html.HtmlTplDashboardRenderAttr.WebContext;
import org.datagear.util.StringUtil;
import org.datagear.web.util.WebUtils;
@ -94,15 +95,25 @@ public class AbstractDataAnalysisController extends AbstractController
return RenderStyle.LIGHT;
}
protected HtmlRenderContext createHtmlRenderContext(HttpServletRequest request, WebContext webContext,
RenderStyle renderStyle, Writer out)
protected RenderContext createHtmlRenderContext(HttpServletRequest request, HtmlTplDashboardRenderAttr renderAttr,
Writer out, WebContext webContext, RenderStyle renderStyle)
{
DefaultHtmlRenderContext renderContext = new DefaultHtmlRenderContext(webContext, out);
HtmlRenderAttributes.setRenderStyle(renderContext, renderStyle);
RenderContext renderContext = new DefaultRenderContext();
renderAttr.inflate(renderContext, out, webContext);
renderAttr.setRenderStyle(renderContext, renderStyle);
renderAttr.setIgnoreRenderAttrs(renderContext,
Arrays.asList(renderAttr.getHtmlWriterName(), renderAttr.getHtmlTitleHandlerName(),
renderAttr.getIgnoreRenderAttrsName(), HtmlTplDashboardRenderAttr.ATTR_NAME));
return renderContext;
}
protected HtmlTplDashboardRenderAttr createHtmlTplDashboardRenderAttr()
{
return new HtmlTplDashboardRenderAttr();
}
protected void setDashboardThemeAttribute(HttpSession session, DashboardTheme theme)
{
session.setAttribute(AbstractDataAnalysisController.class.getSimpleName(), theme);
@ -214,7 +225,7 @@ public class AbstractDataAnalysisController extends AbstractController
if (chartsParamValues == null)
return Collections.EMPTY_MAP;
Map<String, List<? extends Map<String, ?>>> re = new HashMap<String, List<? extends Map<String, ?>>>();
Map<String, List<? extends Map<String, ?>>> re = new HashMap<>();
for (Map.Entry<String, ? extends List<? extends Map<String, ?>>> entry : chartsParamValues.entrySet())
{
@ -226,7 +237,7 @@ public class AbstractDataAnalysisController extends AbstractController
else
{
List<? extends Map<String, ?>> paramValuess = entry.getValue();
List<Map<String, ?>> converteds = new ArrayList<Map<String, ?>>();
List<Map<String, ?>> converteds = new ArrayList<>();
for (int i = 0; i < chartDataSets.length; i++)
{

View File

@ -15,17 +15,16 @@ import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.datagear.analysis.ChartPlugin;
import org.datagear.analysis.ChartPluginManager;
import org.datagear.analysis.DashboardTheme;
import org.datagear.analysis.DataSetResult;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderStyle;
import org.datagear.analysis.TemplateDashboardWidgetResManager;
import org.datagear.analysis.support.html.HtmlChartPlugin;
import org.datagear.analysis.support.html.HtmlRenderAttributes;
import org.datagear.analysis.support.html.HtmlRenderContext;
import org.datagear.analysis.support.html.HtmlRenderContext.WebContext;
import org.datagear.analysis.support.html.HtmlTplDashboard;
import org.datagear.analysis.support.html.HtmlTplDashboardRenderAttr;
import org.datagear.analysis.support.html.HtmlTplDashboardRenderAttr.WebContext;
import org.datagear.analysis.support.html.HtmlTplDashboardWidget;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetHtmlRenderer;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetRenderer.AddPrefixHtmlTitleHandler;
@ -74,7 +73,7 @@ public class ChartController extends AbstractChartPluginAwareController implemen
@Autowired
@Qualifier("chartShowHtmlTplDashboardWidgetHtmlRenderer")
private HtmlTplDashboardWidgetHtmlRenderer<HtmlRenderContext> chartShowHtmlTplDashboardWidgetHtmlRenderer;
private HtmlTplDashboardWidgetHtmlRenderer chartShowHtmlTplDashboardWidgetHtmlRenderer;
private ServletContext servletContext;
@ -103,13 +102,13 @@ public class ChartController extends AbstractChartPluginAwareController implemen
this.chartPluginManager = chartPluginManager;
}
public HtmlTplDashboardWidgetHtmlRenderer<HtmlRenderContext> getChartShowHtmlTplDashboardWidgetHtmlRenderer()
public HtmlTplDashboardWidgetHtmlRenderer getChartShowHtmlTplDashboardWidgetHtmlRenderer()
{
return chartShowHtmlTplDashboardWidgetHtmlRenderer;
}
public void setChartShowHtmlTplDashboardWidgetHtmlRenderer(
HtmlTplDashboardWidgetHtmlRenderer<HtmlRenderContext> chartShowHtmlTplDashboardWidgetHtmlRenderer)
HtmlTplDashboardWidgetHtmlRenderer chartShowHtmlTplDashboardWidgetHtmlRenderer)
{
this.chartShowHtmlTplDashboardWidgetHtmlRenderer = chartShowHtmlTplDashboardWidgetHtmlRenderer;
}
@ -169,7 +168,7 @@ public class ChartController extends AbstractChartPluginAwareController implemen
{
User user = WebUtils.getUser(request, response);
HtmlChartPlugin<HtmlRenderContext> paramPlugin = entity.getHtmlChartPlugin();
HtmlChartPlugin paramPlugin = entity.getHtmlChartPlugin();
if (isEmpty(entity.getId()))
{
@ -374,7 +373,7 @@ public class ChartController extends AbstractChartPluginAwareController implemen
String id = chart.getId();
String htmlTitle = chart.getName();
HtmlTplDashboardWidget<HtmlRenderContext> dashboardWidget = new HtmlTplDashboardWidget<>(id,
HtmlTplDashboardWidget dashboardWidget = new HtmlTplDashboardWidget(id,
this.chartShowHtmlTplDashboardWidgetHtmlRenderer.simpleTemplateContent("UTF-8", htmlTitle,
" position:absolute;\n left:1em;\n right:1em;\n top:1em;\n bottom:1em;\n margin:0 0;\n width:auto;\n height:auto;\n",
new String[] { id }),
@ -384,15 +383,17 @@ public class ChartController extends AbstractChartPluginAwareController implemen
response.setCharacterEncoding(responseEncoding);
response.setContentType(CONTENT_TYPE_HTML);
HtmlTplDashboardRenderAttr renderAttr = createHtmlTplDashboardRenderAttr();
Writer out = response.getWriter();
RenderStyle renderStyle = resolveRenderStyle(request);
HtmlRenderContext renderContext = createHtmlRenderContext(request, createWebContext(request), renderStyle, out);
RenderContext renderContext = createHtmlRenderContext(request, renderAttr, out, createWebContext(request),
renderStyle);
DashboardTheme dashboardTheme = getChartShowHtmlTplDashboardWidgetHtmlRenderer()
.inflateDashboardTheme(renderContext, renderStyle);
.inflateDashboardTheme(renderContext, renderAttr, renderStyle);
AddPrefixHtmlTitleHandler htmlTitleHandler = new AddPrefixHtmlTitleHandler(
getMessage(request, "chart.show.htmlTitlePrefix", getMessage(request, "app.name")));
HtmlRenderAttributes.setHtmlTitleHandler(renderContext, htmlTitleHandler);
renderAttr.setHtmlTitleHandler(renderContext, htmlTitleHandler);
setDashboardThemeAttribute(request.getSession(), dashboardTheme);
HtmlTplDashboard dashboard = dashboardWidget.render(renderContext);
@ -418,15 +419,13 @@ public class ChartController extends AbstractChartPluginAwareController implemen
entity.updateChartPluginName(locale);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void inflateHtmlChartWidgetEntity(HtmlChartWidgetEntity entity, HttpServletRequest request)
{
HtmlChartPlugin<HtmlRenderContext> htmlChartPlugin = entity.getHtmlChartPlugin();
HtmlChartPlugin htmlChartPlugin = entity.getHtmlChartPlugin();
if (htmlChartPlugin != null)
{
htmlChartPlugin = (HtmlChartPlugin<HtmlRenderContext>) (ChartPlugin) this.chartPluginManager
.get(htmlChartPlugin.getId());
htmlChartPlugin = (HtmlChartPlugin) this.chartPluginManager.get(htmlChartPlugin.getId());
entity.setHtmlChartPlugin(htmlChartPlugin);
}

View File

@ -28,7 +28,6 @@ import org.datagear.analysis.support.html.HtmlChartPlugin;
import org.datagear.analysis.support.html.HtmlChartPluginLoadException;
import org.datagear.analysis.support.html.HtmlChartPluginLoader;
import org.datagear.analysis.support.html.HtmlChartPluginScriptObjectWriter;
import org.datagear.analysis.support.html.HtmlRenderContext;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetRenderer;
import org.datagear.management.service.HtmlTplDashboardWidgetEntityService;
import org.datagear.persistence.PagingQuery;
@ -150,9 +149,9 @@ public class ChartPluginController extends AbstractChartPluginAwareController
try
{
Set<HtmlChartPlugin<?>> loaded = loader.loads(zipFile);
Set<HtmlChartPlugin> loaded = loader.loads(zipFile);
for (HtmlChartPlugin<?> chartPlugin : loaded)
for (HtmlChartPlugin chartPlugin : loaded)
pluginInfos.add(toHtmlChartPluginVO(chartPlugin, renderStyle, locale));
}
catch (HtmlChartPluginLoadException e)
@ -176,7 +175,7 @@ public class ChartPluginController extends AbstractChartPluginAwareController
File tmpFile = FileUtil.getFile(this.tempDirectory, pluginFileName);
Set<HtmlChartPlugin<?>> uploads = getDirectoryHtmlChartPluginManager().upload(tmpFile);
Set<HtmlChartPlugin> uploads = getDirectoryHtmlChartPluginManager().upload(tmpFile);
return buildOperationMessageSuccessResponseEntity(request, "chartPlugin.upload.finish", uploads.size());
}
@ -259,7 +258,7 @@ public class ChartPluginController extends AbstractChartPluginAwareController
public void getPluginIcon(HttpServletRequest request, HttpServletResponse response, WebRequest webRequest,
@PathVariable("pluginId") String pluginId) throws Exception
{
ChartPlugin<?> chartPlugin = getDirectoryHtmlChartPluginManager().get(pluginId);
ChartPlugin chartPlugin = getDirectoryHtmlChartPluginManager().get(pluginId);
if (chartPlugin == null)
throw new FileNotFoundException();
@ -294,30 +293,24 @@ public class ChartPluginController extends AbstractChartPluginAwareController
public void getChartPluginManagerJs(HttpServletRequest request, HttpServletResponse response, WebRequest webRequest)
throws Exception
{
List<ChartPlugin<HtmlRenderContext>> plugins = getDirectoryHtmlChartPluginManager()
.getAll(HtmlRenderContext.class);
List<HtmlChartPlugin> plugins = getDirectoryHtmlChartPluginManager().getAll(HtmlChartPlugin.class);
List<HtmlChartPlugin<?>> htmlChartPlugins = new ArrayList<HtmlChartPlugin<?>>(plugins.size());
List<HtmlChartPlugin> htmlChartPlugins = new ArrayList<>(plugins.size());
long lastModified = -1;
if (plugins != null)
{
for (ChartPlugin<HtmlRenderContext> plugin : plugins)
for (HtmlChartPlugin plugin : plugins)
{
if (plugin instanceof HtmlChartPlugin<?>)
{
HtmlChartPlugin<?> htmlChartPlugin = (HtmlChartPlugin<?>) plugin;
htmlChartPlugins.add(htmlChartPlugin);
lastModified = Math.max(lastModified, htmlChartPlugin.getLastModified());
}
htmlChartPlugins.add(plugin);
lastModified = Math.max(lastModified, plugin.getLastModified());
}
}
HtmlTplDashboardWidgetRenderer<?> renderer = getHtmlTplDashboardWidgetEntityService()
HtmlTplDashboardWidgetRenderer renderer = getHtmlTplDashboardWidgetEntityService()
.getHtmlTplDashboardWidgetRenderer();
HtmlChartPlugin<?> htmlChartPluginForGetWidgetException = renderer.getHtmlChartPluginForGetWidgetException();
HtmlChartPlugin htmlChartPluginForGetWidgetException = renderer.getHtmlChartPluginForGetWidgetException();
htmlChartPlugins.add(htmlChartPluginForGetWidgetException);
lastModified = Math.max(lastModified, htmlChartPluginForGetWidgetException.getLastModified());
@ -333,14 +326,14 @@ public class ChartPluginController extends AbstractChartPluginAwareController
out.println("var chartPluginManager = (global.chartPluginManager || (global.chartPluginManager = {}));");
out.println("chartPluginManager.plugins = (chartPluginManager.plugins || {});");
out.println();
out.println("chartPluginManager.get = function(id){ return this.plugins[id]; };");
out.println();
for (int i = 0, len = htmlChartPlugins.size(); i < len; i++)
{
HtmlChartPlugin<?> plugin = htmlChartPlugins.get(i);
HtmlChartPlugin plugin = htmlChartPlugins.get(i);
String pluginVar = "plugin" + i;
this.htmlChartPluginScriptObjectWriter.write(out, plugin, pluginVar);

View File

@ -26,15 +26,17 @@ import org.datagear.analysis.Chart;
import org.datagear.analysis.ChartTheme;
import org.datagear.analysis.DashboardTheme;
import org.datagear.analysis.DataSetResult;
import org.datagear.analysis.RenderContext;
import org.datagear.analysis.RenderStyle;
import org.datagear.analysis.TemplateDashboardWidgetResManager;
import org.datagear.analysis.support.ChartWidget;
import org.datagear.analysis.support.ChartWidgetSource;
import org.datagear.analysis.support.html.HtmlChartPluginRenderOption;
import org.datagear.analysis.support.html.HtmlRenderAttributes;
import org.datagear.analysis.support.html.HtmlRenderContext;
import org.datagear.analysis.support.html.HtmlRenderContext.WebContext;
import org.datagear.analysis.support.DefaultRenderContext;
import org.datagear.analysis.support.html.HtmlChartRenderAttr;
import org.datagear.analysis.support.html.HtmlChartRenderAttr.HtmlChartRenderOption;
import org.datagear.analysis.support.html.HtmlTplDashboard;
import org.datagear.analysis.support.html.HtmlTplDashboardRenderAttr;
import org.datagear.analysis.support.html.HtmlTplDashboardRenderAttr.WebContext;
import org.datagear.analysis.support.html.HtmlTplDashboardWidget;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetRenderer;
import org.datagear.analysis.support.html.HtmlTplDashboardWidgetRenderer.AddPrefixHtmlTitleHandler;
@ -132,7 +134,7 @@ public class DashboardController extends AbstractDataAnalysisController implemen
dashboard.setTemplates(HtmlTplDashboardWidgetEntity.DEFAULT_TEMPLATES);
dashboard.setTemplateEncoding(HtmlTplDashboardWidget.DEFAULT_TEMPLATE_ENCODING);
HtmlTplDashboardWidgetRenderer<HtmlRenderContext> renderer = getHtmlTplDashboardWidgetEntityService()
HtmlTplDashboardWidgetRenderer renderer = getHtmlTplDashboardWidgetEntityService()
.getHtmlTplDashboardWidgetRenderer();
String templateContent = renderer.simpleTemplateContent(dashboard.getTemplateEncoding());
@ -704,16 +706,17 @@ public class DashboardController extends AbstractDataAnalysisController implemen
response.setCharacterEncoding(responseEncoding);
response.setContentType(CONTENT_TYPE_HTML);
HtmlTplDashboardRenderAttr renderAttr = createHtmlTplDashboardRenderAttr();
Writer out = response.getWriter();
RenderStyle renderStyle = resolveRenderStyle(request);
HtmlRenderContext renderContext = createHtmlRenderContext(request, createWebContext(request), renderStyle,
out);
RenderContext renderContext = createHtmlRenderContext(request, renderAttr, out, createWebContext(request),
renderStyle);
DashboardTheme dashboardTheme = getHtmlTplDashboardWidgetEntityService().getHtmlTplDashboardWidgetRenderer()
.inflateDashboardTheme(renderContext, renderStyle);
.inflateDashboardTheme(renderContext, renderAttr, renderStyle);
AddPrefixHtmlTitleHandler htmlTitleHandler = new AddPrefixHtmlTitleHandler(
getMessage(request, "dashboard.show.htmlTitlePrefix", getMessage(request, "app.name")));
HtmlRenderAttributes.setHtmlTitleHandler(renderContext, htmlTitleHandler);
renderAttr.setHtmlTitleHandler(renderContext, htmlTitleHandler);
setDashboardThemeAttribute(request.getSession(), dashboardTheme);
HtmlTplDashboard dashboard = dashboardWidget.render(renderContext, template);
@ -776,16 +779,12 @@ public class DashboardController extends AbstractDataAnalysisController implemen
out.println(".dg-chart-table .dg-chart-table-content table.dataTable tbody > tr.selected,");
out.println(".dg-chart-table .dg-chart-table-content table.dataTable tbody > tr > .selected,");
out.println(".dg-chart-table .dg-chart-table-content table.dataTable.stripe tbody > tr.odd.selected,");
out.println(
".dg-chart-table .dg-chart-table-content table.dataTable.stripe tbody > tr.odd > .selected,");
out.println(".dg-chart-table .dg-chart-table-content table.dataTable.stripe tbody > tr.odd > .selected,");
out.println(".dg-chart-table .dg-chart-table-content table.dataTable.display tbody > tr.odd.selected,");
out.println(
".dg-chart-table .dg-chart-table-content table.dataTable.display tbody > tr.odd > .selected,");
out.println(".dg-chart-table .dg-chart-table-content table.dataTable.display tbody > tr.odd > .selected,");
out.println(".dg-chart-table .dg-chart-table-content table.dataTable.hover tbody > tr.selected:hover,");
out.println(
".dg-chart-table .dg-chart-table-content table.dataTable.hover tbody > tr > .selected:hover,");
out.println(
".dg-chart-table .dg-chart-table-content table.dataTable.display tbody > tr.selected:hover,");
out.println(".dg-chart-table .dg-chart-table-content table.dataTable.hover tbody > tr > .selected:hover,");
out.println(".dg-chart-table .dg-chart-table-content table.dataTable.display tbody > tr.selected:hover,");
out.println(
".dg-chart-table .dg-chart-table-content table.dataTable.display tbody > tr > .selected:hover {");
out.println(" background-color: " + chartTheme.getHighlightTheme().getBackgroundColor() + ";");
@ -824,8 +823,7 @@ public class DashboardController extends AbstractDataAnalysisController implemen
@RequestMapping(value = "/loadChart", produces = CONTENT_TYPE_JSON)
public void loadChart(HttpServletRequest request, HttpServletResponse response, org.springframework.ui.Model model,
@RequestParam("dashboardId") String dashboardId, @RequestParam("chartWidgetId") String chartWidgetId,
@RequestParam("chartElementId") String chartElementId)
throws Throwable
@RequestParam("chartElementId") String chartElementId) throws Throwable
{
SessionHtmlTplDashboardManager dashboardManager = getSessionHtmlTplDashboardManagerNotNull(request);
HtmlTplDashboard dashboard = dashboardManager.get(dashboardId);
@ -841,40 +839,34 @@ public class DashboardController extends AbstractDataAnalysisController implemen
ChartWidgetSource chartWidgetSource = getHtmlTplDashboardWidgetEntityService()
.getHtmlTplDashboardWidgetRenderer().getChartWidgetSource();
ChartWidget<HtmlRenderContext> chartWidget = chartWidgetSource.getChartWidget(chartWidgetId);
ChartWidget chartWidget = chartWidgetSource.getChartWidget(chartWidgetId);
if (chartWidget == null)
throw new RecordNotFoundException();
// 不缓存
response.setContentType(CONTENT_TYPE_JSON);
RenderContext renderContext = new DefaultRenderContext();
HtmlChartRenderAttr renderAttr = new HtmlChartRenderAttr();
PrintWriter out = response.getWriter();
RenderStyle renderStyle = resolveRenderStyle(request);
HtmlRenderContext renderContext = createHtmlRenderContext(request, createWebContext(request), renderStyle,
out);
HtmlChartPluginRenderOption renderOption = new HtmlChartPluginRenderOption();
renderOption.setChartElementId(chartElementId);
HtmlChartRenderOption renderOption = new HtmlChartRenderOption(chartElementId,
"{\"id\": \"" + WebUtils.escapeJavaScriptStringValue(chartWidget.getPlugin().getId()) + "\"}",
"undefined", "{}");
renderOption.setNotWriteChartElement(true);
renderOption.setPluginVarName(
"{\"id\": \"" + WebUtils.escapeJavaScriptStringValue(chartWidget.getPlugin().getId()) + "\"}");
renderOption.setNotWritePluginObject(true);
renderOption.setChartVarName("undefined");
renderOption.setRenderContextVarName("{}");
renderOption.setNotWriteRenderContextObject(true);
renderOption.setNotWriteScriptTag(true);
renderOption.setNotWriteInvoke(true);
renderOption.setWriteChartJson(true);
HtmlChartPluginRenderOption.setOption(renderContext, renderOption);
renderAttr.inflate(renderContext, out, renderOption);
Chart chart = chartWidget.render(renderContext);
synchronized (dashboard)
{
List<Chart> charts = dashboard.getCharts();
List<Chart> newCharts = (charts == null || charts.isEmpty() ? new ArrayList<Chart>()
: new ArrayList<Chart>(charts));
List<Chart> newCharts = (charts == null || charts.isEmpty() ? new ArrayList<>() : new ArrayList<>(charts));
newCharts.add(chart);
dashboard.setCharts(newCharts);
}

View File

@ -100,7 +100,7 @@ public class DirectoryHtmlChartPluginManagerInitializer
{
loadHtmlChartPlugins(this.classpathPattern);
}
catch(Throwable t)
catch (Throwable t)
{
if (LOGGER.isErrorEnabled())
LOGGER.error("Load built-in " + HtmlChartPlugin.class.getSimpleName() + "s error :", t);
@ -134,10 +134,10 @@ public class DirectoryHtmlChartPluginManagerInitializer
}
}
Set<HtmlChartPlugin<?>> plugins = this.directoryHtmlChartPluginManager.upload(tmpDirectory);
Set<HtmlChartPlugin> plugins = this.directoryHtmlChartPluginManager.upload(tmpDirectory);
Set<String> pluginIds = new HashSet<String>();
for (HtmlChartPlugin<?> plugin : plugins)
Set<String> pluginIds = new HashSet<>();
for (HtmlChartPlugin plugin : plugins)
pluginIds.add(plugin.getId());
if (LOGGER.isInfoEnabled())

View File

@ -524,16 +524,6 @@
this.elementJquery().attr("dg-chart-map", value);
};
/**
* 获取图表渲染风格没有则返回undefined
*
* @return "..."
*/
chartBase.renderStyle = function()
{
return this.renderContextAttr("renderStyle");
};
/**
* 获取/设置图表渲染上下文的属性值
*
@ -1645,7 +1635,8 @@
url = (url || name);
var contextPath = this.renderContext.webContext.contextPath;
var webContext = this.renderContextAttr("webContext");
var contextPath = (webContext ? webContext.contextPath : undefined);
if(contextPath && url.indexOf("/") == 0 && url.indexOf(contextPath) != 0)
url = contextPath + url;

View File

@ -29,6 +29,10 @@
this.initCharts(dashboard);
$.extend(dashboard, this.dashboardBase);
this.initListener(dashboard);
//渲染看板内图表时需要chartTheme
var dashboardTheme = dashboard.renderContextAttr("dashboardTheme");
dashboard.renderContextAttr("chartTheme", dashboardTheme.chartTheme);
};
/**
@ -170,7 +174,7 @@
}
else
{
var webContext = this.renderContext.webContext;
var webContext = this.renderContextAttr("webContext");
var data = this.buildUpdateDashboardAjaxData(preUpdates);
@ -426,7 +430,7 @@
*/
dashboardBase.buildUpdateDashboardAjaxData = function(charts)
{
var webContext = this.renderContext.webContext;
var webContext = this.renderContextAttr("webContext");
var data = {};
data[webContext.dashboardIdParam] = this.id;
@ -475,7 +479,7 @@
$(element).attr("id", chartElementId);
}
var webContext = this.renderContext.webContext;
var webContext = this.renderContextAttr("webContext");
var loadChartConfig = dashboardFactory.loadChartConfig;
var _this = this;
@ -546,6 +550,22 @@
chart.renderContext = this.renderContext;
dashboardFactory.initChart(chart);
};
/**
* 获取/设置渲染上下文的属性值
*
* @param attrName
* @param attrValue 要设置的属性值可选不设置则执行获取操作
*/
dashboardBase.renderContextAttr = function(attrName, attrValue)
{
var renderContext = this.renderContext;
if(attrValue == undefined)
return renderContext.attributes[attrName];
else
return renderContext.attributes[attrName] = attrValue;
};
//----------------------------------------
// dashboardBase end