Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion api/src/org/labkey/api/attachments/SvgSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.batik.anim.dom.SVGDOMImplementation;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Strings;
import org.labkey.api.util.PageFlowUtil;
import org.labkey.api.view.NotFoundException;

Expand All @@ -19,6 +20,8 @@ public class SvgSource
{
private final String _filteredSvg;

private Float _height = null;

public SvgSource(String svg)
{
if (StringUtils.isBlank(svg))
Expand All @@ -29,11 +32,19 @@ public SvgSource(String svg)
if (!svg.contains("xmlns=\"" + SVGDOMImplementation.SVG_NAMESPACE_URI + "\"") && !svg.contains("xmlns='" + SVGDOMImplementation.SVG_NAMESPACE_URI + "'"))
svg = svg.replace("<svg", "<svg xmlns='" + SVGDOMImplementation.SVG_NAMESPACE_URI + "'");

int idx = svg.indexOf("height=\"");
if (idx != -1)
{
int heightStart = idx + 8;
int end = svg.indexOf("\"", heightStart);
_height = Float.parseFloat(svg.substring(heightStart, end));
}

// remove xlink:title to prevent org.apache.batik.transcoder.TranscoderException (issue #16173)
svg = svg.replaceAll("xlink:title", "title");

// Reject hrefs. See #45819.
if (StringUtils.containsIgnoreCase(svg, "xlink:href"))
if (Strings.CI.contains(svg, "xlink:href"))
throw new RuntimeException(new TranscoderException("The security settings do not allow any external resources to be referenced from the document"));

_filteredSvg = svg;
Expand All @@ -56,4 +67,9 @@ public Reader getReader()
{
return new StringReader(_filteredSvg);
}

public Float getHeight()
{
return _height;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
import org.labkey.api.view.JspView;
import org.labkey.api.view.NavTree;
import org.labkey.api.view.NotFoundException;
import org.labkey.api.view.VBox;
import org.labkey.api.view.ViewContext;
import org.labkey.api.view.WebPartView;
import org.labkey.api.visualization.GenericChartReport;
Expand Down Expand Up @@ -140,7 +139,7 @@ public static class VisualizationUrlsImpl implements VisualizationUrls
private static final String VISUALIZATION_FILTER_URL = "filterUrl";
private static final String VISUALIZATION_EDIT_PARAM = "edit";
private static final String VISUALIZATION_ID_PARAM = "reportId";
private static final String VISUALIZATION_RENDERTYPE_PARAM = "renderType";
private static final String VISUALIZATION_RENDER_TYPE_PARAM = "renderType";

private void addQueryParams(ActionURL url, Container container, User user, QuerySettings settings)
{
Expand Down Expand Up @@ -184,7 +183,7 @@ public ActionURL getTimeChartDesignerURL(Container container)
{
ActionURL url = getBaseGenericChartURL(container, true);
url.addParameter(QueryParam.schemaName, "study");
url.addParameter(VISUALIZATION_RENDERTYPE_PARAM, "time_chart");
url.addParameter(VISUALIZATION_RENDER_TYPE_PARAM, "time_chart");
return url;
}

Expand Down Expand Up @@ -662,7 +661,6 @@ private ApiQueryResponse getApiResponse(ViewContext context, UserSchema schema,
}
}


@RequiresSiteAdmin
public static class cdsTestGetDataAction extends SimpleViewAction<Object>
{
Expand Down Expand Up @@ -740,8 +738,9 @@ public void validate(Object o, Errors errors)
* Content-type of request must be text/xml, not any kind of multipart
* Returns a PNG image.
*/
@SuppressWarnings("unused")
@RequiresPermission(ReadPermission.class)
public class ExportImageAction extends ExportSVGAction
public static class ExportImageAction extends ExportSVGAction
{
@Override
public ModelAndView handleRequest() throws Exception
Expand All @@ -753,7 +752,14 @@ public ModelAndView handleRequest() throws Exception
DocumentConversionService svc = DocumentConversionService.get();

if (null != svc)
svc.svgToPng(getSVGSource(), response.getOutputStream());
{
// Ensure high resolution image even if browser submits a small SVG. See Issue 53390.
SvgSource svgSource = getSVGSource();
Float height = svgSource.getHeight();
if (height != null)
height = Math.max(height * 2, 2000);
svc.svgToPng(svgSource, response.getOutputStream(), height);
}

return null;
}
Expand All @@ -764,8 +770,9 @@ public ModelAndView handleRequest() throws Exception
* Content-type of request must be text/xml, not any kind of multipart
* Returns a PDF document containing the visualization as a scalable vector graphic
*/
@SuppressWarnings("unused")
@RequiresPermission(ReadPermission.class)
public class ExportPDFAction extends ExportSVGAction
public static class ExportPDFAction extends ExportSVGAction
{
@Override
public ModelAndView handleRequest() throws Exception
Expand Down Expand Up @@ -1133,74 +1140,62 @@ public ApiResponse execute(SaveVisualizationForm form, BindException errors) thr
}
}

@RequiresPermission(ReadPermission.class)
public class TimeChartWizardAction extends SimpleViewAction<ChartWizardReportForm>
private abstract class AbstractChartWizardAction extends SimpleViewAction<ChartWizardReportForm>
{
String _navTitle = "Chart Wizard";
private String _navTitle = "Chart Wizard";

@Override
public ModelAndView getView(ChartWizardReportForm form, BindException errors) throws Exception
{
form.setAllowToggleMode(true);
form.setRenderType("time_chart");

// issue 27439: allow chart wizard report lookup by name if reportId not provided
Report report = getReport(form);
if (form.getReportId() == null && report != null && report.getDescriptor() != null)
form.setReportId(report.getDescriptor().getReportId());

JspView timeChartWizard = new JspView<>("/org/labkey/visualization/views/chartWizard.jsp", form);
timeChartWizard.setTitle(_navTitle);
timeChartWizard.setFrame(WebPartView.FrameType.NONE);
VBox boxView = new VBox(timeChartWizard);
JspView<?> chartWizard = new JspView<>("/org/labkey/visualization/views/chartWizard.jsp", form);
chartWizard.setTitle(_navTitle);
chartWizard.setFrame(WebPartView.FrameType.NONE);

if (report != null)
{
_navTitle = report.getDescriptor().getReportName();
}

return boxView;
return chartWizard;
}

@Override
public void addNavTrail(NavTree root)
{
setHelpTopic("timeChart");
root.addChild(_navTitle);
}
}

@RequiresPermission(ReadPermission.class)
@Action(ActionType.SelectData.class) // TODO rename to just ChartWizardAction
public class GenericChartWizardAction extends SimpleViewAction<ChartWizardReportForm>
@Action(ActionType.SelectData.class)
public class TimeChartWizardAction extends AbstractChartWizardAction
{
String _navTitle = "Chart Wizard";

@Override
public ModelAndView getView(ChartWizardReportForm form, BindException errors) throws Exception
{
form.setAllowToggleMode(true);

// issue 27439: allow chart wizard report lookup by name if reportId not provided
Report report = getReport(form);
if (form.getReportId() == null && report != null && report.getDescriptor() != null)
form.setReportId(report.getDescriptor().getReportId());

JspView view = new JspView<>("/org/labkey/visualization/views/chartWizard.jsp", form);
view.setTitle(_navTitle);
view.setFrame(WebPartView.FrameType.NONE);

if (report != null)
_navTitle = report.getDescriptor().getReportName();
form.setRenderType("time_chart");
setHelpTopic("timeChart");

return view;
return super.getView(form, errors);
}
}

@RequiresPermission(ReadPermission.class)
@Action(ActionType.SelectData.class)
// TODO rename to just ChartWizardAction
public class GenericChartWizardAction extends AbstractChartWizardAction
{
@Override
public void addNavTrail(NavTree root)
public ModelAndView getView(ChartWizardReportForm form, BindException errors) throws Exception
{
setHelpTopic("reportsAndViews");
root.addChild(_navTitle);

return super.getView(form, errors);
}
}

Expand Down