use of org.xwiki.rendering.macro.MacroExecutionException in project xwiki-platform by xwiki.
the class AxisConfigurator method setAxes.
/**
* Set the axes in the chart model.
*
* @param plotType The target plot type.
* @param chartModel The target chart model.
* @throws MacroExecutionException if the axes are incorrectly configured.
*/
public void setAxes(PlotType plotType, SimpleChartModel chartModel) throws MacroExecutionException {
AxisType[] defaultAxisTypes = plotType.getDefaultAxisTypes();
for (int i = 0; i < axisTypes.length; i++) {
AxisType type = axisTypes[i];
if (i >= defaultAxisTypes.length) {
if (type != null) {
throw new MacroExecutionException("To many axes for plot type.");
}
continue;
}
if (type == null) {
type = defaultAxisTypes[i];
}
Axis axis;
switch(type) {
case NUMBER:
NumberAxis numberAxis = new NumberAxis();
axis = numberAxis;
setNumberLimits(numberAxis, i);
break;
case CATEGORY:
axis = new CategoryAxis();
break;
case DATE:
DateAxis dateAxis = new DateAxis();
axis = dateAxis;
dateAxis.setTickMarkPosition(DateTickMarkPosition.END);
if (axisDateFormat[i] != null) {
try {
DateFormat dateFormat = new SimpleDateFormat(axisDateFormat[i], localeConfiguration.getLocale());
dateAxis.setDateFormatOverride(dateFormat);
} catch (IllegalArgumentException e) {
throw new MacroExecutionException(String.format("Invalid date format [%s].", axisDateFormat[i]));
}
}
setDateLimits(dateAxis, i);
break;
default:
throw new MacroExecutionException(String.format("Unsupported axis type [%s]", type.getName()));
}
chartModel.setAxis(i, axis);
}
}
use of org.xwiki.rendering.macro.MacroExecutionException in project xwiki-platform by xwiki.
the class LocaleConfiguration method setParameter.
/**
* Let an implementation set a parameter.
*
* @param key The key of the parameter.
* @param value The value of the parameter.
* @return {@code true} if the parameter was claimed.
* @throws MacroExecutionException if the parameter is invalid in some way.
*/
public boolean setParameter(String key, String value) throws MacroExecutionException {
boolean claimed = true;
if (LOCALE_PARAM.equals(key)) {
boolean valid = true;
Locale l;
try {
l = LocaleUtils.toLocale(value);
if (!LocaleUtils.isAvailableLocale(l)) {
valid = false;
} else {
this.locale = l;
}
} catch (IllegalArgumentException e) {
valid = false;
}
if (!valid) {
throw new MacroExecutionException(String.format("Invalid locale string [%s].", value));
}
} else if (DATEFORMAT_PARAM.equals(key)) {
this.dateFormatString = value;
} else {
claimed = false;
}
return claimed;
}
use of org.xwiki.rendering.macro.MacroExecutionException in project xwiki-platform by xwiki.
the class AbstractTableBlockDataSource method buildDataset.
@Override
public void buildDataset(String macroContent, Map<String, String> parameters, MacroTransformationContext context) throws MacroExecutionException {
validateParameters(parameters);
TableBlock tableBlock = getTableBlock(macroContent, context);
int[] dataRange = getDataRange(tableBlock);
TableDatasetBuilder datasetBuilder;
setChartModel(new SimpleChartModel());
switch(getDatasetType()) {
case CATEGORY:
datasetBuilder = new TableCategoryDatasetBuilder();
break;
case PIE:
datasetBuilder = new TablePieDatasetBuilder();
break;
case TIMETABLE_XY:
datasetBuilder = new TableTimeTableXYDatasetBuilder();
break;
default:
throw new MacroExecutionException(String.format("Unsupported dataset type [%s]", getDatasetType().getName()));
}
setAxes();
datasetBuilder.setLocaleConfiguration(getLocaleConfiguration());
datasetBuilder.setParameters(parameters);
if (SERIES_COLUMNS.equals(series)) {
datasetBuilder.setTranspose(true);
}
buildDataset(tableBlock, dataRange, datasetBuilder);
setDataset(datasetBuilder.getDataset());
}
use of org.xwiki.rendering.macro.MacroExecutionException in project xwiki-platform by xwiki.
the class AbstractTableBlockDataSource method getDataRangeFromParameter.
/**
* Parses the range parameter and return an array on the form [startRow, startColumn, endRow, endColumn]. Any
* element in the array may be {@code null} to indicate no bound.
*
* @return An array as described above.
* @throws MacroExecutionException if the range parameter cannot be parsed.
*/
private Integer[] getDataRangeFromParameter() throws MacroExecutionException {
Integer startColumn = null;
Integer endColumn = null;
Integer startRow = null;
Integer endRow = null;
if (range != null) {
Matcher m = RANGE_PATTERN.matcher(range);
if (!m.matches()) {
throw new MacroExecutionException(String.format("Invalid range specification: [%s].", range));
}
startColumn = getColumnNumberFromIdentifier(m.group(1));
startRow = getRowNumberFromIdentifier(m.group(2));
endColumn = getColumnNumberFromIdentifier(m.group(3));
endRow = getRowNumberFromIdentifier(m.group(4));
if (startColumn != null && endColumn != null && startColumn > endColumn) {
throw new MacroExecutionException(String.format("Invalid data range, end column mustn't come before start column: [%s].", range));
}
if (startRow != null && endRow != null && startRow > endRow) {
throw new MacroExecutionException(String.format("Invalid data range, end row mustn't come before start row: [%s].", range));
}
}
return new Integer[] { startRow, startColumn, endRow, endColumn };
}
use of org.xwiki.rendering.macro.MacroExecutionException in project xwiki-platform by xwiki.
the class AbstractTableBlockDataSource method getDataRange.
/**
* Calculates the data-range that is to be used for plotting the chart.
*
* @param tableBlock the {@link TableBlock}.
* @return an integer array consisting of start-row, start-column, end-row and end-column of the data range.
* @throws MacroExecutionException if it's not possible to determine the data range correctly.
*/
protected int[] getDataRange(TableBlock tableBlock) throws MacroExecutionException {
Integer[] r = getDataRangeFromParameter();
int rowCount = tableBlock.getChildren().size();
if (rowCount > 0) {
TableRowBlock firstRow = (TableRowBlock) tableBlock.getChildren().get(0);
int columnCount = firstRow.getChildren().size();
if (columnCount > 0) {
return new int[] { r[0] != null ? r[0] : 0, r[1] != null ? r[1] : 0, r[2] != null ? r[2] : rowCount - 1, r[3] != null ? r[3] : columnCount - 1 };
}
}
throw new MacroExecutionException("Data table is incomplete.");
}
Aggregations