1 /* 2 * $Id$ 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 package org.apache.struts.webapp.example2; 23 24 25 import org.slf4j.Logger; 26 import org.slf4j.LoggerFactory; 27 28 import jakarta.faces.application.ViewHandler; 29 import jakarta.faces.application.ViewHandlerWrapper; 30 import jakarta.faces.context.FacesContext; 31 32 33 /** 34 * Custom {@code ViewHandler} implementation that adds features 35 * specific to the Struts-Faces Integration Library. It leverages the 36 * "decorator pattern" customization strategy that JSF supports, by 37 * delegating most processing to the {@code ViewHandler} instance 38 * handed to our constructor. 39 */ 40 public class ViewHandlerImpl extends ViewHandlerWrapper { 41 42 43 // -------------------------------------------------------- Static Variables 44 45 46 /** 47 * The {@code Log} instance for this class. 48 */ 49 private final static Logger LOG = 50 LoggerFactory.getLogger(ViewHandlerImpl.class); 51 52 53 // ------------------------------------------------------------ Constructors 54 55 56 /** 57 * Construct a {@code ViewHandlerImpl} decorating the 58 * specified {@code ViewHandler} instance. 59 * 60 * @param oldViewHandler {@code ViewHandler} to be decorated 61 */ 62 public ViewHandlerImpl(ViewHandler oldViewHandler) { 63 super(oldViewHandler); 64 LOG.debug("Creating ViewHandler instance, wrapping handler {}", 65 oldViewHandler); 66 } 67 68 69 // ----------------------------------------------------- Specialized Methods 70 71 72 /** 73 * Replace extension {@code .jsp} with {@code .faces}. 74 */ 75 public String getActionURL(FacesContext context, String viewId) { 76 String ret = super.getActionURL(context, viewId); 77 int i = 0; 78 if (ret.endsWith(".do")) { 79 i = 3; 80 } else if (ret.endsWith(".jsp")) { 81 i = 4; 82 } 83 if (i > 0) { 84 ret = ret.substring(0, ret.length() - i) + ".faces"; 85 } 86 return ret; 87 } 88 }