List of usage examples for java.net CookieHandler setDefault
public static synchronized void setDefault(CookieHandler cHandler)
From source file:com.example.android.networkconnect.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //View fechview= findViewById(R.id.fetch_action); // CookieManager cookieManager = new CookieManager(); CookieHandler.setDefault(new CookieManager()); View UsbBouton = findViewById(R.id.usb_item); this.setContentView(R.layout.mainlayout); mfragment_nom = getIntent().getStringExtra("fragment"); setupFragments();/*w w w.j a v a2 s .c o m*/ showFragment(mbureauFragment); //SensorActivity sa; //jsonobjet //initialisation de la boite de dialog login DialogFragment mLoginDialog = new LoginDialog(); mLoginDialog.show(getSupportFragmentManager(), "LoginDialog"); }
From source file:fr.mixit.android.utils.NetworkUtils.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) static ResponseHttp getInputStreamFromHttpUrlConnection(String url, boolean isPost, String args) { final ResponseHttp myResponse = new ResponseHttp(); HttpURLConnection urlConnection = null; if (cookieManager == null) { cookieManager = new CookieManager(); CookieHandler.setDefault(cookieManager); }// w ww . j a v a2 s . c o m try { String urlWithParams = url; if (!isPost && args != null) { urlWithParams = getGetURL(url, args); } final URL urlObject = new URL(urlWithParams); urlConnection = (HttpURLConnection) urlObject.openConnection(); urlConnection.setConnectTimeout(CONNECTION_TIMEOUT); urlConnection.setReadTimeout(SOCKET_TIMEOUT); // if (cookieSession != null) { // cookieManager.getCookieStore().removeAll(); // cookieManager.getCookieStore().addCookie(cookieSession); // } if (isPost) { urlConnection.setDoOutput(true); } // urlConnection.connect(); if (isPost && args != null) { final byte[] params = args.getBytes(HTTP.UTF_8); urlConnection.setFixedLengthStreamingMode(params.length);// or urlConnection.setChunkedStreamingMode(0); final OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream()); out.write(params); } myResponse.status = urlConnection.getResponseCode(); if (DEBUG_MODE) { Log.d(TAG, "Status code : " + myResponse.status); } myResponse.jsonText = getJson(urlConnection.getInputStream()); } catch (final MalformedURLException e) { if (DEBUG_MODE) { Log.e(TAG, "The URL is malformatted", e); } } catch (final IllegalAccessError e) { if (DEBUG_MODE) { Log.e(TAG, "setDoOutput after openning a connection or already done"); } } catch (final UnsupportedEncodingException e) { if (DEBUG_MODE) { Log.e(TAG, "UTF8 unsupported for args", e); } } catch (final IllegalStateException e) { if (DEBUG_MODE) { Log.e(TAG, "I/O Error", e); } } catch (final IllegalArgumentException e) { if (DEBUG_MODE) { Log.e(TAG, "I/O Error", e); } } catch (final IOException e) { if (DEBUG_MODE) { Log.e(TAG, "I/O Error", e); } } finally { if (urlConnection != null) { urlConnection.disconnect(); } } return myResponse; }
From source file:com.dotmarketing.portlets.rules.actionlet.VisitorsTagsActionletFTest.java
/** * Test adding tags to visitor object//from w w w. j a va2 s. c o m * @throws Exception */ @Test public void addTag1() throws Exception { sysuser = userAPI.getSystemUser(); Host host = hostAPI.findDefaultHost(sysuser, false); // setting up the requirements for testing // a new cotent to create the persona linked to the visitor Contentlet personaContentlet = new Contentlet(); personaContentlet.setStructureInode(PersonaAPI.DEFAULT_PERSONAS_STRUCTURE_INODE); personaContentlet.setHost(host.getIdentifier()); personaContentlet.setLanguageId(languageAPI.getDefaultLanguage().getId()); String name = "persona1" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); personaContentlet.setProperty(PersonaAPI.NAME_FIELD, name); personaContentlet.setProperty(PersonaAPI.KEY_TAG_FIELD, name); personaContentlet.setProperty(PersonaAPI.TAGS_FIELD, "persona"); personaContentlet.setProperty(PersonaAPI.DESCRIPTION_FIELD, "test to delete"); personaContentlet = contentletAPI.checkin(personaContentlet, sysuser, false); contentletAPI.publish(personaContentlet, sysuser, false); Persona persona = new Persona(personaContentlet); // 4 test rules // test 1 : using a single tag createTagActionlet("testing"); // test 2 : using a multiple tags createTagActionlet("persona,asia,china,nigeria"); // test 3 : using a new tag (not from the tag manager) createTagActionlet("newtag"); // test 4 : using multiple a new tags (not from the tag manager) createTagActionlet("new2tag,new3tag,new4tag"); // environment setup // FOLDER Folder folder = folderAPI.createFolders("/tags-actionlet-" + System.currentTimeMillis(), host, sysuser, false); // TEMPLATE Template template = templateAPI.find(BLANK_TEMPLATE_INODE, sysuser, false); // PAGE String page = "tags-page-" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); Contentlet pageContentlet = new Contentlet(); pageContentlet.setStructureInode(HTMLPageAssetAPIImpl.DEFAULT_HTMLPAGE_ASSET_STRUCTURE_INODE); pageContentlet.setHost(host.getIdentifier()); pageContentlet.setProperty(HTMLPageAssetAPIImpl.FRIENDLY_NAME_FIELD, page); pageContentlet.setProperty(HTMLPageAssetAPIImpl.URL_FIELD, page); pageContentlet.setProperty(HTMLPageAssetAPIImpl.TITLE_FIELD, page); pageContentlet.setProperty(HTMLPageAssetAPIImpl.CACHE_TTL_FIELD, "0"); pageContentlet.setProperty(HTMLPageAssetAPIImpl.TEMPLATE_FIELD, template.getIdentifier()); pageContentlet.setLanguageId(languageAPI.getDefaultLanguage().getId()); pageContentlet.setFolder(folder.getInode()); pageContentlet = contentletAPI.checkin(pageContentlet, sysuser, false); contentletAPI.publish(pageContentlet, sysuser, false); // Widget to show the tag String title = "personawidget" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); String body = "<p>$visitor.accruedTags</p>"; Contentlet widgetContentlet = new Contentlet(); Structure contentst = StructureFactory.getStructureByVelocityVarName("webPageContent"); Structure widgetst = StructureFactory.getStructureByVelocityVarName("SimpleWidget"); widgetContentlet.setStructureInode(widgetst.getInode()); widgetContentlet.setHost(host.getIdentifier()); widgetContentlet.setProperty("widgetTitle", title); widgetContentlet.setLanguageId(languageAPI.getDefaultLanguage().getId()); widgetContentlet.setProperty("code", body); widgetContentlet.setFolder(folder.getInode()); widgetContentlet = contentletAPI.checkin(widgetContentlet, sysuser, false); contentletAPI.publish(widgetContentlet, sysuser, false); Container container = null; List<Container> containers = containerAPI.findContainersForStructure(contentst.getInode()); for (Container c : containers) { if (c.getTitle().equals("Blank Container")) { container = c; break; } } MultiTree m = new MultiTree(pageContentlet.getIdentifier(), container.getIdentifier(), widgetContentlet.getIdentifier()); MultiTreeFactory.saveMultiTree(m); // login CookieHandler.setDefault(new CookieManager()); URL testUrl = new URL(baseUrl + "/c/portal_public/login?my_account_cmd=auth&my_account_login=admin@dotcms.com&password=admin&my_account_r_m=true"); IOUtils.toString(testUrl.openStream(), "UTF-8"); String url = baseUrl + folder.getPath() + page + "?mainFrame=true&livePage=0com.dotmarketing.htmlpage.language=1&host_id=" + host.getIdentifier() + "&com.dotmarketing.persona.id=" + persona.getIdentifier() + "&previewPage=2"; testUrl = new URL(url); StringBuilder result = new StringBuilder(); InputStreamReader isr = new InputStreamReader(testUrl.openStream()); BufferedReader br = new BufferedReader(isr); int byteRead; while ((byteRead = br.read()) != -1) { result.append((char) byteRead); } br.close(); // testing Assert.assertTrue("Expected tag 'testing' not found", result.toString().contains("testing")); Assert.assertTrue("Expected tag 'persona' not found", result.toString().contains("persona")); Assert.assertTrue("Expected tag 'asia' not found", result.toString().contains("asia")); Assert.assertTrue("Expected tag 'china' not found", result.toString().contains("china")); Assert.assertTrue("Expected tag 'nigeria' not found", result.toString().contains("nigeria")); Assert.assertTrue("Expected tag 'newtag' not found", result.toString().contains("newtag")); Assert.assertTrue("Expected tag 'new2tag' not found", result.toString().contains("new2tag")); Assert.assertTrue("Expected tag 'new3tag' not found", result.toString().contains("new3tag")); Assert.assertTrue("Expected tag 'new4tag' not found", result.toString().contains("new4tag")); Assert.assertFalse("Unexpected tag 'dollar' found", result.toString().contains("dollar")); // clean up contentletAPI.unpublish(personaContentlet, sysuser, false); contentletAPI.unpublish(widgetContentlet, sysuser, false); contentletAPI.unpublish(pageContentlet, sysuser, false); contentletAPI.archive(personaContentlet, sysuser, false); contentletAPI.archive(widgetContentlet, sysuser, false); contentletAPI.archive(pageContentlet, sysuser, false); contentletAPI.delete(personaContentlet, sysuser, false); contentletAPI.delete(widgetContentlet, sysuser, false); contentletAPI.delete(pageContentlet, sysuser, false); folderAPI.delete(folder, sysuser, false); }
From source file:com.microfocus.application.automation.tools.srf.run.RunFromSrfBuilder.java
public static JSONObject getSrfConnectionData(AbstractBuild<?, ?> build, PrintStream logger) { try {//from w ww.j av a2 s . c o m CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); // Create all-trusting host name verifier HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); String path = build.getProject().getParent().getRootDir().toString(); path = path.concat( "/com.microfocus.application.automation.tools.srf.settings.SrfServerSettingsBuilder.xml"); File file = new File(path); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(file); // This also shows how you can consult the global configuration of the builder JSONObject connectionData = new JSONObject(); String credentialsId = document.getElementsByTagName("credentialsId").item(0).getTextContent(); UsernamePasswordCredentials credentials = CredentialsProvider.findCredentialById(credentialsId, StandardUsernamePasswordCredentials.class, build, URIRequirementBuilder.create().build()); String app = credentials.getUsername(); String tenant = app.substring(1, app.indexOf('_')); String secret = credentials.getPassword().getPlainText(); String server = document.getElementsByTagName("srfServerName").item(0).getTextContent(); // Normalize SRF server URL string if needed if (server.substring(server.length() - 1).equals("/")) { server = server.substring(0, server.length() - 1); } boolean https = true; if (!server.startsWith("https://")) { if (!server.startsWith("http://")) { String tmp = server; server = "https://"; server = server.concat(tmp); } else https = false; } URL urlTmp = new URL(server); if (urlTmp.getPort() == -1) { if (https) server = server.concat(":443"); else server = server.concat(":80"); } String srfProxy = ""; String srfTunnel = ""; try { srfProxy = document.getElementsByTagName("srfProxyName").item(0) != null ? document.getElementsByTagName("srfProxyName").item(0).getTextContent().trim() : null; srfTunnel = document.getElementsByTagName("srfTunnelPath").item(0) != null ? document.getElementsByTagName("srfTunnelPath").item(0).getTextContent() : null; } catch (Exception e) { throw e; } connectionData.put("app", app); connectionData.put("tunnel", srfTunnel); connectionData.put("secret", secret); connectionData.put("server", server); connectionData.put("https", (https) ? "True" : "False"); connectionData.put("proxy", srfProxy); connectionData.put("tenant", tenant); return connectionData; } catch (ParserConfigurationException e) { logger.print(e.getMessage()); logger.print("\n\r"); } catch (SAXException | IOException e) { logger.print(e.getMessage()); } return null; }
From source file:com.hpe.application.automation.tools.srf.run.RunFromSrfBuilder.java
public static JSONObject getSrfConnectionData(AbstractBuild<?, ?> build, PrintStream logger) { try {/* ww w . ja va 2 s . c o m*/ CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); // Create all-trusting host name verifier HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); String path = build.getProject().getParent().getRootDir().toString(); path = path.concat("/com.hpe.application.automation.tools.settings.SrfServerSettingsBuilder.xml"); File file = new File(path); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(file); // This also shows how you can consult the global configuration of the builder JSONObject connectionData = new JSONObject(); String app = document.getElementsByTagName("srfAppName").item(0).getTextContent(); String tenant = app.substring(1, app.indexOf('_')); String secret = document.getElementsByTagName("srfSecretName").item(0).getTextContent(); String server = document.getElementsByTagName("srfServerName").item(0).getTextContent(); boolean https = true; if (!server.startsWith("https://")) { if (!server.startsWith("http://")) { String tmp = server; server = "https://"; server = server.concat(tmp); } else https = false; } URL urlTmp = new URL(server); if (urlTmp.getPort() == -1) { if (https) server = server.concat(":443"); else server = server.concat(":80"); } String srfProxy = ""; String srfTunnel = ""; try { srfProxy = document.getElementsByTagName("srfProxyName").item(0).getTextContent().trim(); srfTunnel = document.getElementsByTagName("srfTunnelPath").item(0).getTextContent(); } catch (Exception e) { throw e; } connectionData.put("app", app); connectionData.put("tunnel", srfTunnel); connectionData.put("secret", secret); connectionData.put("server", server); connectionData.put("https", (https) ? "True" : "False"); connectionData.put("proxy", srfProxy); connectionData.put("tenant", tenant); return connectionData; } catch (ParserConfigurationException e) { logger.print(e.getMessage()); logger.print("\n\r"); } catch (SAXException | IOException e) { logger.print(e.getMessage()); } return null; }
From source file:com.studyjams.mdvideo.PlayerModule.ExoPlayerV2.PlayerActivityV2.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); shouldAutoPlay = true;//from w ww . j a va 2 s . c om mediaDataSourceFactory = buildDataSourceFactory(true); mainHandler = new Handler(); window = new Timeline.Window(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } setContentView(R.layout.player_activity_v2); // View rootView = findViewById(root); simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); // simpleExoPlayerView.setControllerVisibilityListener(this); simpleExoPlayerView.requestFocus(); /**?ExoPlayermediaController**/ simpleExoPlayerView.setUseController(false); controller = (MediaControlView) findViewById(R.id.player_control); controller.setVisibilityListener(new MediaControlView.VisibilityListener() { @Override public void onVisibilityChange(int visibility) { } }); EventBus.getDefault().register(this); }
From source file:com.appunite.appunitevideoplayer.PlayerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.player_activity); root = (ViewGroup) findViewById(R.id.root); root.setOnTouchListener(new OnTouchListener() { @Override//from w ww. j a va 2 s.c o m public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { toggleControlsVisibility(); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { view.performClick(); } return true; } }); root.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_MENU) { return false; } return mediaController.dispatchKeyEvent(event); } }); shutterView = findViewById(R.id.shutter); videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame); surfaceView = (SurfaceView) findViewById(R.id.surface_view); surfaceView.getHolder().addCallback(this); subtitleLayout = (SubtitleLayout) findViewById(R.id.subtitles); toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setNavigationIcon(R.drawable.ic_arrow_back); toolbar.setTitle(getIntent().getStringExtra(TITLE_TEXT_EXTRA)); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); mediaController = new MediaController(this); mediaController.setAnchorView(root); controllerView = (ViewGroup) findViewById(R.id.controller_view); controllerView.addView(mediaController); CookieHandler currentHandler = CookieHandler.getDefault(); if (currentHandler != defaultCookieManager) { CookieHandler.setDefault(defaultCookieManager); } audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this); audioCapabilitiesReceiver.register(); progressBar = (ProgressBar) findViewById(R.id.progress_bar); playButton = (ImageView) findViewById(R.id.play_button_icon); final int playButtonIconDrawableId = getIntent().getIntExtra(PLAY_BUTTON_EXTRA, 0); if (playButtonIconDrawableId != 0) { playButton.setImageDrawable(ContextCompat.getDrawable(this, playButtonIconDrawableId)); playButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { preparePlayer(true); } }); } }
From source file:com.studyjams.mdvideo.PlayerModule.PlayerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.player_activity); View root = findViewById(R.id.root); root.setOnTouchListener(new OnTouchListener() { @Override/*ww w. j a v a 2 s .co m*/ public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { toggleControlsVisibility(); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { view.performClick(); } return true; } }); root.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_MENU) { return false; } return mediaController.dispatchKeyEvent(event); } }); shutterView = findViewById(R.id.shutter); // debugRootView = findViewById(R.id.controls_root); videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame); surfaceView = (SurfaceView) findViewById(R.id.surface_view); surfaceView.getHolder().addCallback(this); // debugTextView = (TextView) findViewById(R.id.debug_text_view); // playerStateTextView = (TextView) findViewById(R.id.player_state_view); subtitleLayout = (SubtitleLayout) findViewById(R.id.subtitles); mediaController = new ExtractorMediaController(this); mediaController.setAnchorView(root); // retryButton = (Button) findViewById(R.id.retry_button); // retryButton.setOnClickListener(this); // videoButton = (Button) findViewById(R.id.video_controls); // audioButton = (Button) findViewById(R.id.audio_controls); // textButton = (Button) findViewById(R.id.text_controls); //?mediaController??window setVolumeControlStream(AudioManager.STREAM_MUSIC); CookieHandler currentHandler = CookieHandler.getDefault(); if (currentHandler != defaultCookieManager) { CookieHandler.setDefault(defaultCookieManager); } audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this); audioCapabilitiesReceiver.register(); }
From source file:com.dotmarketing.portlets.rules.actionlet.PersonaActionletFTest.java
/** * Test the creation of a persona in the backend and if the persona object * change in the $visitor variable for the preview as persona functionality card584 * @throws Exception//from w ww.ja va 2 s. com */ @Test public void addPersona() throws Exception { sysuser = userAPI.getSystemUser(); Host host = hostAPI.findDefaultHost(sysuser, false); Host systemHost = hostAPI.findSystemHost(); /* * Create personas for test */ //Create a Persona related to Single host Contentlet persona = new Contentlet(); persona.setStructureInode(PersonaAPI.DEFAULT_PERSONAS_STRUCTURE_INODE); persona.setHost(host.getIdentifier()); persona.setLanguageId(languageAPI.getDefaultLanguage().getId()); String name = "persona1" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); persona.setProperty(PersonaAPI.NAME_FIELD, name); persona.setProperty(PersonaAPI.KEY_TAG_FIELD, name); persona.setProperty(PersonaAPI.TAGS_FIELD, "persona"); persona.setProperty(PersonaAPI.DESCRIPTION_FIELD, "test to delete"); persona = contentletAPI.checkin(persona, sysuser, false); contentletAPI.publish(persona, sysuser, false); Persona personaA = new Persona(persona); boolean isPersonaAIndexed = contentletAPI.isInodeIndexed(persona.getInode(), 500); Assert.assertTrue(isPersonaAIndexed); //Create a Persona related to System Host Contentlet persona2 = new Contentlet(); persona2.setStructureInode(PersonaAPI.DEFAULT_PERSONAS_STRUCTURE_INODE); persona2.setHost(systemHost.getIdentifier()); persona2.setLanguageId(languageAPI.getDefaultLanguage().getId()); String name2 = "persona2" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); persona2.setProperty(PersonaAPI.NAME_FIELD, name2); persona2.setProperty(PersonaAPI.KEY_TAG_FIELD, name2); persona2.setProperty(PersonaAPI.TAGS_FIELD, "persona"); persona2.setProperty(PersonaAPI.DESCRIPTION_FIELD, "test to delete"); persona2 = contentletAPI.checkin(persona2, sysuser, false); contentletAPI.publish(persona2, sysuser, false); Persona personaB = new Persona(persona2); boolean isPersonaBIndexed = contentletAPI.isInodeIndexed(persona2.getInode(), 500); Assert.assertTrue(isPersonaBIndexed); Assert.assertTrue("PersonaA was not created succesfully", UtilMethods.isSet(personaAPI.find(personaA.getIdentifier(), sysuser, false))); Assert.assertTrue("PersonaB was not created succesfully", UtilMethods.isSet(personaAPI.find(personaB.getIdentifier(), sysuser, false))); /* * Test 1: * Create a test page to see if the personas object * in the $visitor variable change */ Folder ftest = folderAPI.createFolders("/personafoldertest" + System.currentTimeMillis(), host, sysuser, false); //adding page String pageStr = "persona-test-page" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); List<Template> templates = templateAPI.findTemplatesAssignedTo(host); Template template = null; for (Template temp : templates) { if (temp.getTitle().equals("Blank")) { template = temp; break; } } Contentlet contentAsset = new Contentlet(); contentAsset.setStructureInode(HTMLPageAssetAPIImpl.DEFAULT_HTMLPAGE_ASSET_STRUCTURE_INODE); contentAsset.setHost(host.getIdentifier()); contentAsset.setProperty(HTMLPageAssetAPIImpl.FRIENDLY_NAME_FIELD, pageStr); contentAsset.setProperty(HTMLPageAssetAPIImpl.URL_FIELD, pageStr); contentAsset.setProperty(HTMLPageAssetAPIImpl.TITLE_FIELD, pageStr); contentAsset.setProperty(HTMLPageAssetAPIImpl.CACHE_TTL_FIELD, "0"); contentAsset.setProperty(HTMLPageAssetAPIImpl.TEMPLATE_FIELD, template.getIdentifier()); contentAsset.setLanguageId(languageAPI.getDefaultLanguage().getId()); contentAsset.setFolder(ftest.getInode()); contentAsset = contentletAPI.checkin(contentAsset, sysuser, false); contentletAPI.publish(contentAsset, sysuser, false); /*Adding simple widget to show the current persona keytag*/ String title = "personawidget" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); String body = "<p>#if(\"$visitor.persona.keyTag\" == \"" + personaA.getKeyTag() + "\")<h1>showing " + personaA.getKeyTag() + "</h1> #elseif(\"$visitor.persona.keyTag\" == \"" + personaB.getKeyTag() + "\") <h1>showing " + personaB.getKeyTag() + "</h1> #else showing default persona #end</p>"; Contentlet contentAsset2 = new Contentlet(); Structure contentst = StructureFactory.getStructureByVelocityVarName("webPageContent"); Structure widgetst = StructureFactory.getStructureByVelocityVarName("SimpleWidget"); contentAsset2.setStructureInode(widgetst.getInode()); contentAsset2.setHost(host.getIdentifier()); contentAsset2.setProperty("widgetTitle", title); contentAsset2.setLanguageId(languageAPI.getDefaultLanguage().getId()); contentAsset2.setProperty("code", body); contentAsset2.setFolder(ftest.getInode()); contentAsset2 = contentletAPI.checkin(contentAsset2, sysuser, false); contentletAPI.publish(contentAsset2, sysuser, false); Container container = null; List<Container> containers = containerAPI.findContainersForStructure(contentst.getInode()); for (Container c : containers) { if (c.getTitle().equals("Blank Container")) { container = c; break; } } /*Relate widget to page*/ MultiTree m = new MultiTree(contentAsset.getIdentifier(), container.getIdentifier(), contentAsset2.getIdentifier()); MultiTreeFactory.saveMultiTree(m); //Call page to see if the persona functionality is working CookieHandler.setDefault(new CookieManager()); URL testUrl = new URL(baseUrl + "/c/portal_public/login?my_account_cmd=auth&my_account_login=admin@dotcms.com&password=admin&my_account_r_m=true"); IOUtils.toString(testUrl.openStream(), "UTF-8"); String urlpersonaA = baseUrl + ftest.getPath() + pageStr + "?mainFrame=true&livePage=0com.dotmarketing.htmlpage.language=1&host_id=" + host.getIdentifier() + "&com.dotmarketing.persona.id=" + personaA.getIdentifier() + "&previewPage=2"; testUrl = new URL(urlpersonaA); StringBuilder result = new StringBuilder(); InputStreamReader isr = new InputStreamReader(testUrl.openStream()); BufferedReader br = new BufferedReader(isr); int byteRead; while ((byteRead = br.read()) != -1) { result.append((char) byteRead); } br.close(); Assert.assertTrue("Error the page is not showing the Persona expected", result.toString().contains("showing " + personaA.getKeyTag())); String urlpersonaB = baseUrl + ftest.getPath() + pageStr + "?mainFrame=true&livePage=0com.dotmarketing.htmlpage.language=1&host_id=" + host.getIdentifier() + "&com.dotmarketing.persona.id=" + personaB.getIdentifier() + "&previewPage=2"; testUrl = new URL(urlpersonaB); result = new StringBuilder(); isr = new InputStreamReader(testUrl.openStream()); br = new BufferedReader(isr); while ((byteRead = br.read()) != -1) { result.append((char) byteRead); } br.close(); Assert.assertTrue("Error the page is not showing the Persona expected", result.toString().contains("showing " + personaB.getKeyTag())); //remove personas, content, page and folder created for this test contentletAPI.unpublish(persona, sysuser, false); contentletAPI.unpublish(persona2, sysuser, false); contentletAPI.unpublish(contentAsset2, sysuser, false); contentletAPI.unpublish(contentAsset, sysuser, false); contentletAPI.archive(persona, sysuser, false); contentletAPI.archive(persona2, sysuser, false); contentletAPI.archive(contentAsset2, sysuser, false); contentletAPI.archive(contentAsset, sysuser, false); contentletAPI.delete(persona, sysuser, false); contentletAPI.delete(persona2, sysuser, false); contentletAPI.delete(contentAsset2, sysuser, false); contentletAPI.delete(contentAsset, sysuser, false); folderAPI.delete(ftest, sysuser, false); }
From source file:im.ene.toro.exoplayer2.ExoVideoView.java
public ExoVideoView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // By default, TextureView is used for Android 23 and below, and SurfaceView is for the rest boolean useTextureView = context.getResources().getBoolean(R.bool.use_texture_view); if (attrs != null) { TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ExoVideoView, 0, 0); try {//from w w w . j av a 2s. c o m int surfaceType = a.getInt(R.styleable.ExoVideoView_tx2_surfaceType, SURFACE_TYPE_DEFAULT); switch (surfaceType) { case SURFACE_TYPE_SURFACE_VIEW: useTextureView = false; break; case SURFACE_TYPE_TEXTURE_VIEW: useTextureView = true; break; case SURFACE_TYPE_DEFAULT: default: // Unchanged, so don't need to execute the line below // useTextureView = context.getResources().getBoolean(R.bool.use_texture_view); break; } resizeMode = a.getInt(R.styleable.ExoVideoView_tx2_resizeMode, RESIZE_MODE_FIXED_WIDTH); } finally { a.recycle(); } } View view = useTextureView ? new TextureView(context) : new SurfaceView(context); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); view.setLayoutParams(params); surfaceView = view; addView(surfaceView, 0); shutterView = new View(context); ViewGroup.LayoutParams shutterViewParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); shutterView.setLayoutParams(shutterViewParams); shutterView.setBackgroundColor(Color.BLACK); addView(shutterView); window = new Timeline.Window(); componentListener = new ComponentListener(); mediaDataSourceFactory = buildDataSourceFactory(true); mainHandler = new Handler(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } requestFocus(); }