1 package org.jahia.services.htmleditors; 14 15 import java.io.File ; 16 import java.io.IOException ; 17 import java.util.HashSet ; 18 import java.util.Set ; 19 import java.util.Vector ; 20 import java.util.HashMap ; 21 22 import org.apache.commons.digester.Digester; 23 import org.apache.commons.digester.Rule; 24 25 31 class JahiaHtmlEditorsDigester 32 { 33 private Digester digester; 34 private Vector editors; 35 private Vector cssList; 36 37 public JahiaHtmlEditorsDigester(){ 38 this.initDigester(); 39 this.editors = new Vector (); 40 this.cssList = new Vector (); 41 } 42 43 private void initDigester(){ 44 this.digester = new Digester(); 45 46 AddHtmlEditorRule rule = new AddHtmlEditorRule(); 47 digester.addRule("editors/editor", rule); 48 digester.addRule("editors/editor/id", rule.setParamRule); 49 digester.addRule("editors/editor/name", rule.setParamRule); 50 digester.addRule("editors/editor/base-directory", rule.setParamRule); 51 digester.addRule("editors/editor/include-file", rule.setParamRule); 52 digester.addRule("editors/editor/compatibility-tester", rule.setParamRule); 53 digester.addRule("editors/editor/enable-css", rule.setParamRule); 54 digester.addRule("editors/editor/rank", rule.setParamRule); 55 56 AddCSSRule addCSSRule = new AddCSSRule(); 57 digester.addRule("editors/style-sheets/css",addCSSRule); 58 digester.addRule("editors/style-sheets/css/id",addCSSRule.setParamRule); 59 digester.addRule("editors/style-sheets/css/name",addCSSRule.setParamRule); 60 digester.addRule("editors/style-sheets/css/url",addCSSRule.setParamRule); 61 digester.addRule("editors/style-sheets/css/shared",addCSSRule.setParamRule); 62 digester.addRule("editors/style-sheets/css/allowed-sites/site-key", addCSSRule.addAllowedSiteRule); 63 } 64 65 71 public boolean loadHtmlEditors(String sourceFile){ 72 boolean success = false; 73 try { 74 File xmlSourceFile = new File (sourceFile); 75 this.digester.parse(xmlSourceFile); 76 success = true; 77 } catch (org.xml.sax.SAXException saxe) { 78 saxe.printStackTrace(); 79 } catch ( IOException ioe ){ 80 ioe.printStackTrace(); 81 } 82 return success; 83 } 84 85 93 public void addHtmlEditor( String id, 94 String name, 95 String baseDirectory, 96 String includeFile, 97 String compatibilityTester, 98 String enableCSS, 99 int rank ){ 100 101 HtmlEditor editor = 102 new JahiaHtmlEditor(id,name,baseDirectory,includeFile, 103 compatibilityTester,"true".equalsIgnoreCase(enableCSS), rank); 104 this.editors.add(editor); 105 } 106 107 113 public Vector getHtmlEditors(){ 114 return this.editors; 115 } 116 117 123 public Vector getCSSList(){ 124 return this.cssList; 125 } 126 127 final class AddHtmlEditorRule extends Rule { 128 private HashMap params = new HashMap (); 129 SetParamRule setParamRule = new SetParamRule(); 130 131 public void end(String namespace, String name) 132 throws Exception { 133 int rank = -1; 134 if (params.get("rank") != null) { 135 rank = Integer.parseInt((String ) params.get("rank")); 136 } 137 JahiaHtmlEditor editor = new JahiaHtmlEditor((String ) params.get("id"), 138 (String ) params.get("name"), 139 (String ) params.get("base-directory"), 140 (String ) params.get("include-file"), 141 (String ) params.get("compatibility-tester"), 142 "true".equalsIgnoreCase((String ) params.get("enable-css")), 143 rank); 144 params.clear(); 145 editors.add( editor ); 146 } 147 148 final class SetParamRule extends Rule { 149 public void body(String namespace, String name, String text) 150 throws Exception { 151 params.put(name,text); 152 } 153 } 154 } 155 156 final class AddCSSRule extends Rule { 157 private HashMap params = new HashMap (); 158 private Set allowedSites = new HashSet (); 159 SetParamRule setParamRule = new SetParamRule(); 160 AddAllowedSiteRule addAllowedSiteRule = new AddAllowedSiteRule(); 161 162 public void end(String namespace, String name) 163 throws Exception { 164 HtmlEditorCSS css = 165 new HtmlEditorCSS((String ) params.get("id"), 166 (String ) params.get("name"), 167 (String ) params.get("url"), 168 "true".equalsIgnoreCase((String ) params.get("shared"))); 169 170 css.addAllowedSites(this.allowedSites); 171 this.allowedSites = new HashSet (); 172 173 params.clear(); 174 allowedSites.clear(); 175 cssList.add( css ); 176 } 177 178 final class SetParamRule extends Rule { 179 public void body(String namespace, String name, String text) 180 throws Exception { 181 params.put(name,text); 182 } 183 } 184 185 final class AddAllowedSiteRule extends Rule { 186 public void body(String namespace, String name, String text) 187 throws Exception { 188 allowedSites.add(text); 189 } 190 } 191 } 192 } 193 194 | Popular Tags |