Search in sources :

Example 1 with WebUiContext

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

the class MenuView method processProperty.

@Override
public void processProperty(final String name, final Object value) {
    final String stringValue = (String) value;
    if (name.equals("cssClass")) {
        this.cssClass = value.toString();
    } else if (name.equals("numLevels")) {
        this.numLevels = Integer.parseInt(stringValue);
    } else if (name.equals("menuName")) {
        final WebUiContext context = WebUiContext.get();
        setObject(context.getMenu(stringValue));
        if (getObject() == null) {
            throw new IllegalArgumentException("Menu " + value + " does not exist");
        }
    } else if (name.equals("showRoot")) {
        this.showRoot = Boolean.valueOf(stringValue).booleanValue();
    }
}
Also used : WebUiContext(com.revolsys.ui.web.config.WebUiContext)

Example 2 with WebUiContext

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

the class OnLoadTag method doStartTag.

/**
 * Process the start tag.
 *
 * @return SKIP_BODY
 */
@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();
                final Iterator onLoads = page.getOnLoads().iterator();
                out.print("onload=\"");
                while (onLoads.hasNext()) {
                    final String onLoad = (String) onLoads.next();
                    out.print(onLoad);
                    out.print("; ");
                }
                out.print("\"");
            }
        }
        return SKIP_BODY;
    } catch (final Throwable t) {
        throw new JspTagException(t);
    }
}
Also used : Iterator(java.util.Iterator) Page(com.revolsys.ui.web.config.Page) WebUiContext(com.revolsys.ui.web.config.WebUiContext) JspWriter(javax.servlet.jsp.JspWriter)

Example 3 with WebUiContext

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

the class StylesTag 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 Collection styles = page.getStyles();
                String contextPath = context.getContextPath();
                if (contextPath.equals("/")) {
                    contextPath = "";
                }
                final JspWriter out = this.pageContext.getOut();
                final Iterator styleIter = styles.iterator();
                while (styleIter.hasNext()) {
                    final String style = (String) styleIter.next();
                    out.print("<link rel=\"stylesheet\" href=\"");
                    out.print(style);
                    out.println("\" type=\"text/css\" />");
                }
            }
        }
        final SiteNodeController controller = (SiteNodeController) this.pageContext.findAttribute("rsWebController");
        if (controller instanceof PageController) {
            final PageController page = (PageController) controller;
            serializeElements(page.getStyles());
        }
        return SKIP_BODY;
    } catch (final Throwable t) {
        log.error(t.getMessage(), t);
        throw new JspTagException(t.getMessage(), t);
    }
}
Also used : SiteNodeController(com.revolsys.ui.web.config.SiteNodeController) PageController(com.revolsys.ui.web.config.PageController) Iterator(java.util.Iterator) Collection(java.util.Collection) Page(com.revolsys.ui.web.config.Page) WebUiContext(com.revolsys.ui.web.config.WebUiContext) JspWriter(javax.servlet.jsp.JspWriter)

Example 4 with WebUiContext

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

the class IafServletFilter method doFilter.

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    try {
        final HttpServletRequest httpRequest = (HttpServletRequest) request;
        final HttpServletResponse httpResponse = (HttpServletResponse) response;
        final String contextPath = httpRequest.getContextPath();
        WebUiContext.set(new WebUiContext(this.rsWebUiConfig, contextPath, null, httpRequest, httpResponse));
        request.setAttribute("niceConfig", this.rsWebUiConfig);
        chain.doFilter(request, response);
    } finally {
        WebUiContext.set(null);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebUiContext(com.revolsys.ui.web.config.WebUiContext)

Example 5 with WebUiContext

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

the class WebUiFilter method doFilter.

public void doFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException {
    if (this.rsWebUiConfig != null) {
        try {
            final HttpServletRequest httpRequest = request;
            final HttpServletResponse httpResponse = response;
            final String contextPath = httpRequest.getContextPath();
            Page page;
            try {
                page = this.rsWebUiConfig.getPage(request.getServletPath() + request.getPathInfo());
            } catch (final PageNotFoundException e) {
                page = new Page(null, null, "/", false);
            }
            WebUiContext.set(new WebUiContext(this.rsWebUiConfig, contextPath, page, httpRequest, httpResponse));
            request.setAttribute("rsWebUiConfig", this.rsWebUiConfig);
            chain.doFilter(request, response);
        } finally {
            WebUiContext.set(null);
        }
    } else {
        try {
            final String path = request.getServletPath();
            final String serverName = request.getServerName();
            if (this.applicationContext.containsBean(serverName)) {
                this.site = (Site) this.applicationContext.getBean(serverName);
            } else {
                LOG.info("using default site");
                this.site = (Site) this.applicationContext.getBean("default");
            }
            if (this.site != null) {
                final SiteNodeController controller = this.site.getController(path);
                LOG.debug(path + "=" + controller);
                request.setAttribute("site", this.site);
                request.setAttribute("rsWebController", controller);
                if (controller != null) {
                    controller.process(this.servletContext, request, response);
                    return;
                }
            }
            chain.doFilter(request, response);
        } catch (final RuntimeException e) {
            LOG.error(e.getMessage(), e);
            throw e;
        } catch (final ServletException e) {
            LOG.error(e.getMessage(), e);
            throw e;
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) SiteNodeController(com.revolsys.ui.web.config.SiteNodeController) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Page(com.revolsys.ui.web.config.Page) 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