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);
}
}
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);
}
}
}
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;
}
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;
}
}
Aggregations