List of usage examples for java.net URL toString
public String toString()
From source file:cn.org.rapid_framework.generator.util.ResourceHelper.java
/** * Create a URI instance for the given URL, * replacing spaces with "%20" quotes first. * <p>Furthermore, this method works on JDK 1.4 as well, * in contrast to the <code>URL.toURI()</code> method. * @param url the URL to convert into a URI instance * @return the URI instance/* w w w . j ava 2 s . c o m*/ * @throws URISyntaxException if the URL wasn't a valid URI * @see java.net.URL#toURI() */ public static URI toURI(URL url) throws URISyntaxException { return toURI(url.toString()); }
From source file:Which4J.java
/** * Search the specified classloader for the given classname. * // ww w . j a v a 2 s . c o m * @param classname the fully qualified name of the class to search for * @param loader the classloader to search * @return the source location of the resource, or null if it wasn't found */ public static String which(String classname, ClassLoader loader) { if (isArrayType(classname)) { classname = getElementType(classname); } if (isPrimitiveOrVoid(classname)) { return "'" + classname + "' primitive"; } String classnameAsResource = classname.replace('.', '/') + ".class"; if (loader == null) { // some VM's return null from getClassLoader to indicate that // the class was loaded by the bootstrap class loader loader = ClassLoader.getSystemClassLoader(); } URL it = loader.getResource(classnameAsResource); if (it != null) { return it.toString(); } else { return null; } }
From source file:ca.simplegames.micro.utils.ResourceUtils.java
/** * Create a URI instance for the given URL, replacing spaces with * "%20" quotes first./*from ww w . j a v a 2s.co m*/ * <p>Furthermore, this method works on JDK 1.4 as well, * in contrast to the <code>URL.toURI()</code> method. * * @param url the URL to convert into a URI instance * @return the URI instance * @throws URISyntaxException if the URL wasn't a valid URI * @see java.net.URL#toURI() */ public static URI toURI(URL url) throws URISyntaxException { return new URI(StringUtils.replace(url.toString(), " ", "%20")); }
From source file:de.bayern.gdi.services.Service.java
private static URL guessURL(URL url) throws MalformedURLException { String urlStr = url.toString(); if (urlStr.toLowerCase().contains(WFS_URL_EXPR) && urlStr.toLowerCase().contains(GET_CAP_EXPR)) { return url; } else {//from w ww .j a v a2 s . c om if (urlStr.endsWith("?")) { urlStr = urlStr.substring(0, urlStr.lastIndexOf("?")); } return new URL(urlStr + URL_TRY_APPENDIX); } }
From source file:org.LinuxdistroCommunity.android.client.NetworkUtilities.java
public static String getAuthToken(String server, String code) { String token = null;/*from w ww .j av a 2 s. co m*/ final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(PARAM_CODE, code)); params.add(new BasicNameValuePair(PARAM_CLIENT_SECRET, CLIENT_SECRET)); InputStream is = null; URL auth_token_url; try { auth_token_url = getRequestURL(server, PATH_OAUTH_ACCESS_TOKEN, params); Log.i(TAG, auth_token_url.toString()); HttpURLConnection conn = (HttpURLConnection) auth_token_url.openConnection(); conn.setReadTimeout(10000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */); conn.setRequestMethod("GET"); conn.setDoInput(true); // Starts the query conn.connect(); int response_code = conn.getResponseCode(); Log.d(TAG, "The response is: " + response_code); is = conn.getInputStream(); // parse token_response as JSON to get the token out String str_response = readStreamToString(is, 500); Log.d(TAG, str_response); JSONObject response = new JSONObject(str_response); token = response.getString("access_token"); } catch (MalformedURLException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { // Makes sure that the InputStream is closed after the app is // finished using it. if (is != null) { try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } Log.i(TAG, token); return token; }
From source file:com.cloudbees.workflow.rest.external.ChangeSetExt.java
static <T extends ChangeLogSet.Entry> String getCommitUrl(RepositoryBrowser<T> repoBrowser, ChangeLogSet.Entry entry) {/*from w w w .ja v a 2 s.c o m*/ if (repoBrowser == null) { return null; } try { URL changeSetLink = repoBrowser.getChangeSetLink((T) entry); if (changeSetLink == null) { return null; } return changeSetLink.toString(); } catch (IOException e) { return null; } }
From source file:com.sencko.basketball.stats.advanced.FIBAJsonParser.java
private static Game readGameFromNet(String location) throws IOException, MalformedURLException { InputStream jsonInputStream;//from ww w. java 2 s. co m String prefix = "http://webcast-a.live.sportingpulseinternational.com/matches/"; String suffix = "//data.json"; String html_suffix = "//index.html"; URL url = new URL(prefix + location + suffix); logger.log(Level.FINEST, "Downloading file {0} from internet", url.toString()); URLConnection connection = url.openConnection(); connection.connect(); jsonInputStream = connection.getInputStream(); try { Game game = readGameFromStream(jsonInputStream); try { URL html_url = new URL(prefix + location + html_suffix); String html = IOUtils.toString(html_url, "UTF-8"); Matcher match = teamAndTime.matcher(html); if (match.matches()) { game.getTm().get(1).setTeam(match.group(1)); game.getTm().get(2).setTeam(match.group(2)); Calendar calendar = Calendar.getInstance(); //TimeZone.getTimeZone("EET") calendar.set(Integer.parseInt(match.group(7)), Integer.parseInt(match.group(6)) - 1, Integer.parseInt(match.group(5)), Integer.parseInt(match.group(3)), Integer.parseInt(match.group(4))); game.setDate(calendar.getTime()); } } catch (Exception ex) { ex.printStackTrace(); } return game; } finally { jsonInputStream.close(); } }
From source file:com.canoo.webtest.util.WebtestEmbeddingUtil.java
/** * Copies WebTest resources (ie webtest.xml, tools/*, the XSLs, CSSs and pictures, ...) package in WebTest jar file * into the provide folder. Indeed different Ant tasks can't work with resources in a jar file. * @param targetFolder the folder in which resources should be copied to * @throws java.io.IOException if the resources can be accessed or copied */// w w w. j a v a 2s . c o m static void copyWebTestResources(final File targetFolder) throws IOException { final String resourcesPrefix = "com/canoo/webtest/resources/"; final URL webtestXmlUrl = WebtestEmbeddingUtil.class.getClassLoader() .getResource(resourcesPrefix + "webtest.xml"); if (webtestXmlUrl == null) { throw new IllegalStateException("Can't find resource " + resourcesPrefix + "webtest.xml"); } else if (webtestXmlUrl.toString().startsWith("jar:file")) { final String urlJarFileName = webtestXmlUrl.toString().replaceFirst("^jar:file:([^\\!]*).*$", "$1"); final String jarFileName = URLDecoder.decode(urlJarFileName, Charset.defaultCharset().name()); final JarFile jarFile = new JarFile(jarFileName); final String urlPrefix = StringUtils.removeEnd(webtestXmlUrl.toString(), "webtest.xml"); for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) { final JarEntry jarEntry = entries.nextElement(); if (jarEntry.getName().startsWith(resourcesPrefix)) { final String relativeName = StringUtils.removeStart(jarEntry.getName(), resourcesPrefix); final URL url = new URL(urlPrefix + relativeName); final File targetFile = new File(targetFolder, relativeName); FileUtils.forceMkdir(targetFile.getParentFile()); FileUtils.copyURLToFile(url, targetFile); } } } else if (webtestXmlUrl.toString().startsWith("file:")) { // we're probably developing and/or have a custom version of the resources in classpath final File webtestXmlFile = FileUtils.toFile(webtestXmlUrl); final File resourceFolder = webtestXmlFile.getParentFile(); FileUtils.copyDirectory(resourceFolder, targetFolder); } else { throw new IllegalStateException( "Resource " + resourcesPrefix + "webtest.xml is not in a jar file: " + webtestXmlUrl); } }
From source file:com.concursive.connect.web.portal.ProjectPortalUtils.java
public static DashboardPage retrieveDashboardPage(ProjectPortalBean portalBean) throws Exception { // Use the project-portal-config.xml to determine the dashboard page to use for the current url URL resource = ProjectPortalUtils.class.getResource("/portal/project-portal-config.xml"); LOG.debug("portal config file: " + resource.toString()); XMLUtils library = new XMLUtils(resource); // The nodes are listed under the <navigation> tag Element portal = XMLUtils.getFirstChild(library.getDocumentElement(), "portal", "type", "navigation"); String moduleLayout = null;//from ww w.j a v a2 s . com String page = null; String modulePermission = null; // Look through the modules NodeList moduleNodeList = portal.getElementsByTagName("module"); for (int i = 0; i < moduleNodeList.getLength(); i++) { Node thisModule = moduleNodeList.item(i); NodeList urlNodeList = ((Element) thisModule).getElementsByTagName("url"); for (int j = 0; j < urlNodeList.getLength(); j++) { Element urlElement = (Element) urlNodeList.item(j); // Construct a ProjectPortalURL and add to the list for retrieving String name = urlElement.getAttribute("name"); // <url name="/show" object="/" page="project profile"/> if (name.equals("/" + portalBean.getAction())) { String object = urlElement.getAttribute("object"); if (object.equals("/" + portalBean.getDomainObject())) { // Set the module for tab highlighting portalBean.setModule(((Element) thisModule).getAttribute("name")); // Set the page for looking up page = urlElement.getAttribute("page"); // Set the layout filename to find the referenced page moduleLayout = ((Element) thisModule).getAttribute("layout"); // Set the permission required for viewing this page modulePermission = ((Element) thisModule).getAttribute("permission"); break; } } } } URL moduleResource = ProjectPortalUtils.class.getResource("/portal/" + moduleLayout); LOG.debug("module config file: " + moduleResource.toString()); XMLUtils module = new XMLUtils(moduleResource); Element moduleElement = XMLUtils.getFirstChild(module.getDocumentElement(), "navigation"); NodeList pageNodeList = moduleElement.getElementsByTagName("page"); if (pageNodeList.getLength() == 0) { LOG.warn("No pages found in moduleLayout: " + moduleLayout); } for (int j = 0; j < pageNodeList.getLength(); j++) { Node thisPage = pageNodeList.item(j); String pageName = ((Element) thisPage).getAttribute("name"); if (pageName.equals(page)) { LOG.debug("Found page " + pageName); // Find a portal template to use Project thisProject = ProjectUtils.loadProject(portalBean.getProjectId()); DashboardPage dashboardPage = null; if (thisProject.getCategoryId() > -1) { // Use a category specific portal ProjectCategory category = ProjectUtils.loadProjectCategory(thisProject.getCategoryId()); LOG.debug("Trying a category specific portal: " + page + ": " + category.getDescription().toLowerCase()); dashboardPage = DashboardUtils.loadDashboardPage(DashboardTemplateList.TYPE_NAVIGATION, (portalBean.isPopup() ? page + "-popup" : page) + ": " + category.getDescription().toLowerCase(), moduleLayout); } if (dashboardPage == null) { LOG.debug("Trying a specific portal: " + page); dashboardPage = DashboardUtils.loadDashboardPage(DashboardTemplateList.TYPE_NAVIGATION, (portalBean.isPopup() ? page + "-popup" : page), moduleLayout); } if (dashboardPage == null) { LOG.warn("Page not found: " + page); System.out.println("ProjectPortalUtils-> * PAGE NOT FOUND *"); return null; } dashboardPage.setProjectId(thisProject.getId()); // Set the dashboard page's module permission if it doesn't have a page permission if (dashboardPage.getPermission() == null) { dashboardPage.setPermission(modulePermission); } return dashboardPage; } } return null; }
From source file:com.liusoft.sc.startup.DigesterFactory.java
/** * Turn on DTD and/or validation (based on the parser implementation) *///w w w .ja va 2s . c o m protected static void configureSchema(Digester digester) { URL url = DigesterFactory.class.getResource(Constants.WebSchemaResourcePath_24); if (url == null) { log.error("Could not get url for " + Constants.WebSchemaResourcePath_24); } else { digester.setSchema(url.toString()); } }