From: Julien V. <vi...@us...> - 2004-05-11 20:23:44
|
User: vietj Date: 04/05/11 13:23:37 Modified: common/src/main/org/jboss/nukes/common/util EntityTable.java Tools.java Log: modified the entity table to have two entity table, FULL=all the entities, BASIC=all the entities except gt,lt,amp,quot Revision Changes Path 1.2 +58 -4 nukes/common/src/main/org/jboss/nukes/common/util/EntityTable.java Index: EntityTable.java =================================================================== RCS file: /cvsroot/jboss/nukes/common/src/main/org/jboss/nukes/common/util/EntityTable.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- EntityTable.java 17 Feb 2004 20:58:02 -0000 1.1 +++ EntityTable.java 11 May 2004 20:23:35 -0000 1.2 @@ -16,9 +16,30 @@ public class EntityTable { - private static String[] charToEntity = new String[65536]; + /** + * All HTML entities. + */ + public static final EntityTable FULL = new EntityTable(); + + /** + * All HTML entities except the HTML chars which are used to do HTML itself. + */ + public static final EntityTable BASIC = new BasicEntityTable(); - static + private static class BasicEntityTable extends EntityTable + { + public BasicEntityTable() + { + remove('<'); + remove('>'); + remove('"'); + remove('&'); + } + } + + private String[] charToEntity = new String[65536]; + + protected EntityTable() { put(160, "nbsp"); put(161, "iexcl"); @@ -274,16 +295,49 @@ put(8364, "euro"); } - private static void put(int c, String entity) + protected final void put(int c, String entity) { charToEntity[c] = entity; } + protected final void remove(int c) + { + charToEntity[c] = null; + } + /** * Returns null if no entity is found or return the converted entity. */ - public static String lookup(char c) + public final String lookup(char c) { return charToEntity[c]; } + + public final String convertEntities(String txt) + { + StringBuffer result = null; + char[] chars = txt.toCharArray(); + int previous = 0; + for (int current = 0;current < chars.length;current++) + { + String replacement = lookup(chars[current]); + // Do we have a replacement + if (replacement != null) + { + // We lazy create the result + if (result == null) + { + // Allocate 1/2 more than the current txt size + result = new StringBuffer(txt.length() * 3 / 2); + } + // Append the previous chars if any + result.append(chars, previous, current - previous); + // Append the replaced entity + result.append('&').append(replacement).append(';'); + // Update the previous pointer + previous = current + 1; + } + } + return result != null ? result.toString() : txt; + } } 1.5 +1 -29 nukes/common/src/main/org/jboss/nukes/common/util/Tools.java Index: Tools.java =================================================================== RCS file: /cvsroot/jboss/nukes/common/src/main/org/jboss/nukes/common/util/Tools.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Tools.java 10 May 2004 16:50:57 -0000 1.4 +++ Tools.java 11 May 2004 20:23:35 -0000 1.5 @@ -23,7 +23,7 @@ /** * @author <a href="mailto:ju...@jb...">Julien Viet</a> - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ public class Tools { @@ -185,32 +185,4 @@ throw new Error("Cannot create VMID"); } } - - public static String convertEntities(String txt) - { - StringBuffer result = null; - char[] chars = txt.toCharArray(); - int previous = 0; - for (int current = 0;current < chars.length;current++) - { - String replacement = EntityTable.lookup(chars[current]); - // Do we have a replacement - if (replacement != null) - { - // We lazy create the result - if (result == null) - { - // Allocate 1/2 more than the current txt size - result = new StringBuffer(txt.length() * 3 / 2); - } - // Append the previous chars if any - result.append(chars, previous, current - previous); - // Append the replaced entity - result.append('&').append(replacement).append(';'); - // Update the previous pointer - previous = current + 1; - } - } - return result != null ? result.toString() : txt; - } } |