Search in sources :

Example 6 with WebUiContext

use of com.revolsys.ui.web.config.WebUiContext in project com.revolsys.open by revolsys.

the class ScriptsTag method doStartTag.

/**
 * Process the start tag.
 *
 * @return SKIP_BODY
 * @throws JspException If there was an exception processing the tag.
 */
@Override
public int doStartTag() throws JspException {
    try {
        final WebUiContext context = WebUiContext.get();
        if (context != null) {
            final Page page = context.getPage();
            if (page != null) {
                final JspWriter out = this.pageContext.getOut();
                String contextPath = context.getContextPath();
                if (contextPath.equals("/")) {
                    contextPath = "";
                }
                final Iterator scripts = page.getScripts().iterator();
                while (scripts.hasNext()) {
                    final String script = (String) scripts.next();
                    out.print("<script type=\"text/javascript\" src=\"");
                    out.print(contextPath);
                    out.print(script);
                    out.println("\">\n</script>");
                }
            }
        }
        final SiteNodeController controller = (SiteNodeController) this.pageContext.findAttribute("rsWebController");
        if (controller instanceof PageController) {
            final PageController page = (PageController) controller;
            writeScripts(page.getScripts());
        }
    } catch (final Throwable t) {
        log.error(t.getMessage(), t);
    }
    return SKIP_BODY;
}
Also used : SiteNodeController(com.revolsys.ui.web.config.SiteNodeController) PageController(com.revolsys.ui.web.config.PageController) Iterator(java.util.Iterator) Page(com.revolsys.ui.web.config.Page) WebUiContext(com.revolsys.ui.web.config.WebUiContext) JspWriter(javax.servlet.jsp.JspWriter)

Example 7 with WebUiContext

use of com.revolsys.ui.web.config.WebUiContext in project com.revolsys.open by revolsys.

the class IafServlet method processRequest.

/**
 * Process the service request, uses the full path name of the request to
 * finds the page definition. The component heirarchy, list of request
 * processors and the menu tree from the config are used to handle the
 * request. If a PageNotFoundException was thrown by any of the request
 * processors a 404 response error code is set and no further processing is
 * performed. If a RedirectException is thrown the response is redirected to
 * the url from the exception.
 *
 * @param request the servlet request
 * @param response the servlet response
 * @exception ServletException if any unhandled exceptions occured during the
 *              processing of the request
 * @exception IOException if there was a problem sending data to the client
 * @see PageNotFoundException
 * @see RedirectException
 */
public void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    try {
        String path = request.getServletPath();
        final String pathInfo = request.getPathInfo();
        if (pathInfo != null && !path.endsWith(pathInfo)) {
            path += pathInfo;
        }
        boolean secure = false;
        final String contextPath = request.getContextPath();
        if (path.endsWith(".wp")) {
            path = path.substring(0, path.length() - 3);
        } else if (path.endsWith(".wps")) {
            secure = true;
            path = path.substring(0, path.length() - 4);
        }
        final Page page = this.applicationConfig.getPage(contextPath + path);
        WebUiContext.set(new WebUiContext(this.applicationConfig, contextPath, page, request, response));
        if (page.isSecure() && !secure) {
            response.sendRedirect(page.getFullUrl());
            return;
        }
        processArguments(page, request);
        processAttributes(page, request);
        request.setAttribute("niceConfig", this.applicationConfig);
        request.setAttribute("nicePage", page);
        final String menuName = request.getParameter("menuName");
        request.setAttribute("menuSelected", menuName);
        request.setAttribute("title", page.getTitle());
        page.invokeActions(this.servletContext, request, response);
        final Layout layout = page.getLayout();
        if (layout != null) {
            final String file = layout.getFile();
            if (file != null && file.length() > 0) {
                forward(file, request, response);
            }
        }
    } catch (final FinishRequestException fre) {
        // Do nothing as the actions have handled the request
        return;
    } catch (final AuthenticationException pne) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    } catch (final PageNotFoundException pne) {
        log.error(pne.getMessage(), pne);
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } catch (final RedirectException re) {
        response.sendRedirect(response.encodeRedirectURL(re.getUrl()));
    } catch (final Throwable t) {
        log.error(t.getMessage(), t);
        throw new ServletException(t);
    }
}
Also used : ServletException(javax.servlet.ServletException) FinishRequestException(com.revolsys.ui.web.exception.FinishRequestException) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) Layout(com.revolsys.ui.web.config.Layout) AuthenticationException(com.revolsys.ui.web.exception.AuthenticationException) Page(com.revolsys.ui.web.config.Page) WebUiContext(com.revolsys.ui.web.config.WebUiContext) RedirectException(com.revolsys.ui.web.exception.RedirectException)

Example 8 with WebUiContext

use of com.revolsys.ui.web.config.WebUiContext in project com.revolsys.open by revolsys.

the class PageMenuView method processProperty.

@Override
public void processProperty(final String name, final Object value) {
    final String stringValue = (String) value;
    if (name.equals("menuName")) {
        final WebUiContext context = WebUiContext.get();
        setObject(context.getPage().getMenu(stringValue));
    } else {
        super.processProperty(name, value);
    }
}
Also used : WebUiContext(com.revolsys.ui.web.config.WebUiContext)

Aggregations

WebUiContext (com.revolsys.ui.web.config.WebUiContext)8 Page (com.revolsys.ui.web.config.Page)5 SiteNodeController (com.revolsys.ui.web.config.SiteNodeController)3 Iterator (java.util.Iterator)3 JspWriter (javax.servlet.jsp.JspWriter)3 PageController (com.revolsys.ui.web.config.PageController)2 PageNotFoundException (com.revolsys.ui.web.exception.PageNotFoundException)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Layout (com.revolsys.ui.web.config.Layout)1 AuthenticationException (com.revolsys.ui.web.exception.AuthenticationException)1 FinishRequestException (com.revolsys.ui.web.exception.FinishRequestException)1 RedirectException (com.revolsys.ui.web.exception.RedirectException)1 Collection (java.util.Collection)1