1 9 10 package org.jboss.portal.format.parser.entity; 11 12 import org.jboss.portal.format.parser.AbstractParser; 13 import org.jboss.portal.format.parser.TextEvent; 14 import org.jboss.portal.format.util.EntityTable; 15 16 22 public class HTML4_0CharacterEntityReferenceParser extends AbstractParser 23 { 24 25 private final TextEvent textEvent = new TextEvent(); 26 private final CharacterEntityReferenceEvent cere = new CharacterEntityReferenceEvent(); 27 private final char[] buffer = new char[10]; 28 29 public void parse(char[] chars, int startOffset, int length) 30 { 31 int endOffset = startOffset + length; 33 int previousOffset = startOffset; 34 35 for (int currentOffset = startOffset;currentOffset < endOffset;currentOffset++) 37 { 38 char c = chars[currentOffset]; 39 String result = EntityTable.FULL.lookup(c); 40 if (result != null) 41 { 42 if (currentOffset > previousOffset) 43 { 44 textEvent.setText(chars, previousOffset, currentOffset - previousOffset); 45 handler.handle(textEvent); 46 } 47 48 int size = result.length(); 49 buffer[0] = '&'; 50 result.getChars(0, size, buffer, 1); 51 buffer[size + 1] = ';'; 52 cere.setText(buffer, 0, size + 2); 53 handler.handle(cere); 54 previousOffset = currentOffset + 1; 55 } 56 } 57 58 if (endOffset > previousOffset) 60 { 61 textEvent.setText(chars, previousOffset, endOffset - previousOffset); 62 handler.handle(textEvent); 63 } 64 } 65 66 } 67 | Popular Tags |