Format

Class format formats the .htm files pulled from the net. These files are to be transferred over to the client. Formatting of the html tags have to be performed for the purposes explained below.

Method clipper accesses the globalfiledbase for the names of the files (both .htm and gif/jpg). It opens each .htm file and checks for the strings "<A HREF=" and "<IMG SRC=" representing the tags for the .htm and image files respectively.

1.       If the .htm filename does not contain the reference substring, e.g. "spor", they will not be pulled by the application and since such files were not pulled, they will not be available to a browser at the client end.

It is therefore necessary that the tag is not recognised by the browser when the mouse pointer tries to bring it into the focus. If the tag itself is corrupted the browser will not recognise it.

Method clipper( ) replaces the ending characters "f=" with spaces thereby corrupting the tag.

e. g.

<a href="http://www.timesofindia.com/pagepolitics.htm"><img src="../images/politics.gif"></a>

after clipping becomes

<a hre                                                 pagepolitics.htm"><img src="               politics.gif"></a>

2.       Even if the .htm filename does contain the reference substring, e.g. "spor", and if such files were pulled and transferred over to the client machine, they will not be available to a browser at the intranet client since the tag gives an URL as the source of the files even if they are available on the client machine. If the protocol, the host name and the path is clipped and only the filename is left out, the browser will pick the files from the local directory. Method clipper( ) replaces the protocol, host name and the path with spaces leaving out only the filename.

e. g.

<A HREF="http://www.timesofindia.com/today/pagespor/spor2.htm">
<IMG SRC="..\images\next.gif" ></A>

after clipping becomes
<A HREF="                                                                     spor2.htm">
<IMG SRC="               next.gif"></A>

//filename format.java
import java.io.*; import java.util.*; import java.lang.*; public class format { public static void clipper( ) throws Exception { String sr = "<A HRE"; String sr1 = "<IMG S"; String arraytostring; char aa[ ]; int i = 0; int j = 0; int k; int ptr,ptr1,clipchars; int count = 0; int z,old=0,new1=0; char myfile[ ]; myfile = new char[100]; String strlinknames[ ]; strlinknames = new String[400]; // contents of myfile array,after converting InetClient.print("\n "); InetClient.print("\n_____________________________________"); int o; InetClient.print("\nclipping files:\n "); try { int htm_cntr = 0; for(o=0; o< InetClient.fileindex; o++) { if(InetClient.globalfiledbase[o].lastIndexOf(".htm")!=-1) { //Skipping this file if (InetClient.f_modified[o] == false) continue; InetClient.print(" "+InetClient.globalfiledbase[o]); htm_cntr++; if (htm_cntr == 8) { InetClient.print("\n\n"); htm_cntr =0; } FileInputStream fip = new FileInputStream(InetClient.globalfiledbase[o]); FileOutputStream fop = new FileOutputStream("dummy.htm"); File fp = new File(InetClient.globalfiledbase[o]); int g; aa = new char[6]; if(fp.exists( ) && fp.isFile( )) //&& fp.canRead( )) { while((g = fip.read( ))!=-1) { fop.write(g); for(k=1;k<=5;k++) { aa[k-1] = Character.toUpperCase(aa[k]); } aa[5] = Character.toUpperCase((char)g); //aa[7] arraytostring = new String(aa); ptr = sr.compareTo(arraytostring); ptr1 = sr1.compareTo(arraytostring); arraytostring=arraytostring.trim( ); if(ptr*ptr1 == 0) { char bb[ ] = new char[300]; int b; for(int gg=0;gg<300;gg++) bb[gg] = 0; b=0; //waits till it gets 1st " while((i=fip.read( ))!='"') { bb[b] = (char)i; b++; } if(i=='"') { bb[b] = (char)i; b++; }//end if " count=0;//reinitialisation while((i=fip.read( ))!='"') //waits till it gets 2nd " { myfile[count] = (char)i; //copies contents betn " " count++; //i.e. copies file/addrsname }//end while 1 String myfiletostring; //#1 myfiletostring = new String(myfile); //#1 myfiletostring = myfiletostring.trim( ); String random = myfiletostring; old = myfiletostring.length( ); myfiletostring = myfiletostring.toLowerCase(Locale.getDefault( )); int greater,forslash,backslash; forslash = myfiletostring.lastIndexOf('\\'); backslash =myfiletostring.lastIndexOf('/'); if(forslash>backslash) { greater=forslash; } else { greater=backslash; } myfiletostring=myfiletostring.substring(greater+1); int gg; int value = myfiletostring.lastIndexOf(sint.refstr);//"spor"); if((ptr == 0 && value != -1)||ptr1==0) { for(int kk=0;kk < b;kk++) fop.write(bb[kk]); } else { for(int kk=0;kk < b;kk++) fop.write(' '); } new1 = myfiletostring.length( ); clipchars = old - new1; if((ptr == 0 && value != -1)||ptr1==0) { int hh = clipchars ; for(int oo=0;oo < hh;oo++) fop.write(' '); for(gg=0;gg < myfiletostring.length( );gg++) { fop.write((int)myfiletostring.charAt(gg)); } } else{ for(gg=0;gg < random.length( );gg++) { fop.write((int)random.charAt(gg)); } } fop.write('"'); for(z=0;z < 100;z++) //To ensure that array is cleared run **ak352.java myfile[z]='\0'; } //end ptr 0 } //while ends // int hh = clipchars // for(int oo=0;oo < hh;oo++) // fop.write('\0'); }//end of if file fop.close( );//very important to close otherwise collects garbage from previous files fip.close( ); FileInputStream fis = new FileInputStream("dummy.htm"); int qq; FileOutputStream fos = new FileOutputStream(InetClient.globalfiledbase[o]); while((qq=fis.read( ))!=-1) { fos.write(qq); } fis.close( ); fos.close( ); }// end of if .htm test }//end for loop InetClient.print("\n"); File lost = new File("dummy.htm"); //delete last occurence of file. lost.delete( ); //InetClient.print("\n_____________________________________"); System.out.println("Clipping done!"); } catch(Exception e) { InetClient.print("In Clipper catch"+e); } } } //end of class

next >>

Index