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.faces.renderer; 23 24 25 import java.io.IOException; 26 27 import org.apache.struts.faces.util.StrutsContext; 28 import org.apache.struts.faces.util.Utils; 29 import org.slf4j.Logger; 30 import org.slf4j.LoggerFactory; 31 32 import jakarta.faces.component.UIComponent; 33 import jakarta.faces.context.FacesContext; 34 import jakarta.faces.context.ResponseWriter; 35 36 37 /** 38 * {@code Renderer} implementation for the {@code base} tag 39 * from the <em>Struts-Faces Integration Library</em>. 40 * 41 * @version $Rev$ $Date$ 42 */ 43 public class BaseRenderer extends AbstractRenderer { 44 45 46 // -------------------------------------------------------- Static Variables 47 48 49 /** 50 * The {@code Log} instance for this class. 51 */ 52 private final Logger log = 53 LoggerFactory.getLogger(BaseRenderer.class); 54 55 56 // ---------------------------------------------------------- Public Methods 57 58 59 /** 60 * Render an HTML {@code base} element. 61 * 62 * @param context {@code FacesContext} for the request we are processing 63 * @param component {@code UIComponent} to be rendered 64 * 65 * @throws IOException if an input/output error occurs while rendering 66 * @throws NullPointerException if {@code context} or {@code component} 67 * is null 68 */ 69 public void encodeEnd(FacesContext context, UIComponent component) 70 throws IOException { 71 72 if (context == null || component == null) { 73 throw new NullPointerException(); 74 } 75 76 final String uri = StrutsContext.uri(context); 77 78 log.trace("viewId='{}' --> uri='{}'", 79 context.getViewRoot().getViewId(), uri); 80 81 ResponseWriter writer = context.getResponseWriter(); 82 writer.startElement("base", component); 83 writer.writeURIAttribute("href", uri, null); 84 String target = Utils.getMapValue(String.class, component.getAttributes(), "target"); 85 if (target != null) { 86 writer.writeAttribute("target", target, "target"); 87 } 88 writer.endElement("base"); 89 writer.writeText("\n", null); 90 91 } 92 }