import java.util.ArrayList;
-import org.eclipse.core.internal.net.ProxyManager;
-import org.eclipse.core.net.proxy.IProxyData;
-import org.eclipse.core.net.proxy.IProxyService;
+//import org.eclipse.core.internal.net.ProxyManager;
+//import org.eclipse.core.net.proxy.IProxyData;
+//import org.eclipse.core.net.proxy.IProxyService;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.Section;
import org.tizen.location.core.model.GeoLocationVO;
import org.tizen.location.map.page.MapImage;
-@SuppressWarnings("restriction")
+//@SuppressWarnings("restriction")
public class Map extends AbstractInjectorItem {
private static String LABEL = Messages.Map_0;
private DefaultTableModel model = new DefaultTableModel(new GeoLocationVO());
private ArrayList<TableViewer> viewerList = new ArrayList<TableViewer>();
- public static String host = null;
- public static int port = -1;
+ //public static String host = null;
+ //public static int port = -1;
@Override
protected void addPages() {
- init();
+ //init();
addPage(new MapImage(this, Messages.Map_1, model));
}
-
+
+ /*
private void init() {
// Get Preferences - General - Network Connections
IProxyService proxyManager = ProxyManager.getProxyManager();
// DebugLog.log("[Activator] proxy initiate...." + System.getProperty("network.proxy_host") + " : " + //$NON-NLS-3$
// System.getProperty("network.proxy_port")); //$NON-NLS-1$
}
-
+ */
public void addViewer(TableViewer viewer){
viewerList.add(viewer);
}
--- /dev/null
+/*
+ * org.tizen.location.core
+ *
+ * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Sungmin Ha <sungmin82.ha@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ * DongKyun Yun <dk77.yun@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.location.map.page;
+
+import java.util.Calendar;
+import java.util.logging.FileHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+public class DebugLog {
+ private static final String LOG_FILE_NAME = "injector.log";
+ private static Logger logger;
+
+ static {
+ synchronized(DebugLog.class) {
+ init();
+ }
+ }
+
+ private static void init() {
+ logger = Logger.getLogger("Event Injector");
+ logger.setUseParentHandlers(false);
+ //File logFolder;
+ Handler logFileHandler;
+ try {
+ /*
+ logFolder = new File(FilePath.getInstance().getTizenVmsArchPath());
+ if (!logFolder.exists()) {
+ logFolder.mkdirs();
+ }
+ */
+ logFileHandler = new FileHandler(/*logFolder.getAbsolutePath() + File.separator + */LOG_FILE_NAME);
+
+ logger.setLevel(Level.ALL);
+ logFileHandler.setLevel(Level.INFO);
+
+ logFileHandler.setFormatter(new LoggerFormatter());
+ logger.addHandler(logFileHandler);
+ } catch (Exception e) {
+ logger.setLevel(Level.OFF);
+ e.getMessage();
+ }
+ }
+
+ public static void log(String msg) {
+ logger.info(msg);
+ }
+}
+
+class LoggerFormatter extends Formatter {
+ public String format(LogRecord record) {
+ StringBuffer sb = new StringBuffer();
+ Calendar cal = Calendar.getInstance();
+ cal.setTimeInMillis(record.getMillis());
+
+ // [YYYY.MM.DD HH:MM:SS][LEVEL][CLASS.METHOD] MESSAGE
+ sb.append('[');
+ sb.append(cal.get(Calendar.YEAR));
+ sb.append('.');
+ sb.append(cal.get(Calendar.MONTH));
+ sb.append('.');
+ sb.append(cal.get(Calendar.DAY_OF_MONTH));
+ sb.append(' ');
+ sb.append(cal.get(Calendar.HOUR_OF_DAY));
+ sb.append(':');
+ sb.append(cal.get(Calendar.MINUTE));
+ sb.append(':');
+ sb.append(cal.get(Calendar.SECOND));
+ sb.append(']');
+ sb.append('[');
+ sb.append(record.getLevel());
+ sb.append(']');
+ sb.append('[');
+ sb.append(record.getSourceClassName().substring(record.getSourceClassName().lastIndexOf(".") + 1));
+ sb.append('.');
+ sb.append(record.getSourceMethodName());
+ sb.append("] ");
+ sb.append(record.getMessage());
+
+ // in case when called Logger.throwing()
+ Throwable t = record.getThrown();
+ if (t != null) {
+ StackTraceElement[] stacks = t.getStackTrace();
+ sb.append('\n');
+ sb.append(t.toString());
+ for (int i = 0; i < stacks.length; i++) {
+ sb.append('\n');
+ sb.append(stacks[i].toString());
+ }
+ }
+ sb.append('\n');
+ return sb.toString();
+ }
+}
+
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.URI;
import java.net.URL;
import java.net.UnknownHostException;
+import java.util.List;
//import java.util.ArrayList;
//import java.util.List;
import org.tizen.injector.provider.AbstractInjectorItem;
import org.tizen.injector.provider.AbstractInjectorPage;
//import org.tizen.location.core.injector.AbstractLocationInjector;
-import org.tizen.location.core.injector.DebugLog;
+//import org.tizen.location.core.injector.DebugLog;
import org.tizen.location.core.injector.LocationInjector;
import org.tizen.location.core.model.GeoLocationVO;
import org.tizen.location.core.protocol.GeoLocation;
}
- private void createGoogleMapScript() {
- if(Map.host == null && Map.port == -1)
- {
- try {
- //make a URL to a known source
- URL url = new URL("http://www.google.com");
-
- //open a connection to that source
- HttpURLConnection urlConnect = (HttpURLConnection)url.openConnection();
- //trying to retrieve data from the source. If there
- //is no connection, this line will fail
- urlConnect.connect();
- boolean isLoading = false;
- if (urlConnect.getResponseCode() != -1) {
- // parsing title
- BufferedReader in = new BufferedReader (new InputStreamReader(urlConnect.getInputStream()));
- String line;
- String pre = "<title>";
- String tail = "</title>";
-
- boolean isNextLine = false;
- while((line = in.readLine()) != null) {
- if (line.contains(pre) || isNextLine) {
- if (line.contains("google")) {
- isLoading = true;
- }
- if (!isLoading && !line.contains(tail)) {
- isNextLine = true;
- continue;
- }
- break;
+ private boolean checkGoogle() {
+ try {
+ //make a URL to a known source
+ URL url = new URL("http://www.google.com");
+
+ //open a connection to that source
+ HttpURLConnection urlConnect = (HttpURLConnection)url.openConnection();
+ //trying to retrieve data from the source. If there
+ //is no connection, this line will fail
+ urlConnect.connect();
+ boolean isLoading = false;
+ if (urlConnect.getResponseCode() != -1) {
+ // parsing title
+ BufferedReader in = new BufferedReader (new InputStreamReader(urlConnect.getInputStream()));
+ String line;
+ String pre = "<title>";
+ String tail = "</title>";
+
+ boolean isNextLine = false;
+ while((line = in.readLine()) != null) {
+ if (line.contains(pre) || isNextLine) {
+ if (line.contains("google")) {
+ isLoading = true;
}
+ if (!isLoading && !line.contains(tail)) {
+ isNextLine = true;
+ continue;
+ }
+ break;
}
- in.close();
}
+ in.close();
+ }
- if (!isLoading) {
- this.googleMapScript = "<html><head></head><body bgcolor=#dcdcdc oncontextmenu='return false'><br><br><br><br>" +
- "<center>Failed to load the map.<br>Please check the network status!</center></body></html>";
- return;
- }
- urlConnect.disconnect();
- } catch (UnknownHostException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
- this.googleMapScript = "<html><head></head><body bgcolor=#dcdcdc oncontextmenu='return false'><br><br><br><br><center>Can't connect to network.</center></body></html>";
- return;
- }
- catch (IOException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
+ if (!isLoading) {
this.googleMapScript = "<html><head></head><body bgcolor=#dcdcdc oncontextmenu='return false'><br><br><br><br>" +
- "<center>Failed to load the map.<br>" + e.getMessage() +
- "</center></body></html>";
+ "<center>Failed to load the map.<br>Please check the network status!</center></body></html>";
+ return false;
+ }
+ urlConnect.disconnect();
+ } catch (UnknownHostException e) {
+ // TODO Auto-generated catch block
+ //e.printStackTrace();
+ this.googleMapScript = "<html><head></head><body bgcolor=#dcdcdc oncontextmenu='return false'><br><br><br><br><center>Can't connect to network.</center></body></html>";
+ return false;
+ }
+ catch (IOException e) {
+ // TODO Auto-generated catch block
+ //e.printStackTrace();
+ this.googleMapScript = "<html><head></head><body bgcolor=#dcdcdc oncontextmenu='return false'><br><br><br><br>" +
+ "<center>Failed to load the map.<br>" + e.getMessage() +
+ "</center></body></html>";
+ return false;
+ }
+
+ return true;
+ }
+
+ private String host = null;
+ private int port = -1;
+ private boolean checkProxy() {
+ System.setProperty("java.net.useSystemProxies","true");
+ try {
+ List<Proxy> l = ProxySelector.getDefault().select(new URI("http://www.google.com/"));
+ for (Proxy proxy : l ) {
+ DebugLog.log("proxy hostname : " + proxy.type());
+ InetSocketAddress addr = (InetSocketAddress)proxy.address();
+ if(addr == null) {
+ DebugLog.log("no proxy");
+ return false;
+ } else {
+ host = addr.getHostName();
+ port = addr.getPort();
+ DebugLog.log("proxy hostname : " + host);
+ DebugLog.log("proxy port : " + port);
+ return true;
+ }
+ }
+ } catch (Exception e) {
+ DebugLog.log("checkProxy() : " + e.getMessage());
+ }
+ return false;
+ }
+
+ private void createGoogleMapScript() {
+ if (checkProxy()) {
+ DebugLog.log("System proxy is used.");
+ if (checkGoogle()) {
+ if (host != null) {
+ System.setProperty("network.proxy_host", host);
+ if (port != -1) {
+ System.setProperty("network.proxy_port", "" + port);
+ }
+ }
+ } else {
+ DebugLog.log("Failure to access the site using system proxy.");
+ System.setProperty("java.net.useSystemProxies", "false");
+ }
+ } else {
+ System.setProperty("java.net.useSystemProxies", "false");
+ DebugLog.log("System proxy is not used.");
+ if (!checkGoogle()) {
return;
}
}
@Override
public void completed(ProgressEvent event) {
-// DebugLog.log("[Map] Map Loading: Compelete");
+ DebugLog.log("[Map] Map Loading: Compelete");
}
@Override