Search in sources :

Example 1 with SiteNodeController

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

the class DisplayConfigAction method addSiteNode.

private void addSiteNode(final ElementContainer view, final SiteNode siteNode) {
    if (siteNode != null) {
        final ElementContainer nodeView = new ElementContainer();
        view.add(nodeView);
        final String path = siteNode.getPath();
        if (path == null) {
            nodeView.add(new XmlTagElement(HtmlElem.H4, "/"));
        } else {
            nodeView.add(new XmlTagElement(HtmlElem.H4, path));
        }
        final SiteNodeController controller = siteNode.getController();
        if (controller instanceof PageController) {
            final PageController pageController = (PageController) controller;
            final ElementContainer pageView = new ElementContainer(new DefinitionListLayout());
            nodeView.add(pageView);
            pageView.add("Actions");
            final ElementContainer actionsView = new ElementContainer(new UnorderedListLayout());
            pageView.add(actionsView);
            for (final Iterator actions = pageController.getActions().iterator(); actions.hasNext(); ) {
                final Action action = (Action) actions.next();
                actionsView.add(action.getClass().getName());
            }
            pageView.add("Menus");
            final ElementContainer menusView = new ElementContainer(new UnorderedListLayout());
            pageView.add(menusView);
            for (final Iterator menus = pageController.getMenus().entrySet().iterator(); menus.hasNext(); ) {
                final Map.Entry entry = (Entry) menus.next();
                final String name = (String) entry.getKey();
                final Menu menu = (Menu) entry.getValue();
                addMenu(menusView, name, menu);
            }
        }
        final Collection nodes = siteNode.getNodes();
        if (!nodes.isEmpty()) {
            final ElementContainer childNodesView = new ElementContainer(new UnorderedListLayout());
            nodeView.add(childNodesView);
            for (final Iterator nodeIter = nodes.iterator(); nodeIter.hasNext(); ) {
                final SiteNode childNode = (SiteNode) nodeIter.next();
                addSiteNode(childNodesView, childNode);
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) Action(com.revolsys.ui.web.config.Action) ElementContainer(com.revolsys.ui.html.view.ElementContainer) DivElementContainer(com.revolsys.ui.html.view.DivElementContainer) UnorderedListLayout(com.revolsys.ui.html.layout.UnorderedListLayout) SiteNodeController(com.revolsys.ui.web.config.SiteNodeController) Entry(java.util.Map.Entry) PageController(com.revolsys.ui.web.config.PageController) DefinitionListLayout(com.revolsys.ui.html.layout.DefinitionListLayout) Iterator(java.util.Iterator) Collection(java.util.Collection) Menu(com.revolsys.ui.model.Menu) XmlTagElement(com.revolsys.ui.html.view.XmlTagElement) Map(java.util.Map) SiteNode(com.revolsys.ui.web.config.SiteNode)

Example 2 with SiteNodeController

use of com.revolsys.ui.web.config.SiteNodeController 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 3 with SiteNodeController

use of com.revolsys.ui.web.config.SiteNodeController 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)

Example 4 with SiteNodeController

use of com.revolsys.ui.web.config.SiteNodeController 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)

Aggregations

SiteNodeController (com.revolsys.ui.web.config.SiteNodeController)4 Page (com.revolsys.ui.web.config.Page)3 PageController (com.revolsys.ui.web.config.PageController)3 WebUiContext (com.revolsys.ui.web.config.WebUiContext)3 Iterator (java.util.Iterator)3 Collection (java.util.Collection)2 JspWriter (javax.servlet.jsp.JspWriter)2 DefinitionListLayout (com.revolsys.ui.html.layout.DefinitionListLayout)1 UnorderedListLayout (com.revolsys.ui.html.layout.UnorderedListLayout)1 DivElementContainer (com.revolsys.ui.html.view.DivElementContainer)1 ElementContainer (com.revolsys.ui.html.view.ElementContainer)1 XmlTagElement (com.revolsys.ui.html.view.XmlTagElement)1 Menu (com.revolsys.ui.model.Menu)1 Action (com.revolsys.ui.web.config.Action)1 SiteNode (com.revolsys.ui.web.config.SiteNode)1 PageNotFoundException (com.revolsys.ui.web.exception.PageNotFoundException)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1