import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.equinox.internal.p2.ui.misc.StringMatcher;
import org.eclipse.jface.fieldassist.ComboContentAdapter;
import org.json.JSONException;
import org.json.JSONObject;
+import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+
/**
* @author pplitzner
* @date 22.05.2014
toolkit.adapt(btnBioCaseProvider, true, true);
btnBioCaseProvider.setText("BioCASE Provider");
// txtAccessPoint = new Combo(this, SWT.BORDER);
-// CdmPreference biocaseProvider = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.BioCaseProvider);
-// if (biocaseProvider != null){
-// String items[] = biocaseProvider.getValue().split(";");
-// txtAccessPoint.setItems(items);
-// }
+//
txtAccessPoint = new Combo(this, SWT.BORDER);
-
+ Set<String> itemList = new HashSet<>();
URL url;
String response = null;
try {
- url = new URL("http://www.biocase.org/whats_biocase/gbif_biocase.cgi");
+ url = new URL("https://www.biocase.org/whats_biocase/gbif_biocase.cgi");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Accept", "application/json");
// conn.setReadTimeout(TIMEOUT*9);
if (conn.getResponseCode() != 200) {
- throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
+ //TODO
}
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
int i = 0;
String service_url = null;
- items = new String[jsonResponseArray.length()];
+
+// items = new String[jsonResponseArray.length()];
while (i<jsonResponseArray.length()){
JSONObject object = jsonResponseArray.getJSONObject(i);
service_url = (String) object.get("service_url");
if (service_url != null){
- txtAccessPoint.add(service_url);
- items[i] = service_url;
+ if (itemList.add(service_url)){
+ txtAccessPoint.add(service_url);
+ }
+// items[i] = service_url;
}
i++;
}
// TODO Auto-generated catch block
e.printStackTrace();
}
-
+ String biocaseProvider = PreferencesUtil.getStringValue(PreferencePredicate.BioCaseProvider.getKey());
+ if (biocaseProvider != null){
+ String items[] = biocaseProvider.split(";");
+ for (String item: items){
+ if (itemList.add(item)){
+ txtAccessPoint.add(item);
+ }
+ }
+ }
+ items = new String[itemList.size()];
+ items = itemList.toArray(items);
GridData dataProviderUri = new GridData();
dataProviderUri.horizontalAlignment = GridData.FILL;