Search in sources :

Example 1 with PageNotFoundException

use of com.revolsys.ui.web.exception.PageNotFoundException in project com.revolsys.open by revolsys.

the class PageController method processArguments.

/**
 * @param page
 * @param request
 * @throws PageNotFoundException
 */
private void processArguments(final HttpServletRequest request) throws ActionException {
    for (final Iterator arguments = getArguments().iterator(); arguments.hasNext(); ) {
        final Argument argument = (Argument) arguments.next();
        final String name = argument.getName();
        Object value = null;
        String stringValue = request.getParameter(name);
        if (stringValue == null) {
            stringValue = argument.getDefault();
        }
        if (stringValue != null) {
            final Class argumentType = argument.getType();
            try {
                value = argument.valueOf(stringValue);
            } catch (final NumberFormatException e) {
                throw new PageNotFoundException("Page argument is not a valid number: " + name);
            }
        }
        if (value != null) {
            request.setAttribute(name, value);
        } else if (argument.isRequired()) {
            throw new PageNotFoundException("Missing page argument: " + name);
        }
    }
}
Also used : PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) Iterator(java.util.Iterator)

Example 2 with PageNotFoundException

use of com.revolsys.ui.web.exception.PageNotFoundException in project com.revolsys.open by revolsys.

the class Config method getPage.

public Page getPage(final String path) throws PageNotFoundException {
    Page page = this.pages.get(path);
    if (page != null) {
        return page;
    } else {
        // Check to see if there is a page match for any of the parent paths
        String parentPath = path;
        for (int pathIndex = parentPath.lastIndexOf('/'); pathIndex != -1; pathIndex = parentPath.lastIndexOf('/')) {
            parentPath = parentPath.substring(0, pathIndex);
            page = this.pages.get(parentPath);
            if (page != null) {
                return page;
            }
        }
        // Check to see if there is a page match using a regular expression
        for (final Pattern pattern : this.pagePatterns) {
            final Matcher matcher = pattern.matcher(path);
            if (matcher.matches()) {
                return this.pageByPattern.get(pattern);
            }
        }
        throw new PageNotFoundException();
    }
}
Also used : Pattern(java.util.regex.Pattern) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) Matcher(java.util.regex.Matcher)

Example 3 with PageNotFoundException

use of com.revolsys.ui.web.exception.PageNotFoundException in project com.revolsys.open by revolsys.

the class HtmlUiBuilder method addObjectViewPage.

public void addObjectViewPage(final TabElementContainer tabs, final Object object, final String prefix) {
    final HttpServletRequest request = getRequest();
    if (object == null) {
        throw new PageNotFoundException();
    } else {
        final String pageName = getName(prefix, "view");
        final Page page = getPage(pageName);
        if (page == null) {
            throw new PageNotFoundException("Page not found " + pageName);
        } else {
            final List<KeySerializer> serializers = getSerializers(pageName, "view");
            final Element detailView = newDetailView(object, serializers);
            setPageTitle(request, pageName);
            final Menu actionMenu = new Menu();
            final Menu editMenu = addMenuItem(actionMenu, prefix, "edit", "Edit", "_top");
            if (editMenu != null) {
                editMenu.addProperty("buttonClass", "btn-primary");
            }
            final ElementContainer view = new ElementContainer(detailView);
            addMenuElement(view, actionMenu);
            final String tabId = getTypeName() + "_" + pageName;
            final String title = getPageTitle(pageName);
            tabs.add(tabId, title, view);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) ElementContainer(com.revolsys.ui.html.view.ElementContainer) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) ButtonsToolbarElement(com.revolsys.ui.html.view.ButtonsToolbarElement) Element(com.revolsys.ui.html.view.Element) Page(com.revolsys.ui.web.config.Page) Menu(com.revolsys.ui.model.Menu) KeySerializer(com.revolsys.ui.html.serializer.key.KeySerializer)

Example 4 with PageNotFoundException

use of com.revolsys.ui.web.exception.PageNotFoundException 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 5 with PageNotFoundException

use of com.revolsys.ui.web.exception.PageNotFoundException in project com.revolsys.open by revolsys.

the class IafConfigXmlProcessor method processDynamicMenu.

public Menu processDynamicMenu(final StaxReader parser) throws XMLStreamException, IOException {
    final String name = parser.getAttributeValue(null, "name");
    String pageRef = parser.getAttributeValue(null, "pageRef");
    String title = parser.getAttributeValue(null, "title");
    final String anchor = parser.getAttributeValue(null, "anchor");
    String url = parser.getAttributeValue(null, "uri");
    final String condition = parser.getAttributeValue(null, "condition");
    final String loaderClassName = parser.getAttributeValue(null, "class");
    if (pageRef != null) {
        pageRef = pageRef.trim();
        if (!pageRef.equals("")) {
            try {
                final Page page = this.config.getPageByName(pageRef);
                url = page.getPath();
                if (title == null || title.trim().equals("")) {
                    title = page.getTitle();
                }
            } catch (final PageNotFoundException e) {
                log.error(e.getMessage(), e);
                getContext().addError(e.getMessage(), e, parser.getLocation());
            }
        }
    }
    try {
        final Class loaderClass = Class.forName(loaderClassName);
        final Constructor loaderCons = loaderClass.getConstructor(new Class[] { Config.class });
        final MenuItemLoader loader = (MenuItemLoader) loaderCons.newInstance(new Object[] { this.config });
        final DynamicMenu menu = new DynamicMenu(name, title, url, anchor, condition, loader);
        while (parser.nextTag() == XMLStreamConstants.START_ELEMENT) {
            final Object object = process(parser);
            if (object instanceof WebProperty) {
                final WebProperty webProperty = (WebProperty) object;
                loader.setProperty(webProperty.getName(), webProperty.getValue());
            }
        }
        return menu;
    } catch (final InvocationTargetException e) {
        final Throwable t = e.getCause();
        log.error(t.getMessage(), t);
        getContext().addError(t.getMessage(), t, parser.getLocation());
    } catch (final Exception e) {
        log.error(e.getMessage(), e);
        getContext().addError(e.getMessage(), e, parser.getLocation());
    }
    return null;
}
Also used : PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) Constructor(java.lang.reflect.Constructor) InvocationTargetException(java.lang.reflect.InvocationTargetException) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XMLStreamException(javax.xml.stream.XMLStreamException)

Aggregations

PageNotFoundException (com.revolsys.ui.web.exception.PageNotFoundException)9 Page (com.revolsys.ui.web.config.Page)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ButtonsToolbarElement (com.revolsys.ui.html.view.ButtonsToolbarElement)2 ElementContainer (com.revolsys.ui.html.view.ElementContainer)2 TabElementContainer (com.revolsys.ui.html.view.TabElementContainer)2 Menu (com.revolsys.ui.model.Menu)2 WebUiContext (com.revolsys.ui.web.config.WebUiContext)2 ServletException (javax.servlet.ServletException)2 Form (com.revolsys.ui.html.form.Form)1 HtmlUiBuilderObjectForm (com.revolsys.ui.html.form.HtmlUiBuilderObjectForm)1 UiBuilderObjectForm (com.revolsys.ui.html.form.UiBuilderObjectForm)1 KeySerializer (com.revolsys.ui.html.serializer.key.KeySerializer)1 Element (com.revolsys.ui.html.view.Element)1 Argument (com.revolsys.ui.web.config.Argument)1 Layout (com.revolsys.ui.web.config.Layout)1 SiteNodeController (com.revolsys.ui.web.config.SiteNodeController)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