import ACM.*; import java.io.*; import java.awt.*; import java.net.*; public class CollectionPlug { public boolean flagmore = false; //true means there are more results public short docs_stored = 0; //How many docs the parser has found public int how_many_prop = 5; public String thefinalquery = ""; private boolean already_got_p; private Doc[] tdocs = new Doc[100]; private short total = 0; private static String add_url_object = "http://www.acm.org"; private static String url_header = "http://www.acm.org/pubs/toc/toc-search.cgi?Pattern="; private static String url_tail = "&Boolean=AND&Partial=No&Limit="; private boolean[] properties = new boolean[5]; // What properties I have // entry0 title // entry1 author // entry2 abstract // entry3 url // entry4 transcript url public CollectionPlug () { for(int i=0;i<5;i++) properties[i] = false; how_many_prop = 0; return; } public void SetProperties (String[] prop) { int aux; how_many_prop = 0; if (prop.length == 0) { //if prop is an empty list, then all the properties in Doc!! for(int i=0;i")) { line = dis.readLine(); //System.out.println("j=" + j); //System.out.println(line); if (j==-3) { //We have found docs.... //Getting docs one by one and storing them in tdocs if (LineIsBeginDoc(line)) { tdocs[counter++] = GetDoc(dis);//reads from dis.readLine //the doc object //the next line should //be

or


//or the end


} else { j = -4; //That's all!! } } if (j==-2) { //Are there more docs? //Looking for

Actual number of matches is //greater than specified max. flagmore = getFlagMore(line); if (flagmore) { line= dis.readLine(); //discard rest of the message } j = -3; } if (j==-1) { //Getting number of docs found total = getTotalDocs(line); if (total != -1) { //There are docs j = -2; counter = 0; } } } System.out.println("Total docs found:" + total); System.out.println("Docs found by the parser: " + docs_stored); if (this.total > this.docs_stored) { // This means we have a parser problem and we are not // able to get all the docs, or the connection went down // just in the middle of the transmission // So, we set the flag to: yet more docs to come this.flagmore = true; } // now we remove the old ones. The ones we send in the // previous connection. Remember, this is a RequestItems if ((docs_stored - last) < 1) { // No new docs found remove_all(); this.flagmore = false; return(0); } total = (short)(total - last); remove_old(last); docs_stored = (short)(docs_stored - last); return(docs_stored); // Here, maybe we should return // total instead ?????? // To prevent errors it's better // docs_stored, since is the actual // number of found docs. } public short connect( String k, String h) throws Exception { //k: list of keywords; h: stop at the h first matches String url = ""; Object content; String result; URLConnection mycon; int counter = 0; //Setting url k = k.replace(' ','+'); url = url_header; url = url.concat(k); url = url.concat(url_tail); this.thefinalquery = url; url = url.concat(h); System.out.println("\nSending URL:\n" + url); URL myURL = new URL(url); mycon = myURL.openConnection(); mycon.setRequestProperty("Authorization","Basic Z2VyYXJkQGRiLnN0YW5mb3JkLmVkdTo="); System.out.println("Authorization" + mycon.getRequestProperty("Authorization")); mycon.connect(); DataInputStream dis = new DataInputStream(mycon.getInputStream()); String line = dis.readLine(); short j = -1; while (!line.equals("")) { line = dis.readLine(); if (j==-3) { //We have found docs.... //Getting docs one by one and storing them in tdocs if (LineIsBeginDoc(line)) { tdocs[counter++] = GetDoc(dis);//reads from dis.readLine //the doc object //the next line should //be

or


//or the end


} else { j = -4; //That's all!! } } if (j==-2) { //Are there more docs? //Looking for

Actual number of matches is //greater than specified max. flagmore = getFlagMore(line); if (flagmore) { line= dis.readLine(); //discard rest of the message } j = -3; } if (j==-1) { //Getting number of docs found total = getTotalDocs(line); if (total != -1) { //There are docs j = -2; counter = 0; } } } System.out.println("Total docs found:" + total); System.out.println("Docs found by the parser: " + docs_stored); if (this.total > this.docs_stored) { // This means we have a parser problem and we are not // able to get all the docs, or the connection went down // just in the middle of the transmission // So, we set the flag to: yet more docs to come this.flagmore = true; } return(this.docs_stored); // Here, maybe we should return // total instead ?????? // To prevent errors it's better // docs_stored, since is the actual // number of found docs. } public String[] SetValuesProperties (short p) { String[] aux = new String[this.how_many_prop]; int j = 0; if (properties[0]) { aux[j++] = tdocs[p].title; } if (properties[1]) { aux[j++] = tdocs[p].author; } if (properties[2]) { aux[j++] = tdocs[p].vabstract; } if (properties[3]) { aux[j++] = tdocs[p].url; } if (properties[4]) { aux[j] = tdocs[p].url2; } return aux; } public String[] SetValuesProperties (short p, String[] propnames) { String[] aux = new String[propnames.length]; if ( !(my_props(propnames)) ) return aux; int j = 0; for(int i=0; i } line = dis.readLine();//Gets the title index = line.indexOf(""); if ( index == 0) { index = line.indexOf(""); //We've got the line where the doc begins try { ltitle = line.substring(3, index); } catch (Exception e) { System.out.println("Error parsing the line" + e); return object; } } else { return object; } line = dis.readLine();//Gets
line = dis.readLine();//Gets the authors index = line.indexOf("
"); if (index == -1) { return object; } else { try { lauthor = line.substring(0,index); } catch (Exception e) { System.out.println("Error parsing the line" + e); return object; } } line = dis.readLine();//Gets the abstract index = line.indexOf("
"); if (index == -1) { return object; } else { try { labstract = line.substring(0,index); } catch (Exception e) { System.out.println("Error parsing the line" + e); return object; } } line = dis.readLine();//Gets the url index = line.indexOf(""); lurl = add_url_object; String aux2 = aux.substring(0,index -1); lurl = lurl.concat(aux2); //now we try to get the second url aux = aux.substring(index +1,aux.length()); index = aux.indexOf(""); lurl2 = add_url_object; aux2 = aux.substring(0,index); lurl2 = lurl2.concat(aux2); line = dis.readLine();//Gets

} } catch (Exception e) { System.out.println("Error parsing the line" + e); return object; } } object.Doc(ltitle,lauthor,labstract,lurl,lurl2); //System.out.println("The Object is: " + object.toString()); docs_stored++; return object; } private boolean LineIsBeginDoc (String line) { int index = -1; index = line.indexOf("


"); if ( index == 0) { //We've got the line where the doc begins already_got_p = false; return true; } index = line.indexOf("


"); if ( index == 0) { //We've got the end of results return false; } index = line.indexOf("

"); if ( index == 0) { //We've got the line where the doc begins already_got_p = true; return true; } return false; } private boolean getFlagMore(String line) { int index = -1; index = line.indexOf("

Actual number of matches is greater than"); if ( index == 0) { //We've got the line where the number documents is return true; } return false; } private short getTotalDocs(String line) { int index = -1; String aux; index = line.indexOf("

Found"); if ( index == 0) { //We've got the line where the number documents is try { index = line.indexOf(" "); //System.out.println("Index of documents: " + index); aux = line.substring(index + 1); //System.out.println(aux); index = aux.indexOf(" "); aux = aux.substring(0, index); //System.out.println(aux); } catch (Exception e) { System.out.println("Error parsing the line" + e); return -1; } return (Short.parseShort(aux)); } return -1; } }