clearwing

changeset 163:6d8910cb48cc 1.3.3-stv-gwt

..
author Stelios <stv@roe.ac.uk>
date Thu Apr 28 14:59:14 2016 +0300 (2016-04-28)
parents ab78dae03eaf
children c3ab5bef2a7e
files src/GENIUS-gwt-app/public/Genius.html src/GENIUS-gwt-app/src/WEB-INF/lib/json.jar src/GENIUS-gwt-app/src/com/genius/uk/client/AutocompleteService.java src/GENIUS-gwt-app/src/com/genius/uk/client/AutocompleteServiceAsync.java src/GENIUS-gwt-app/src/com/genius/uk/client/Genius.java src/GENIUS-gwt-app/src/com/genius/uk/server/AutocompleteServiceImpl.java src/GENIUS-gwt-app/src/com/genius/uk/server/AutocompleteServiceImplAsync.java src/GENIUS-gwt-app/war/Genius.html src/GENIUS-gwt-app/war/WEB-INF/classes/Genius.html src/GENIUS-gwt-app/war/WEB-INF/classes/adql_syntax/adql.js src/GENIUS-gwt-app/war/WEB-INF/classes/adql_syntax/tap-autocomplete.js src/GENIUS-gwt-app/war/WEB-INF/classes/adql_syntax/tap-hint.js src/GENIUS-gwt-app/war/WEB-INF/classes/com/genius/uk/client/Genius$1.class src/GENIUS-gwt-app/war/WEB-INF/classes/com/genius/uk/client/Genius$1MyHandler.class src/GENIUS-gwt-app/war/WEB-INF/classes/com/genius/uk/client/Genius.class src/GENIUS-gwt-app/war/WEB-INF/web.xml
line diff
     1.1 --- a/src/GENIUS-gwt-app/public/Genius.html	Wed Apr 13 20:48:57 2016 +0300
     1.2 +++ b/src/GENIUS-gwt-app/public/Genius.html	Thu Apr 28 14:59:14 2016 +0300
     1.3 @@ -36,7 +36,7 @@
     1.4      $( document ).ready(function() {
     1.5  	  var params = {
     1.6  	    textfieldid: "textfield",
     1.7 -	    web_service_path: 'mywebapp/greet',
     1.8 +	    web_service_path: 'mywebapp/autocomplete',
     1.9  	    html_resource: jQuery("#content_dbaccess_SQL_form #tap_endpoint").val(),
    1.10  	    tap_resource: "",
    1.11  	    autocomplete_info_id: "autocomplete_info",
     2.1 Binary file src/GENIUS-gwt-app/src/WEB-INF/lib/json.jar has changed
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/GENIUS-gwt-app/src/com/genius/uk/client/AutocompleteService.java	Thu Apr 28 14:59:14 2016 +0300
     3.3 @@ -0,0 +1,12 @@
     3.4 +package com.genius.uk.client;
     3.5 +
     3.6 +import com.google.gwt.user.client.rpc.RemoteService;
     3.7 +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
     3.8 +
     3.9 +/**
    3.10 + * The client-side stub for the RPC service.
    3.11 + */
    3.12 +@RemoteServiceRelativePath("autocomplete")
    3.13 +public interface AutocompleteService extends RemoteService {
    3.14 +	String autocompleteServer(String name) throws IllegalArgumentException;
    3.15 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/GENIUS-gwt-app/src/com/genius/uk/client/AutocompleteServiceAsync.java	Thu Apr 28 14:59:14 2016 +0300
     4.3 @@ -0,0 +1,14 @@
     4.4 +package com.genius.uk.client;
     4.5 +
     4.6 +import javax.servlet.Servlet;
     4.7 +
     4.8 +import com.google.gwt.user.client.rpc.AsyncCallback;
     4.9 +import com.google.gwt.user.client.rpc.RemoteService;
    4.10 +import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
    4.11 +
    4.12 +/**
    4.13 + * The async counterpart of <code>AutocompleteService</code>.
    4.14 + */
    4.15 +public interface AutocompleteServiceAsync{
    4.16 +	void autocompleteServer(String input, AsyncCallback<String> callback) throws IllegalArgumentException;
    4.17 +}
     5.1 --- a/src/GENIUS-gwt-app/src/com/genius/uk/client/Genius.java	Wed Apr 13 20:48:57 2016 +0300
     5.2 +++ b/src/GENIUS-gwt-app/src/com/genius/uk/client/Genius.java	Thu Apr 28 14:59:14 2016 +0300
     5.3 @@ -26,9 +26,9 @@
     5.4  			+ "attempting to contact the server. Please check your network " + "connection and try again.";
     5.5  
     5.6  	/**
     5.7 -	 * Create a remote service proxy to talk to the server-side Greeting service.
     5.8 +	 * Create a remote service proxy to talk to the server-side Autocomplete service.
     5.9  	 */
    5.10 -	private final GreetingServiceAsync greetingService = GWT.create(GreetingService.class);
    5.11 +	private final AutocompleteServiceAsync autocompleteService = GWT.create(AutocompleteService.class);
    5.12  
    5.13  	
    5.14  	/**
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/GENIUS-gwt-app/src/com/genius/uk/server/AutocompleteServiceImpl.java	Thu Apr 28 14:59:14 2016 +0300
     6.3 @@ -0,0 +1,45 @@
     6.4 +package com.genius.uk.server;
     6.5 +
     6.6 +import com.genius.uk.client.AutocompleteService;
     6.7 +import com.genius.uk.shared.FieldVerifier;
     6.8 +import com.google.gwt.user.server.rpc.RemoteServiceServlet;
     6.9 +
    6.10 +/**
    6.11 + * The server-side implementation of the RPC service.
    6.12 + */
    6.13 +@SuppressWarnings("serial")
    6.14 +public class AutocompleteServiceImpl extends RemoteServiceServlet implements AutocompleteService {
    6.15 +
    6.16 +	public String autocompleteServer(String input) throws IllegalArgumentException {
    6.17 +		// Verify that the input is valid. 
    6.18 +		if (!FieldVerifier.isValidName(input)) {
    6.19 +			// If the input is not valid, throw an IllegalArgumentException back to
    6.20 +			// the client.
    6.21 +			throw new IllegalArgumentException("Name must be at least 4 characters long");
    6.22 +		}
    6.23 +
    6.24 +		String serverInfo = getServletContext().getServerInfo();
    6.25 +		String userAgent = getThreadLocalRequest().getHeader("User-Agent");
    6.26 +
    6.27 +		// Escape data from the client to avoid cross-site script vulnerabilities.
    6.28 +		input = escapeHtml(input);
    6.29 +		userAgent = escapeHtml(userAgent);
    6.30 +
    6.31 +		return "Hello, " + input + "!<br><br>I am running " + serverInfo + ".<br><br>It looks like you are using:<br>"
    6.32 +				+ userAgent;
    6.33 +	}
    6.34 +
    6.35 +	/**
    6.36 +	 * Escape an html string. Escaping data received from the client helps to
    6.37 +	 * prevent cross-site script vulnerabilities.
    6.38 +	 * 
    6.39 +	 * @param html the html string to escape
    6.40 +	 * @return the escaped string
    6.41 +	 */
    6.42 +	private String escapeHtml(String html) {
    6.43 +		if (html == null) {
    6.44 +			return null;
    6.45 +		}
    6.46 +		return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
    6.47 +	}
    6.48 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/GENIUS-gwt-app/src/com/genius/uk/server/AutocompleteServiceImplAsync.java	Thu Apr 28 14:59:14 2016 +0300
     7.3 @@ -0,0 +1,264 @@
     7.4 +package com.genius.uk.server;
     7.5 +
     7.6 +import javax.servlet.annotation.WebServlet;
     7.7 +
     7.8 +import com.genius.uk.client.AutocompleteServiceAsync;
     7.9 +import com.genius.uk.shared.FieldVerifier;
    7.10 +import com.google.gwt.user.client.rpc.AsyncCallback;
    7.11 +
    7.12 +import java.io.IOException;
    7.13 +import java.io.PrintWriter;
    7.14 +import java.net.URL;
    7.15 +import java.net.URLEncoder;
    7.16 +import java.util.ArrayList;
    7.17 +import java.util.Enumeration;
    7.18 +import java.util.Random;
    7.19 +
    7.20 +import javax.servlet.ServletException;
    7.21 +import javax.servlet.http.HttpServlet;
    7.22 +import javax.servlet.http.HttpServletRequest;
    7.23 +import javax.servlet.http.HttpServletResponse;
    7.24 +
    7.25 +import org.json.JSONArray;
    7.26 +import org.json.JSONException;
    7.27 +import org.json.JSONObject;
    7.28 +
    7.29 +import java.io.IOException;
    7.30 +import java.net.MalformedURLException;
    7.31 +import java.net.URI;
    7.32 +import java.net.URL;
    7.33 +import java.sql.SQLException;
    7.34 +import java.util.Iterator;
    7.35 +
    7.36 +import uk.ac.starlink.table.RowSequence;
    7.37 +import uk.ac.starlink.table.StarTable;
    7.38 +import uk.ac.starlink.table.StoragePolicy;
    7.39 +import uk.ac.starlink.table.TableFormatException;
    7.40 +import uk.ac.starlink.util.URLDataSource;
    7.41 +import uk.ac.starlink.votable.VOTableBuilder;
    7.42 +
    7.43 +/**
    7.44 + * The server-side implementation of the RPC service.
    7.45 + */
    7.46 +@SuppressWarnings("serial")
    7.47 +@WebServlet(name = "AutocompleteImplAsync", urlPatterns = { "/autocompleteAsync" })
    7.48 +public class AutocompleteServiceImplAsync extends HttpServlet {
    7.49 +
    7.50 +	@Override
    7.51 +	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    7.52 +		handleRequest(req, res);
    7.53 +	}
    7.54 +
    7.55 +	@Override
    7.56 +	protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    7.57 +		handleRequest(req, res);
    7.58 +
    7.59 +	}
    7.60 +
    7.61 +	/**
    7.62 +	 * Handle a request
    7.63 +	 * 
    7.64 +	 * @param req
    7.65 +	 * @param res
    7.66 +	 * @throws IOException
    7.67 +	 */
    7.68 +	public void handleRequest(HttpServletRequest req, HttpServletResponse res) throws IOException {
    7.69 +
    7.70 +		res.setContentType("application/json");
    7.71 +		res.setCharacterEncoding("UTF-8");
    7.72 +
    7.73 +		PrintWriter out = res.getWriter();
    7.74 +
    7.75 +		String lang = "ADQL";
    7.76 +		String tapformat = "VOTABLE";
    7.77 +		String request = "doQuery";
    7.78 +		String keyword = (req.getParameter("keyword") == null) ? "" : req.getParameter("keyword");
    7.79 +		String mode = (req.getParameter("mode") == null) ? "" : req.getParameter("mode");
    7.80 +		String keyword_type = (req.getParameter("keyword_type") == null) ? "" : req.getParameter("keyword_type");
    7.81 +		String optional_keyword = (req.getParameter("optional_keyword") == null) ? ""
    7.82 +				: req.getParameter("optional_keyword");
    7.83 +		String optional_catalogues = (req.getParameter("optional_catalogues") == null) ? ""
    7.84 +				: req.getParameter("optional_catalogues");
    7.85 +		String query = "";
    7.86 +		String tapService = "http://www.cadc-ccda.hia-iha.nrc-cnrc.gc.ca/tap/";
    7.87 +
    7.88 +		JSONArray array = new JSONArray();
    7.89 +		int count_dots = keyword.length() - keyword.replace(".", "").length();
    7.90 +
    7.91 +		if (keyword_type.toLowerCase() == "schema") {
    7.92 +			query = "SELECT table_name FROM TAP_SCHEMA.tables WHERE schema_name='" + keyword + "'";
    7.93 +			if (optional_keyword != null && optional_keyword != "") {
    7.94 +				query += " AND (table_name LIKE '" + optional_keyword + "%' OR table_name LIKE '"
    7.95 +						+ keyword + "." + optional_keyword + "%')";
    7.96 +			}
    7.97 +			String queryURLStr = tapService + "/sync?REQUEST=doQuery&VERSION=1.0&LANG=ADQL&QUERY="
    7.98 +					+ URLEncoder.encode(query, "UTF-8");
    7.99 +			queryURLStr = queryURLStr.replaceAll(" ", "%20");
   7.100 +			array = starTableToJSONArray(urlToStartable(queryURLStr));
   7.101 +			if (optional_keyword != null && optional_keyword != "") {
   7.102 +				array = filter_name(array, optional_keyword);
   7.103 +			}
   7.104 +		} else if (keyword_type.toLowerCase() == "table" || (count_dots >= 2)) {
   7.105 +
   7.106 +			query = "SELECT column_name FROM TAP_SCHEMA.columns WHERE table_name LIKE '%." + keyword
   7.107 +					+ "' OR  table_name='" + keyword + "'";
   7.108 +			if (optional_keyword != null && optional_keyword != "") {
   7.109 +				query += " AND (column_name LIKE '" + optional_keyword + "%' OR column_name LIKE '"
   7.110 +						+ keyword + "." + optional_keyword + "%')";
   7.111 +			}
   7.112 +			String queryURLStr = tapService + "/sync?REQUEST=doQuery&VERSION=1.0&LANG=ADQL&QUERY="
   7.113 +					+ URLEncoder.encode(query, "UTF-8");
   7.114 +			queryURLStr = queryURLStr.replaceAll(" ", "%20");
   7.115 +			array = starTableToJSONArray(urlToStartable(queryURLStr));
   7.116 +
   7.117 +		} else if (keyword != "") {
   7.118 +
   7.119 +			query = "SELECT table_name FROM TAP_SCHEMA.tables WHERE schema_name='" + keyword + "'";
   7.120 +			if (optional_keyword != null && optional_keyword != "") {
   7.121 +				query += " AND (table_name LIKE '" + optional_keyword + "%' OR table_name LIKE '"
   7.122 +						+ keyword + "." + optional_keyword + "%')";
   7.123 +			}
   7.124 +			String queryURLStr = tapService + "/sync?REQUEST=doQuery&VERSION=1.0&LANG=ADQL&QUERY="
   7.125 +					+ URLEncoder.encode(query, "UTF-8");
   7.126 +			queryURLStr = queryURLStr.replaceAll(" ", "%20");
   7.127 +			array = starTableToJSONArray(urlToStartable(queryURLStr));
   7.128 +			if (array.length() <= 0) {
   7.129 +
   7.130 +				query = "SELECT column_name FROM TAP_SCHEMA.columns WHERE table_name LIKE '%." + keyword
   7.131 +						+ "' OR  table_name='" + keyword + "'";
   7.132 +				if (optional_keyword != null && optional_keyword != "") {
   7.133 +					query += " AND (column_name LIKE '" + optional_keyword + "%' OR column_name LIKE '"
   7.134 +							+ keyword + "." + optional_keyword + "%')";
   7.135 +
   7.136 +				}
   7.137 +				queryURLStr = tapService + "/sync?REQUEST=doQuery&VERSION=1.0&LANG=ADQL&QUERY="
   7.138 +						+ URLEncoder.encode(query, "UTF-8");
   7.139 +				queryURLStr = queryURLStr.replaceAll(" ", "%20");
   7.140 +				array = starTableToJSONArray(urlToStartable(queryURLStr));
   7.141 +
   7.142 +			}
   7.143 +		
   7.144 +			if (optional_keyword != null && optional_keyword != "") {
   7.145 +				array = filter_name(array, optional_keyword);
   7.146 +			}
   7.147 +			
   7.148 +		} else {
   7.149 +			try {
   7.150 +				if (optional_catalogues != "" && optional_catalogues != null) {
   7.151 +
   7.152 +					JSONArray json_array = new JSONArray(optional_catalogues);
   7.153 +
   7.154 +					for (int i = 0; i < json_array.length(); i++) {
   7.155 +
   7.156 +						query = "SELECT table_name FROM TAP_SCHEMA.tables WHERE schema_name='" + json_array.get(i)
   7.157 +								+ "'";
   7.158 +						String queryURLStr = tapService + "/sync?REQUEST=doQuery&VERSION=1.0&LANG=ADQL&QUERY="
   7.159 +								+ URLEncoder.encode(query, "UTF-8");
   7.160 +						queryURLStr = queryURLStr.replaceAll(" ", "%20");
   7.161 +						JSONArray newArray = starTableToJSONArray(urlToStartable(queryURLStr));
   7.162 +						for (int y = 0; y < newArray.length(); y++) {
   7.163 +							array.put(newArray.get(y));
   7.164 +						}
   7.165 +					}
   7.166 +
   7.167 +				} else {
   7.168 +					query = "SELECT schema_name FROM TAP_SCHEMA.schemas";
   7.169 +					String queryURLStr = tapService + "/sync?REQUEST=doQuery&VERSION=1.0&LANG=ADQL&QUERY="
   7.170 +							+ URLEncoder.encode(query, "UTF-8");
   7.171 +					queryURLStr = queryURLStr.replaceAll(" ", "%20");
   7.172 +					array = starTableToJSONArray(urlToStartable(queryURLStr));
   7.173 +
   7.174 +				}
   7.175 +
   7.176 +			} catch (JSONException e) {
   7.177 +				// TODO Auto-generated catch block
   7.178 +				e.printStackTrace();
   7.179 +			}
   7.180 +		}
   7.181 +
   7.182 +		out.print(array);
   7.183 +		out.flush();
   7.184 +	}
   7.185 +
   7.186 +	/**
   7.187 +	 * Given a query URL (tap/sync?...), generate a StarTable
   7.188 +	 * 
   7.189 +	 * @param queryURLStr
   7.190 +	 * @return
   7.191 +	 * @throws TableFormatException
   7.192 +	 * @throws IOException
   7.193 +	 */
   7.194 +	public StarTable urlToStartable(String queryURLStr) throws TableFormatException, IOException {
   7.195 +		URL queryURL = new URL(queryURLStr);
   7.196 +		URLDataSource source = new URLDataSource(queryURL);
   7.197 +		VOTableBuilder builder = new VOTableBuilder();
   7.198 +		StarTable star = builder.makeStarTable(source, false, StoragePolicy.getDefaultPolicy());
   7.199 +		return star;
   7.200 +	}
   7.201 +
   7.202 +	/**
   7.203 +	 * Get a JSONArray from a Startable
   7.204 +	 * 
   7.205 +	 * @param star
   7.206 +	 * @return
   7.207 +	 */
   7.208 +	public JSONArray starTableToJSONArray(StarTable star) {
   7.209 +
   7.210 +		ArrayList<String[]> keyword_list = new ArrayList<String[]>();
   7.211 +
   7.212 +		JSONArray array = new JSONArray();
   7.213 +		int nCol = star.getColumnCount();
   7.214 +		RowSequence rseq;
   7.215 +		try {
   7.216 +			rseq = star.getRowSequence();
   7.217 +
   7.218 +			while (rseq.next()) {
   7.219 +				Object[] row = rseq.getRow();
   7.220 +				for (int icol = 0; icol < nCol; icol++) {
   7.221 +					keyword_list.add(new String[] { (String) row[icol] });
   7.222 +				}
   7.223 +			}
   7.224 +			rseq.close();
   7.225 +			array = new JSONArray(keyword_list);
   7.226 +		} catch (IOException e) {
   7.227 +			// TODO Auto-generated catch block
   7.228 +			e.printStackTrace();
   7.229 +		}
   7.230 +		return array;
   7.231 +	}
   7.232 +
   7.233 +	public JSONArray filter_name(JSONArray original_list, String keyword) {
   7.234 +
   7.235 +		JSONArray filtered_list = new JSONArray();
   7.236 +
   7.237 +		for (int i = 0; i < original_list.length(); i++) {
   7.238 +
   7.239 +			String string_value = "";
   7.240 +			try {
   7.241 +			
   7.242 +				String[] item_arr =  (String[]) original_list.get(i);
   7.243 +				String item = item_arr[0];
   7.244 +
   7.245 +				// Grab the last segment
   7.246 +				string_value = item.substring(item.lastIndexOf(".") + 1);
   7.247 +
   7.248 +			} catch (Exception e) {
   7.249 +				e.printStackTrace();
   7.250 +			}
   7.251 +
   7.252 +			if (keyword != "") {
   7.253 +				if (string_value.toLowerCase().startsWith(keyword.toLowerCase())) {
   7.254 +					filtered_list.put(string_value);
   7.255 +				}
   7.256 +			} else {
   7.257 +				if (string_value!=""){
   7.258 +				    filtered_list.put(string_value);
   7.259 +				}
   7.260 +			}
   7.261 +		}
   7.262 +
   7.263 +		return filtered_list;
   7.264 +
   7.265 +	}
   7.266 +
   7.267 +}
     8.1 --- a/src/GENIUS-gwt-app/war/Genius.html	Wed Apr 13 20:48:57 2016 +0300
     8.2 +++ b/src/GENIUS-gwt-app/war/Genius.html	Thu Apr 28 14:59:14 2016 +0300
     8.3 @@ -36,16 +36,16 @@
     8.4      $( document ).ready(function() {
     8.5  	  var params = {
     8.6  	    textfieldid: "textfield",
     8.7 -	    web_service_path: 'genius/greetAsync',
     8.8 +	    web_service_path: 'genius/autocompleteAsync',
     8.9  	    html_resource: jQuery("#content_dbaccess_SQL_form #tap_endpoint").val(),
    8.10  	    tap_resource: "",
    8.11 -	    autocomplete_info_id: "autocomplete_info",
    8.12 -	    autocomplete_loader_id: "autocomplete_loader",
    8.13 +	    autocomplete_info_id: "",
    8.14 +	    autocomplete_loader_id: "",
    8.15  	    servicemode: "TAP",
    8.16 -	    initial_catalogues: ["GACS"]
    8.17 +	    initial_catalogues: ["caom2"]
    8.18  	  }
    8.19  
    8.20 -	  var autocomplete = new TapAutocomplete(params);
    8.21 +	  var autocompleteInstance = new TapAutocomplete(params);
    8.22  
    8.23      });
    8.24  
    8.25 @@ -67,7 +67,7 @@
    8.26        </div>
    8.27      </noscript>
    8.28  
    8.29 -    <h1>Web Application Starter Project</h1>
    8.30 +    <h1>Genius Autocomplete Demo</h1>
    8.31  
    8.32      <table align="center">
    8.33        <tr>
     9.1 --- a/src/GENIUS-gwt-app/war/WEB-INF/classes/Genius.html	Wed Apr 13 20:48:57 2016 +0300
     9.2 +++ b/src/GENIUS-gwt-app/war/WEB-INF/classes/Genius.html	Thu Apr 28 14:59:14 2016 +0300
     9.3 @@ -36,7 +36,7 @@
     9.4      $( document ).ready(function() {
     9.5  	  var params = {
     9.6  	    textfieldid: "textfield",
     9.7 -	    web_service_path: 'mywebapp/greet',
     9.8 +	    web_service_path: 'mywebapp/autocomplete',
     9.9  	    html_resource: jQuery("#content_dbaccess_SQL_form #tap_endpoint").val(),
    9.10  	    tap_resource: "",
    9.11  	    autocomplete_info_id: "autocomplete_info",
    10.1 --- a/src/GENIUS-gwt-app/war/WEB-INF/classes/adql_syntax/adql.js	Wed Apr 13 20:48:57 2016 +0300
    10.2 +++ b/src/GENIUS-gwt-app/war/WEB-INF/classes/adql_syntax/adql.js	Thu Apr 28 14:59:14 2016 +0300
    10.3 @@ -107,6 +107,7 @@
    10.4    }
    10.5  
    10.6    return {
    10.7 +	 
    10.8      startState: function(base) {
    10.9        return {tokenize: tokenBase,
   10.10                context: null,
    11.1 --- a/src/GENIUS-gwt-app/war/WEB-INF/classes/adql_syntax/tap-autocomplete.js	Wed Apr 13 20:48:57 2016 +0300
    11.2 +++ b/src/GENIUS-gwt-app/war/WEB-INF/classes/adql_syntax/tap-autocomplete.js	Thu Apr 28 14:59:14 2016 +0300
    11.3 @@ -29,24 +29,19 @@
    11.4      this.istap = true;
    11.5    }
    11.6  
    11.7 -  if (typeof availableTags == 'undefined') {
    11.8 -    availableTags = [];
    11.9 -  }
   11.10  
   11.11 -
   11.12 -  if (editor == null && !jQuery('.CodeMirror').length > 0) {
   11.13 +  if (this.editor == null && !jQuery('.CodeMirror').length > 0) {
   11.14      CodeMirror.commands.autocomplete = function(cm) {
   11.15        CodeMirror.tapHint(cm, CodeMirror.adqlHint, {
   11.16          webServicePath: params.web_service_path,
   11.17          tapResource: params.tap_resource,
   11.18          useAutocompleteService: (params.servicemode.toLowerCase() == "tap"),
   11.19 -	autocompleteLoader: params.autocomplete_loader_id,
   11.20 +	    autocompleteLoader: params.autocomplete_loader_id,
   11.21          autocompleteInfo: params.autocomplete_info_id,
   11.22 -       
   11.23        });
   11.24      }
   11.25  
   11.26 -    var editor = CodeMirror.fromTextArea(document.getElementById(params.textfieldid), {
   11.27 +   this.editor = CodeMirror.fromTextArea(document.getElementById(params.textfieldid), {
   11.28        mode: "text/x-adql",
   11.29        tabMode: "indent",
   11.30        lineNumbers: true,
   11.31 @@ -60,6 +55,13 @@
   11.32      });
   11.33    }
   11.34  
   11.35 +  if (typeof this.editor.availableTags == 'undefined') {
   11.36 +	  this.editor.availableTags = [
   11.37 +     		"SELECT", "FROM", "ORDER BY","WHERE", "TOP","IN", "AND", "OR", "WITH", "DESC", "ASC", "JOIN", "AS", "HAVING", "ABS",
   11.38 + 			"GROUP","BY", "INNER","OUTER","CROSS","LEFT","RIGHT","FULL","ON","USING","MIN","MAX","COUNT","DISTINCT","ALL","LIKE","ACOS","ASIN","ATAN","ATAN2","COS","SIN","TAN","COT","IS","NOT","NULL","NATURAL","EXISTS","BETWEEN","AREA","BOX","CENTROID","CIRCLE","CONTAINS","COORD1","COORD2","COORDSYS","DISTANCE","INTERSECTS","POINT","POLYGON","REGION"
   11.39 + 		];
   11.40 +  }
   11.41 +
   11.42    if (params.servicemode.toLowerCase() == "tap") {
   11.43      this.load_metadata_for_autocomplete(this.initial_catalogues);
   11.44    } else {
   11.45 @@ -74,9 +76,6 @@
   11.46   *
   11.47   */
   11.48  TapAutocomplete.prototype.push_metadata_content_html = function(data) {
   11.49 -  if (typeof availableTags == 'undefined') {
   11.50 -    availableTags = [];
   11.51 -  }
   11.52  
   11.53    var content = document.createElement('div');
   11.54    content.innerHTML = data;
   11.55 @@ -86,12 +85,12 @@
   11.56      var str = jQuery.trim(jQuery(tr[i]).justtext());
   11.57      var arr = str.split(".");
   11.58      for (var y = 0; y < arr.length; y++) {
   11.59 -      availableTags.push(arr[y]);
   11.60 +    	this.editor.availableTags.push(arr[y]);
   11.61      }
   11.62    }
   11.63    for (var i = 0; i < tr2.length; i++) {
   11.64 -    if (!contains(availableTags, tr2[i].innerHTML)) {
   11.65 -      availableTags.push(tr2[i].innerHTML);
   11.66 +    if (!contains(this.editor.availableTags, tr2[i].innerHTML)) {
   11.67 +    	this.editor.availableTags.push(tr2[i].innerHTML);
   11.68      }
   11.69    }
   11.70  
   11.71 @@ -106,15 +105,12 @@
   11.72  
   11.73  TapAutocomplete.prototype.push_metadata_json = function(data) {
   11.74    
   11.75 -  if (typeof availableTags == 'undefined') {
   11.76 -    availableTags = [];
   11.77 -  }
   11.78    if (data.length > 0) {
   11.79      for (var i = 0; i < data.length; i++) {
   11.80        var str = jQuery.trim(data[i]);
   11.81        var arr = str.split(".");
   11.82        for (var y = 0; y < arr.length; y++) {
   11.83 -        availableTags.push(arr[y]);
   11.84 +    	  this.editor.availableTags.push(arr[y]);
   11.85        }
   11.86      }
   11.87    }
   11.88 @@ -194,8 +190,8 @@
   11.89    }
   11.90  
   11.91    function push_metadata_content_html(data) {
   11.92 -    if (typeof availableTags == 'undefined') {
   11.93 -       availableTags = [];
   11.94 +	if (!_this.editor.availableTags) {
   11.95 +		_this.editor.availableTags = [];
   11.96      }
   11.97  
   11.98      var content = document.createElement('div');
   11.99 @@ -206,13 +202,13 @@
  11.100        var str = jQuery.trim(jQuery(tr[i]).text());
  11.101        var arr = str.split(".");
  11.102        for (var y = 0; y < arr.length; y++) {
  11.103 -       availableTags.push(arr[y]);
  11.104 +    	  _this.editor.availableTags.push(arr[y]);
  11.105        }
  11.106      }
  11.107  
  11.108      for (var i = 0; i < tr2.length; i++) {
  11.109 -      if (!contains(availableTags, tr2[i].innerHTML)) {
  11.110 -        availableTags.push(tr2[i].innerHTML);
  11.111 +      if (!contains(_this.editor.availableTags, tr2[i].innerHTML)) {
  11.112 +    	  _this.editor.availableTags.push(tr2[i].innerHTML);
  11.113        }
  11.114      }
  11.115  
  11.116 @@ -261,19 +257,17 @@
  11.117  
  11.118  
  11.119    function push_metadata_json(data) {
  11.120 -    if (typeof availableTags == 'undefined') {
  11.121 -       availableTags = [];
  11.122 -    }
  11.123      if (data.length > 0) {
  11.124        for (var i = 0; i < data.length; i++) {
  11.125          var str = jQuery.trim(data[i]);
  11.126          var arr = str.split(".");
  11.127          for (var y = 0; y < arr.length; y++) {
  11.128 -          availableTags.push(arr[y]);
  11.129 +        	_this.editor.availableTags.push(arr[y]);
  11.130          }
  11.131        }
  11.132      }
  11.133  
  11.134 +
  11.135    }
  11.136  
  11.137    optional_catalogues=JSON.stringify(optional_catalogues);
  11.138 @@ -294,10 +288,10 @@
  11.139      },
  11.140      success: function(data) {
  11.141  
  11.142 +
  11.143        if (data != "") {
  11.144          push_metadata_json(data);
  11.145        }
  11.146 -
  11.147        if (_this.autocomplete_info) jQuery("#" + _this.autocomplete_info).html("CTRL + Space to activate auto-complete");
  11.148        if (_this.autocomplete_loader) jQuery("#" + _this.autocomplete_loader).hide();
  11.149      }
    12.1 --- a/src/GENIUS-gwt-app/war/WEB-INF/classes/adql_syntax/tap-hint.js	Wed Apr 13 20:48:57 2016 +0300
    12.2 +++ b/src/GENIUS-gwt-app/war/WEB-INF/classes/adql_syntax/tap-hint.js	Thu Apr 28 14:59:14 2016 +0300
    12.3 @@ -41,6 +41,16 @@
    12.4      if (givenOptions["autocompleteLoader"]) editor.autocompleteLoader = givenOptions["autocompleteLoader"];
    12.5      if (givenOptions["autocompleteInfo"]) editor.autocompleteInfo = givenOptions["autocompleteInfo"];
    12.6      if (givenOptions["useAutocompleteService"]) editor.useAutocompleteService = givenOptions["useAutocompleteService"];
    12.7 +    if (givenOptions["availableTags"]){
    12.8 +    	editor.availableTags = givenOptions["availableTags"];
    12.9 +    } else {
   12.10 +    	if (!editor.availableTags){
   12.11 +    	    editor.availableTags = [
   12.12 +    	              		"SELECT", "FROM", "ORDER BY","WHERE", "TOP","IN", "AND", "OR", "WITH", "DESC", "ASC", "JOIN", "AS", "HAVING", "ABS",
   12.13 +    	          			"GROUP","BY", "INNER","OUTER","CROSS","LEFT","RIGHT","FULL","ON","USING","MIN","MAX","COUNT","DISTINCT","ALL","LIKE","ACOS","ASIN","ATAN","ATAN2","COS","SIN","TAN","COT","IS","NOT","NULL","NATURAL","EXISTS","BETWEEN","AREA","BOX","CENTROID","CIRCLE","CONTAINS","COORD1","COORD2","COORDSYS","DISTANCE","INTERSECTS","POINT","POLYGON","REGION"
   12.14 +    	          		];
   12.15 +    	}
   12.16 +    }
   12.17  
   12.18      for (var opt in defaults)
   12.19        if (defaults.hasOwnProperty(opt)) {
   12.20 @@ -49,6 +59,7 @@
   12.21  
   12.22  
   12.23      function collectHints(previousToken) {
   12.24 +
   12.25        // We want a single cursor position.
   12.26        if (editor.somethingSelected()) return;
   12.27  
   12.28 @@ -59,8 +70,8 @@
   12.29          (tempToken.start != previousToken.start || tempToken.type != previousToken.type)) {
   12.30          return;
   12.31        }
   12.32 -
   12.33        var result = getHints(editor, givenOptions);
   12.34 +      console.log(result);
   12.35        if (!result || !result.list.length) return;
   12.36        var completions = result.list;
   12.37  
   12.38 @@ -176,7 +187,6 @@
   12.39    function getCompletionsAdql(token, context, keywords, options, editor, optional_keyword) {
   12.40  
   12.41      optional_keyword = (typeof optional_keyword === 'undefined') ? '' : optional_keyword;
   12.42 -
   12.43      var found = [],
   12.44        start = token.string;
   12.45  
   12.46 @@ -186,9 +196,9 @@
   12.47      }
   12.48  
   12.49      function gatherCompletions(obj) {
   12.50 -      if (typeof obj == "string") forEach(availableTags, maybeAdd);
   12.51 -      else if (obj instanceof Array) forEach(availableTags, maybeAdd);
   12.52 -      else if (obj instanceof Function) forEach(availableTags, maybeAdd);
   12.53 +      if (typeof obj == "string") forEach(editor.availableTags, maybeAdd);
   12.54 +      else if (obj instanceof Array) forEach(editor.availableTags, maybeAdd);
   12.55 +      else if (obj instanceof Function) forEach(editor.availableTags, maybeAdd);
   12.56        for (var name in obj) maybeAdd(name);
   12.57      }
   12.58  
   12.59 @@ -267,10 +277,8 @@
   12.60          if (editor.autocompleteLoader) jQuery("#" + editor.autocompleteLoader).hide();
   12.61        },
   12.62        success: function(data) {
   12.63 -
   12.64          if (data != "") {
   12.65 -          //var tables = jQuery.parseJSON(data);
   12.66 -          pushMetadataJson(tables, tags, parentText, keyword);
   12.67 +          pushMetadataJson(data, tags, parentText, keyword);
   12.68          }
   12.69  
   12.70          if (editor.autocompleteInfo) jQuery("#" + editor.autocompleteInfo).html("CTRL + Space to activate auto-complete");
   12.71 @@ -292,11 +300,10 @@
   12.72  
   12.73        if (str.toLowerCase().indexOf(start.toLowerCase()) == 0 && !jsArrayContains(found, str)) found.push(str);
   12.74      }
   12.75 -
   12.76      function gatherCompletions(obj) {
   12.77 -      if (typeof obj == "string") forEach(availableTags, maybeAdd);
   12.78 -      else if (obj instanceof Array) forEach(availableTags, maybeAdd);
   12.79 -      else if (obj instanceof Function) forEach(availableTags, maybeAdd);
   12.80 +      if (typeof obj == "string") forEach(editor.availableTags, maybeAdd);
   12.81 +      else if (obj instanceof Array) forEach(editor.availableTags, maybeAdd);
   12.82 +      else if (obj instanceof Function) forEach(editor.availableTags, maybeAdd);
   12.83        for (var name in obj) maybeAdd(name);
   12.84      }
   12.85  
   12.86 @@ -338,6 +345,7 @@
   12.87  
   12.88  
   12.89    function scriptHint(editor, keywords, getToken, options) {
   12.90 +
   12.91      // Find the token at the cursor
   12.92      var cur = editor.getCursor(),
   12.93      token = getToken(editor, cur),
   12.94 @@ -419,7 +427,6 @@
   12.95        context.push(tprop);
   12.96  
   12.97      }
   12.98 -
   12.99      if (editor.useAutocompleteService != true) {
  12.100  
  12.101        return {
  12.102 @@ -452,7 +459,7 @@
  12.103    }
  12.104  
  12.105    CodeMirror.adqlHint = function(editor, options) {
  12.106 -    return scriptHint(editor, availableTags,
  12.107 +    return scriptHint(editor, editor.availableTags,
  12.108        function(e, cur) {
  12.109          return e.getTokenAt(cur);
  12.110        },
    13.1 Binary file src/GENIUS-gwt-app/war/WEB-INF/classes/com/genius/uk/client/Genius$1.class has changed
    14.1 Binary file src/GENIUS-gwt-app/war/WEB-INF/classes/com/genius/uk/client/Genius$1MyHandler.class has changed
    15.1 Binary file src/GENIUS-gwt-app/war/WEB-INF/classes/com/genius/uk/client/Genius.class has changed
    16.1 --- a/src/GENIUS-gwt-app/war/WEB-INF/web.xml	Wed Apr 13 20:48:57 2016 +0300
    16.2 +++ b/src/GENIUS-gwt-app/war/WEB-INF/web.xml	Thu Apr 28 14:59:14 2016 +0300
    16.3 @@ -7,23 +7,23 @@
    16.4  
    16.5    <!-- Servlets -->
    16.6    <servlet>
    16.7 -    <servlet-name>greetServlet</servlet-name>
    16.8 -    <servlet-class>com.genius.uk.server.GreetingServiceImpl</servlet-class>
    16.9 +    <servlet-name>autocompleteServlet</servlet-name>
   16.10 +    <servlet-class>com.genius.uk.server.AutocompleteServiceImpl</servlet-class>
   16.11    </servlet>
   16.12    
   16.13    <servlet-mapping>
   16.14 -    <servlet-name>greetServlet</servlet-name>
   16.15 -    <url-pattern>/genius/greet</url-pattern>
   16.16 +    <servlet-name>autocompleteServlet</servlet-name>
   16.17 +    <url-pattern>/genius/autocomplete</url-pattern>
   16.18    </servlet-mapping>
   16.19    
   16.20      <servlet>
   16.21 -    <servlet-name>greetServletAsync</servlet-name>
   16.22 -    <servlet-class>com.genius.uk.server.GreetingServiceImplAsync</servlet-class>
   16.23 +    <servlet-name>autocompleteServletAsync</servlet-name>
   16.24 +    <servlet-class>com.genius.uk.server.AutocompleteServiceImplAsync</servlet-class>
   16.25    </servlet>
   16.26    
   16.27    <servlet-mapping>
   16.28 -    <servlet-name>greetServletAsync</servlet-name>
   16.29 -    <url-pattern>/genius/greetAsync</url-pattern>
   16.30 +    <servlet-name>autocompleteServletAsync</servlet-name>
   16.31 +    <url-pattern>/genius/autocompleteAsync</url-pattern>
   16.32    </servlet-mapping>
   16.33    
   16.34    <!-- Default page to serve -->