Search in sources :

Example 1 with IUIComponent

use of org.pentaho.platform.api.ui.IUIComponent in project pentaho-platform by pentaho.

the class UIServlet method doGet.

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    PentahoSystem.systemEntryPoint();
    try {
        OutputStream outputStream = response.getOutputStream();
        String path = request.getContextPath();
        IPentahoSession userSession = getPentahoSession(request);
        HttpSession session = request.getSession();
        // $NON-NLS-1$
        String type = MediaType.valueOf(request.getParameter("type")).toString();
        if (type == null) {
            // $NON-NLS-1$
            type = "text/html";
        }
        // find out which component is going to fulfill this request
        // $NON-NLS-1$
        String componentName = StringEscapeUtils.escapeHtml(request.getParameter("component"));
        if (componentName == null) {
            // $NON-NLS-1$
            response.setContentType("text/html");
            StringBuffer buffer = new StringBuffer();
            formatErrorMessage(userSession, buffer, "UIServlet.ERROR_0001_COMPONENT_NOT_SPECIFIED");
            outputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
            return;
        }
        response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
        // TODO switch this to the interface once stable
        IUIComponent component = (IUIComponent) session.getAttribute(componentName);
        if (component == null) {
            component = getComponent(componentName);
            if (component == null) {
                // $NON-NLS-1$
                response.setContentType("text/html");
                StringBuffer buffer = new StringBuffer();
                formatErrorMessage(userSession, buffer, "UIServlet.ERROR_0002_COMPONENT_INVALID");
                outputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
                return;
            }
            session.setAttribute(componentName, component);
        }
        if (!component.validate()) {
            // TODO need an error here
            return;
        }
        String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/content?type=" + type + "&component=" + componentName + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
        "&";
        response.setContentType(type);
        HttpOutputHandler outputHandler = new HttpOutputHandler(response, outputStream, true);
        SimpleUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
        HttpServletRequestHandler requestHandler = new HttpServletRequestHandler(userSession, null, request, outputHandler, urlFactory);
        requestHandler.handleUIRequest(component, type);
    } finally {
        PentahoSystem.systemExitPoint();
    }
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) HttpSession(javax.servlet.http.HttpSession) OutputStream(java.io.OutputStream) HttpOutputHandler(org.pentaho.platform.web.http.HttpOutputHandler) IUIComponent(org.pentaho.platform.api.ui.IUIComponent) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory)

Aggregations

OutputStream (java.io.OutputStream)1 HttpSession (javax.servlet.http.HttpSession)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 IUIComponent (org.pentaho.platform.api.ui.IUIComponent)1 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)1 HttpOutputHandler (org.pentaho.platform.web.http.HttpOutputHandler)1