private static final Logger getLogger() {
return Logger.getLogger(Application.class.getName());
}
+
+ /**
+ * Returns a Root with the given id.
+ * <p>
+ * This is meant for framework internal use.
+ * </p>
+ *
+ * @param rootId
+ * The root id
+ * @return The root with the given id or null if not found
+ */
+ public Root getRootById(int rootId) {
+ return roots.get(rootId);
+ }
}
* @return the Root ancestor of this connector, or <code>null</code> if none
* is found.
*/
- protected Root getRoot() {
+ public Root getRoot() {
ClientConnector connector = this;
while (connector != null) {
if (connector instanceof Root) {
/* Handle the request */
if (requestType == RequestType.FILE_UPLOAD) {
- applicationManager.handleFileUpload(root, wrappedRequest,
- wrappedResponse);
+ // Root is resolved in handleFileUpload by
+ // PortletCommunicationManager
+ applicationManager.handleFileUpload(application,
+ wrappedRequest, wrappedResponse);
return;
} else if (requestType == RequestType.BROWSER_DETAILS) {
applicationManager.handleBrowserDetailsRequest(
/* Handle the request */
if (requestType == RequestType.FILE_UPLOAD) {
- Root root = application.getRootForRequest(request);
- if (root == null) {
- throw new ServletException(ERROR_NO_ROOT_FOUND);
- }
- applicationManager.handleFileUpload(root, request, response);
+ // Root is resolved in communication manager
+ applicationManager.handleFileUpload(application, request,
+ response);
return;
} else if (requestType == RequestType.UIDL) {
Root root = application.getRootForRequest(request);
*/
protected void doHandleSimpleMultipartFileUpload(WrappedRequest request,
WrappedResponse response, StreamVariable streamVariable,
- String variableName, Connector owner, String boundary)
+ String variableName, ClientConnector owner, String boundary)
throws IOException {
// multipart parsing, supports only one file for request, but that is
// fine for our current terminal
final String mimeType = rawMimeType;
try {
- /*
- * safe cast as in GWT terminal all variable owners are expected to
- * be components.
- */
- Component component = (Component) owner;
- if (component.isReadOnly()) {
+ // TODO Shouldn't this check connectorEnabled?
+ if (owner == null) {
throw new UploadException(
- "Warning: file upload ignored because the componente was read-only");
+ "File upload ignored because the connector for the stream variable was not found");
+ }
+ if (owner instanceof Component) {
+ if (((Component) owner).isReadOnly()) {
+ throw new UploadException(
+ "Warning: file upload ignored because the componente was read-only");
+ }
}
boolean forgetVariable = streamToReceiver(simpleMultiPartReader,
streamVariable, filename, mimeType, contentLength);
*/
protected void doHandleXhrFilePost(WrappedRequest request,
WrappedResponse response, StreamVariable streamVariable,
- String variableName, Connector owner, int contentLength)
+ String variableName, ClientConnector owner, int contentLength)
throws IOException {
// These are unknown in filexhr ATM, maybe add to Accept header that
}
- abstract String getStreamVariableTargetUrl(Connector owner, String name,
- StreamVariable value);
+ abstract String getStreamVariableTargetUrl(ClientConnector owner,
+ String name, StreamVariable value);
- abstract protected void cleanStreamVariable(Connector owner, String name);
+ abstract protected void cleanStreamVariable(ClientConnector owner,
+ String name);
/**
* Gets the bootstrap handler that should be used for generating the pages
import com.vaadin.terminal.gwt.client.communication.SharedState;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
+import com.vaadin.ui.Root;
/**
* Interface implemented by all connectors that are capable of communicating
* the extension to remove.
*/
public void removeExtension(Extension extension);
+
+ /**
+ * Returns the root this connector is attached to
+ *
+ * @return The Root this connector is attached to or null if it is not
+ * attached to any Root
+ */
+ public Root getRoot();
}
import com.vaadin.terminal.StreamVariable;
import com.vaadin.terminal.WrappedRequest;
import com.vaadin.terminal.WrappedResponse;
-import com.vaadin.terminal.gwt.client.Connector;
import com.vaadin.ui.Root;
/**
* @throws IOException
* @throws InvalidUIDLSecurityKeyException
*/
- public void handleFileUpload(Root root, WrappedRequest request,
- WrappedResponse response) throws IOException,
- InvalidUIDLSecurityKeyException {
+ public void handleFileUpload(Application application,
+ WrappedRequest request, WrappedResponse response)
+ throws IOException, InvalidUIDLSecurityKeyException {
/*
- * URI pattern: APP/UPLOAD/[PID]/[NAME]/[SECKEY] See #createReceiverUrl
+ * URI pattern: APP/UPLOAD/[ROOTID]/[PID]/[NAME]/[SECKEY] See
+ * #createReceiverUrl
*/
String pathInfo = request.getRequestPathInfo();
.indexOf(AbstractApplicationServlet.UPLOAD_URL_PREFIX)
+ AbstractApplicationServlet.UPLOAD_URL_PREFIX.length();
String uppUri = pathInfo.substring(startOfData);
- String[] parts = uppUri.split("/", 3); // 0 = pid, 1= name, 2 = sec key
- String variableName = parts[1];
- String connectorId = parts[0];
+ String[] parts = uppUri.split("/", 4); // 0= rootid, 1 = cid, 2= name, 3
+ // = sec key
+ String rootId = parts[0];
+ String connectorId = parts[1];
+ String variableName = parts[2];
+ Root root = application.getRootById(Integer.parseInt(rootId));
+ Root.setCurrent(root);
StreamVariable streamVariable = pidToNameToStreamVariable.get(
connectorId).get(variableName);
String secKey = streamVariableToSeckey.get(streamVariable);
- if (secKey.equals(parts[2])) {
+ if (secKey.equals(parts[3])) {
- Connector source = getConnector(root, connectorId);
+ ClientConnector source = getConnector(root, connectorId);
String contentType = request.getContentType();
if (contentType.contains("boundary")) {
// Multipart requests contain boundary string
private Map<StreamVariable, String> streamVariableToSeckey;
@Override
- String getStreamVariableTargetUrl(Connector owner, String name,
+ String getStreamVariableTargetUrl(ClientConnector owner, String name,
StreamVariable value) {
/*
* We will use the same APP/* URI space as ApplicationResources but
* prefix url with UPLOAD
*
- * eg. APP/UPLOAD/[PID]/[NAME]/[SECKEY]
+ * eg. APP/UPLOAD/[ROOTID]/[PID]/[NAME]/[SECKEY]
*
* SECKEY is created on each paint to make URL's unpredictable (to
* prevent CSRF attacks).
* handling post
*/
String paintableId = owner.getConnectorId();
- String key = paintableId + "/" + name;
+ int rootId = owner.getRoot().getRootId();
+ String key = rootId + "/" + paintableId + "/" + name;
if (pidToNameToStreamVariable == null) {
pidToNameToStreamVariable = new HashMap<String, Map<String, StreamVariable>>();
}
@Override
- protected void cleanStreamVariable(Connector owner, String name) {
+ protected void cleanStreamVariable(ClientConnector owner, String name) {
Map<String, StreamVariable> nameToStreamVar = pidToNameToStreamVariable
.get(owner.getConnectorId());
nameToStreamVar.remove("name");
import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager;
import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager.DragEventType;
import com.vaadin.ui.Component;
+import com.vaadin.ui.Root;
public class DragAndDropService implements VariableOwner, ClientConnector {
private Logger getLogger() {
return Logger.getLogger(DragAndDropService.class.getName());
}
+
+ public Root getRoot() {
+ return null;
+ }
}
import com.vaadin.terminal.StreamVariable;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.terminal.VariableOwner;
-import com.vaadin.terminal.gwt.client.Connector;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Component;
import com.vaadin.ui.CustomLayout;
public void addVariable(VariableOwner owner, String name,
StreamVariable value) throws PaintException {
- String url = manager.getStreamVariableTargetUrl((Connector) owner,
- name, value);
+ String url = manager.getStreamVariableTargetUrl(
+ (ClientConnector) owner, name, value);
if (url != null) {
addVariable(owner, name, url);
} // else { //NOP this was just a cleanup by component }
super(application);
}
- public void handleFileUpload(Root root, WrappedRequest request,
- WrappedResponse response) throws IOException {
+ public void handleFileUpload(Application application,
+ WrappedRequest request, WrappedResponse response)
+ throws IOException {
String contentType = request.getContentType();
String name = request.getParameter("name");
String ownerId = request.getParameter("rec-owner");
- Connector owner = getConnector(root, ownerId);
+ String rootId = request.getParameter("rootId");
+
+ Root root = application.getRootById(Integer.parseInt(rootId));
+ Root.setCurrent(root);
+
+ ClientConnector owner = getConnector(root, ownerId);
+
StreamVariable streamVariable = ownerToNameToStreamVariable.get(owner)
.get(name);
private Map<Connector, Map<String, StreamVariable>> ownerToNameToStreamVariable;
@Override
- String getStreamVariableTargetUrl(Connector owner, String name,
+ String getStreamVariableTargetUrl(ClientConnector owner, String name,
StreamVariable value) {
if (ownerToNameToStreamVariable == null) {
ownerToNameToStreamVariable = new HashMap<Connector, Map<String, StreamVariable>>();
resurl.setResourceID("UPLOAD");
resurl.setParameter("name", name);
resurl.setParameter("rec-owner", owner.getConnectorId());
+ resurl.setParameter("rootId", "" + owner.getRoot().getRootId());
resurl.setProperty("name", name);
resurl.setProperty("rec-owner", owner.getConnectorId());
+ resurl.setProperty("rootId", "" + owner.getRoot().getRootId());
return resurl.toString();
}
}
@Override
- protected void cleanStreamVariable(Connector owner, String name) {
+ protected void cleanStreamVariable(ClientConnector owner, String name) {
Map<String, StreamVariable> map = ownerToNameToStreamVariable
.get(owner);
map.remove(name);