home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Netobjs / Install.exe / data1.cab / Components / SiteMapper / web_structure_builder.class (.txt) < prev   
Encoding:
Java Class File  |  1998-12-16  |  3.2 KB  |  110 lines

  1. import java.util.StringTokenizer;
  2. import java.util.Vector;
  3.  
  4. class web_structure_builder {
  5.    public Vector web_list = new Vector();
  6.    public Vector web_tree = new Vector();
  7.    public int max_level = 0;
  8.    boolean continu = true;
  9.    static final String seperator_string = "%";
  10.    static final String level_string = "#";
  11.    static final String dont_publish_string = "|";
  12.  
  13.    String build_web_structures(Vector branch, int current_level, String current_entry, StringTokenizer tokenizer) {
  14.       int count = 0;
  15.       this.record_max_level(current_level);
  16.  
  17.       while(this.continu) {
  18.          int level = this.find_level(current_entry);
  19.          if (level == current_level) {
  20.             ++count;
  21.             this.add_entry(branch, level, current_entry.substring(current_entry.lastIndexOf("#") + 1));
  22.             if (!tokenizer.hasMoreTokens()) {
  23.                this.continu = false;
  24.                return null;
  25.             }
  26.  
  27.             current_entry = tokenizer.nextToken();
  28.          } else {
  29.             if (level <= current_level) {
  30.                return current_entry;
  31.             }
  32.  
  33.             if (count == 0) {
  34.                System.out.println("heirarchy file format error");
  35.                return null;
  36.             }
  37.  
  38.             tree_entry prev_entry = (tree_entry)branch.elementAt(count - 1);
  39.             prev_entry.children = new Vector();
  40.             current_entry = this.build_web_structures(prev_entry.children, current_level + 1, current_entry, tokenizer);
  41.          }
  42.       }
  43.  
  44.       return null;
  45.    }
  46.  
  47.    web_structure_builder(StringTokenizer tokenizer) {
  48.       this.build_web_structures(this.web_tree, 0, tokenizer.nextToken(), tokenizer);
  49.    }
  50.  
  51.    void restrict_tree(Vector branch, int max_level) {
  52.       for(int i = 0; i < branch.size(); ++i) {
  53.          tree_entry entry = (tree_entry)branch.elementAt(i);
  54.          if (entry.level > max_level) {
  55.             entry.in_use = false;
  56.          } else {
  57.             entry.in_use = true;
  58.             this.web_list.addElement((Object)entry);
  59.          }
  60.  
  61.          if (entry.children != null) {
  62.             this.restrict_tree(entry.children, max_level);
  63.          }
  64.       }
  65.  
  66.    }
  67.  
  68.    void record_max_level(int current_level) {
  69.       if (current_level > this.max_level) {
  70.          this.max_level = current_level;
  71.       }
  72.  
  73.    }
  74.  
  75.    void add_entry(Vector branch, int level, String entry) {
  76.       boolean publish = true;
  77.       if (entry.startsWith("|")) {
  78.          publish = false;
  79.          entry = entry.substring(1);
  80.       }
  81.  
  82.       StringTokenizer st = new StringTokenizer(entry, "%");
  83.       if (st.countTokens() > 1) {
  84.          String name = st.nextToken();
  85.          String url = st.nextToken();
  86.          tree_entry new_entry = new tree_entry(name, url, level, publish);
  87.          branch.addElement(new_entry);
  88.          this.web_list.addElement(new_entry);
  89.       } else {
  90.          System.out.println("incorrect format");
  91.       }
  92.    }
  93.  
  94.    int find_level(String entry) {
  95.       int level = 0;
  96.       String temp_level_string = "#";
  97.  
  98.       for(int i = 0; i < entry.length(); ++i) {
  99.          if (!entry.startsWith(temp_level_string)) {
  100.             return level;
  101.          }
  102.  
  103.          temp_level_string = temp_level_string + "#";
  104.          ++level;
  105.       }
  106.  
  107.       return 0;
  108.    }
  109. }
  110.