Example usage for javax.servlet.http HttpSession HttpSession

List of usage examples for javax.servlet.http HttpSession HttpSession

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession HttpSession.

Prototype

HttpSession

Source Link

Usage

From source file:org.orbeon.oxf.processor.JFreeChartProcessor.java

protected ChartInfo createChart(org.orbeon.oxf.pipeline.api.PipelineContext context,
        JFreeChartSerializer.ChartConfig chartConfig) {

    Document data = readInputAsDOM4J(context, getInputByName(INPUT_DATA));

    Dataset ds;//from   w w w.ja v  a2 s . c om
    if (chartConfig.getType() == JFreeChartSerializer.ChartConfig.PIE_TYPE
            || chartConfig.getType() == JFreeChartSerializer.ChartConfig.PIE3D_TYPE)
        ds = createPieDataset(chartConfig, data);
    else if (chartConfig.getType() == ChartConfig.XY_LINE_TYPE)
        ds = createXYDataset(chartConfig, data);
    else if (chartConfig.getType() == ChartConfig.TIME_SERIES_TYPE)
        ds = createTimeSeriesDataset(chartConfig, data);
    else
        ds = createDataset(chartConfig, data);

    JFreeChart chart = drawChart(chartConfig, ds);
    ChartRenderingInfo info = new ChartRenderingInfo();

    String file;
    try {
        final ExternalContext.Session session = ((ExternalContext) context
                .getAttribute(PipelineContext.EXTERNAL_CONTEXT)).getSession(true);
        file = ServletUtilities.saveChartAsPNG(chart, chartConfig.getxSize(), chartConfig.getySize(), info,
                new HttpSession() {
                    public Object getAttribute(String s) {
                        return session.getAttributesMap(PortletSession.APPLICATION_SCOPE).get(s);
                    }

                    public Enumeration getAttributeNames() {
                        return Collections.enumeration(
                                session.getAttributesMap(PortletSession.APPLICATION_SCOPE).keySet());
                    }

                    public long getCreationTime() {
                        return session.getCreationTime();
                    }

                    public String getId() {
                        return session.getId();
                    }

                    public long getLastAccessedTime() {
                        return session.getLastAccessedTime();
                    }

                    public int getMaxInactiveInterval() {
                        return session.getMaxInactiveInterval();
                    }

                    public ServletContext getServletContext() {
                        return null;
                    }

                    public HttpSessionContext getSessionContext() {
                        return null;
                    }

                    public Object getValue(String s) {
                        return getAttribute(s);
                    }

                    public String[] getValueNames() {
                        List list = new ArrayList();
                        for (Enumeration e = getAttributeNames(); e.hasMoreElements();) {
                            list.add(e.nextElement());
                        }
                        String[] array = new String[list.size()];
                        list.toArray(array);
                        return array;
                    }

                    public void invalidate() {
                        session.invalidate();
                    }

                    public boolean isNew() {
                        return session.isNew();
                    }

                    public void putValue(String s, Object o) {
                        setAttribute(s, o);
                    }

                    public void removeAttribute(String s) {
                        session.getAttributesMap(PortletSession.APPLICATION_SCOPE).remove(s);
                    }

                    public void removeValue(String s) {
                        removeAttribute(s);
                    }

                    public void setAttribute(String s, Object o) {
                        session.getAttributesMap(PortletSession.APPLICATION_SCOPE).put(s, o);
                    }

                    public void setMaxInactiveInterval(int i) {
                        session.setMaxInactiveInterval(i);
                    }
                });
    } catch (Exception e) {
        throw new OXFException(e);
    }
    return new ChartInfo(info, file);
}