void putToSite() { // get full path of current buffer: String fullPath = buffer.getPath(); String here = fullPath; // chop off the /filename part: int i = here.lastIndexOf("/"); if (i > 0) here = here.substring(0,i); boolean searching = true; File f = null; while (searching) { // normalize path: if (here.equals("/")) here = ""; // look for site definition: f = new File(here + "/.site"); // if we can read a site definition or we're at the root, stop: if (f.canRead() || here.equals("")) searching = false; else { // walk up the directory tree: i = here.lastIndexOf("/"); if (i > 0) here = here.substring(0,i); else searching = false; } } if (f.canRead()) { // read the location from the site definition: BufferedReader br = new BufferedReader(new FileReader(f)); String site = br.readLine(); // strip trailing / if present: i = site.lastIndexOf("/"); if (i == site.length()-1) site = site.substring(0,i); // strip site root from path: int l = here.length(); int f = fullPath.length(); String relPath = fullPath.substring(l,f); exec("cp "+fullPath+" "+site+relPath); } } putToSite();