/** * Gets the URI for the given {@code resource}. * <p> * The URI won't be handled (and won't work) if {@code resource} is not * registered in the session. * * @see #registerResource(StreamResource) * * @param resource * stream resource * @return resource URI */ public static URI getURI(StreamResource resource) { return getURI(resource.getId(), resource.getFileName()); }
/** * Registers a stream resource in the session and returns registration * handler. * <p> * You can get resource URI to use it in the application (e.g. set an * attribute value or property value) via the registration handler. The * registration handler should be used to unregister resource when it's not * needed anymore. Note that it is the developer's responsibility to * unregister resources. Otherwise resources won't be garbage collected * until the session expires which causes memory leak. * * @param resource * stream resource to register * @return registration handler. */ public StreamResourceRegistration registerResource( StreamResource resource) { assert session.hasLock(); Registration registration = new Registration(this, resource.getId(), resource.getFileName()); resources.put(registration.getResourceUri(), resource); return registration; }