/** Executes a test-run for the specified platform */ private void executeForPlatform( TestRun.TestRunServer selServerConfig, Map<String, String> testServer, Platform platform) { List<Browser> availableBrowsers = platform.getAvailableBrowsers(); for (Browser browser : availableBrowsers) { String connDef = browser.getConnectionDef(); BaseTestCase.setBrowser(connDef); String msg = "Test Environment: name=" + selServerConfig.getName() + " host=" + testServer.get("host") + " port=" + testServer.get("port") + " browser=" + connDef + " speed=" + selServerConfig.getSpeed(); log.log(Level.INFO, msg); System.out.println("----------------------------------------"); System.out.println(msg); System.out.println("----------------------------------------"); // execute test suites executeTestClasses(selServerConfig.testSuites); } }
// @Test public void test() throws Exception { String url = "http://img.ifeng.com/tres/auto/9/2010/0627/109_4916108228_20100627111203.jpg"; Browser browser = new Browser(); browser.getConnection(url); WriterUtil.write("d:/img.jpg", browser.getStream()); }
public static List<Browser> getVersions(Browser.GROUP group) { List<Browser> result = new LinkedList<Browser>(); for (Browser browser : browsers) { if (browser.getGroup() == group) { result.add(browser); } } return result; }
/** "Return" invokes smart scroll, which closes up current section, and opens next. */ public boolean eventAfter(AWTEvent e, Point scrn, Node obsn) { int eid = e.getID(); // System.out.println("Outliner eventBefore "+eid+", outActive_="+outActive_); if (outActive_ != null && outActive_.isSet() && outActive_.isOpen() /*always true?*/ /* && outSects_.indexOf(outActive_)==-1*/ && /*active_ &&*/ eid == KeyEvent.KEY_PRESSED && ((KeyEvent) e).getKeyChar() == ' ' // ).getKeyCode()==KeyEvent.VK_ENTER ) { Browser br = getBrowser(); // find next OutlineSpan next = nextSection(outActive_.getStart().leaf); Node outn = outActive_.getStart().leaf; IScrollPane isp = outn.getIScrollPane(); VScrollbar vsb = isp.getVsb(); int y = vsb.getValue(), h = isp.bbox.height; if (next != null) { Leaf l = (Leaf) next.getStart().leaf; Point rel = l.getRelLocation(isp); // if next on screen open next, closing up previous of <= level // System.out.println(y+" .. "+l.getNextLeaf()+"/"+rel.y+" .. "+(y+h)); if (y < rel.y && rel.y < y + h) { // close up current and previous while <= level int level = Integers.parseInt(next.getAttr(OutlineSpan.ATTR_LEVEL), 1); for (OutlineSpan prev = outActive_; prev != null; prev = prevSection(prev.getStart().leaf)) { br.eventq(OutlineSpan.MSG_CLOSE, prev); if (Integers.parseInt(prev.getAttr(OutlineSpan.ATTR_LEVEL), Integer.MIN_VALUE) <= level) break; // stop after first at same level as next/new current } outActive_ = next; br.eventq(OutlineSpan.MSG_OPEN, outActive_); // includes l.scrollTo(0,0, true); // System.out.println("open "+outActive_); } // else fall through to scroll return true; } else if (y + h >= vsb.getMax()) { // at end, just close up // System.out.println("couldn't find next OutlineSpan"); -- at end br.eventq(OutlineSpan.MSG_CLOSE, outActive_); outActive_ = null; } // close current and open next // br.setGrab(this); // get key release // return true; } return false; }
@Test public void testPaipai() throws Exception { String url = "http://bbs.paipai.com/portal.php"; browser.getConnection(url); String html = browser.getHTML(); // // browser.postConnection("http://bbs.paipai.com/forum.php?mod=post&action=reply&fid=13&tid=1656875&referer=http%3A//bbs.paipai.com/thread-1656875-1-1.html%3FPTAG%3D32272.2.13", httphead); System.out.println(html); }
public void test_changedLorg_eclipse_swt_browser_ProgressEvent() { Display display = Display.getCurrent(); Shell shell = new Shell(display); Browser browser = new Browser(shell, SWT.NONE); browser.addProgressListener( new ProgressListener() { public void changed(ProgressEvent event) {} public void completed(ProgressEvent event) {} }); shell.close(); }
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(2, true)); final Browser browser; try { browser = new Browser(shell, SWT.NONE); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } GridData data = new GridData(GridData.FILL_BOTH); data.horizontalSpan = 2; browser.setLayoutData(data); Button headersButton = new Button(shell, SWT.PUSH); headersButton.setText("Send custom headers"); data = new GridData(); data.horizontalAlignment = GridData.FILL; headersButton.setLayoutData(data); headersButton.addListener( SWT.Selection, event -> browser.setUrl( "http://www.ericgiguere.com/tools/http-header-viewer.html", null, new String[] {"User-agent: SWT Browser", "Custom-header: this is just a demo"})); Button postDataButton = new Button(shell, SWT.PUSH); postDataButton.setText("Send post data"); data = new GridData(); data.horizontalAlignment = GridData.FILL; postDataButton.setLayoutData(data); postDataButton.addListener( SWT.Selection, event -> browser.setUrl( "https://bugs.eclipse.org/bugs/buglist.cgi", "emailassigned_to1=1&bug_severity=enhancement&bug_status=NEW&email1=platform-swt-inbox&emailtype1=substring", null)); shell.setBounds(10, 10, 600, 600); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
public UserAgent(String userAgentString) { String userAgentLowercaseString = userAgentString == null ? null : userAgentString.toLowerCase(); Browser browser = Browser.parseUserAgentLowercaseString(userAgentLowercaseString); OperatingSystem operatingSystem = OperatingSystem.UNKNOWN; // BOTs don't have an interesting OS for us if (browser != Browser.BOT) operatingSystem = OperatingSystem.parseUserAgentLowercaseString(userAgentLowercaseString); this.operatingSystem = operatingSystem; this.browser = browser; this.id = ((operatingSystem.getId() << 16) + browser.getId()); this.userAgentString = userAgentString; }
/** * Notification that the script has completed the setup and should go about its own internal * initialization. */ public void initialize() { touchTime = (SFTime) fields.get("touchTime"); // Listen to events on touchTime touchTime.addX3DEventListener(this); // Create nodes directly in the parent scene X3DScene scene = (X3DScene) browser.getExecutionContext(); X3DShapeNode shape = (X3DShapeNode) scene.createNode("Shape"); X3DGeometryNode box = (X3DGeometryNode) scene.createNode("Box"); X3DNode touchSensor = scene.createNode("TouchSensor"); shape.setGeometry(box); // Create a Group to hold the nodes X3DGroupingNode group = (X3DGroupingNode) scene.createNode("Group"); // Add the shape and sensor to the group group.addChild(shape); group.addChild(touchSensor); // Add the nodes to the scene scene.addRootNode(group); // Get a handle to the toplevel execution context scene.addRoute(touchSensor, "touchTime", selfRef, "touchTime"); }
public static void browserTab() { TabItem tab = new TabItem(folder, SWT.CLOSE); tab.setText("A Browser"); tab.setToolTipText("A Web browser"); Browser browser = null; try { browser = new Browser(folder, SWT.NONE); } catch (SWTError e) { Label label = new Label(folder, SWT.BORDER); label.setText("Could not initialize browser"); tab.setControl(label); } if (browser != null) { browser.setUrl("http://www.mindview.net"); tab.setControl(browser); } }
// public static WebDriver getInstance(Browser browser, String username, String password) { public static WebDriver getDriver() { if (webDriver != null) { return webDriver; } Browser browser = new Browser(); browser.setName(get(BROWSER_NAME_KEY)); if (CHROME.equals(browser.getName())) { webDriver = new ChromeDriver(); logger.info("ChromeDriver has created"); } else if (FIREFOX.equals(browser.getName())) { FirefoxProfile ffProfile = new FirefoxProfile(); // Authenication Hack for Firefox // if (username != null && password != null) { // ffProfile.setPreference("network.http.phishy-userpass-length", 255); // } ffProfile.setPreference("network.http.phishy-userpass-length", 255); try { webDriver = new FirefoxDriver(); } catch (WebDriverException wdex) { // TODO ������� ���� � ��������� FirefoxBinary binary = new FirefoxBinary(new File("D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe")); webDriver = new FirefoxDriver(binary, new FirefoxProfile()); // driver = new InternetExplorerDriver(); } catch (Throwable th) { th.printStackTrace(); } logger.info("FirefoxDriver has created"); } else if (INTERNET_EXPLORER.equals(browser.getName())) { webDriver = new InternetExplorerDriver(); logger.info("InternetExplorerDriver has created"); } else { webDriver = new ChromeDriver(); logger.info("ChromeDriver has created"); } return webDriver; }
protected void setup(AutomationMain mainFactory, ApplicationContext context) throws AutomationFrameworkException { if (this.context == null) { this.context = context; if (StringUtils.isNotBlank(this.baseUrl)) { Browser.getCurrentBrowser().get(baseUrl); } } }
private static void _testName(String name, StringBuffer result) throws Exception { String urlName = CodeUtil.URLEncoder(name); // String url = // "http://www.google.com.hk/search?hl=zh-CN&newwindow=1&safe=strict&client=aff-1616dh&affdom=1616dh.com&channel=footer&q=" // + urlName + "&oq=" + urlName + // "&aq=f&aqi=&aql=&gs_sm=e&gs_upl=26669l27054l0l3l3l0l0l0l0l0l0ll0"; String url = "http://www.baidu.com/baidu?word=" + urlName + "&tn=myie2&ch=3"; browser.getConnection(url); int count = RegexpUtil.matchGroups(browser.getHTML(), "(" + name + ".{0,10}公司)").length; System.out.println(count); result.append(name).append("=>").append(count).append("\r\n"); Thread.sleep(5 * 1000); }
/* (non-Javadoc) * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((browser == null) ? 0 : browser.hashCode()); result = prime * result + id; result = prime * result + ((operatingSystem == null) ? 0 : operatingSystem.hashCode()); return result; }
public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); shell.setText("Mozilla"); final Browser browser; try { browser = new Browser(shell, SWT.MOZILLA); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } shell.open(); browser.setUrl("http://mozilla.org"); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
public void createXmlMessages() throws Exception { Browser.createXmlMessages(); MMS.createXmlMessages(); JavaApp.createXmlMessages(); // IM should be last to generate id_name for all other applications!!! // set flag to avoid duplicationNAP names before calling createXmlMessages() // The method setNAPFlagForIMAndValidate() should be changed for new applications Validator.setNAPFlagForIMAndValidate(); IM.createXmlMessages(); }
public boolean semanticEventAfter(SemanticEvent se, String msg) { Object arg = se.getArg(); String winclass = getAttr("winclass"); if (MSG_NEW == msg && this == arg && winclass != null) { Map<String, Object> attrs = (Map) CHashMap.getInstance(getAttr("attrs")); Browser br = getBrowser(); Layer layer = (getAttr("doc") == null ? br.getRoot() : br.getCurDocument()) .getLayer(getAttr("layer", Layer.SCRATCH)); // System.out.println("system layer behaviors\n\t"); // for (Iterator<> i=systemLayer.behaviorIterator(); i.hasNext(); ) // System.out.println(((Behavior)i.next()).getName()+" "); Behavior.getInstance(winclass /*for now -- getName() not right*/, winclass, attrs, layer); // if (win.getTitle()==null) win.setTitle(getAttr("title")); // share TITLE attribute with // target VFrame, if it doesn't have one // if (lastbbox_==null) lastbbox_=win.getBounds(); else { // win.setLocation(lastbbox_.x,lastbbox_.y); win.setSize(lastbbox_.width,lastbbox_.height); } // getBrowser().eventq(VFrame.SHOWEVENT, win); -- part of VFrame restore() } // if (VFrame.SHOWEVENT==msg && this==arg) System.out.println("SHOW on "+winclass); return super.semanticEventAfter(se, msg); }
/** * Create with suffix. If the browser use suffix, appropriate suffix will be add to browser * version path (for Unix computer Unix suffix, for Windows computer Windows suffix), otherwise * return path * * @return Path including suffix according to browser settings and computer type */ public String getPath(Computer computer, Browser browser) { if (computer instanceof SlaveComputer) { boolean isUnix = ((SlaveComputer) computer).isUnix(); if ((!isUnix) && browser.getUseSuffixs()) { return (path + browser.getSuffixWindows()); } try { if (isUnix && browser.getUseSuffixs() && browser .getUnixForSuffix() .contains((String) computer.getSystemProperties().get("os.name"))) { return (path + browser.getSuffixUnix()); } } catch (IOException ex) { Logger.getLogger(BrowserVersion.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(BrowserVersion.class.getName()).log(Level.SEVERE, null, ex); } } return path; }
private DesiredCapabilities getBrowserCapabilities(Browser browser) { DesiredCapabilities capabilities = new DesiredCapabilities(); if (browser.getName().equals("internet explorer")) { capabilities.setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); } else if (Browser.CHROME == browser) { ChromeOptions options = new ChromeOptions(); options.addArguments( Arrays.asList("allow-running-insecure-content", "ignore-certificate-errors")); options.addArguments("--start-maximized"); capabilities.setCapability(ChromeOptions.CAPABILITY, options); } else { FirefoxProfile profile = new FirefoxProfile(); if (Browser.MOBILE == browser) { profile.setPreference( "general.useragent.override", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"); profile.setAcceptUntrustedCertificates(true); } if (Browser.NOCOOKIE == browser) { profile.setPreference("network.cookie.cookieBehavior", 2); } profile.setEnableNativeEvents(true); capabilities.setCapability(FirefoxDriver.PROFILE, profile); } if (Browser.NOJS == browser) { capabilities.setJavascriptEnabled(false); } else { capabilities.setJavascriptEnabled(true); } capabilities.setBrowserName(browser.getName()); if (StringUtils.isNotEmpty(browser.getVersion())) { capabilities.setVersion(browser.getVersion()); } capabilities.setPlatform(Platform.ANY); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); capabilities.setCapability("trustAllSSLCertificates", true); return capabilities; }
/** * Returns UserAgent based on combined string representation * * @param name * @return */ public static UserAgent valueOf(String name) { if (name == null) throw new NullPointerException("Name is null"); String[] elements = name.split("-"); if (elements.length == 2) { OperatingSystem operatingSystem = OperatingSystem.valueOf(elements[0]); Browser browser = Browser.valueOf(elements[1]); return new UserAgent(operatingSystem, browser); } throw new IllegalArgumentException("Invalid string for userAgent " + name); }
@Action public void showContestWebSite() { stopCountdown(); try { Browser.openUrl("http://bridgecontest.org"); } catch (IOException ex) { JOptionPane.showMessageDialog( this, resourceMap.getString("browserOpenFail.text"), resourceMap.getString("messageBox.title"), JOptionPane.INFORMATION_MESSAGE); } }
private static void initializeTestParameters(String[] args) { System.setProperty("ReportPath", args[0]); Properties properties = Settings.getInstance(); testParameters = new SeleniumTestParameters(args[1], args[2]); if (args.length >= 4 && !args[3].equalsIgnoreCase("SKIP")) { testParameters.setCurrentTestDescription(args[3]); } if (args.length >= 5 && !args[4].equalsIgnoreCase("SKIP")) { testParameters.setIterationMode(IterationOptions.valueOf(args[4])); } else { testParameters.setIterationMode(IterationOptions.RunAllIterations); } if (args.length >= 6 && !args[5].equalsIgnoreCase("SKIP")) { testParameters.setStartIteration(Integer.parseInt(args[5])); } if (args.length >= 7 && !args[6].equalsIgnoreCase("SKIP")) { testParameters.setEndIteration(Integer.parseInt(args[6])); } if (args.length >= 8 && !args[7].equalsIgnoreCase("SKIP")) { testParameters.setBrowser(Browser.valueOf(args[7])); } else { testParameters.setBrowser(Browser.valueOf(properties.getProperty("DefaultBrowser"))); } if (args.length >= 9 && !args[8].equalsIgnoreCase("SKIP")) { testParameters.setBrowserVersion(args[8]); } if (args.length >= 10 && !args[9].equalsIgnoreCase("SKIP")) { testParameters.setPlatform(Platform.valueOf(args[9])); } else { testParameters.setPlatform(Platform.valueOf(properties.getProperty("DefaultPlatform"))); } }
@Override public void start(Stage pStage) { // create the scene stage = pStage; stage.setTitle("Web View"); URL startFile = this.getClass().getResource("/resources/html/layout.html"); System.out.println("startFile: " + startFile); Resources resources = new Resources(); resources.addStyle( this.getResource("bower_components/bootstrap/dist/css/bootstrap.css").toExternalForm()); resources.addStyle(this.getResource("css/styles.css").toExternalForm()); resources.addJsHead( this.getResource("bower_components/jquery/dist/jquery.js").toExternalForm()); resources.addJsHead(this.getResource("js/scripts.js").toExternalForm()); Browser browser = new Browser(resources, new JsObject(stage)); scene = new Scene(browser.run(startFile.toExternalForm()), 750, 500, Color.web("#666970")); stage.setScene(scene); scene.getStylesheets().add("webviewsample/BrowserToolbar.css"); stage.show(); }
/* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final UserAgent other = (UserAgent) obj; if (browser == null) { if (other.browser != null) return false; } else if (!browser.equals(other.browser)) return false; if (id != other.id) return false; if (operatingSystem == null) { if (other.operatingSystem != null) return false; } else if (!operatingSystem.equals(other.operatingSystem)) return false; return true; }
/** * Initializes and returns page class instance * * @param page - page class * @throws PageObjectException */ protected <T extends AbstractPageObject> T initPage(T page) throws PageObjectException { // get locators Locale locale; try { locale = new Locale(AutomationMain.getConfigProperties().getContentLanguage()); } catch (AutomationFrameworkException e) { throw new PageObjectException("Main factory initialization exception.", e); } try { Browser browser = Browser.getCurrentBrowser(); LOG.info("Current URL: " + getCurrentUrl()); if (StringUtils.isNotBlank(page.getPageUrl()) && !browser.getCurrentUrl().contains(page.getPageUrl())) { LOG.error("Navigate to URL: " + page.getPageUrl()); throw new PageObjectException( "Page validation exception. Expected page URL is " + page.getPageUrl() + " URL in fact " + getCurrentUrl()); } page.setPageFactory(this); page.init(browser, locale); LOG.info(page.getClass().getName() + " page created."); } catch (Exception e) { throw new PageObjectException( "Unable initialize " + page.getClass().getName() + " page by URL: " + page.getPageUrl() + "\n" + e.getMessage(), e); } return page; }
private URL buildURL(URL url) throws UnsupportedEncodingException, MalformedURLException { String fullURLString = url.toString(); fullURLString += "/runner"; boolean hasFirstParameter = false; if (overrideURL != null) { fullURLString += "?url=" + URLEncoder.encode(overrideURL, "UTF-8"); hasFirstParameter = true; } else if (configuration.getTestURL() != null) { fullURLString += "?url=" + URLEncoder.encode(configuration.getTestURL().toString(), "UTF-8"); hasFirstParameter = true; } if (remoteBrowser != null) { fullURLString += (hasFirstParameter ? "&" : "?"); fullURLString += "browserId=" + remoteBrowser.getId(); } return new URL(fullURLString); }
public synchronized void initialize() { Browser browser = targetTestBrowser; if (browser == null) { browser = Browser.valueOf(Browser.class, System.getProperty("browser", "firefox").toUpperCase()); } WebDriver webDriver = createDriver(browser); delegate.set(webDriver); drivers.add(webDriver); try { webDriver .manage() .timeouts() .pageLoadTimeout(60, TimeUnit.SECONDS) .setScriptTimeout(30, TimeUnit.SECONDS) .implicitlyWait(20, TimeUnit.SECONDS); webDriver.manage().window().maximize(); } catch (Exception e) { LOGGER.error("ODWebDriverProvider initialize()", e); // $NON-NLS-1$ throw new RuntimeException(e); } }
@Override protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { parser.parse(value); if (!parser.hasParseError()) { String browser = parser.getBrowser(); // if (!browser.isEmpty()) { Browser b; b = Browser.valueOf(browser); context.getCounter(b).increment(1); } if (parser.isInvalidBytesValue()) { context.getCounter(LogRecord.INAVLID_BYTES_VALUE).increment(1); } // SumCountWritable scw = new SumCountWritable(parser.getBytesDouble(), 1); context.write(new Text(parser.getIP()), scw); } else { System.err.println("Ignoring possibly corrupt input: " + value); context.getCounter(LogRecord.BAD).increment(1); } }
/** * Parses the input row String into a Java object. For performance reasons this works in-place * updating the fields within this SnowPlowEventStruct, rather than creating a new one. * * @param row The raw String containing the row contents * @return true if row was successfully parsed, false otherwise * @throws SerDeException For any exception during parsing */ public boolean updateByParsing(String row) throws SerDeException { // First we reset the object's fields nullify(); // We have to handle any header rows if (row.startsWith("#Version:") || row.startsWith("#Fields:")) { return false; // Empty row will be discarded by Hive } final Matcher m = cfRegex.matcher(row); // 0. First check our row is kosher // -> is row from a CloudFront log? Will throw an exception if not if (!m.matches()) throw new SerDeException("Row does not match expected CloudFront regexp pattern"); // -> was generated by sp.js? If not (e.g. favicon.ico request), then silently return final String object = m.group(8); final String querystring = m.group(12); if (!(object.startsWith("/ice.png") || object.equals("/i") || object.startsWith("/i?")) || isNullField(querystring)) { // Also works if Forward Query String = yes return false; } // 1. Now we retrieve the fields which get directly passed through this.dt = m.group(1); this.tm = m.group(2); // CloudFront date format matches Hive's this.user_ipaddress = m.group(5); // 2. Now grab the user agent final String ua = m.group(11); try { this.useragent = decodeSafeString(ua); } catch (Exception e) { getLog().warn(e.getClass().getSimpleName() + " on { useragent: " + ua + " }"); } // 3. Next we dis-assemble the user agent... final UserAgent userAgent = UserAgent.parseUserAgentString(ua); // -> browser fields final Browser b = userAgent.getBrowser(); this.br_name = b.getName(); this.br_family = b.getGroup().getName(); final Version v = userAgent.getBrowserVersion(); this.br_version = (v == null) ? null : v.getVersion(); this.br_type = b.getBrowserType().getName(); this.br_renderengine = b.getRenderingEngine().toString(); // -> OS-related fields final OperatingSystem os = userAgent.getOperatingSystem(); this.os_name = os.getName(); this.os_family = os.getGroup().getName(); this.os_manufacturer = os.getManufacturer().getName(); // -> device/hardware-related fields this.dvce_type = os.getDeviceType().getName(); this.dvce_ismobile = os.isMobileDevice(); this.dvce_ismobile_bt = (byte) (this.dvce_ismobile ? 1 : 0); // 4. Now for the versioning (tracker versioning is handled below) this.v_collector = collectorVersion; this.v_etl = "serde-" + ProjectSettings.VERSION; // 5. Now we generate the event ID this.event_id = generateEventId(); // 6. Now we dis-assemble the querystring. String qsUrl = null; // We use this in the block below, and afterwards List<NameValuePair> params = null; // We re-use this for efficiency try { params = URLEncodedUtils.parse(URI.create("http://localhost/?" + querystring), cfEncoding); // For performance, don't convert to a map, just loop through and match to our variables as we // go for (NameValuePair pair : params) { final String name = pair.getName(); final String value = pair.getValue(); final QuerystringFields field; try { field = QuerystringFields.valueOf( name.toUpperCase()); // Java pre-7 can't switch on a string, so hash the string } catch (IllegalArgumentException e) { getLog().warn("Unexpected params { " + name + ": " + value + " }"); continue; } try { switch (field) { // Common fields case E: this.event = asEventType(value); break; case IP: this.user_ipaddress = value; break; case AID: this.app_id = value; break; case P: this.platform = value; break; case TID: this.txn_id = value; break; case UID: this.user_id = value; break; case FP: this.user_fingerprint = value; break; case VID: this.visit_id = Integer.parseInt(value); break; case TSTAMP: // Replace our timestamp fields with the client's timestamp String[] timestamp = value.split(" "); this.dt = timestamp[0]; this.tm = timestamp[1]; break; case TV: this.v_tracker = value; break; case LANG: this.br_lang = value; break; case F_PDF: if ((this.br_features_pdf = stringToByte(value)) == 1) this.br_features.add("pdf"); break; case F_FLA: if ((this.br_features_flash = stringToByte(value)) == 1) this.br_features.add("fla"); break; case F_JAVA: if ((this.br_features_java = stringToByte(value)) == 1) this.br_features.add("java"); break; case F_DIR: if ((this.br_features_director = stringToByte(value)) == 1) this.br_features.add("dir"); break; case F_QT: if ((this.br_features_quicktime = stringToByte(value)) == 1) this.br_features.add("qt"); break; case F_REALP: if ((this.br_features_realplayer = stringToByte(value)) == 1) this.br_features.add("realp"); break; case F_WMA: if ((this.br_features_windowsmedia = stringToByte(value)) == 1) this.br_features.add("wma"); break; case F_GEARS: if ((this.br_features_gears = stringToByte(value)) == 1) this.br_features.add("gears"); break; case F_AG: if ((this.br_features_silverlight = stringToByte(value)) == 1) this.br_features.add("ag"); break; case COOKIE: this.br_cookies = stringToBoolean(value); this.br_cookies_bt = (byte) (this.br_cookies ? 1 : 0); break; case RES: String[] resolution = value.split("x"); if (resolution.length != 2) throw new Exception("Couldn't parse res field"); this.dvce_screenwidth = Integer.parseInt(resolution[0]); this.dvce_screenheight = Integer.parseInt(resolution[1]); break; case CD: this.br_colordepth = value; break; case TZ: this.os_timezone = decodeSafeString(value); break; case REFR: this.page_referrer = decodeSafeString(value); break; case URL: qsUrl = pair.getValue(); // We might use this later for the page URL break; // Page-view only case PAGE: this.page_title = decodeSafeString(value); break; // Event only case EV_CA: this.ev_category = decodeSafeString(value); break; case EV_AC: this.ev_action = decodeSafeString(value); break; case EV_LA: this.ev_label = decodeSafeString(value); break; case EV_PR: this.ev_property = decodeSafeString(value); break; case EV_VA: this.ev_value = decodeSafeString(value); break; // Ecommerce case TR_ID: this.tr_orderid = decodeSafeString(value); break; case TR_AF: this.tr_affiliation = decodeSafeString(value); break; case TR_TT: this.tr_total = decodeSafeString(value); break; case TR_TX: this.tr_tax = decodeSafeString(value); break; case TR_SH: this.tr_shipping = decodeSafeString(value); break; case TR_CI: this.tr_city = decodeSafeString(value); break; case TR_ST: this.tr_state = decodeSafeString(value); break; case TR_CO: this.tr_country = decodeSafeString(value); break; case TI_ID: this.ti_orderid = decodeSafeString(value); break; case TI_SK: this.ti_sku = decodeSafeString(value); break; case TI_NA: this.ti_name = decodeSafeString(value); break; case TI_CA: this.ti_category = decodeSafeString(value); break; case TI_PR: this.ti_price = decodeSafeString(value); break; case TI_QU: this.ti_quantity = decodeSafeString(value); break; } } catch (Exception e) { getLog().warn(e.getClass().getSimpleName() + " on { " + name + ": " + value + " }"); } } } catch (IllegalArgumentException e) { getLog().warn("Corrupted querystring { " + querystring + " }"); } // 7. Choose the page_url final String cfUrl = m.group(10); if (!isNullField(cfUrl)) { // CloudFront didn't provide the URL as cs(Referer) this.page_url = cfUrl; // The CloudFront cs(Referer) URL } else { try { this.page_url = decodeSafeString( qsUrl); // Use the decoded querystring URL. Might be null (returned as null) } catch (Exception e) { getLog().warn(e.getClass().getSimpleName() + " on { qsUrl: " + qsUrl + " }"); } } // 8. Finally handle the marketing fields in the page_url // Re-use params to avoid creating another object if (this.page_url != null) { params = null; try { params = URLEncodedUtils.parse(URI.create(this.page_url), "UTF-8"); } catch (IllegalArgumentException e) { getLog().warn("Couldn't parse page_url: " + page_url); } if (params != null) { // For performance, don't convert to a map, just loop through and match to our variables as // we go for (NameValuePair pair : params) { final String name = pair.getName(); final String value = pair.getValue(); final MarketingFields field; try { field = MarketingFields.valueOf( name.toUpperCase()); // Java pre-7 can't switch on a string, so hash the string } catch (IllegalArgumentException e) { // Do nothing: non-marketing related querystring fields are not an issue. continue; } try { switch (field) { // Marketing fields case UTM_MEDIUM: this.mkt_medium = decodeSafeString(value); break; case UTM_SOURCE: this.mkt_source = decodeSafeString(value); break; case UTM_TERM: this.mkt_term = decodeSafeString(value); break; case UTM_CONTENT: this.mkt_content = decodeSafeString(value); break; case UTM_CAMPAIGN: this.mkt_campaign = decodeSafeString(value); break; } } catch (Exception e) { getLog().warn(e.getClass().getSimpleName() + " on { " + name + ": " + value + " }"); } } } } return true; // Successfully updated the row. }
/** * Set the active/visible Browser. * * @param browser The Browser to make selected. */ public void setCurrentBrowser(Browser browser) { Tab tab = Tabs.getInstance().getTab(browser.getId()); if (tab != null) { Tabs.getInstance().selectTab(tab.getId()); } }