00001 package org.hfbk.util; 00002 00003 import java.io.File; 00004 import java.io.IOException; 00005 import java.net.URL; 00006 00007 import org.dronus.graph.Node; 00008 import org.hfbk.vis.Prefs; 00009 import org.hfbk.vis.source.Source; 00010 00011 public class Updater { 00012 00013 static final String visPath = "VisClient/"; 00014 00015 static final String sourcePath = "org/hfbk/vis/source"; 00016 00017 public static void update() { 00018 System.out.print("Checking for sources update.. "); 00019 Source s= Source.getSource(Prefs.current.baseURL 00020 + "graph.php?action=getgraph&source=files&path=" + visPath 00021 + sourcePath); 00022 try { 00023 s.join(); 00024 } catch (InterruptedException e) { 00025 throw new RuntimeException(e); 00026 } 00027 00028 Node root = s.graph.getRoot(); 00029 00030 boolean updated=false; 00031 00032 for (Node file : root.getFromNodes()) 00033 if (file.type.equals("URL") 00034 && file.text.matches("Source.*\\.class")) { 00035 File target = new File(sourcePath + "/" + file.text); 00036 if (!target.exists()|| target.lastModified() / 1000 < Long.parseLong(file.getSubNodeText("date"))) 00037 try { 00038 updated=true; 00039 URL url = new URL(Prefs.current.baseURL + visPath + sourcePath + "/" + file.text); 00040 HTTPUtils.download(url, target); 00041 } catch (IOException e) { 00042 throw new RuntimeException(e); 00043 } 00044 } 00045 if(!updated) System.out.println("already up to date!"); 00046 } 00047 00048 public static void main(String[] args) { 00049 Updater.update(); 00050 } 00051 00052 }