1 22 23 package org.xquark.util; 24 25 import java.util.ArrayList ; 26 27 import org.xml.sax.*; 28 import org.xml.sax.ext.LexicalHandler ; 29 30 31 public class MultiplexerDecorator extends HandlerDecorator { 32 33 private ContentHandler[] contentHandlers; 34 private LexicalHandler [] lexicalHandlers; 35 private ErrorHandler[] errorHandlers; 36 37 public MultiplexerDecorator(ArrayList handlers) { 38 ArrayList chList = new ArrayList (); 39 ArrayList lhList = new ArrayList (); 40 ArrayList ehList = new ArrayList (); 41 for (int i = 0; i < handlers.size(); i++) { 42 Object handler = handlers.get(i); 43 if (handler instanceof ContentHandler) 44 chList.add(handler); 45 if (handler instanceof LexicalHandler ) 46 lhList.add(handler); 47 if (handler instanceof ErrorHandler) 48 ehList.add(handler); 49 } 50 contentHandlers = (ContentHandler[]) chList.toArray(new ContentHandler[0]); 51 lexicalHandlers = (LexicalHandler []) lhList.toArray(new LexicalHandler [0]); 52 errorHandlers = (ErrorHandler[]) ehList.toArray(new ErrorHandler[0]); 53 } 54 public void startDocument() throws SAXException 58 { 59 super.startDocument(); 60 for (int i = 0; i < contentHandlers.length; i++) 61 contentHandlers[i].startDocument(); 62 } 63 64 public void startElement(String str, String str1, String str2, Attributes attributes) 65 throws SAXException 66 { 67 super.startElement(str, str1, str2, attributes); 68 for (int i = 0; i < contentHandlers.length; i++) 69 contentHandlers[i].startElement(str, str1, str2, attributes); 70 } 71 72 public void setDocumentLocator(Locator locator) 73 { 74 super.setDocumentLocator(locator); 75 for (int i = 0; i < contentHandlers.length; i++) 76 contentHandlers[i].setDocumentLocator(locator); 77 } 78 79 public void endDocument() throws SAXException 80 { 81 super.endDocument(); 82 for (int i = 0; i < contentHandlers.length; i++) 83 contentHandlers[i].endDocument(); 84 } 85 86 public void characters(char[] values, int param, int param2) 87 throws SAXException 88 { 89 super.characters(values, param, param2); 90 for (int i = 0; i < contentHandlers.length; i++) 91 contentHandlers[i].characters(values, param, param2); 92 } 93 94 public void processingInstruction(String str, String str1) 95 throws SAXException 96 { 97 super.processingInstruction(str, str1); 98 for (int i = 0; i < contentHandlers.length; i++) 99 contentHandlers[i].processingInstruction(str, str1); 100 } 101 102 public void endElement(String str, String str1, String str2) 103 throws SAXException 104 { 105 super.endElement(str, str1, str2); 106 for (int i = 0; i < contentHandlers.length; i++) 107 contentHandlers[i].endElement(str, str1, str2); 108 } 109 110 public void startPrefixMapping(String str, String str1) throws SAXException 111 { 112 super.startPrefixMapping(str, str1); 113 for (int i = 0; i < contentHandlers.length; i++) 114 contentHandlers[i].startPrefixMapping(str, str1); 115 } 116 117 public void ignorableWhitespace(char[] values, int param, int param2) 118 throws SAXException 119 { 120 super.ignorableWhitespace(values, param, param2); 121 for (int i = 0; i < contentHandlers.length; i++) 122 contentHandlers[i].ignorableWhitespace(values, param, param2); 123 } 124 125 public void endPrefixMapping(String str) throws SAXException 126 { 127 super.endPrefixMapping(str); 128 for (int i = 0; i < contentHandlers.length; i++) 129 contentHandlers[i].endPrefixMapping(str); 130 } 131 132 public void skippedEntity(String str) throws SAXException 133 { 134 super.skippedEntity(str); 135 for (int i = 0; i < contentHandlers.length; i++) 136 contentHandlers[i].skippedEntity(str); 137 } 138 139 public void startDTD(String name, String publicId, String systemId) 143 throws SAXException 144 { 145 super.startDTD(name, publicId, systemId); 146 for (int i = 0; i < lexicalHandlers.length; i++) 147 lexicalHandlers[i].startDTD(name, publicId, systemId); 148 } 149 150 public void endDTD() throws SAXException 151 { 152 super.endDTD(); 153 for (int i = 0; i < lexicalHandlers.length; i++) 154 lexicalHandlers[i].endDTD(); 155 } 156 157 public void startEntity(String name) throws SAXException 158 { 159 super.startEntity(name); 160 for (int i = 0; i < lexicalHandlers.length; i++) 161 lexicalHandlers[i].startEntity(name); 162 } 163 164 public void endEntity(String name) throws SAXException 165 { 166 super.endEntity(name); 167 for (int i = 0; i < lexicalHandlers.length; i++) 168 lexicalHandlers[i].endEntity(name); 169 } 170 171 public void startCDATA() throws SAXException 172 { 173 super.startCDATA(); 174 for (int i = 0; i < lexicalHandlers.length; i++) 175 lexicalHandlers[i].startCDATA(); 176 } 177 178 public void endCDATA() throws SAXException 179 { 180 super.endCDATA(); 181 for (int i = 0; i < lexicalHandlers.length; i++) 182 lexicalHandlers[i].endCDATA(); 183 } 184 185 public void comment(char ch[], int start, int length) throws SAXException 186 { 187 super.comment(ch, start, length); 188 for (int i = 0; i < lexicalHandlers.length; i++) 189 lexicalHandlers[i].comment(ch, start, length); 190 } 191 192 203 public void warning(SAXParseException e) 204 throws SAXException 205 { 206 super.warning(e); 207 for (int i = 0; i < errorHandlers.length; i++) 208 errorHandlers[i].warning(e); 209 } 210 211 212 220 public void error(SAXParseException e) 221 throws SAXException 222 { 223 super.error(e); 224 for (int i = 0; i < errorHandlers.length; i++) 225 errorHandlers[i].error(e); 226 } 227 228 229 237 public void fatalError(SAXParseException e) 238 throws SAXException 239 { 240 super.fatalError(e); 241 for (int i = 0; i < errorHandlers.length; i++) 242 errorHandlers[i].fatalError(e); 243 } 244 245 } 246 | Popular Tags |