1 package org.jahia.services.htmleditors; 14 15 import java.io.File ; 16 import java.util.Enumeration ; 17 import java.util.Vector ; 18 19 import org.jahia.exceptions.JahiaException; 20 import org.jahia.exceptions.JahiaInitializationException; 21 import org.jahia.registries.ServicesRegistry; 22 import org.jahia.services.sites.JahiaSite; 23 import org.jahia.settings.SettingsBean; 24 25 26 31 public class HtmlEditorsBaseService extends HtmlEditorsService 32 { 33 private static org.apache.log4j.Logger logger = 34 org.apache.log4j.Logger.getLogger (HtmlEditorsBaseService.class); 35 36 static private HtmlEditorsBaseService instance = null; 37 private HtmlEditorsFactory htmlEditorsFactory = null; 38 private String htmlEditorsRootDiskPath = ""; 39 private String htmlEditorsContextPath = ""; 40 private String htmlEditorsConfigFile = ""; 41 42 protected HtmlEditorsBaseService() { 43 logger.info("***** Starting the HtmlEditorsBaseService *****" ); 44 } 45 46 public static HtmlEditorsBaseService getInstance() { 47 if (instance == null) { 48 instance = new HtmlEditorsBaseService(); 49 } 50 return instance; 51 } 52 53 public void init( SettingsBean jSettings ) 54 throws JahiaInitializationException { 55 56 this.htmlEditorsRootDiskPath = jSettings.getJahiaHtmlEditorsDiskPath(); 57 this.htmlEditorsContextPath = jSettings.getHtmlEditorsContext(); 58 StringBuffer buff = new StringBuffer (jSettings.getJahiaEtcDiskPath()); 59 buff.append(File.separator); 60 buff.append("htmleditors"); 61 buff.append(File.separator); 62 buff.append(this.configFileName); 63 this.htmlEditorsConfigFile = buff.toString(); 64 65 try { 66 htmlEditorsFactory = 67 new JahiaHtmlEditorsFactory( this.htmlEditorsConfigFile ); 68 } catch ( Throwable t ){ 69 throw new JahiaInitializationException("Error init Html Editor Service",t); 70 } 71 } 72 73 78 public void reloadConfigurationFile() throws JahiaException{ 79 htmlEditorsFactory = 80 new JahiaHtmlEditorsFactory( this.htmlEditorsConfigFile ); 81 } 82 83 89 public Enumeration getEditors() 90 throws JahiaException 91 { 92 return htmlEditorsFactory.getEditors().elements(); 93 } 94 95 102 public Enumeration getEditors(int siteID) 103 throws JahiaException 104 { 105 Vector res = new Vector (); 106 Vector editors = htmlEditorsFactory.getEditors(); 107 int size = editors.size(); 108 HtmlEditor htmlEditor = null; 109 for ( int i=0 ; i<size ; i++ ){ 110 htmlEditor = (HtmlEditor)editors.get(i); 111 if ( htmlEditor.isSiteAuthorized(siteID) ){ 112 res.add(htmlEditor); 113 } 114 } 115 return res.elements(); 116 } 117 118 125 public Enumeration getCSSs(int siteID) 126 throws JahiaException 127 { 128 JahiaSite site = ServicesRegistry.getInstance() 129 .getJahiaSitesService().getSite(siteID); 130 Vector res = new Vector (); 131 132 if ( site == null ){ 133 return res.elements(); 134 } 135 136 Vector cssList = htmlEditorsFactory.getCSSs(); 137 int size = cssList.size(); 138 HtmlEditorCSS css = null; 139 for ( int i=0 ; i<size ; i++ ){ 140 css = (HtmlEditorCSS)cssList.get(i); 141 if ( css.isShared() || css.isSiteAllowed(site.getSiteKey()) ){ 142 res.add(css); 143 } 144 } 145 return res.elements(); 146 } 147 148 155 public HtmlEditor getEditor(String id) 156 throws JahiaException 157 { 158 return htmlEditorsFactory.getEditor(id); 159 } 160 161 169 public void authorizeSite(int siteID, String id) 170 throws JahiaException 171 { 172 } 174 175 182 public void unAuthorizeSite(int siteID, String id) 183 throws JahiaException 184 { 185 } 187 188 196 public boolean isSiteAutorized(int siteID, String id) 197 { 198 return true; 199 } 200 201 } 202 203 | Popular Tags |