#!/bin/sh
# $Id$
# elvis: javasun		-- Search Java API docs (java.sun.com)
. surfraw || exit 1

w3_config_hook () {
    def SURFRAW_java_product se
    def SURFRAW_java_version 6
}

w3_usage_hook () {
    cat <<EOF
Usage: $w3_argv0 [options] [search words]...
Description:
  Search Sun Java API docs (java.sun.com)
Local options:
  -v 				Java API version (1.2, 1.3, 1.4, 5, 6)
  -p 				Java product (se, ee, me)
EOF

    w3_global_usage
}

w3_parse_option_hook () {
    opt="$1"
    optarg="$2"
    case "$opt" in
    -v*) setopt SURFRAW_java_version $optarg ;;
    -p*) setopt SURFRAW_java_product $optarg ;;
     *) return 1 ;;
    esac
    return 0
}

w3_config
w3_parse_args "$@"

case "$SURFRAW_java_product" in
    [sS][eE])
	case "$SURFRAW_java_version" in
	    6) JAVA_SITE="javase/6/docs/api" ;;
	    5) JAVA_SITE="j2se/1.5.0/docs/api" ;;
	    1.4) JAVA_SITE="j2se/1.4.2/docs/api" ;;
	    1.3) JAVA_SITE="j2se/1.3/docs/api" ;;
	    *)
		echo "Docs for J2SE $SURFRAW_java_version are not available"
		exit 1 ;;
	esac ;;
	
    [eE][eE])
	case "$SURFRAW_java_version" in
	    6|5) JAVA_SITE="javaee/5/docs/api" ;;
	    1.4) JAVA_SITE="j2ee/1.4/docs/api" ;;
	    1.3) JAVA_SITE="j2ee/sdk_1.3/techdocs/api" ;;
	    1.2) JAVA_SITE="j2ee/sdk_1.2.1/techdocs/api" ;;
	    *) echo "Docs for J2EE $SURFRAW_java_version are not available"
	esac ;;

    [mM][eE])
	JAVA_SITE="j2me/docs" ;;
    *)
	echo "$SURFRAW_java_product is not a valid Java product"
	exit 1 ;;
esac

if test -z "$w3_args"; then
    w3_browse_url "http://download.oracle.com/${JAVA_SITE}"
else
    button=`w3_url_escape "I'm Feeling Lucky"`
    escaped_args=`w3_url_of_arg $w3_args`
    w3_browse_url "http://www.google.com/search?q=${escaped_args}&sitesearch=download.oracle.com/${JAVA_SITE}&btnI=${button}"
fi
