Improved escape JSON in charts.
This commit is contained in:
parent
62390fd4a0
commit
c2fd782860
5 changed files with 31 additions and 37 deletions
|
@ -52,7 +52,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import fr.devinsy.strings.StringList;
|
||||
import fr.devinsy.strings.StringsUtils;
|
||||
import fr.devinsy.xidyn.utils.XidynUtils;
|
||||
|
||||
/**
|
||||
* The Class StatoolInfosUtils.
|
||||
|
@ -81,30 +80,6 @@ public class StatoolInfosUtils
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape JSONXML.
|
||||
*
|
||||
* @param data
|
||||
* the data
|
||||
* @return the string
|
||||
*/
|
||||
public static String escapeJSONXML(final String data)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = XidynUtils.escapeXmlBlank(data.replace('\'', ' '));
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* File local date time.
|
||||
*
|
||||
|
|
|
@ -21,7 +21,6 @@ package fr.devinsy.statoolinfos.htmlize.charts;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
|
||||
import fr.devinsy.strings.StringList;
|
||||
|
||||
/**
|
||||
|
@ -79,10 +78,8 @@ public class BarChart
|
|||
*/
|
||||
public void add(final String label, final double value, final ChartColor color)
|
||||
{
|
||||
String escapedLabel = StatoolInfosUtils.escapeJSONXML(label);
|
||||
|
||||
this.labels.add(escapedLabel);
|
||||
this.datasets.get(0).add(new BarChartData(escapedLabel, value, color));
|
||||
this.labels.add(label);
|
||||
this.datasets.get(0).add(new BarChartData(label, value, color));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import fr.devinsy.strings.StringList;
|
||||
import fr.devinsy.strings.StringsUtils;
|
||||
import fr.devinsy.xidyn.utils.XidynUtils;
|
||||
|
||||
/**
|
||||
* The Class ChabuUtils.
|
||||
|
@ -184,6 +185,30 @@ public class ChabuUtils
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape JSONXML.
|
||||
*
|
||||
* @param data
|
||||
* the data
|
||||
* @return the string
|
||||
*/
|
||||
public static String escapeJSONXML(final String data)
|
||||
{
|
||||
String result;
|
||||
|
||||
if (data == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = XidynUtils.escapeXmlBlank(data.replace("'", "\\\\'"));
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalise month date.
|
||||
*
|
||||
|
@ -627,7 +652,7 @@ public class ChabuUtils
|
|||
for (String string : source)
|
||||
{
|
||||
target.append("'");
|
||||
target.append(string);
|
||||
target.append(escapeJSONXML(string));
|
||||
target.append("'");
|
||||
target.append(",");
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
|
||||
* Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* This file is part of StatoolInfos, simple service statistics tool.
|
||||
*
|
||||
|
@ -21,7 +21,6 @@ package fr.devinsy.statoolinfos.htmlize.charts;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
|
||||
import fr.devinsy.strings.StringList;
|
||||
|
||||
/**
|
||||
|
@ -79,9 +78,7 @@ public class PieChart
|
|||
*/
|
||||
public void add(final String label, final double value, final ChartColor color)
|
||||
{
|
||||
String targetLabel = StatoolInfosUtils.escapeJSONXML(label);
|
||||
|
||||
this.datas.add(new PieChartData(targetLabel, value, color));
|
||||
this.datas.add(new PieChartData(label, value, color));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
|
||||
* Copyright (C) 2020-2021 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* This file is part of StatoolInfos, simple service statistics tool.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue