1 14 package org.jahia.engines.shared; 15 16 import java.util.Enumeration ; 17 import java.util.Hashtable ; 18 19 import javax.servlet.http.HttpServletRequest ; 20 21 import org.jahia.exceptions.JahiaException; 22 import org.jahia.registries.ServicesRegistry; 23 import org.jahia.services.htmleditors.HtmlEditor; 24 import org.jahia.services.htmleditors.HtmlEditorCSS; 25 import org.jahia.services.htmleditors.HtmlEditorsService; 26 import org.jahia.services.htmleditors.JahiaClientCapabilities; 27 import java.util.Vector ; 28 import java.io.Serializable ; 29 30 38 public class HtmlEditorsViewHelper implements Serializable { 39 40 private Hashtable editors; 41 private Vector editorList; 42 private Hashtable enabledCSSs; 43 private String defaultEditor; 44 private String defaultCSS; 45 46 public HtmlEditorsViewHelper(){ 47 this.editors = new Hashtable (); 48 this.editorList = new Vector (); 49 this.enabledCSSs = new Hashtable (); 50 this.defaultEditor = ""; 51 this.defaultCSS = ""; 52 } 53 54 59 public HtmlEditorsViewHelper(String defaultEditor){ 60 this.editors = new Hashtable (); 61 this.editorList = new Vector (); 62 this.enabledCSSs = new Hashtable (); 63 this.defaultEditor = defaultEditor; 64 } 65 66 73 public void loadHtmlEditors(int siteID, HttpServletRequest request) 74 throws JahiaException { 75 HtmlEditorsService heServ = ServicesRegistry.getInstance() 76 .getHtmlEditorsService(); 77 JahiaClientCapabilities clientCapabilities = 78 new JahiaClientCapabilities( request.getHeader( "user-agent" ) ); 79 Enumeration enumeration = heServ.getEditors(siteID); 80 HtmlEditor editor = null; 81 while ( enumeration.hasMoreElements() ) 82 { 83 editor = (HtmlEditor)enumeration.nextElement(); 84 if ( editor.isClientCapable( clientCapabilities ) ){ 85 this.editors.put(editor.getId(),editor); 86 this.editorList.add(editor); 87 } 88 } 89 90 enumeration = heServ.getCSSs(siteID); 92 HtmlEditorCSS css = null; 93 while ( enumeration.hasMoreElements() ) 94 { 95 css = (HtmlEditorCSS)enumeration.nextElement(); 96 this.enabledCSSs.put(css.getId(),css); 97 } 98 99 } 100 101 105 public String getDefaultEditorID(){ 106 return this.defaultEditor; 107 } 108 109 114 public void setDefaultEditorID(String id){ 115 if ( id==null ){ 116 id = ""; 117 } 118 this.defaultEditor = id; 119 } 120 121 126 public void setDefaultCSSID(String id){ 127 if ( id==null ){ 128 id = ""; 129 } 130 this.defaultCSS = id; 131 } 132 133 137 public String getDefaultCSSID(){ 138 return this.defaultCSS; 139 } 140 141 146 public Enumeration getEditors(){ 147 return this.editorList.elements(); 148 } 149 150 155 public Hashtable getEnabledCSSs(){ 156 return this.enabledCSSs; 157 } 158 163 public HtmlEditor getDefaultEditor(){ 164 HtmlEditor editor = (HtmlEditor)this.editors.get(this.defaultEditor); 165 return editor; 166 } 167 168 174 public HtmlEditor getDefaultEditor(boolean firstAvailableIfAny){ 175 HtmlEditor editor = getDefaultEditor(); 176 if ( !firstAvailableIfAny ){ 177 return editor; 178 } 179 if ( editor == null && this.editorList.size() > 0 ){ 180 editor = (HtmlEditor)this.editorList.get(0); 181 } 182 return editor; 183 } 184 185 } 186 | Popular Tags |