Search in sources :

Example 6 with PageNotFoundException

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

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

the class IafServlet method processArguments.

/**
 * @param page
 * @param request
 * @throws PageNotFoundException
 */
private void processArguments(final Page page, final HttpServletRequest request) throws ActionException {
    for (final Object element : page.getArguments()) {
        final Argument argument = (Argument) element;
        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) Argument(com.revolsys.ui.web.config.Argument)

Example 8 with PageNotFoundException

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

the class PathAliasController method handleRequest.

@Override
public ModelAndView handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    String path = request.getServletPath() + request.getPathInfo();
    if (path.startsWith(this.prefix)) {
        if (getOriginalPrefix().length() == 0) {
            final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
            requestAttributes.setAttribute(PATH_PREFIX, this.prefix.replaceAll(this.aliasPrefix + "$", ""), RequestAttributes.SCOPE_REQUEST);
        }
        path = path.replaceFirst(this.prefix, this.aliasPrefix);
        if (!forward(request, response, path)) {
            throw new PageNotFoundException();
        }
    }
    return null;
}
Also used : PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) RequestAttributes(org.springframework.web.context.request.RequestAttributes)

Example 9 with PageNotFoundException

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

the class HtmlUiBuilder method newObjectEditPage.

public Element newObjectEditPage(final T object, final String prefix) throws IOException, ServletException {
    if (object == null) {
        throw new PageNotFoundException();
    } else {
        final HttpServletRequest request = HttpServletUtils.getRequest();
        final Set<String> parameterNamesToSave = new HashSet<>();
        parameterNamesToSave.add(getIdParameterName());
        final String pageName = getName(prefix, "edit");
        final Form form = newTableForm(object, pageName);
        for (final String param : parameterNamesToSave) {
            form.addSavedParameter(param, request.getParameter(param));
        }
        form.initialize(request);
        if (form.isPosted() && form.isMainFormTask()) {
            if (form.isValid() && preUpdate(form, object)) {
                updateObject(object);
                postUpdate(object);
                final Map<String, Object> parameters = new HashMap<>();
                // Get after object has changed
                final Object id = Property.get(object, getIdPropertyName());
                parameters.put(getIdParameterName(), id);
                final Page viewPage = getPage(prefix, "view");
                final String url = viewPage.getFullUrl(parameters);
                redirectAfterCommit(url);
                return new TabElementContainer();
            } else {
                setRollbackOnly(object);
            }
        } else {
            setRollbackOnly(object);
        }
        final Page page = getPage(prefix, "edit");
        final String title = page.getExpandedTitle();
        request.setAttribute("title", title);
        final Menu actionMenu = new Menu();
        addMenuItem(actionMenu, prefix, "view", "Cancel", "_top").addProperty("buttonClass", "btn-danger");
        addMenuItem(actionMenu, prefix, "edit", "Revert to Saved", "_top").addProperty("buttonClass", "btn-warning");
        final String name = form.getName();
        final Menu saveItem = new Menu("Save", "javascript:$('#" + name + "').submit()");
        saveItem.addProperty("buttonClass", "btn-primary");
        actionMenu.addMenuItem(saveItem);
        final ButtonsToolbarElement buttonsToolbar = new ButtonsToolbarElement(actionMenu);
        final ElementContainer view = new ElementContainer(form, buttonsToolbar);
        final TabElementContainer tabs = new TabElementContainer();
        tabs.add(title, view);
        return tabs;
    }
}
Also used : ElementContainer(com.revolsys.ui.html.view.ElementContainer) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) UiBuilderObjectForm(com.revolsys.ui.html.form.UiBuilderObjectForm) HtmlUiBuilderObjectForm(com.revolsys.ui.html.form.HtmlUiBuilderObjectForm) Form(com.revolsys.ui.html.form.Form) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Page(com.revolsys.ui.web.config.Page) TabElementContainer(com.revolsys.ui.html.view.TabElementContainer) HttpServletRequest(javax.servlet.http.HttpServletRequest) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) Menu(com.revolsys.ui.model.Menu) ButtonsToolbarElement(com.revolsys.ui.html.view.ButtonsToolbarElement) HashSet(java.util.HashSet)

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