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