home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / INTERNET / NETSCAP4.06 / CP32E406.EXE / netcast.z / ncjava10.jar / netscape / netcast / application / SiteData.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-27  |  10.3 KB  |  372 lines

  1. package netscape.netcast.application;
  2.  
  3. import java.applet.Applet;
  4. import java.io.File;
  5. import java.util.Date;
  6. import java.util.ResourceBundle;
  7. import java.util.Vector;
  8. import netscape.javascript.JSObject;
  9. import netscape.net.Cache;
  10. import netscape.security.AppletSecurity;
  11. import netscape.security.Principal;
  12. import netscape.security.PrivilegeManager;
  13. import netscape.security.Target;
  14.  
  15. public class SiteData extends DataItem implements UpdateParent {
  16.    static final int SITE_ERROR = -2;
  17.    static final int SITE_INACTIVE = -1;
  18.    static final int SITE_IDLE = 0;
  19.    static final int SITE_UPDATING = 1;
  20.    static int UPDATE_MAX = Integer.parseInt(NCPrefsManager.GetData("netcaster.updateMax", "2"));
  21.    static final long PERM_SD_INSITE = 8192L;
  22.    private static int m_NumUpdates;
  23.    protected String m_CacheName;
  24.    protected String m_CacheFileName;
  25.    protected Cache m_Cache;
  26.    protected int m_Depth;
  27.    private HTMLCrawler crawler;
  28.    private boolean StopProgressBar = true;
  29.  
  30.    public SiteData(Applet var1) {
  31.       super.m_Applet = (ConstPR4)var1;
  32.       super.m_Status = -1;
  33.       super.m_Type = 1;
  34.       super.m_Frequency = -1;
  35.       super.m_UpdateTime = -1;
  36.       super.m_LastUpdate = 0L;
  37.       super.m_State = 0;
  38.    }
  39.  
  40.    public SiteData(Applet var1, String var2) {
  41.       super.m_State = 0;
  42.       super.m_Status = -1;
  43.       super.m_Applet = (ConstPR4)var1;
  44.       ((DataItem)this).loadData(var2);
  45.    }
  46.  
  47.    public int getDepth() {
  48.       return this.m_Depth;
  49.    }
  50.  
  51.    public void setDepth(int var1) {
  52.       this.m_Depth = var1;
  53.    }
  54.  
  55.    public boolean crawlInSite() {
  56.       return (super.m_Permissions & 8192L) != 0L;
  57.    }
  58.  
  59.    public void setCrawlInSite(Boolean var1) {
  60.       if (var1) {
  61.          super.m_Permissions |= 8192L;
  62.       } else {
  63.          super.m_Permissions &= -8193L;
  64.       }
  65.    }
  66.  
  67.    public synchronized int getNumUpdates() {
  68.       return m_NumUpdates;
  69.    }
  70.  
  71.    protected int loadDataSetup(Vector var1, Vector var2) throws IllegalArgumentException {
  72.       int var3 = 0;
  73.       String var4 = ((DataItem)this).getPrefsKey();
  74.       var3 = super.loadDataSetup(var1, var2);
  75.       if (var1.size() != var2.size()) {
  76.          throw new IllegalArgumentException("Different count of preference keys and values");
  77.       } else {
  78.          var1.addElement(var4 + ".updateFrequency");
  79.          var2.addElement("-1");
  80.          var1.addElement(var4 + ".updateTime");
  81.          var2.addElement("-1");
  82.          var1.addElement(var4 + ".cacheName");
  83.          var2.addElement((Object)null);
  84.          var1.addElement(var4 + ".cacheFilename");
  85.          var2.addElement((Object)null);
  86.          var1.addElement(var4 + ".depth");
  87.          var2.addElement("1");
  88.          var1.addElement(var4 + ".maxSize");
  89.          var2.addElement("0");
  90.          var1.addElement(var4 + ".startTime");
  91.          var2.addElement("0");
  92.          var1.addElement(var4 + ".endTime");
  93.          var2.addElement("0");
  94.          return var3 + 8;
  95.       }
  96.    }
  97.  
  98.    protected void reflectLoadedData(String[] var1, String[] var2) {
  99.       super.reflectLoadedData(var1, var2);
  100.  
  101.       for(int var3 = 0; var3 < var1.length; ++var3) {
  102.          String var4 = var1[var3].substring(var1[var3].lastIndexOf(46) + 1);
  103.          if (var4.compareTo("updateFrequency") == 0) {
  104.             super.m_Frequency = Integer.parseInt(var2[var3]);
  105.          } else if (var4.compareTo("updateTime") == 0) {
  106.             super.m_UpdateTime = Integer.parseInt(var2[var3]);
  107.          } else if (var4.compareTo("cacheName") == 0) {
  108.             this.m_CacheName = var2[var3];
  109.          } else if (var4.compareTo("cacheFilename") == 0) {
  110.             this.m_CacheFileName = var2[var3];
  111.          } else if (var4.compareTo("depth") == 0) {
  112.             this.m_Depth = Integer.parseInt(var2[var3]);
  113.          } else if (var4.compareTo("maxSize") == 0) {
  114.             super.m_MaxSize = Integer.parseInt(var2[var3]);
  115.          } else if (var4.compareTo("startTime") == 0) {
  116.             super.m_StartTime = Integer.parseInt(var2[var3]);
  117.          } else if (var4.compareTo("endTime") == 0) {
  118.             super.m_EndTime = Integer.parseInt(var2[var3]);
  119.          }
  120.       }
  121.  
  122.    }
  123.  
  124.    protected int saveDataSetup(Vector var1, Vector var2) throws IllegalArgumentException {
  125.       int var3 = 0;
  126.       String var4 = ((DataItem)this).getPrefsKey();
  127.       var3 = super.saveDataSetup(var1, var2);
  128.       if (var1.size() != var2.size()) {
  129.          throw new IllegalArgumentException("Different count of preference keys and values");
  130.       } else {
  131.          var1.addElement(var4 + ".updateFrequency");
  132.          var2.addElement(String.valueOf(super.m_Frequency));
  133.          var1.addElement(var4 + ".updateTime");
  134.          var2.addElement(String.valueOf(super.m_UpdateTime));
  135.          var1.addElement(var4 + ".cacheName");
  136.          var2.addElement(this.m_CacheName);
  137.          var1.addElement(var4 + ".cacheFilename");
  138.          var2.addElement(this.m_CacheFileName);
  139.          var1.addElement(var4 + ".depth");
  140.          var2.addElement(String.valueOf(this.m_Depth));
  141.          var1.addElement(var4 + ".maxSize");
  142.          var2.addElement(String.valueOf(super.m_MaxSize));
  143.          var1.addElement(var4 + ".startTime");
  144.          var2.addElement(String.valueOf(super.m_StartTime));
  145.          var1.addElement(var4 + ".endTime");
  146.          var2.addElement(String.valueOf(super.m_EndTime));
  147.          return var3 + 8;
  148.       }
  149.    }
  150.  
  151.    public String[][] getMenuItems() {
  152.       int var2 = 1;
  153.       String[][] var1;
  154.       if (((DataItem)this).isDeletable()) {
  155.          var1 = new String[4][2];
  156.       } else {
  157.          var1 = new String[3][2];
  158.       }
  159.  
  160.       if (super.m_Status != 1 && this.crawler == null) {
  161.          var1[0][0] = "Start Update";
  162.          var1[0][1] = "update_start";
  163.       } else {
  164.          var1[0][0] = "Stop Update";
  165.          var1[0][1] = "update_stop";
  166.       }
  167.  
  168.       if (((DataItem)this).isDeletable()) {
  169.          var1[var2][0] = "Delete";
  170.          var1[var2++][1] = "delete";
  171.       }
  172.  
  173.       var1[var2][0] = "-";
  174.       var1[var2++][1] = "";
  175.       var1[var2][0] = "Properties";
  176.       var1[var2++][1] = "props";
  177.       return var1;
  178.    }
  179.  
  180.    public void processMenuItem(String var1) {
  181.       if (var1.compareTo("update_start") == 0) {
  182.          this.update();
  183.       } else if (var1.compareTo("update_stop") == 0) {
  184.          this.cancelUpdate();
  185.       } else {
  186.          super.processMenuItem(var1);
  187.       }
  188.    }
  189.  
  190.    public void added(CategoryData var1, boolean var2) {
  191.       super.added(var1, var2);
  192.       if (this.m_CacheName == null || this.m_CacheFileName == null) {
  193.          Date var3 = new Date();
  194.          this.m_CacheFileName = (new Integer(var3.getMonth())).toString() + "" + (new Integer(var3.getDate())).toString() + "" + (new Integer(var3.getMinutes())).toString() + "" + (new Integer(var3.getSeconds())).toString() + ".db";
  195.          this.m_CacheName = super.m_Name;
  196.       }
  197.  
  198.       this.m_Cache = new Cache("//", this.m_CacheFileName, this.m_CacheName, super.m_MaxSize);
  199.       NSTimer.master.add(Const.scheduler, 0L, this);
  200.       ++DataItem.m_NumItems;
  201.       if (!var2) {
  202.          NCPrefsManager.SaveData("netcaster.channel.count", String.valueOf(DataItem.m_NumItems - 1));
  203.          NCPrefsManager.SaveData("netcaster.channel.channel_" + (DataItem.m_NumItems - 1), ((DataItem)this).getPrefsName());
  204.       }
  205.  
  206.       if (!var2) {
  207.          ((DataItem)this).saveData("netcaster.channel");
  208.       }
  209.  
  210.    }
  211.  
  212.    public synchronized void autoUpdate() {
  213.       if (super.m_Applet.constManager.ws == null || super.m_Applet.constManager.ws.getEnvironment().networkEnabled()) {
  214.          this.m_Cache = new Cache("//", this.m_CacheFileName, this.m_CacheName, super.m_MaxSize);
  215.          if (super.m_Status != 1 && this.crawler == null) {
  216.             this.crawler = new HTMLCrawler(super.m_URL, this.m_Cache, this, this.m_Depth, NCPrefsManager.GetData("profile.directory", "") + File.separator + "archive" + File.separator + this.m_CacheFileName, super.m_MaxSize, this.crawlInSite(), false);
  217.             PrivilegeManager var1 = AppletSecurity.getPrivilegeManager();
  218.             Principal var3 = PrivilegeManager.getSystemPrincipal();
  219.             Target var2 = Target.findTarget("Netcaster", var3);
  220.             var1.enablePrivilege(var2);
  221.             this.crawler.setPriority(1);
  222.             var1.revertPrivilege(var2);
  223.             this.crawler.start();
  224.          }
  225.       }
  226.    }
  227.  
  228.    public void update() {
  229.       if (super.m_Applet.constManager.ws == null || super.m_Applet.constManager.ws.getEnvironment().networkEnabled()) {
  230.          if (super.m_Status != 1) {
  231.             super.m_Status = 1;
  232.             this.crawler = new HTMLCrawler(super.m_URL, this.m_Cache, this, this.m_Depth, NCPrefsManager.GetData("profile.directory", "") + File.separator + "archive" + File.separator + this.m_CacheFileName, super.m_MaxSize, this.crawlInSite(), true);
  233.             PrivilegeManager var1 = AppletSecurity.getPrivilegeManager();
  234.             Principal var3 = PrivilegeManager.getSystemPrincipal();
  235.             Target var2 = Target.findTarget("Netcaster", var3);
  236.             var1.enablePrivilege(var2);
  237.             this.crawler.setPriority(1);
  238.             var1.revertPrivilege(var2);
  239.             this.crawler.start();
  240.          }
  241.       }
  242.    }
  243.  
  244.    public void updateStarted() {
  245.       super.m_Status = 1;
  246.       long var1 = System.currentTimeMillis();
  247.       ((DataItem)this).setLastUpdate(var1);
  248.       if (super.m_ItemView != null && super.m_Applet != null) {
  249.          JSObject var3 = JSObject.getWindow(super.m_Applet);
  250.          JSObject[] var4 = new JSObject[]{super.m_ItemView};
  251.          var3.call("animateGo", var4);
  252.       }
  253.  
  254.       ((DataItem)this).setLastUpdate(System.currentTimeMillis());
  255.    }
  256.  
  257.    public synchronized void updateComplete(int var1) {
  258.       super.m_Status = 0;
  259.       --m_NumUpdates;
  260.       this.crawler = null;
  261.       if (this.StopProgressBar) {
  262.          if (var1 == 1) {
  263.             ((DataItem)this).setState(1);
  264.             this.setError((String)null);
  265.          } else if (var1 == 0) {
  266.             this.setError((String)null);
  267.          } else {
  268.             ResourceBundle var2 = ResourceBundle.getBundle("netscape.netcast.application.NetcasterStrings");
  269.             ((DataItem)this).setState(-1);
  270.             switch (var1) {
  271.                case -4:
  272.                   this.setError(var2.getString("site down error"));
  273.                   break;
  274.                case -3:
  275.                   this.setError(var2.getString("robots error"));
  276.                   break;
  277.                case -2:
  278.                   this.setError(var2.getString("depth value error"));
  279.                   break;
  280.                case -1:
  281.                   this.setError(var2.getString("Cache size error"));
  282.                   break;
  283.                default:
  284.                   this.setError((String)null);
  285.             }
  286.          }
  287.  
  288.          if (super.m_ItemView != null && super.m_Applet != null) {
  289.             JSObject var4 = JSObject.getWindow(super.m_Applet);
  290.             JSObject[] var3 = new JSObject[]{super.m_ItemView};
  291.             var4.call("animateStop", var3);
  292.             return;
  293.          }
  294.       } else {
  295.          this.StopProgressBar = true;
  296.       }
  297.  
  298.    }
  299.  
  300.    public void remove() {
  301.       this.cancelUpdate();
  302.       NSTimer.master.remove(Const.scheduler, this);
  303.    }
  304.  
  305.    public void deleted(CategoryData var1) {
  306.       this.remove();
  307.       this.cancelUpdate();
  308.       super.deleted(var1);
  309.       NCPrefsManager.SaveData("netcaster.channel.count", String.valueOf(--DataItem.m_NumItems));
  310.       PrivilegeManager.enablePrivilege("Netcaster");
  311.       this.m_Cache = new Cache("//", this.m_CacheFileName, this.m_CacheName, super.m_MaxSize);
  312.       this.m_Cache.delete();
  313.       File var2 = new File(NCPrefsManager.GetData("profile.directory", "") + File.separator + "archive" + File.separator + this.m_CacheFileName);
  314.       var2.delete();
  315.       Object var3 = null;
  316.    }
  317.  
  318.    public void updateProps() {
  319.       NSTimer.master.remove(Const.scheduler, this);
  320.       NSTimer.master.add(Const.scheduler, 0L, this);
  321.    }
  322.  
  323.    public void close() {
  324.       this.remove();
  325.       this.m_Cache = new Cache("//", this.m_CacheFileName, this.m_CacheName, super.m_MaxSize);
  326.       this.m_Cache.close();
  327.       super.close();
  328.    }
  329.  
  330.    public synchronized void setError(String var1) {
  331.       super.setError(var1);
  332.       if (var1 != null) {
  333.          ((DataItem)this).setState(-1);
  334.       }
  335.  
  336.       ((DataItem)this).updateLEDImage(false);
  337.    }
  338.  
  339.    public void cancelUpdate() {
  340.       if (super.m_Status == 1) {
  341.          this.StopProgressBar = false;
  342.          if (super.m_ItemView != null && super.m_Applet != null) {
  343.             JSObject var1 = JSObject.getWindow(super.m_Applet);
  344.             JSObject[] var2 = new JSObject[]{super.m_ItemView};
  345.             var1.call("animateStop", var2);
  346.          }
  347.  
  348.          this.crawler.setStopUpdate();
  349.       }
  350.  
  351.    }
  352.  
  353.    public static synchronized boolean canICrawl(boolean var0) {
  354.       if (m_NumUpdates >= UPDATE_MAX && !var0) {
  355.          return false;
  356.       } else {
  357.          ++m_NumUpdates;
  358.          return true;
  359.       }
  360.    }
  361.  
  362.    public void openCache() {
  363.       this.m_Cache = new Cache("//", this.m_CacheFileName, this.m_CacheName, super.m_MaxSize);
  364.    }
  365.  
  366.    public void clearCache() {
  367.       PrivilegeManager.enablePrivilege("Netcaster");
  368.       this.m_Cache = new Cache("//", this.m_CacheFileName, this.m_CacheName, super.m_MaxSize);
  369.       this.m_Cache.clear();
  370.    }
  371. }
  372.