1 29 30 package nextapp.echo2.webrender; 31 32 import java.util.ArrayList ; 33 import java.util.Collections ; 34 import java.util.Enumeration ; 35 import java.util.HashSet ; 36 import java.util.List ; 37 import java.util.Locale ; 38 import java.util.Set ; 39 40 import nextapp.echo2.webrender.service.SynchronizeService; 41 import nextapp.echo2.webrender.util.DomUtil; 42 43 import org.w3c.dom.Element ; 44 45 50 public class ClientAnalyzerProcessor 51 implements SynchronizeService.ClientMessagePartProcessor { 52 53 58 private static final Set VALID_PROPERTIES; 59 static { 60 Set set = new HashSet (); 61 set.add(ClientProperties.NAVIGATOR_APP_CODE_NAME); 62 set.add(ClientProperties.NAVIGATOR_APP_NAME); 63 set.add(ClientProperties.NAVIGATOR_APP_VERSION); 64 set.add(ClientProperties.NAVIGATOR_COOKIE_ENABLED); 65 set.add(ClientProperties.NAVIGATOR_JAVA_ENABLED); 66 set.add(ClientProperties.NAVIGATOR_LANGUAGE); 67 set.add(ClientProperties.NAVIGATOR_PLATFORM); 68 set.add(ClientProperties.NAVIGATOR_USER_AGENT); 69 set.add(ClientProperties.SCREEN_WIDTH); 70 set.add(ClientProperties.SCREEN_HEIGHT); 71 set.add(ClientProperties.SCREEN_COLOR_DEPTH); 72 set.add(ClientProperties.UTC_OFFSET); 73 VALID_PROPERTIES = Collections.unmodifiableSet(set); 74 } 75 76 83 private void analyze(ClientProperties clientProperties) { 84 Connection conn = WebRenderServlet.getActiveConnection(); 85 86 Enumeration localeEnum = conn.getRequest().getLocales(); 87 List localeList = new ArrayList (); 88 while (localeEnum.hasMoreElements()) { 89 localeList.add(localeEnum.nextElement()); 90 } 91 clientProperties.setProperty(ClientProperties.LOCALES, localeList.toArray(new Locale [localeList.size()])); 92 93 clientProperties.setProperty(ClientProperties.REMOTE_HOST, conn.getRequest().getRemoteHost()); 94 95 String userAgent = clientProperties.getString(ClientProperties.NAVIGATOR_USER_AGENT).toLowerCase(); 96 97 boolean browserOpera = userAgent.indexOf("opera") != -1; 98 boolean browserSafari = userAgent.indexOf("safari") != -1; 99 boolean browserKonqueror = userAgent.indexOf("konqueror") != -1; 100 101 boolean deceptiveUserAgent = browserOpera || browserSafari || browserKonqueror; 105 106 boolean browserMozilla = !deceptiveUserAgent && userAgent.indexOf("gecko") != -1; 107 boolean browserFireFox = userAgent.indexOf("firefox") != -1; 108 boolean browserInternetExplorer = !deceptiveUserAgent && userAgent.indexOf("msie") != -1; 109 110 int majorVersion = -1, minorVersion = -1; 111 112 if (browserOpera) { 114 clientProperties.setProperty(ClientProperties.BROWSER_OPERA, Boolean.TRUE); 115 if (userAgent.indexOf("opera/9") != -1 || userAgent.indexOf("opera 9") != -1) { 116 majorVersion = 9; 117 } else if (userAgent.indexOf("opera/8") != -1 || userAgent.indexOf("opera 8") != -1) { 118 majorVersion = 8; 119 } else { 120 majorVersion = 9; 123 } 124 } else if (browserKonqueror) { 125 clientProperties.setProperty(ClientProperties.BROWSER_KONQUEROR, Boolean.TRUE); 126 } else if (browserSafari) { 127 clientProperties.setProperty(ClientProperties.BROWSER_SAFARI, Boolean.TRUE); 128 } else if (browserMozilla) { 129 clientProperties.setProperty(ClientProperties.BROWSER_MOZILLA, Boolean.TRUE); 130 if (browserFireFox) { 131 clientProperties.setProperty(ClientProperties.BROWSER_MOZILLA_FIREFOX, Boolean.TRUE); 132 } 133 } else if (browserInternetExplorer) { 134 clientProperties.setProperty(ClientProperties.BROWSER_INTERNET_EXPLORER, Boolean.TRUE); 135 if (userAgent.indexOf("msie 6.") != -1) { 136 majorVersion = 6; 137 } else if (userAgent.indexOf("msie 7.") != -1) { 138 majorVersion = 7; 139 } 140 } 141 142 if (majorVersion != -1) { 143 clientProperties.setProperty(ClientProperties.BROWSER_VERSION_MAJOR, Integer.toString(majorVersion)); 144 } 145 146 if (minorVersion != -1) { 147 clientProperties.setProperty(ClientProperties.BROWSER_VERSION_MINOR, Integer.toString(minorVersion)); 148 } 149 150 if (browserInternetExplorer) { 152 clientProperties.setProperty(ClientProperties.QUIRK_IE_REPAINT, Boolean.TRUE); 153 clientProperties.setProperty(ClientProperties.QUIRK_TEXTAREA_CONTENT, Boolean.TRUE); 154 clientProperties.setProperty(ClientProperties.QUIRK_IE_TEXTAREA_NEWLINE_OBLITERATION, Boolean.TRUE); 155 clientProperties.setProperty(ClientProperties.QUIRK_IE_SELECT_LIST_DOM_UPDATE, Boolean.TRUE); 156 clientProperties.setProperty(ClientProperties.QUIRK_CSS_BORDER_COLLAPSE_INSIDE, Boolean.TRUE); 157 clientProperties.setProperty(ClientProperties.QUIRK_CSS_BORDER_COLLAPSE_FOR_0_PADDING, Boolean.TRUE); 158 159 clientProperties.setProperty(ClientProperties.NOT_SUPPORTED_CSS_OPACITY, Boolean.TRUE); 160 161 clientProperties.setProperty(ClientProperties.PROPRIETARY_IE_CSS_EXPRESSIONS_SUPPORTED, Boolean.TRUE); 162 clientProperties.setProperty(ClientProperties.PROPRIETARY_EVENT_MOUSE_ENTER_LEAVE_SUPPORTED, Boolean.TRUE); 163 clientProperties.setProperty(ClientProperties.PROPRIETARY_IE_OPACITY_FILTER_REQUIRED, Boolean.TRUE); 164 165 clientProperties.setProperty(ClientProperties.QUIRK_IE_TABLE_PERCENT_WIDTH_SCROLLBAR_ERROR, Boolean.TRUE); 167 clientProperties.setProperty(ClientProperties.QUIRK_IE_SELECT_PERCENT_WIDTH, Boolean.TRUE); 168 169 if (majorVersion < 7) { 170 clientProperties.setProperty(ClientProperties.PROPRIETARY_IE_PNG_ALPHA_FILTER_REQUIRED, Boolean.TRUE); 172 clientProperties.setProperty(ClientProperties.QUIRK_CSS_POSITIONING_ONE_SIDE_ONLY, Boolean.TRUE); 173 clientProperties.setProperty(ClientProperties.QUIRK_CSS_BACKGROUND_ATTACHMENT_USE_FIXED, Boolean.TRUE); 174 clientProperties.setProperty(ClientProperties.QUIRK_IE_SELECT_Z_INDEX, Boolean.TRUE); 175 } 176 } 177 if (browserOpera) { 178 clientProperties.setProperty(ClientProperties.QUIRK_TEXTAREA_CONTENT, Boolean.TRUE); 179 clientProperties.setProperty(ClientProperties.QUIRK_OPERA_NO_CSS_TEXT, Boolean.TRUE); 180 clientProperties.setProperty(ClientProperties.QUIRK_SELECT_REQUIRES_NULL_OPTION, Boolean.TRUE); 181 clientProperties.setProperty(ClientProperties.QUIRK_IE_SELECT_PERCENT_WIDTH, Boolean.TRUE); 182 if (majorVersion < 9) { 183 clientProperties.setProperty(ClientProperties.NOT_SUPPORTED_CSS_OPACITY, Boolean.TRUE); 184 } 185 } 186 if (browserMozilla) { 187 clientProperties.setProperty(ClientProperties.QUIRK_SELECT_REQUIRES_NULL_OPTION, Boolean.TRUE); 188 clientProperties.setProperty(ClientProperties.QUIRK_MOZILLA_TEXT_INPUT_REPAINT, Boolean.TRUE); 189 clientProperties.setProperty(ClientProperties.QUIRK_MOZILLA_PERFORMANCE_LARGE_DOM_REMOVE, Boolean.TRUE); 190 } 191 192 if (browserKonqueror) { 193 clientProperties.setProperty(ClientProperties.QUIRK_SELECT_REQUIRES_NULL_OPTION, Boolean.TRUE); 194 clientProperties.setProperty(ClientProperties.QUIRK_IE_SELECT_PERCENT_WIDTH, Boolean.TRUE); 195 clientProperties.setProperty(ClientProperties.NOT_SUPPORTED_CSS_MANIPULATION, Boolean.TRUE); 196 } 197 198 if (browserSafari) { 199 clientProperties.setProperty(ClientProperties.NOT_SUPPORTED_CSS_MANIPULATION, Boolean.TRUE); 200 } 201 } 202 203 206 public String getName() { 207 return "EchoClientAnalyzer"; 208 } 209 210 214 public void process(UserInstance userInstance, Element messagePartElement) { 215 ClientProperties clientProperties = new ClientProperties(); 216 Element [] propertyElements = DomUtil.getChildElementsByTagName(messagePartElement, "property"); 217 for (int i = 0; i < propertyElements.length; ++i) { 218 String propertyName = propertyElements[i].getAttribute("name"); 219 if (VALID_PROPERTIES.contains(propertyName)) { 220 String type = propertyElements[i].getAttribute("type"); 221 if ("text".equals(type)) { 222 clientProperties.setProperty(propertyName, propertyElements[i].getAttribute("value")); 223 } else if ("integer".equals(type)) { 224 try { 225 clientProperties.setProperty(propertyName, 226 new Integer (propertyElements[i].getAttribute("value"))); 227 } catch (NumberFormatException ex) { } 228 } else if ("boolean".equals(type)) { 229 clientProperties.setProperty(propertyName, 230 new Boolean ("true".equals(propertyElements[i].getAttribute("value")))); 231 } 232 } 233 } 234 userInstance.setClientProperties(clientProperties); 235 analyze(clientProperties); 236 } 237 } 238 | Popular Tags |