FileDocCategorySizeDatePackage
SuiteDownloadInfo.javaAPI DocJ2ME MIDP 2.05492Thu Nov 07 12:02:24 GMT 2002com.sun.midp.dev

SuiteDownloadInfo

public class SuiteDownloadInfo extends Object
This class represents the Information need to download a MIDlet suite and display it to a user, in a list.

Fields Summary
String
url
URL for the JAD of this suite
String
label
label to display to the User for this suite
Constructors Summary
SuiteDownloadInfo(String theUrl, String theLabel)
Constructs a SuiteDownloadInfo.

param
theUrl URL for this suite
param
theLabel label for this suite

        url = theUrl;
        label = theLabel;
    
Methods Summary
private static booleanfindChar(java.io.InputStreamReader page, char targetChar)
Find the next given char in an HTML page move past it.

param
page HTML page to be read
param
targetChar char to move past
return
true if string found, else false
exception
IOException is thrown if any error prevents the download of the HTML page.

        int currentChar;

        currentChar = page.read();
        while (Character.toLowerCase((char)currentChar) != targetChar) {
            if (currentChar == -1) {
                return false;
            }

            currentChar = page.read();
        }

        return true;
    
private static booleanfindString(java.io.InputStreamReader page, java.lang.String targetString)
Find the next given string in an HTML page move past it.

param
page HTML page to be read
param
targetString string to move past
return
true if string found, else false
exception
IOException is thrown if any error prevents the download of the HTML page.

        for (int i = 0; i < targetString.length(); i++) {
            if (!findChar(page, targetString.charAt(i))) {
                return false;
            }
        }

        return true;
    
static java.util.VectorgetDownloadInfoFromPage(java.io.InputStreamReader page)
Read a HTML page and pickout the links for MIDlet suites. A MIDlet suite links end with .jad

param
page HTML page to be read
return
vector of URL/Label pairs
exception
IOException is thrown if any error prevents the download of the HTML page.

        Vector suites = new Vector();
        SuiteDownloadInfo info;
        
        info = getNextJadLink(page);
        while (info != null) {
            if (info.url.endsWith(".jad") ||
                    info.url.endsWith(".jar")) {
                suites.addElement(info);
            }

            info = getNextJadLink(page);
        }

        return suites;
    
private static com.sun.midp.dev.SuiteDownloadInfogetNextJadLink(java.io.InputStreamReader page)
Read a HTML page and pickout next link.

param
page HTML page to be read
return
URL/Label pair
exception
IOException is thrown if any error prevents the download of the HTML page.

        String url;
        String label;

        url = getNextUrl(page);
        if (url == null) {
            return null;
        }

        label = getNextLabel(page);
        if (label == null) {
            label = url;
        }

        return new SuiteDownloadInfo(url, label);
    
private static java.lang.StringgetNextLabel(java.io.InputStreamReader page)
Read a HTML page and pickout the text after the beginning anchor.

param
page HTML page to be read
return
label
exception
IOException is thrown if any error prevents the download of the HTML page.

        int currentChar;
        StringBuffer label;

        if (!findChar(page, '>")) {
            return null;
        }

        label = new StringBuffer();

        currentChar = page.read();
        while (currentChar != '<") {
            if (currentChar == -1) {
                return null;
            }

            label.append((char)currentChar);
            currentChar = page.read();
        }

        if (label.length() == 0) {
            return null;
        }

        return label.toString();
    
private static java.lang.StringgetNextUrl(java.io.InputStreamReader page)
Read a HTML page and pickout next href.

param
page HTML page to be read
return
URL
exception
IOException is thrown if any error prevents the download of the HTML page.

        int currentChar;
        StringBuffer url;

        if (!findString(page, "href=\"")) {
            return null;
        }

        url = new StringBuffer();

        currentChar = page.read();
        while (currentChar != '"") {
            if (currentChar == -1) {
                return null;
            }

            url.append((char)currentChar);
            currentChar = page.read();
        }

        if (url.length() == 0) {
            return null;
        }

        return url.toString();