CodeHtml.java :  » Web-Framework » wingS » com » javujavu » javux » util » code » Java Open Source

Java Open Source » Web Framework » wingS 
wingS » com » javujavu » javux » util » code » CodeHtml.java
package com.javujavu.javux.util.code;

public class CodeHtml
{
  private static final String[] tags=
  {
    "\u00C6AElig",
    "\u00C1Aacute",
    "\u00C2Acirc",
    "\u00C0Agrave",
    "\u0391Alpha",
    "\u00C5Aring",
    "\u00C3Atilde",
    "\u00C4Auml",
    "\u0392Beta",
    "\u00C7Ccedil",
    "\u03A7Chi",
    "\u2021Dagger",
    "\u0394Delta",
    "\u00D0ETH",
    "\u00C9Eacute",
    "\u00CAEcirc",
    "\u00C8Egrave",
    "\u0395Epsilon",
    "\u0397Eta",
    "\u00CBEuml",
    "\u0393Gamma",
    "\u00CDIacute",
    "\u00CEIcirc",
    "\u00CCIgrave",
    "\u0399Iota",
    "\u00CFIuml",
    "\u039AKappa",
    "\u039BLambda",
    "\u039CMu",
    "\u00D1Ntilde",
    "\u039DNu",
    "\u0152OElig",
    "\u00D3Oacute",
    "\u00D4Ocirc",
    "\u00D2Ograve",
    "\u03A9Omega",
    "\u039FOmicron",
    "\u00D8Oslash",
    "\u00D5Otilde",
    "\u00D6Ouml",
    "\u03A6Phi",
    "\u03A0Pi",
    "\u2033Prime",
    "\u03A8Psi",
    "\u03A1Rho",
    "\u0160Scaron",
    "\u03A3Sigma",
    "\u00DETHORN",
    "\u03A4Tau",
    "\u0398Theta",
    "\u00DAUacute",
    "\u00DBUcirc",
    "\u00D9Ugrave",
    "\u03A5Upsilon",
    "\u00DCUuml",
    "\u039EXi",
    "\u00DDYacute",
    "\u0178Yuml",
    "\u0396Zeta",
    "\u00E1aacute",
    "\u00E2acirc",
    "\u00B4acute",
    "\u00E6aelig",
    "\u00E0agrave",
    "\u2135alefsym",
    "\u03B1alpha",
    "\u0026amp",
    "\u2227and",
    "\u2220ang",
    "\u00E5aring",
    "\u2248asymp",
    "\u00E3atilde",
    "\u00E4auml",
    "\u201Ebdquo",
    "\u03B2beta",
    "\u00A6brvbar",
    "\u2022bull",
    "\u2229cap",
    "\u00E7ccedil",
    "\u00B8cedil",
    "\u00A2cent",
    "\u03C7chi",
    "\u02C6circ",
    "\u2663clubs",
    "\u2245cong",
    "\u00A9copy",
    "\u21B5crarr",
    "\u222Acup",
    "\u00A4curren",
    "\u21D3dArr",
    "\u2020dagger",
    "\u2193darr",
    "\u00B0deg",
    "\u03B4delta",
    "\u2666diams",
    "\u00F7divide",
    "\u00E9eacute",
    "\u00EAecirc",
    "\u00E8egrave",
    "\u2205empty",
    "\u2003emsp",
    "\u2002ensp",
    "\u03B5epsilon",
    "\u2261equiv",
    "\u03B7eta",
    "\u00F0eth",
    "\u00EBeuml",
    "\u20ACeuro",
    "\u2203exist",
    "\u0192fnof",
    "\u2200forall",
    "\u00BDfrac12",
    "\u00BCfrac14",
    "\u00BEfrac34",
    "\u2044frasl",
    "\u03B3gamma",
    "\u2265ge",
    "\u003Egt",
    "\u21D4hArr",
    "\u2194harr",
    "\u2665hearts",
    "\u2026hellip",
    "\u00EDiacute",
    "\u00EEicirc",
    "\u00A1iexcl",
    "\u00ECigrave",
    "\u2111image",
    "\u221Einfin",
    "\u222Bint",
    "\u03B9iota",
    "\u00BFiquest",
    "\u2208isin",
    "\u00EFiuml",
    "\u03BAkappa",
    "\u21D0lArr",
    "\u03BBlambda",
    "\u2329lang",
    "\u00ABlaquo",
    "\u2190larr",
    "\u2308lceil",
    "\u201Cldquo",
    "\u2264le",
    "\u230Alfloor",
    "\u2217lowast",
    "\u25CAloz",
    "\u200Elrm",
    "\u2039lsaquo",
    "\u2018lsquo",
    "\u003Clt",
    "\u00AFmacr",
    "\u2014mdash",
    "\u00B5micro",
    "\u00B7middot",
    "\u2212minus",
    "\u03BCmu",
    "\u2207nabla",
    "\u00A0nbsp",
    "\u2013ndash",
    "\u2260ne",
    "\u220Bni",
    "\u00ACnot",
    "\u2209notin",
    "\u2284nsub",
    "\u00F1ntilde",
    "\u03BDnu",
    "\u00F3oacute",
    "\u00F4ocirc",
    "\u0153oelig",
    "\u00F2ograve",
    "\u203Eoline",
    "\u03C9omega",
    "\u03BFomicron",
    "\u2295oplus",
    "\u2228or",
    "\u00AAordf",
    "\u00BAordm",
    "\u00F8oslash",
    "\u00F5otilde",
    "\u2297otimes",
    "\u00F6ouml",
    "\u00B6para",
    "\u2202part",
    "\u2030permil",
    "\u22A5perp",
    "\u03C6phi",
    "\u03C0pi",
    "\u03D6piv",
    "\u00B1plusmn",
    "\u00A3pound",
    "\u2032prime",
    "\u220Fprod",
    "\u221Dprop",
    "\u03C8psi",
    "\"quot",
    "\u21D2rArr",
    "\u221Aradic",
    "\u232Arang",
    "\u00BBraquo",
    "\u2192rarr",
    "\u2309rceil",
    "\u201Drdquo",
    "\u211Creal",
    "\u00AEreg",
    "\u230Brfloor",
    "\u03C1rho",
    "\u200Frlm",
    "\u203Arsaquo",
    "\u2019rsquo",
    "\u201Asbquo",
    "\u0161scaron",
    "\u22C5sdot",
    "\u00A7sect",
    "\u00ADshy",
    "\u03C3sigma",
    "\u03C2sigmaf",
    "\u223Csim",
    "\u2660spades",
    "\u2282sub",
    "\u2286sube",
    "\u2211sum",
    "\u2283sup",
    "\u00B9sup1",
    "\u00B2sup2",
    "\u00B3sup3",
    "\u2287supe",
    "\u00DFszlig",
    "\u03C4tau",
    "\u2234there4",
    "\u03B8theta",
    "\u03D1thetasym",
    "\u2009thinsp",
    "\u00FEthorn",
    "\u02DCtilde",
    "\u00D7times",
    "\u2122trade",
    "\u21D1uArr",
    "\u00FAuacute",
    "\u2191uarr",
    "\u00FBucirc",
    "\u00F9ugrave",
    "\u00A8uml",
    "\u03D2upsih",
    "\u03C5upsilon",
    "\u00FCuuml",
    "\u2118weierp",
    "\u03BExi",
    "\u00FDyacute",
    "\u00A5yen",
    "\u00FFyuml",
    "\u03B6zeta",
    "\u200Dzwj",
    "\u200Czwnj"    
  };
  public static String decode(String in)
  {
    if(in.indexOf('&')==-1) return in;
    int len= in.length();
    StringBuffer out= new StringBuffer(len);
    char c;
    int wasAmp= 0;
    int ampPos= 0;
    int ampVal= 0;
    for(int i= 0; i<len; i++)
    {
      c= in.charAt(i);
      if(wasAmp==0)
      {
        if(c=='&')
        {
          wasAmp= 100;
          ampPos= i;
        }
        else out.append(c);
      }
      else if(wasAmp==100)
      {
        if(c=='#') wasAmp= 200;
        else
        {
          wasAmp= 5000;
          for(int j= 0; j<tags.length; j++)
          {
            if(c==tags[j].charAt(1))
            {
              wasAmp= 1000+j;
              ampVal= tags[j].charAt(0);
              break;
            }
          }
        }
      }
      else if(wasAmp==200)
      {
        if(c>='0' && c<='9')
        {
          wasAmp= 300;
          ampVal= c-'0';
        }
        else if(c=='x' || c=='X')
        {
          wasAmp= 400;
          ampVal= 0;
        }
        else wasAmp= 5000;
      }
      else if(c==';')
      {
        out.append((char)ampVal);
        wasAmp= 0;
      }
      else if(wasAmp==300)
      {
        if(c>='0' && c<='9')
        {
          ampVal= ampVal*10+c-'0';
        }
        else wasAmp= 5000;
      }
      else if(wasAmp==400)
      {
        if(c>='0' && c<='9')
        {
          ampVal= ampVal*16+c-'0';
        }
        else if(c>='a' && c<='f')
        {
          ampVal= ampVal*16+c-'a'+10;
        }
        if(c>='A' && c<='F')
        {
          ampVal= ampVal*16+c-'A'+10;
        }
        else wasAmp= 5000;
      }
      else
      {
        if(c!=tags[wasAmp-1000].charAt(i-ampPos))
        {
          int j= wasAmp-1000+1, k;
          wasAmp= 5000;
          for(; j<tags.length; j++)
          {
            if(i-ampPos>=tags[j].length()) break;
            for(k= ampPos+1; k<i; k++)
            {
              if(in.charAt(k)!=tags[j].charAt(k-ampPos))
              {
                break;
              }
            }
            if(k<i) break;
            if(c==tags[j].charAt(i-ampPos))
            {
              wasAmp= 1000+j;
              ampVal= tags[j].charAt(0);
              break;
            }
          }
        }
      }
      if(wasAmp==5000)
      {
        out.append('&');
        i= ampPos;
        wasAmp= 0;
      }
    }
    return out.toString();
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.