/* JJT: 0.2.2 */

package w3c.pics.parser;


class PICSUser_Node extends SimpleNode implements URLEvalNode {
  PICSUser_Node(int id) {
    super(id);
  }

  String text = null;
  
  public String getText() {
    return text;
  }

  public boolean isValid(String URL) {
    String noatsign = text.substring(0, text.length()-1);
    int endscheme = URL.indexOf("//");
    if (endscheme==-1)
      return false;
    int atsign = URL.indexOf("@");
    if (atsign==-1) {
      if (noatsign.equals("*")) 
	return true;
      else
	return false;
    }
    String URLuser = URL.substring(endscheme+2, atsign);
    if (noatsign.startsWith("%*")) {
      if (noatsign.equals("%*")) {
	if (URLuser.equals("*")) {
	  return true;
	}
      }
      else if (noatsign.endsWith("%*")) {
	String nostar = noatsign.substring(2, noatsign.length()-2);
	if (URLuser.equals("*"+nostar+"*")) {
	  return true;
	}
      }
      else if (noatsign.endsWith("*")) {
	String nostar = noatsign.substring(2, noatsign.length()-1);
	if (URLuser.startsWith("*"+nostar)) {
	  return true;
	}
      }
      else {
	String nostar = noatsign.substring(2);
	if (URLuser.equals("*"+nostar)) {
	  return true;
	}
      }
    }
    else if (noatsign.startsWith("*")) {
      if (noatsign.equals("*")) {
	  return true;
      }
      else if (noatsign.endsWith("%*")) {
	String nostar = noatsign.substring(1, noatsign.length()-2);
	if (URLuser.endsWith(nostar+"*")) {
	  return true;
	}
      }
      else if (noatsign.endsWith("*")) {
	String nostar = noatsign.substring(1, noatsign.length()-1);
	int match = URLuser.indexOf(nostar);
	if (match!=-1) {
	  return true;
	}
      }
      else {
	String nostar = noatsign.substring(1);
	if (URLuser.endsWith(nostar)) {
	  return true;
	}
      }
    }
    else {
      if (noatsign.endsWith("%*")) {
	String nostar = noatsign.substring(0, noatsign.length()-2);
	if (URLuser.equals(nostar+"*")) {
	  return true;
	}
      }
      else if (noatsign.endsWith("*")) {
	String nostar = noatsign.substring(0, noatsign.length()-1);
	if (URLuser.startsWith(nostar)) {
	  return true;
	}
      }
      else {
	if (noatsign.equals(URLuser)) {
	  return true;
	}
      }
    }
    return false;
  }

}
