List of usage examples for com.vaadin.shared ApplicationConstants APP_PROTOCOL_PREFIX
String APP_PROTOCOL_PREFIX
To view the source code for com.vaadin.shared ApplicationConstants APP_PROTOCOL_PREFIX.
Click Source Link
From source file:org.lucidj.vaadinui.GlobalResourceHandlerEx.java
License:Apache License
@Override public void register(Resource resource, ClientConnector ownerConnector) { // Business as usual super.register(resource, ownerConnector); // In order to show resources properly, we hook register() to filter // all ClassResources that can be transformed into BundleResources. // The trick is actually quite simple, we take the associatedClass and // use it to find out what bundle it belongs. With the source bundle, // getting the resource becomes a trivial bundle.getResource(). // Do we need to override this resource? if (resource instanceof ClassResource) { // We use only explicit associatedClass, because the current UI available // on ClassResource may come from an unrelated bundle Class associated_class = (Class) get_object_field(resource, "associatedClass"); String resource_name = (String) get_object_field(resource, "resourceName"); // Is the magic possible?? if (associated_class != null && resource_name != null) { // After super.register() we can retrieve the uri assigned internally String uri = super.getUri(ownerConnector, (ConnectorResource) resource); String path = uri.substring(ApplicationConstants.APP_PROTOCOL_PREFIX.length() - 1); // Now we can track the resource from uri down to its source bundle Bundle source_bundle = FrameworkUtil.getBundle(associated_class); path_to_resource.put(path, new BundleResource(source_bundle, resource_name)); // Keep the linked connector allowing cleanup path_to_connector.put(path, ownerConnector); }// w w w . jav a 2s . c o m } }