6.7 Profile: Scanning the Different Cases

<..search preamble info..>
 switch( ch = buff[i] ){
    case  ’<’:  token = "";
                type = <.new tok.>;
                break;
    case  ’>’:  if( token != null ){
                   token = token . replaceAll( "\\s+", " ");
                   <.at token end.>
                   token = null;
                }
                break;
    case ’\n’:
    case   ’:  if( token != null ){
                   <.at token space.>
                }
                break;
    case  ’"’:
    case ’\’’:  if( token == null ){ break; }
                <.public and system ids.>
    default:    if( token != null ){
                   if( type == <.pre doctype.> ){
                      if( ch == ’D’ ){
                         type = <.doctype.>;
                         token += (char) ch;
                      } else { token = null; type = <.undef type.>; }
                   }
                   else
                   if( token.equals("") && (type == <.new tok.>) ){
                      <.get token type.>
                   } else { token += (char) ch; }
 }              }
 -_-_-

<..public and system ids..>
 if( !token.trim().equals("") ){
    if( token.trim().charAt(0) == ch ){
      if( type == <.public id.> ){
         publicId = token.trim().substring(1);
         type = <.system id.>;
         token = "";
         break;
      }
      else if( type == <.system id.> ){
         systemId = token.trim().substring(1);
         token = null;
         break;
      }
 } }
 -_-_-

<..get token type..>
 switch( ch ){
    case ’!’: type = <.pre doctype.>;
              break;
    case ’?’: type = <.proc instruction.> ;
              break;
    default:  if( Character.isLetter(ch)
                  && ((root == null) || (metaType == null)) ){
                 type = <.root or meta.>;
                 token += (char) ch;
              } else { token = null; }
 }
 -_-_-

<..at token end..>
 if( type == <.proc instruction.> ){
    if( xtpipes == null ){
       int n = token.length();
       if( (n > 1) && (token.charAt( n - 1 ) == ’?’)
                   && (token.startsWith("xtpipes") ) ){
          String s = token . substring(7,n-1) . replaceAll( "\\s+", "");
          n = s.length();
          if( (n>6) && (s.startsWith("file="))
                    && (s.charAt(5) == s.charAt(n-1)) ){
            xtpipes = s.substring(6,n-1);
    }  }  }
 } else if( type == <.meta.> ){
    if( metaType == null ){
       token = token . replaceAll( "\\s+", "");
       int k = token.indexOf("http-equiv");
       int n = token.indexOf("content");
       if( (k != -1) && (n != -1) ){
          if( token.length() > (Math.max(k,n)+3) ){
             if( token.substring(k+12).startsWith("Content-Type") ){
                token = token.substring(n+9);
                n = token.indexOf(";");
                if( n !=-1 ){ metaType = token.substring(0,n); }
    }  }  }  }
 } else if( (type == <.root or meta.>) && (root == null) ){
    root = token;
 }
 -_-_-

<..at token space..>
 if( type == <.root or meta.> ){
    if( token.equals("meta") ){
       if( metaType == null ){
          type = <.meta.>;
          token = " ";
       } else {
          token = null;
       }
    } else {
       if( root == null ){
         root = token;
       }
       token = null;
    }
 } else if( type == <.doctype.> ){
    if( token.equals("DOCTYPE") ){
       type = <.doctype root.>;
       token = " ";
    } else { token = null; }
 } else if( type == <.doctype root.> ){
    if( !token.trim().equals("") ){
       dtdRoot = token.trim();
       token = " ";
       type = <.doctype id.>;
    } else { token = null; }
 } else if( type == <.doctype id.> ){
    if( !token.trim().equals("") ){
       token = token.trim();
       if( token.equals("PUBLIC") ){
          type = <.public id.>;
          token = "";
       } else if( token.equals("SYSTEM") ){
          type = <.system id.>;
          token = "";
       } else { token = null; }
    }
 } else { token +=  ’; }
 -_-_-

<..InputObject fields..>+
 String dtdRoot = null,
       publicId = null,
       systemId = null,
        xtpipes = null,
            url = null,
       metaType = null,
    contentType = null,
           root = null;
 -_-_-

<..undef type..>
 0
 -_-_-

<..new tok..>
 1
 -_-_-

<..root or meta..>
 2
 -_-_-

<..pre doctype..>
 3
 -_-_-

<..doctype..>
 4
 -_-_-

<..doctype root..>
 5
 -_-_-

<..doctype id..>
 6
 -_-_-

<..public id..>
 7
 -_-_-

<..system id..>
 8
 -_-_-

<..proc instruction..>
 9
 -_-_-

<..proc root..>
 10
 -_-_-

<..meta..>
 11
 -_-_-