Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String getActionURL(FacesContext context, String viewId) {
- if (context == null) {
- String message = MessageUtils.getExceptionMessageString
- (MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "context");
- throw new NullPointerException(message);
- }
- if (viewId == null) {
- String message = MessageUtils.getExceptionMessageString
- (MessageUtils.NULL_PARAMETERS_ERROR_MESSAGE_ID, "viewId");
- throw new NullPointerException(message);
- }
- if (viewId.charAt(0) != '/') {
- String message =
- MessageUtils.getExceptionMessageString(
- MessageUtils.ILLEGAL_VIEW_ID_ID,
- viewId);
- if (logger.isLoggable(Level.SEVERE)) {
- logger.log(Level.SEVERE, "jsf.illegal_view_id_error", viewId);
- }
- throw new IllegalArgumentException(message);
- }
- // Acquire the context path, which we will prefix on all results
- ExternalContext extContext = context.getExternalContext();
- String contextPath = extContext.getRequestContextPath();
- // Acquire the mapping used to execute this request (if any)
- String mapping = Util.getFacesMapping(context);
- // If no mapping can be identified, just return a server-relative path
- if (mapping == null) {
- return (contextPath + viewId);
- }
- // Deal with prefix mapping
- if (Util.isPrefixMapped(mapping)) {
- if (mapping.equals("/*")) {
- return (contextPath + viewId);
- } else {
- return (contextPath + mapping + viewId);
- }
- }
- // Deal with extension mapping
- int period = viewId.lastIndexOf('.');
- if (period < 0) {
- return (contextPath + viewId + mapping);
- } else if (!viewId.endsWith(mapping)) {
- return (contextPath + viewId.substring(0, period) + mapping);
- } else {
- return (contextPath + viewId);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement