⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chartserviceimpl.java

📁 GridSphere 门户 提供一个基于 portlet 的高级开放源代码门户。GridSphere 是在欧盟提供基金的 GridLab 项目下开发的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package org.gridsphere.services.core.charts.impl;import org.apache.oro.text.perl.Perl5Util;import org.exolab.castor.xml.MarshalException;import org.exolab.castor.xml.ValidationException;import org.gridsphere.portlet.service.PortletServiceException;import org.gridsphere.portlet.service.PortletServiceUnavailableException;import org.gridsphere.portlet.service.spi.PortletServiceConfig;import org.gridsphere.portlet.service.spi.PortletServiceFactory;import org.gridsphere.portlet.service.spi.PortletServiceProvider;import org.gridsphere.services.core.charts.*;import org.gridsphere.services.core.secdir.FileLocationID;import org.gridsphere.services.core.secdir.SecureDirectoryService;import java.io.File;import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;import java.util.Date;/** * @author <a href="mailto:tkucz@icis.pcz.pl">Tomasz Kuczynski</a> * @version $Id: ChartServiceImpl.java 5032 2006-08-17 18:15:06Z novotny $ */public class ChartServiceImpl implements ChartService, PortletServiceProvider {    private boolean inited = false;    private SecureDirectoryService secureDirectoryService;    private static final String CHART_SERVICE_DIRECTORY = "_chart_service_directory_";    private Perl5Util util = new Perl5Util();    public void init(PortletServiceConfig config) throws PortletServiceUnavailableException {        if (!inited) {            System.setProperty("java.awt.headless", "true");            try {                secureDirectoryService = (SecureDirectoryService)PortletServiceFactory.createPortletService(SecureDirectoryService.class, true);            } catch (PortletServiceException e) {                throw new PortletServiceUnavailableException("Unable to get instance of SecureDirectoryService!", e);            }	    inited = true;        }    }    public void destroy() {    }    public String getChartUrl(FileLocationID fileLocationID) {        return getDownloadChartUrl(fileLocationID, null);    }    public String getDownloadChartUrl(FileLocationID fileLocationID, String saveAs) {        String userID = fileLocationID.getUserID();        String appName = fileLocationID.getCategory();        String resource = fileLocationID.getFilePath();        String chartUrl = null;        try {            refreshChart(fileLocationID);            ChartDescriptor chartDescriptor = readChartDescriptor(userID, appName, resource);            Image imageInfo = chartDescriptor.getFileInfo().getImage();            chartUrl = (saveAs != null ? secureDirectoryService.getDownloadFileUrl(secureDirectoryService.createFileLocationID(userID,                    imageInfo.getAppName(),                    imageInfo.getFilename() + (imageInfo.getType().equals("JPEG") ? ".jpeg" : ".png")),                    saveAs,                    null) :                    secureDirectoryService.getFileUrl(secureDirectoryService.createFileLocationID(userID,                            imageInfo.getAppName(),                            imageInfo.getFilename() + (imageInfo.getType().equals("JPEG") ? ".jpeg" : ".png"))));        } catch (Exception e) {        }        return chartUrl;    }    public ChartDescriptor createPieChart(FileLocationID fileLocationID, org.jfree.data.DefaultPieDataset dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "Pie");    }    public ChartDescriptor createPie3DChart(FileLocationID fileLocationID, org.jfree.data.DefaultPieDataset dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "Pie3D");    }    public ChartDescriptor createBarChart(FileLocationID fileLocationID, org.jfree.data.DefaultCategoryDataset dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "Bar");    }    public ChartDescriptor createBar3DChart(FileLocationID fileLocationID, org.jfree.data.DefaultCategoryDataset dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "Bar3D");    }    public ChartDescriptor createStackedBarChart(FileLocationID fileLocationID, org.jfree.data.DefaultCategoryDataset dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "StackedBar");    }    public ChartDescriptor createStackedBar3DChart(FileLocationID fileLocationID, org.jfree.data.DefaultCategoryDataset dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "StackedBar3D");    }    public ChartDescriptor createAreaChart(FileLocationID fileLocationID, org.jfree.data.DefaultCategoryDataset dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "Area");    }    public ChartDescriptor createStackedAreaChart(FileLocationID fileLocationID, org.jfree.data.DefaultCategoryDataset dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "StackedArea");    }    public ChartDescriptor createLineChart(FileLocationID fileLocationID, org.jfree.data.DefaultCategoryDataset dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "Line");    }    public ChartDescriptor createGanttChart(FileLocationID fileLocationID, org.jfree.data.gantt.TaskSeriesCollection dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "Gantt");    }    public ChartDescriptor createBarXYChart(FileLocationID fileLocationID, org.jfree.data.XYSeriesCollection dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "BarXY");    }    public ChartDescriptor createAreaXYChart(FileLocationID fileLocationID, org.jfree.data.XYSeriesCollection dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "AreaXY");    }    public ChartDescriptor createLineXYChart(FileLocationID fileLocationID, org.jfree.data.XYSeriesCollection dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "LineXY");    }    public ChartDescriptor createStepAreaXYChart(FileLocationID fileLocationID, org.jfree.data.XYSeriesCollection dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "StepAreaXY");    }    public ChartDescriptor createBarXYChart(FileLocationID fileLocationID, org.jfree.data.time.TimeSeriesCollection dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "BarXY");    }    public ChartDescriptor createTimeSeriesChart(FileLocationID fileLocationID, org.jfree.data.time.TimeSeriesCollection dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "TimeSeries");    }    public ChartDescriptor createStepXYChart(FileLocationID fileLocationID, org.jfree.data.time.TimeSeriesCollection dataset) throws IOException, Exception {        return createChart(fileLocationID, dataset, "StepXY");    }    private ChartDescriptor createChart(FileLocationID fileLocationID, org.jfree.data.Dataset dataset, String type) throws IOException, Exception {        String userID = fileLocationID.getUserID();        String appName = fileLocationID.getCategory();        String resource = fileLocationID.getFilePath();        if (appName.equals(CHART_SERVICE_DIRECTORY))            throw new IOException("AppName collides with internal chart service directory !!!");        ChartDescriptor chartDescriptor = null;        try {            chartDescriptor = createChartDescriptor(userID, appName, resource, type, dataset);            writeChartDescriptor(userID, appName, resource, chartDescriptor);        } catch (MarshalException e) {            throw new Exception("Unable to write create chart description file (MarshalException).", e);        } catch (ValidationException e) {            throw new Exception("Unable to write create chart description file (ValidationException).", e);        }        chartDescriptor.getChartInfo().setRefresh(true);        return chartDescriptor;    }    public void setChartDataset(FileLocationID fileLocationID, org.jfree.data.Dataset inDataset, long datasetTimeStamp) throws IOException, Exception {        String userID = fileLocationID.getUserID();        String appName = fileLocationID.getCategory();        String resource = fileLocationID.getFilePath();        ChartDescriptor chartDescriptor = readChartDescriptor(userID, appName, resource);        if (chartDescriptor.getFileInfo().getDataset().getTimestamp() < datasetTimeStamp)            setChartDataset(fileLocationID, inDataset);    }    public void setChartDataset(FileLocationID fileLocationID, org.jfree.data.Dataset inDataset) throws IOException, Exception {        String userID = fileLocationID.getUserID();        String appName = fileLocationID.getCategory();        String resource = fileLocationID.getFilePath();        ChartDescriptor chartDescriptor = readChartDescriptor(userID, appName, resource);        String datasetType = chartDescriptor.getFileInfo().getDataset().getType();        if (!inDataset.getClass().getName().equals(datasetType))            throw new Exception("Incompatibile dataset type (" + datasetType + ") expected.");        writeDataset(userID, appName, resource, inDataset);        chartDescriptor.getFileInfo().getDataset().setTimestamp(new Date().getTime());        chartDescriptor.getChartInfo().setRefresh(true);        writeChartDescriptor(userID, appName, resource, chartDescriptor);    }    public void setChartDescriptor(FileLocationID fileLocationID, ChartDescriptor inChartDescriptor) throws IOException, Exception {        String userID = fileLocationID.getUserID();        String appName = fileLocationID.getCategory();        String resource = fileLocationID.getFilePath();        ChartDescriptor chartDescriptor = getChartDescriptor(fileLocationID);        Image inChartImage = inChartDescriptor.getFileInfo().getImage();        Image chartImage = chartDescriptor.getFileInfo().getImage();        if (!inChartImage.getAppName().equals(chartImage.getAppName()) ||                !inChartImage.getFilename().equals(chartImage.getFilename()) ||                !inChartImage.getType().equals(chartImage.getType())) {            try {                getChartImageFile(fileLocationID).delete();            } catch (Exception e) {                getChartImageFile(fileLocationID).deleteOnExit();            }            inChartDescriptor.getChartInfo().setRefresh(true);        }        Dataset inDataset = inChartDescriptor.getFileInfo().getDataset();        Dataset dataset = chartDescriptor.getFileInfo().getDataset();        if (!inDataset.getAppName().equals(dataset.getAppName()) ||                !inDataset.getFilename().equals(dataset.getFilename())) {            inDataset.setTimestamp(new Date().getTime());            inChartDescriptor.getChartInfo().setRefresh(true);        }//        inChartDescriptor.getChartInfo().setRefresh(true); - in getChartDescriptor(String userID, String appName, String resource) - allows to change chart settings, and refresh chart after first dataset change        writeChartDescriptor(userID, appName, resource, inChartDescriptor);    }    public ChartDescriptor getChartDescriptor(FileLocationID fileLocationID) throws IOException, Exception {        String userID = fileLocationID.getUserID();        String appName = fileLocationID.getCategory();        String resource = fileLocationID.getFilePath();        ChartDescriptor chartDescriptor = readChartDescriptor(userID, appName, resource);        chartDescriptor.getChartInfo().setRefresh(true);        return chartDescriptor;    }    public void setChartTitle(FileLocationID fileLocationID, String title) throws IOException, Exception {        ChartDescriptor chartDescriptor = getChartDescriptor(fileLocationID);        chartDescriptor.getChartInfo().setTitle(title);        setChartDescriptor(fileLocationID, chartDescriptor);    }    public String[] getChartList(FileLocationID fileLocationID) {        String userID = fileLocationID.getUserID();        String appName = fileLocationID.getCategory();        String path = fileLocationID.getFilePath();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -