View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.renderkit.renderer;
21  
22  import org.apache.myfaces.tobago.context.Markup;
23  import org.apache.myfaces.tobago.internal.component.AbstractUIObject;
24  import org.apache.myfaces.tobago.internal.util.HtmlRendererUtils;
25  import org.apache.myfaces.tobago.renderkit.RendererBase;
26  import org.apache.myfaces.tobago.renderkit.css.TobagoClass;
27  import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
28  import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
29  import org.apache.myfaces.tobago.util.ResourceUtils;
30  import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
31  
32  import javax.faces.context.FacesContext;
33  import java.io.IOException;
34  
35  public class ObjectRenderer<T extends AbstractUIObject> extends RendererBase<T> {
36  
37    @Override
38    public void encodeEndInternal(final FacesContext facesContext, final T component) throws IOException {
39      final TobagoResponseWriter writer = getResponseWriter(facesContext);
40      final Markup markup = component.getMarkup();
41  
42      writer.startElement(HtmlElements.IFRAME);
43      writer.writeAttribute(HtmlAttributes.FRAMEBORDER, "0", false);
44      final String clientId = component.getClientId(facesContext);
45      writer.writeIdAttribute(clientId);
46      String name = component.getName();
47      if (name == null) {
48        name = clientId;
49      }
50      writer.writeNameAttribute(name);
51      HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
52      writer.writeAttribute(HtmlAttributes.SRC, component.getSrc(), true);
53      writer.writeClassAttribute(
54          TobagoClass.OBJECT,
55          TobagoClass.OBJECT.createMarkup(markup),
56          component.getCustomClass(),
57          markup != null && markup.contains(Markup.SPREAD) ? TobagoClass.SPREAD : null);
58  
59      String sandbox = component.getSandbox();
60      if (sandbox != null) {
61        writer.writeAttribute(HtmlAttributes.SANDBOX, sandbox, false);
62      }
63  
64      writer.writeText(ResourceUtils.getString(facesContext, "object.noframe"));
65      writer.writeText(" ");
66      if (component.getSrc() != null) {
67        writer.writeText(component.getSrc());
68      }
69  
70      writer.endElement(HtmlElements.IFRAME);
71    }
72  }