View Javadoc
1   /*
2    * Copyright (c) 2011-2024 PrimeFaces Extensions
3    *
4    *  Permission is hereby granted, free of charge, to any person obtaining a copy
5    *  of this software and associated documentation files (the "Software"), to deal
6    *  in the Software without restriction, including without limitation the rights
7    *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    *  copies of the Software, and to permit persons to whom the Software is
9    *  furnished to do so, subject to the following conditions:
10   *
11   *  The above copyright notice and this permission notice shall be included in
12   *  all copies or substantial portions of the Software.
13   *
14   *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20   *  THE SOFTWARE.
21   */
22  package org.primefaces.extensions.component.keynote;
23  
24  import java.io.IOException;
25  
26  import javax.faces.component.UIComponent;
27  import javax.faces.context.FacesContext;
28  import javax.faces.context.ResponseWriter;
29  
30  import org.primefaces.extensions.util.Attrs;
31  import org.primefaces.renderkit.CoreRenderer;
32  
33  public class KeynoteItemRenderer extends CoreRenderer {
34  
35      public static final String ITEM_CLASS = "ui-keynote-item";
36      public static final String SPEAKER_NOTE_CLASS = "notes";
37  
38      @Override
39      public void encodeEnd(final FacesContext context, final UIComponent component) throws IOException {
40          final ResponseWriter writer = context.getResponseWriter();
41          final UIKeynoteItem uiKeynoteItem = (UIKeynoteItem) component;
42  
43          writer.startElement("section", null);
44  
45          if (uiKeynoteItem.isMarkdown()) {
46              writer.writeAttribute("data-markdown", "", null);
47              writer.writeAttribute("data-separator", uiKeynoteItem.getSeparator(), null);
48              writer.writeAttribute("data-separator-vertical", uiKeynoteItem.getSeparatorVertical(), null);
49          }
50  
51          if (uiKeynoteItem.getBackgroundColor() != null) {
52              writer.writeAttribute("data-background-color", uiKeynoteItem.getBackgroundColor(), null);
53          }
54          if (uiKeynoteItem.getBackgroundImage() != null) {
55              writer.writeAttribute("data-background-image", uiKeynoteItem.getBackgroundImage(), null);
56          }
57          if (uiKeynoteItem.getBackgroundSize() != null) {
58              writer.writeAttribute("data-background-size", uiKeynoteItem.getBackgroundSize(), null);
59          }
60          if (uiKeynoteItem.getBackgroundPosition() != null) {
61              writer.writeAttribute("data-background-position", uiKeynoteItem.getBackgroundPosition(), null);
62          }
63          if (uiKeynoteItem.getBackgroundRepeat() != null) {
64              writer.writeAttribute("data-background-repeat", uiKeynoteItem.getBackgroundRepeat(), null);
65          }
66          if (uiKeynoteItem.getBackgroundOpacity() != null) {
67              writer.writeAttribute("data-background-opacity", uiKeynoteItem.getBackgroundOpacity(), null);
68          }
69          if (uiKeynoteItem.getBackgroundVideo() != null) {
70              writer.writeAttribute("data-background-video", uiKeynoteItem.getBackgroundVideo(), null);
71          }
72          if (uiKeynoteItem.isBackgroundVideoLoop()) {
73              writer.writeAttribute("data-background-video-loop", "", null);
74          }
75          if (uiKeynoteItem.isBackgroundVideoMuted()) {
76              writer.writeAttribute("data-background-video-muted", "", null);
77          }
78          if (uiKeynoteItem.getVisibility() != null) {
79              writer.writeAttribute("data-visibility", uiKeynoteItem.getVisibility(), null);
80          }
81  
82          if (uiKeynoteItem.getStyleClass() != null) {
83              writer.writeAttribute(Attrs.CLASS, ITEM_CLASS + " " + uiKeynoteItem.getStyleClass(), null);
84          }
85          else {
86              writer.writeAttribute(Attrs.CLASS, ITEM_CLASS, null);
87          }
88  
89          if (uiKeynoteItem.isMarkdown()) {
90              writer.startElement("textarea", null);
91              writer.writeAttribute("data-template", "", null);
92          }
93  
94          // encode content
95          renderChildren(context, uiKeynoteItem);
96  
97          if (uiKeynoteItem.isMarkdown()) {
98              writer.endElement("textarea");
99          }
100 
101         if (uiKeynoteItem.getNote() != null) {
102             writer.startElement("aside", null);
103             writer.writeAttribute(Attrs.CLASS, SPEAKER_NOTE_CLASS, null);
104             writer.writeText(uiKeynoteItem.getNote(), null);
105             writer.endElement("aside");
106         }
107 
108         writer.endElement("section");
109     }
110 
111     @Override
112     public boolean getRendersChildren() {
113         return true;
114     }
115 
116     @Override
117     public void encodeChildren(final FacesContext fc, final UIComponent component) {
118         // nothing to do
119     }
120 }