public URL normalizeURI(URI relativeOrAbsoluteURI) { // TODO: I have one device (Netgear 834DG DSL Router) that sends a <URLBase>, and even that is wrong (port)! // This can be fixed by "re-enabling" UPnP in the upnpService after a reboot, it will then use the right port... // return URIUtil.createAbsoluteURL(getDescriptorURL(), relativeOrAbsoluteURI); if (getDetails() != null && getDetails().getBaseURL() != null) { // If we have an <URLBase>, all URIs are relative to it return URIUtil.createAbsoluteURL(getDetails().getBaseURL(), relativeOrAbsoluteURI); } else { // Otherwise, they are relative to the descriptor location return URIUtil.createAbsoluteURL(getIdentity().getDescriptorURL(), relativeOrAbsoluteURI); } }
@Override public void setAVTransportURI(UnsignedIntegerFourBytes instanceId, String currentURI, String currentURIMetaData) throws AVTransportException { URI uri; try { uri = new URI(currentURI); } catch (Exception ex) { throw new AVTransportException( ErrorCode.INVALID_ARGS, "CurrentURI can not be null or malformed" ); } if (currentURI.startsWith("http:")) { try { HttpFetch.validate(URIUtil.toURL(uri)); } catch (Exception ex) { throw new AVTransportException( AVTransportErrorCode.RESOURCE_NOT_FOUND, ex.getMessage() ); } } else if (!currentURI.startsWith("file:")) { throw new AVTransportException( ErrorCode.INVALID_ARGS, "Only HTTP and file: resource identifiers are supported" ); } // TODO: Check mime type of resource against supported types // TODO: DIDL fragment parsing and handling of currentURIMetaData getInstance(instanceId).setURI(uri); }
protected String getDevicePath(Device device) { if (device.getIdentity().getUdn() == null) { throw new IllegalStateException("Can't generate local URI prefix without UDN"); } StringBuilder s = new StringBuilder(); s.append(DEVICE).append("/"); s.append(URIUtil.encodePathSegment(device.getIdentity().getUdn().getIdentifierString())); return s.toString(); }
/** * Use this constructor if your local icon data can be resolved on the classpath, for * example: <code>MyClass.class.getResource("/my/icon.png)</code> * * @param url A URL of the icon data that can be read with <code>new File(url.toURI())</code>. */ public Icon(String mimeType, int width, int height, int depth, URL url) throws IOException{ this(mimeType, width, height, depth, new File(URIUtil.toURI(url))); }
public static String encodePathParamName(final String pathParamName) { return encode(PATH_PARAM_NAME, pathParamName, "UTF-8"); }
/** * Guarantees that the returned URI is absolute, no matter what the argument is. * * @param base An absolute base URI, can be null! * @param uri A string that either represents a relative or an already absolute URI * @return An absolute URI * @throws IllegalArgumentException If the base URI is null and the given URI string is not absolute */ public static URI createAbsoluteURI(URI base, String uri) throws IllegalArgumentException { return createAbsoluteURI(base, URI.create(uri)); }
public static URI createRelativeURI(URL base, URI full) throws IllegalArgumentException { try { return createRelativeURI(base.toURI(), full); } catch (Exception ex) { throw new IllegalArgumentException("Can't convert base URL to URI", ex); } }
public static URI createRelativePathURI(URI uri) { assertRelativeURI("Given", uri); // Remove all "./" segments URI normalizedURI = uri.normalize(); // Remove all "../" segments String uriString = normalizedURI.toString(); int idx; while ((idx = uriString.indexOf("../")) != -1) uriString = uriString.substring(0, idx) + uriString.substring(idx + 3); // Make relative path while (uriString.startsWith("/")) uriString = uriString.substring(1); return URI.create(uriString); }
/** * Use this constructor if your local icon data can be resolved on the classpath, for * example: <code>MyClass.class.getResource("/my/icon.png)</code> * * @param url A URL of the icon data that can be read with <code>new File(url.toURI())</code>. */ public Icon(String mimeType, int width, int height, int depth, URL url) throws IOException{ this(mimeType, width, height, depth, new File(URIUtil.toURI(url))); }
public static String encodePathParamValue(final String pathParamValue) { return encode(PATH_PARAM_VALUE, pathParamValue, "UTF-8"); }
public static URL createAbsoluteURL(URI base, URI relativeOrNot) throws IllegalArgumentException { try { return createAbsoluteURI(base, relativeOrNot).toURL(); } catch (Exception ex) { throw new IllegalArgumentException("Absolute URI can not be converted to URL", ex); } }
public static URI createRelativeURI(URI base, URL full) throws IllegalArgumentException { try { return createRelativeURI(base, full.toURI()); } catch (Exception ex) { throw new IllegalArgumentException("Can't convert full URL to URI", ex); } }
/** * @return An HTTP URL with the address, port, and path of this location. */ public URL getURL() { return URIUtil.createAbsoluteURL(networkAddress.getAddress(), networkAddress.getPort(), path); }
log.fine("Preparing HTTP request message with method '" + requestOperation.getHttpMethodName() + "': " + requestMessage); URL url = URIUtil.toURL(requestOperation.getURI());
s.append(DEVICE).append("/"); s.append(URIUtil.encodePathSegment(device.getIdentity().getUdn().getIdentifierString()));
/** * Use this constructor if your local icon data can be resolved on the classpath, for * example: <code>MyClass.class.getResource("/my/icon.png)</code> * * @param url A URL of the icon data that can be read with <code>new File(url.toURI())</code>. */ public Icon(String mimeType, int width, int height, int depth, URL url) throws IOException{ this(mimeType, width, height, depth, new File(URIUtil.toURI(url))); }
public static String encodePathSegment(final String pathSegment) { return encode(PATH_SEGMENT, pathSegment, "UTF-8"); }
public static URL createAbsoluteURL(URL base, URI relativeOrNot) throws IllegalArgumentException { if (base == null && !relativeOrNot.isAbsolute()) { throw new IllegalArgumentException("Base URL is null and given URI is not absolute"); } else if (base == null && relativeOrNot.isAbsolute()) { try { return relativeOrNot.toURL(); } catch (Exception ex) { throw new IllegalArgumentException("Base URL was null and given URI can't be converted to URL"); } } else { try { assert base != null; URI baseURI = base.toURI(); URI absoluteURI = createAbsoluteURI(baseURI, relativeOrNot); return absoluteURI.toURL(); } catch (Exception ex) { throw new IllegalArgumentException( "Base URL is not an URI, or can't create absolute URI (null?), " + "or absolute URI can not be converted to URL", ex); } } }
public static URI createRelativeURI(URL base, URL full) throws IllegalArgumentException { try { return createRelativeURI(base.toURI(), full.toURI()); } catch (Exception ex) { throw new IllegalArgumentException("Can't convert base or full URL to URI", ex); } }
public URL normalizeURI(URI relativeOrAbsoluteURI) { // TODO: I have one device (Netgear 834DG DSL Router) that sends a <URLBase>, and even that is wrong (port)! // This can be fixed by "re-enabling" UPnP in the upnpService after a reboot, it will then use the right port... // return URIUtil.createAbsoluteURL(getDescriptorURL(), relativeOrAbsoluteURI); if (getDetails() != null && getDetails().getBaseURL() != null) { // If we have an <URLBase>, all URIs are relative to it return URIUtil.createAbsoluteURL(getDetails().getBaseURL(), relativeOrAbsoluteURI); } else { // Otherwise, they are relative to the descriptor location return URIUtil.createAbsoluteURL(getIdentity().getDescriptorURL(), relativeOrAbsoluteURI); } }