1 11 package org.eclipse.ui.internal.intro.impl.model; 12 13 import java.net.*; 14 import java.util.*; 15 16 20 public class IntroURLParser { 21 22 private String url_string = null; 23 private boolean hasProtocol = false; 24 private boolean isIntroUrl = false; 25 private String action = null; 26 private Properties parameters = null; 27 28 private IntroURL introURL = null; 29 30 33 public IntroURLParser(String url) { 34 url_string = url; 35 parseUrl(url); 37 if (isIntroUrl) { 38 introURL = new IntroURL(action, parameters); 40 } 41 } 42 43 private void parseUrl(String url) { 44 if (url == null) 45 return; 46 URL url_inst = null; 47 try { 48 url_inst = new URL(url); 49 } catch (MalformedURLException e) { 50 return; 52 } 53 54 if (url_inst.getProtocol() != null) { 55 hasProtocol = true; 58 isIntroUrl = isIntoUrl(url_inst); 59 if (isIntroUrl) { 60 action = getPathAsAction(url_inst); 62 parameters = getQueryParameters(url_inst); 63 } 64 return; 65 } 66 67 return; 69 } 70 71 79 private boolean isIntoUrl(URL url) { 80 if (!url.getProtocol().equalsIgnoreCase(IntroURL.INTRO_PROTOCOL)) 81 return false; 83 84 if (url.getHost().equalsIgnoreCase(IntroURL.INTRO_HOST_ID)) 85 return true; 86 return false; 87 } 88 89 96 private String getPathAsAction(URL url) { 97 String action = url.getPath(); 99 if (action != null) 101 action = action.substring(1); 102 return action; 103 } 104 105 111 public Properties getQueryParameters(URL url) { 112 Properties properties = new Properties(); 114 String query = url.getQuery(); 115 if (query == null) 116 return properties; 119 120 String [] params = query.split("&"); for (int i = 0; i < params.length; i++) { 123 String [] keyValuePair = params[i].split("="); properties.setProperty(keyValuePair[0], keyValuePair[1]); 128 } 129 return properties; 130 } 131 132 135 public boolean hasProtocol() { 136 return hasProtocol; 137 } 138 139 142 public boolean hasIntroUrl() { 143 return isIntroUrl; 144 } 145 146 150 public IntroURL getIntroURL() { 151 return introURL; 152 } 153 154 } 155 | Popular Tags |