1 package org.jahia.services.htmleditors; 14 15 import java.util.Hashtable ; 16 import java.util.Vector ; 17 18 import org.jahia.exceptions.JahiaException; 19 import java.util.Collections ; 20 21 26 class JahiaHtmlEditorsFactory implements HtmlEditorsFactory 27 { 28 private Hashtable htmlEditors; 29 private Hashtable htmlEditorCSSs; 30 private JahiaHtmlEditorsDigester htmlEditorsDigester; 31 32 35 private String configFile; 36 37 41 public JahiaHtmlEditorsFactory(String configFile) throws JahiaException{ 42 this.configFile = configFile; 43 this.htmlEditors = new Hashtable (); 44 this.htmlEditorCSSs = new Hashtable (); 45 this.htmlEditorsDigester = new JahiaHtmlEditorsDigester(); 46 47 if ( !loadEditors() ){ 48 throw new JahiaException("Error load html editors config file", 49 "Error load html editors config file", 50 JahiaException.CONFIG_ERROR, 51 JahiaException.CONFIG_ERROR); 52 } 53 } 54 55 61 public Vector getEditors() 62 throws JahiaException 63 { 64 Vector v = new Vector (this.htmlEditors.values()); 65 Collections.sort(v); 66 return v; 67 } 68 69 75 public Vector getCSSs() 76 throws JahiaException 77 { 78 Vector v = new Vector (this.htmlEditorCSSs.values()); 79 return v; 80 } 81 82 89 public HtmlEditor getEditor(String id) 90 throws JahiaException { 91 if ( id == null ){ 92 return null; 93 } 94 return (HtmlEditor)this.htmlEditors.get(id); 95 } 96 97 104 public HtmlEditorCSS getCSS(String id) throws JahiaException { 105 if ( id == null ){ 106 return null; 107 } 108 return (HtmlEditorCSS)this.htmlEditorCSSs.get(id); 109 } 110 111 116 public boolean loadEditors(){ 117 118 boolean success = this.htmlEditorsDigester.loadHtmlEditors(this.configFile); 119 if ( !success ){ 120 return false; 121 } 122 123 this.htmlEditors = new Hashtable (); 124 125 Vector v = this.htmlEditorsDigester.getHtmlEditors(); 126 int size = v.size(); 127 HtmlEditor editor = null; 128 for ( int i=0; i<size; i++ ){ 129 editor = (HtmlEditor)v.get(i); 130 this.htmlEditors.put(editor.getId(),editor); 131 } 132 133 v = this.htmlEditorsDigester.getCSSList(); 134 size = v.size(); 135 HtmlEditorCSS css = null; 136 for ( int i=0; i<size; i++ ){ 137 css = (HtmlEditorCSS)v.get(i); 138 this.htmlEditorCSSs.put(css.getId(),css); 139 } 140 return true; 141 } 142 } 143 144 | Popular Tags |