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.renderkit.html.scarborough.standard.tag;
21  
22  import org.apache.myfaces.tobago.component.UIOut;
23  import org.apache.myfaces.tobago.renderkit.LayoutComponentRendererBase;
24  import org.apache.myfaces.tobago.renderkit.css.Classes;
25  import org.apache.myfaces.tobago.renderkit.css.Style;
26  import org.apache.myfaces.tobago.renderkit.html.HtmlElements;
27  import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtils;
28  import org.apache.myfaces.tobago.renderkit.util.RenderUtils;
29  import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
30  
31  import javax.faces.component.UIComponent;
32  import javax.faces.context.FacesContext;
33  import java.io.IOException;
34  import java.util.StringTokenizer;
35  
36  public class OutRenderer extends LayoutComponentRendererBase {
37  
38    @Override
39    public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
40  
41      UIOut out = (UIOut) component;
42  
43      String text = RenderUtils.currentValue(out);
44      if (text == null) {
45        text = "";
46      }
47  
48      TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
49  
50      boolean escape = out.isEscape();
51      boolean createSpan = out.isCreateSpan();
52  
53      if (createSpan) {
54        String id = out.getClientId(facesContext);
55        writer.startElement(HtmlElements.SPAN, out);
56        writer.writeIdAttribute(id);
57        HtmlRendererUtils.writeDataAttributes(facesContext, writer, out);
58        Style style = new Style(facesContext, out);
59        writer.writeStyleAttribute(style);
60        HtmlRendererUtils.renderDojoDndItem(out, writer, true);
61        writer.writeClassAttribute(Classes.create(out));
62        HtmlRendererUtils.renderTip(out, writer);
63      }
64      if (escape) {
65        StringTokenizer tokenizer = new StringTokenizer(text, "\r\n");
66        while (tokenizer.hasMoreTokens()) {
67          String token = tokenizer.nextToken();
68          writer.writeText(token);
69          if (tokenizer.hasMoreTokens()) {
70            writer.startElement(HtmlElements.BR, null);
71            writer.endElement(HtmlElements.BR);
72          }
73        }
74      } else {
75        writer.writeText("", null);
76        writer.write(text);
77      }
78      if (createSpan) {
79        writer.endElement(HtmlElements.SPAN);
80      }
81    }
82  }