com.bstek.ureport.console.chart.ChartServletAction Maven / Gradle / Ivy
/*******************************************************************************
* Copyright 2017 Bstek
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package com.bstek.ureport.console.chart;
import java.io.IOException;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bstek.ureport.cache.CacheUtils;
import com.bstek.ureport.chart.ChartData;
import com.bstek.ureport.console.RenderPageServletAction;
import com.bstek.ureport.model.Report;
import com.bstek.ureport.utils.UnitUtils;
/**
* @author Jacky.gao
* @since 2017年6月30日
*/
public class ChartServletAction extends RenderPageServletAction {
@Override
public void execute(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method=retriveMethod(req);
if(method!=null){
invokeMethod(method, req, resp);
}
}
public void storeData(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String file=req.getParameter("_u");
file=decode(file);
Map parameters = buildParameters(req);
String fullName=file+parameters.toString();
Report report=CacheUtils.getReport(fullName);
if(report==null){
return;
}
String chartId=req.getParameter("_chartId");
String base64Data=req.getParameter("_base64Data");
String prefix="data:image/png;base64,";
if(base64Data!=null){
if(base64Data.startsWith(prefix)){
base64Data=base64Data.substring(prefix.length(),base64Data.length());
}
}
Map map=report.getContext().getChartDataMap();
ChartData chartData=map.get(chartId);
if(chartData==null)return;
chartData.setBase64Data(base64Data);
String width=req.getParameter("_width");
String height=req.getParameter("_height");
chartData.setHeight(UnitUtils.pixelToPoint(Integer.valueOf(height)));
chartData.setWidth(UnitUtils.pixelToPoint(Integer.valueOf(width)));
}
@Override
public String url() {
return "/chart";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy