Пример #1
0
  /**
   * Split a string based on the presence of a specified separator. Returns an array of arbitrary
   * length. The end of each element in the array is indicated by the separator of the end of the
   * string. If there is a separator immediately before the end of the string, the final element
   * will be empty. None of the strings will contain the separator. Useful when separating strings
   * such as "foo/bar/bas" using separator "/".
   *
   * @param sep The separator.
   * @param s The string to split.
   * @return An array of strings. Each string in the array is determined by the location of the
   *     provided sep in the original string, s. Whitespace not stripped.
   */
  private String[] splitSeparator(String sep, String s) {
    Vector v = new Vector();
    int tokenStart = 0;
    int tokenEnd = 0;

    while ((tokenEnd = s.indexOf(sep, tokenStart)) != -1) {
      v.addElement(s.substring(tokenStart, tokenEnd));
      tokenStart = tokenEnd + 1;
    }
    // Add the final element.
    v.addElement(s.substring(tokenStart));

    String[] retVal = new String[v.size()];
    v.copyInto(retVal);
    return retVal;
  }
Пример #2
0
  /** Return an enumeration of all the accessible applets on this page. */
  public Enumeration getApplets() {
    AppletSecurity security = (AppletSecurity) System.getSecurityManager();
    Vector v = new Vector();
    SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect");

    for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) {
      AppletPanel p = (AppletPanel) e.nextElement();
      if (p.getDocumentBase().equals(panel.getDocumentBase())) {

        SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect");
        if (panelSp.implies(sp)) {
          v.addElement(p.applet);
        }
      }
    }
    return v.elements();
  }
Пример #3
0
  /** Get an applet by name. */
  public Applet getApplet(String name) {
    AppletSecurity security = (AppletSecurity) System.getSecurityManager();
    name = name.toLowerCase();
    SocketPermission panelSp = new SocketPermission(panel.getCodeBase().getHost(), "connect");
    for (Enumeration e = appletPanels.elements(); e.hasMoreElements(); ) {
      AppletPanel p = (AppletPanel) e.nextElement();
      String param = p.getParameter("name");
      if (param != null) {
        param = param.toLowerCase();
      }
      if (name.equals(param) && p.getDocumentBase().equals(panel.getDocumentBase())) {

        SocketPermission sp = new SocketPermission(p.getCodeBase().getHost(), "connect");

        if (panelSp.implies(sp)) {
          return p.applet;
        }
      }
    }
    return null;
  }
Пример #4
0
 /** How many applets are running? */
 public static int countApplets() {
   return appletPanels.size();
 }