use of com.vaadin.flow.server.AbstractStreamResource in project flow by vaadin.
the class AnchorTest method disabledAnchor_setResource_hrefIsRemoved_enableAnchor_hrefIsRestored.
@Test
public void disabledAnchor_setResource_hrefIsRemoved_enableAnchor_hrefIsRestored() {
mockUI();
AbstractStreamResource resource = new AbstractStreamResource() {
@Override
public String getName() {
return "foo";
}
};
Anchor anchor = new Anchor(resource, "bar");
String href = anchor.getHref();
anchor.setEnabled(false);
Assert.assertFalse(anchor.getElement().hasAttribute("href"));
Assert.assertEquals(href, anchor.getHref());
anchor.setEnabled(true);
Assert.assertEquals(href, anchor.getHref());
}
use of com.vaadin.flow.server.AbstractStreamResource in project flow by vaadin.
the class AnchorTest method disabledAnchor_setResourceWhenDisabled_enableAnchor_resourceIsPreserved.
@Test
public void disabledAnchor_setResourceWhenDisabled_enableAnchor_resourceIsPreserved() {
Anchor anchor = new Anchor("foo", "bar");
anchor.setEnabled(false);
mockUI();
anchor.setHref(new AbstractStreamResource() {
@Override
public String getName() {
return "baz";
}
});
anchor.setEnabled(true);
Assert.assertTrue(anchor.getElement().hasAttribute("href"));
}
use of com.vaadin.flow.server.AbstractStreamResource in project flow by vaadin.
the class AnchorTest method disabledAnchor_setResourceWhenDisabled_hrefIsPreserved.
@Test
public void disabledAnchor_setResourceWhenDisabled_hrefIsPreserved() {
mockUI();
AbstractStreamResource resource = new AbstractStreamResource() {
@Override
public String getName() {
return "foo";
}
};
Anchor anchor = new Anchor(resource, "bar");
String href = anchor.getHref();
anchor.setEnabled(false);
anchor.setHref(new AbstractStreamResource() {
@Override
public String getName() {
return "baz";
}
});
anchor.setEnabled(true);
Assert.assertTrue(anchor.getElement().hasAttribute("href"));
Assert.assertNotEquals(href, anchor.getHref());
}
use of com.vaadin.flow.server.AbstractStreamResource in project flow by vaadin.
the class ElementAttributeMap method unsetResource.
private void unsetResource(String attribute) {
ensureResourceRegistrations();
StreamRegistration registration = resourceRegistrations.get(attribute);
Optional<AbstractStreamResource> resource = Optional.empty();
if (registration != null) {
resource = Optional.ofNullable(registration.getResource());
}
unregisterResource(attribute);
resource.ifPresent(res -> deferRegistration(attribute, res));
}
use of com.vaadin.flow.server.AbstractStreamResource in project flow by vaadin.
the class StreamRequestHandler method handleRequest.
@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException {
String pathInfo = request.getPathInfo();
if (pathInfo == null) {
return false;
}
// remove leading '/'
assert pathInfo.startsWith(Character.toString(PATH_SEPARATOR));
pathInfo = pathInfo.substring(1);
if (!pathInfo.startsWith(DYN_RES_PREFIX)) {
return false;
}
Optional<AbstractStreamResource> abstractStreamResource;
session.lock();
try {
abstractStreamResource = StreamRequestHandler.getPathUri(pathInfo).flatMap(session.getResourceRegistry()::getResource);
if (!abstractStreamResource.isPresent()) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Resource is not found for path=" + pathInfo);
return true;
}
} finally {
session.unlock();
}
if (abstractStreamResource.isPresent()) {
AbstractStreamResource resource = abstractStreamResource.get();
if (resource instanceof StreamResource) {
resourceHandler.handleRequest(session, request, response, (StreamResource) resource);
} else if (resource instanceof StreamReceiver) {
StreamReceiver streamReceiver = (StreamReceiver) resource;
String[] parts = parsePath(pathInfo);
receiverHandler.handleRequest(session, request, response, streamReceiver, parts[0], parts[1]);
} else {
getLogger().warn("Received unknown stream resource.");
}
}
return true;
}
Aggregations