GetLinks

Class getlinks is used by the class pull to actually get the files from the URL. Class pull downloads the index/homepage from the net, scans it for references to the URL and passes the references as an array of strings to the method createlinks( ) in this class. Method createlinks, recursively for each link/reference, calls itself to get the file and uses class stringsearch to get a list of links for that file.

// filename getLinks.java

import java.io.*; import java.net.*; public class getLinks { stringSearch str1 = new stringSearch( ); CConnection cc1 = new CConnection( ); int filecntr = 0; public getLinks( ) //constructor for future consideration { } public void createLink(String[ ] filename1) throws Exception { String recursiveFiles[ ], webPage_hd; recursiveFiles = new String[400]; boolean Addrs; URL u2; int count2 = str1.nlinks; for(int ii = 0;ii < count2; ii++) { // coding done taking html format into consideration. // For javascript, etc. add/modify the code. Addrs = filename1[ii].regionMatches(true,0,"http://",0,7); // System.out.println("Addrs -> "+Addrs); if(Addrs == true) { u2 = new URL(filename1[ii]); filename1[ii] = settrims.mytrims(filename1[ii]); } else { if(filename1[ii].lastIndexOf(".gif") !=-1 || filename1[ii].lastIndexOf(".jpg") !=-1) { System.out.println("new URL for images"+filename1[ii]); if(filename1[ii].startsWith("..",0)) filename1[ii] = filename1[ii].substring(2); sint.urlname = sint.urlname.substring(0,(sint.urlname.indexOf('/')+1)); u2 = new URL("http://"+sint.urlname+filename1[ii]); //HTTP URL } else u2 = new URL(InetClient.u,filename1[ii]); //Partial URL } String xx = filename1[ii].trim( ); int max; int backslash = xx.lastIndexOf('\\'); int forslash = xx.lastIndexOf('/'); if(backslash>forslash) max = backslash; else max = forslash; xx = xx.substring(max+1); if(settrims.xnoloops(xx)) { webPage_hd = cc1.getwebPage(u2,filename1[ii]); InetClient.globalfiledbase[InetClient.fileindex] = xx; filecntr++; if(filecntr == 8) { filecntr = 0; InetClient.print("\n\n"); } InetClient.print(" "+xx); InetClient.fileindex++; if(webPage_hd.lastIndexOf(".htm")!=-1) { recursiveFiles = str1.strSearch(webPage_hd); createLink(recursiveFiles); } } } //ends for loop } }

next >>

Index