List of usage examples for java.net URI URI
public URI(String str) throws URISyntaxException
From source file:Main.java
/** * Opens the given website in the default browser, or show a message saying * that no default browser could be accessed. *//* w w w . j a va 2 s . c o m*/ public static void browse(Component parent, String uri) { boolean error = false; if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) { try { Desktop.getDesktop().browse(new URI(uri)); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } catch (IOException ex) { error = true; } } else { error = true; } if (error) { String msg = "Impossible to open the default browser from the application.\nSorry."; JOptionPane.showMessageDialog(parent, msg); } }
From source file:Main.java
/** * Opens the given website in the default browser, or shows a message saying * that no default browser could be accessed. *//* w w w . j ava 2s.c o m*/ public static void browse(String url, Component msgParent) { boolean error = false; if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Action.BROWSE)) { try { Desktop.getDesktop().browse(new URI(url)); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } catch (IOException ex) { error = true; } } else { error = true; } if (error) { String msg = "Impossible to open the default browser from the application.\nSorry."; JOptionPane.showMessageDialog(msgParent, msg); } }
From source file:Main.java
public static boolean isURI(String str) { if (str.indexOf(':') == -1) return false; str = str.toLowerCase(Locale.ENGLISH).trim(); if (!str.startsWith("http://") && !str.startsWith("https://") && !str.startsWith("ftp://")) return false; try {/*from w ww. j a v a2s . c o m*/ URI uri = new URI(str); String proto = uri.getScheme(); if (proto == null) return false; if (proto.equals("http") || proto.equals("https") || proto.equals("ftp")) { if (uri.getHost() == null) return false; String path = uri.getPath(); if (path != null) { int len = path.length(); for (int i = 0; i < len; i++) { if ("?<>:*|\"".indexOf(path.charAt(i)) > -1) return false; } } } return true; } catch (Exception ex) { return false; } }
From source file:Main.java
public static URI toURI(String name) { try {//from w w w . j a va 2 s . c o m return new URI(name); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * Retrieves the raw (unescaped) path and query parameters from the URI, stripping out the scheme, host, and port. * The path will begin with a leading '/'. For example, 'http://example.com/some/resource?param%20name=param%20value' * would return '/some/resource?param%20name=param%20value'. * * @param uriString the URI to parse, containing a scheme, host, port, path, and query parameters * @return the unescaped path and query parameters from the URI * @throws URISyntaxException if the specified URI is invalid or cannot be parsed *//*from w w w. j a va 2 s.c o m*/ public static String getRawPathAndParamsFromUri(String uriString) throws URISyntaxException { URI uri = new URI(uriString); String path = uri.getRawPath(); String query = uri.getRawQuery(); if (query != null) { return path + '?' + query; } else { return path; } }
From source file:Main.java
/** * Create a HTML hyperlink in JLabel component * * @param label/* www. ja v a2s . co m*/ * @param url * @param text */ public static void createHyperLink(JLabel label, final String url, String text) { label.setToolTipText(url); label.setText("<html><a href=\"\">" + text + "</a></html>"); label.setCursor(new Cursor(Cursor.HAND_CURSOR)); label.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop().browse(new URI(url)); } catch (IOException ex) { throw new RuntimeException(ex); } catch (URISyntaxException ex) { throw new RuntimeException(ex); } } }); }
From source file:Main.java
public static void openWebpage(String url) throws IOException, URISyntaxException { openWebpage(new URI(url)); }
From source file:Main.java
private static boolean isInvalidOrigin(String origin) { if (origin.isEmpty() || origin.contains("%")) { return true; }//from ww w . j a va2 s . c o m try { return new URI(origin).getScheme() == null; } catch (URISyntaxException e) { return true; } }
From source file:Main.java
public static void deepCopyDocument(Document ttml, File target) throws IOException { try {//ww w . j a v a2 s .com XPathFactory xPathfactory = XPathFactory.newInstance(); XPath xpath = xPathfactory.newXPath(); XPathExpression expr = xpath.compile("//*/@backgroundImage"); NodeList nl = (NodeList) expr.evaluate(ttml, XPathConstants.NODESET); for (int i = 0; i < nl.getLength(); i++) { Node backgroundImage = nl.item(i); URI backgroundImageUri = URI.create(backgroundImage.getNodeValue()); if (!backgroundImageUri.isAbsolute()) { copyLarge(new URI(ttml.getDocumentURI()).resolve(backgroundImageUri).toURL().openStream(), new File(target.toURI().resolve(backgroundImageUri).toURL().getFile())); } } copyLarge(new URI(ttml.getDocumentURI()).toURL().openStream(), target); } catch (XPathExpressionException e) { throw new IOException(e); } catch (URISyntaxException e) { throw new IOException(e); } }
From source file:cz.muni.fi.pa165.rentalofconstructionmachinery.restclient.MachineRestController.java
public static void deleteMachine(Long id) throws URISyntaxException { String url = MACHINE_URL + id; rt.exchange(new URI(url), HttpMethod.DELETE, new HttpEntity<>(httpHeaders), Object.class); }