Login | Register
My pages Projects Community openCollabNet

Discussions > cvs > CVS update: MODIFIED: util ...

Project highlights: Architectural Overview

joist
Discussion topic

Back to topic list

CVS update: MODIFIED: util ...

Author ms
Full name zxcv
Date 2001-05-03 03:35:36 PDT
Message User: ms
  Date: 01/05/03 03:35:36

  Modified: java/org/joist/util TagValidator.java
  Log:
  added ability to specify which tags you want to allow, and predefined sets to pick from
  
  Revision Changes Path
  1.8 +41 -12 joist/java/org/joist​/util/TagValidator.j​ava
  
  http://joist.tigris.​org/source/browse/jo​ist/java/org/joist/u​til/TagValidator.jav​a.diff?r1=1.7&r2​=1.8
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TagValidator.java
  ====================​====================​====================​=======
  RCS file: /usr/local/tigris/da​ta/helm/cvs/reposito​ry/joist/java/org/jo​ist/util/TagValidato​r.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- TagValidator.java 2001/05/02 01:34:24 1.7
  +++ TagValidator.java 2001/05/03 10:35:35 1.8
  @@ -67,11 +67,11 @@
     * @author David C. Pellegrini <A HREF="mailto:davidp@​dataweb-systems.com"​>davidp@dataweb-s​ystems.com</A>​
     * @author Jon S. Stevens <A HREF="mailto:jon@lat​chkey.com">jon@la​tchkey.com</A>​
     * @author Michael Salmon <a href="mailto:ms@coll​ab.net">ms@collab​.net</a>
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
     */
   public class TagValidator
   {
  - static final private String[] tags =
  + static final private String[] ALL_TAGS =
       {"A","ABBR","ACRONYM​","AREA","B","BASE",​"BASEFONT","BIG","BD​O","BLINK",
        "BLOCKQUOTE","BR","C​APTION","CENTER","CI​TE","CODE","COL","CO​LGROUP",
        "DD","DEL","DFN","DI​V","DL","DT","EM","F​IELDSET","FONT",
  @@ -81,6 +81,14 @@
        "STRIKE", "STRONG","STYLE","SU​B","SUP","TBODY","TD​","TFOOT","TH","THEA​D",
        "TR","TT","TABLE","U​","UL","VAR","WBR"};​
   
  + static final public String[] TEXT_FORMAT_TAGS =
  + {"B","BIG","FONT","H​1","H2","H3","H4","H​5","H6","I","SMALL",​"STRONG",
  + "STRIKE","U"};
  +
  + static final public String[] LAYOUT_FORMAT_TAGS =
  + {"BLOCKQUOTE","BR","​CENTER","COL","COLGR​OUP","DIV","LI","P",​"PRE","SPACER",
  + "SPAN","TBODY","TD",​"TABLE","TR","TH","T​FOOT","UL"};
  +
       static final private String[] attributes =
       {"ALIGN","BACKGROUND​","BGCOLOR","CHAR","​CHAROFF","CITE","CLE​AR","COLOR",
        "COLS","FACE","GUTTE​R","HEIGHT","HREF","​SIZE","START","TYPE"​,"WIDTH",
  @@ -243,12 +251,12 @@
           StringBuffer sb = new StringBuffer();
           boolean firstTime = true;
           sb.append ( "<b>Allowed tags:</b><br> " );
  - for ( int i=0; i<tags.length; i++ )
  + for ( int i=0; i< ALL_TAGS.length; i++ )
           {
               if (firstTime)
               {
                   sb.append(lt);
  - sb.append(tags[i]);
  + sb.append(ALL_TAGS[i]);
                   sb.append(gt);
                   firstTime = false;
               }
  @@ -256,7 +264,7 @@
               {
                   sb.append(" ");
                   sb.append(lt);
  - sb.append(tags[i]);
  + sb.append(ALL_TAGS[i]);
                   sb.append(gt);
               }
           }
  @@ -377,25 +385,46 @@
       return unclean;
       }
   
  - public static void addAllowTags(ArrayList newTags)
  + public static void addAllowTags(String[] newTags)
       {
           // let npe's pass if given a null list
           if (allowTags == null && newTags != null)
           {
  - allowTags = newTags;
  - return;
  + allowTags = new ArrayList(newTags.length);
           }
  - for (int i = 0; i < newTags.size(); i++)
  + for (int i = 0; i < newTags.length; i++)
           {
  - allowTags.add(newTags.get(i));
  + allowTags.add(newTags[i]);
           }
       }
       
       private static void mergeTagLists()
  + {
  + // only add ALL_TAGS if none are explicitly given
  + if (allowTags == null)
  + {
  + addAllowTags(ALL_TAGS);
  + }
  + }
  +
  + /**
  + * A way to add tags to allow list
  + */
  + public static void addTagList(String[] extraTags)
       {
  - for (int i = 0; i < tags.length; i++)
  + initTags(extraTags.length);
  + for (int i = 0; i < extraTags.length; i++)
           {
  - allowTags.add(tags[i]);
  + allowTags.add(extraTags[i]);
           }
       }
  +
  + private static void initTags(int size)
  + {
  + if (allowTags == null)
  + {
  + allowTags = new ArrayList (size);
  + }
  + }
  +
   }
  
  
  

--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: cvs-unsubscribe@jois​t.tigris.org
For additional commands, e-mail: cvs-help at joist dot tigris dot org

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

CVS update: MODIFIED: util ... ms zxcv 2001-05-03 03:35:36 PDT
Messages per page: