1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecm.webui.form.field;
18
19 import org.exoplatform.ecm.webui.form.DialogFormField;
20 import org.exoplatform.ecm.webui.utils.DialogFormUtil;
21 import org.exoplatform.portal.resource.SkinConfig;
22 import org.exoplatform.portal.resource.SkinService;
23 import org.exoplatform.portal.webui.util.Util;
24 import org.exoplatform.services.wcm.utils.WCMCoreUtils;
25 import org.exoplatform.webui.form.UIFormInputBase;
26 import org.exoplatform.webui.form.UIFormRichtextInput;
27
28 import java.util.Collection;
29
30
31
32
33
34
35
36 public class UIFormRichtextField extends DialogFormField {
37
38 private final String TOOLBAR = "toolbar";
39 private final String WIDTH = "width";
40 private final String HEIGHT = "height";
41 private final String ENTERMODE = "enterMode";
42 private final String SHIFT_ENTER_MODE = "shiftEnterMode";
43
44 private String toolbar;
45 private String width;
46 private String height;
47 private String enterMode;
48 private String shiftEnterMode;
49
50 public UIFormRichtextField(String name, String label, String[] arguments) {
51 super(name, label, arguments);
52 }
53
54 @SuppressWarnings("unchecked")
55 public <T extends UIFormInputBase> T createUIFormInput() throws Exception {
56 UIFormRichtextInput richtext = new UIFormRichtextInput(name, name, defaultValue);
57 setPredefineOptions();
58 richtext.setToolbar(toolbar);
59 richtext.setWidth(width);
60 richtext.setHeight(height);
61 richtext.setEnterMode(enterMode);
62 richtext.setShiftEnterMode(shiftEnterMode);
63 richtext.setIgnoreParserHTML(true);
64
65 StringBuffer contentsCss = new StringBuffer();
66 contentsCss.append("[");
67 SkinService skinService = WCMCoreUtils.getService(SkinService.class);
68 String skin = Util.getUIPortalApplication().getUserPortalConfig().getPortalConfig().getSkin();
69 String portal = Util.getUIPortal().getName();
70 Collection<SkinConfig> portalSkins = skinService.getPortalSkins(skin);
71 SkinConfig customSkin = skinService.getSkin(portal, Util.getUIPortalApplication()
72 .getUserPortalConfig()
73 .getPortalConfig()
74 .getSkin());
75 if (customSkin != null) portalSkins.add(customSkin);
76 for (SkinConfig portalSkin : portalSkins) {
77 contentsCss.append("'").append(portalSkin.createURL(Util.getPortalRequestContext().getControllerContext())).append("',");
78 }
79 contentsCss.append("'/commons-extension/ckeditor/contents.css'");
80 contentsCss.append("]");
81 richtext.setCss(contentsCss.toString());
82
83 if(validateType != null) {
84 DialogFormUtil.addValidators(richtext, validateType);
85 }
86 return (T)richtext;
87 }
88
89 private void setPredefineOptions() {
90 if (options == null) return;
91 for(String option: options.split(",")) {
92 String[] entry = option.split(":");
93 if(TOOLBAR.equals(entry[0])) {
94 toolbar = entry[1];
95 } else if(WIDTH.equals(entry[0])) {
96 width = entry[1];
97 } else if(HEIGHT.equals(entry[0])) {
98 height = entry[1];
99 } else if(ENTERMODE.equals(entry[0])) {
100 enterMode = entry[1];
101 } else if(SHIFT_ENTER_MODE.equals(entry[0])) {
102 shiftEnterMode = entry[1];
103 }
104 }
105 }
106
107 }