1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.primefaces.extensions.component.documentviewer;
23
24 import java.util.Locale;
25
26 import javax.faces.application.ResourceDependency;
27 import javax.faces.component.UIGraphic;
28 import javax.faces.context.FacesContext;
29
30 import org.primefaces.util.LocaleUtils;
31
32
33
34
35
36
37
38
39 @ResourceDependency(library = "primefaces", name = "jquery/jquery.js")
40 @ResourceDependency(library = "primefaces", name = "jquery/jquery-plugins.js")
41 @ResourceDependency(library = "primefaces", name = "core.js")
42 @ResourceDependency(library = "primefaces-extensions", name = "primefaces-extensions.js")
43 public class DocumentViewer extends UIGraphic {
44
45 public static final String COMPONENT_TYPE = "org.primefaces.extensions.component.DocumentViewer";
46 public static final String COMPONENT_FAMILY = "org.primefaces.extensions.component";
47 private static final String DEFAULT_RENDERER = "org.primefaces.extensions.component.DocumentViewerRenderer";
48
49 private Locale appropriateLocale;
50
51 @SuppressWarnings("java:S115")
52 protected enum PropertyKeys {
53
54 width,
55 height,
56 style,
57 title,
58 name,
59 library,
60 cache,
61 page,
62 download,
63 locale,
64 disableFontFace,
65 nameddest,
66 pagemode,
67 zoom;
68
69 }
70
71 public DocumentViewer() {
72 setRendererType(DEFAULT_RENDERER);
73 }
74
75 @Override
76 public String getFamily() {
77 return COMPONENT_FAMILY;
78 }
79
80 public Locale calculateLocale() {
81 if (appropriateLocale == null) {
82 final FacesContext fc = FacesContext.getCurrentInstance();
83 appropriateLocale = LocaleUtils.resolveLocale(fc, getLocale(), getClientId(fc));
84 }
85 return appropriateLocale;
86 }
87
88 public String getWidth() {
89 return (String) this.getStateHelper().eval(PropertyKeys.width, null);
90 }
91
92 public void setWidth(final String width) {
93 this.getStateHelper().put(PropertyKeys.width, width);
94 }
95
96 public String getHeight() {
97 return (String) this.getStateHelper().eval(PropertyKeys.height, null);
98 }
99
100 public void setHeight(final String height) {
101 this.getStateHelper().put(PropertyKeys.height, height);
102 }
103
104 public String getStyle() {
105 return (String) this.getStateHelper().eval(PropertyKeys.style, null);
106 }
107
108 public void setStyle(final String style) {
109 this.getStateHelper().put(PropertyKeys.style, style);
110 }
111
112 public String getName() {
113 return (String) getStateHelper().eval(PropertyKeys.name, null);
114 }
115
116 public void setName(final String _name) {
117 getStateHelper().put(PropertyKeys.name, _name);
118 }
119
120 public String getTitle() {
121 return (String) getStateHelper().eval(PropertyKeys.title, null);
122 }
123
124 public void setTitle(final String _title) {
125 getStateHelper().put(PropertyKeys.title, _title);
126 }
127
128 public String getLibrary() {
129 return (String) getStateHelper().eval(PropertyKeys.library, null);
130 }
131
132 public void setLibrary(final String _library) {
133 getStateHelper().put(PropertyKeys.library, _library);
134 }
135
136 public boolean isCache() {
137 return (Boolean) getStateHelper().eval(PropertyKeys.cache, false);
138 }
139
140 public void setCache(final boolean _cache) {
141 getStateHelper().put(PropertyKeys.cache, _cache);
142 }
143
144 public Integer getPage() {
145 return (Integer) getStateHelper().eval(PropertyKeys.page);
146 }
147
148 public void setPage(final Integer page) {
149 this.getStateHelper().put(PropertyKeys.page, page);
150 }
151
152 public void setDownload(final String download) {
153 getStateHelper().put(PropertyKeys.download, download);
154 }
155
156 public String getDownload() {
157 return (String) getStateHelper().eval(PropertyKeys.download, null);
158 }
159
160 public void setNameddest(final String nameddest) {
161 getStateHelper().put(PropertyKeys.nameddest, nameddest);
162 }
163
164 public String getNameddest() {
165 return (String) getStateHelper().eval(PropertyKeys.nameddest, null);
166 }
167
168 public void setPagemode(final String pagemode) {
169 getStateHelper().put(PropertyKeys.pagemode, pagemode);
170 }
171
172 public String getPagemode() {
173 return (String) getStateHelper().eval(PropertyKeys.pagemode, null);
174 }
175
176 public Object getLocale() {
177 return getStateHelper().eval(PropertyKeys.locale, null);
178 }
179
180 public void setLocale(final Object locale) {
181 getStateHelper().put(PropertyKeys.locale, locale);
182 }
183
184 public void setZoom(final String zoom) {
185 getStateHelper().put(PropertyKeys.zoom, zoom);
186 }
187
188 public String getZoom() {
189 return (String) getStateHelper().eval(PropertyKeys.zoom, null);
190 }
191
192 public boolean isDisableFontFace() {
193 return (Boolean) getStateHelper().eval(PropertyKeys.disableFontFace, true);
194 }
195
196 public void setDisableFontFace(final boolean _disableFontFace) {
197 getStateHelper().put(PropertyKeys.disableFontFace, _disableFontFace);
198 }
199
200 @Override
201 public Object saveState(FacesContext context) {
202
203 appropriateLocale = null;
204
205 return super.saveState(context);
206 }
207 }