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.localized;
23  
24  import java.util.Locale;
25  
26  import javax.faces.component.UIComponentBase;
27  import javax.faces.context.FacesContext;
28  
29  import org.primefaces.util.LocaleUtils;
30  
31  /**
32   * <code>Localized</code> component.
33   *
34   * @author Jasper de Vries &lt;jepsar@gmail.com&gt;
35   * @since 11.0.3
36   */
37  public class Localized extends UIComponentBase {
38  
39      public static final String COMPONENT_TYPE = "org.primefaces.extensions.component.Localized";
40      public static final String COMPONENT_FAMILY = "org.primefaces.extensions.component";
41      public static final String DEFAULT_RENDERER = "org.primefaces.extensions.component.LocalizedRenderer";
42  
43      // @formatter:off
44      @SuppressWarnings("java:S115")
45      public enum PropertyKeys {
46          name,
47          folder,
48          locale,
49          escape,
50          evalEl,
51          markdown
52      }
53      // @formatter:on
54  
55      public Localized() {
56          setRendererType(DEFAULT_RENDERER);
57      }
58  
59      @Override
60      public String getFamily() {
61          return COMPONENT_FAMILY;
62      }
63  
64      public Locale calculateLocale(FacesContext facesContext) {
65          return LocaleUtils.resolveLocale(facesContext, getLocale(), getClientId(facesContext));
66      }
67  
68      public String getName() {
69          return (String) getStateHelper().eval(PropertyKeys.name, null);
70      }
71  
72      public void setName(final String name) {
73          getStateHelper().put(PropertyKeys.name, name);
74      }
75  
76      public String getFolder() {
77          return (String) getStateHelper().eval(PropertyKeys.folder, null);
78      }
79  
80      public void setFolder(final String folder) {
81          getStateHelper().put(PropertyKeys.folder, folder);
82      }
83  
84      public Object getLocale() {
85          return getStateHelper().eval(PropertyKeys.locale, null);
86      }
87  
88      public void setLocale(final Object locale) {
89          getStateHelper().put(PropertyKeys.locale, locale);
90      }
91  
92      public boolean isEscape() {
93          return (Boolean) getStateHelper().eval(PropertyKeys.escape, true);
94      }
95  
96      public void setEscape(final boolean escape) {
97          getStateHelper().put(PropertyKeys.escape, escape);
98      }
99  
100     public boolean isEvalEl() {
101         return (Boolean) getStateHelper().eval(PropertyKeys.evalEl, false);
102     }
103 
104     public void setEvalEl(final boolean evalEl) {
105         getStateHelper().put(PropertyKeys.evalEl, evalEl);
106     }
107 
108     public boolean isMarkdown() {
109         return (Boolean) getStateHelper().eval(PropertyKeys.markdown, false);
110     }
111 
112     public void setMarkdown(final boolean markdown) {
113         getStateHelper().put(PropertyKeys.markdown, markdown);
114     }
115 
116 }