From: Petter Holmström Date: Fri, 30 Oct 2009 12:57:44 +0000 (+0000) Subject: Work-In-Progress X-Git-Tag: 6.7.0.beta1~2266^2~24 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7bb03090e2568c57a9e8db83ef9b0a2c807bcf1b;p=vaadin-framework.git Work-In-Progress svn changeset:9510/svn branch:portlet_2.0 --- diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java index 10278e6537..ac04468975 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java @@ -13,6 +13,7 @@ import javax.portlet.PortletConfig; import javax.portlet.PortletException; import javax.portlet.PortletRequest; import javax.portlet.PortletResponse; +import javax.portlet.PortletSession; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.portlet.ResourceRequest; @@ -91,7 +92,7 @@ public abstract class AbstractApplicationPortlet implements Portlet, try { /* Find out which application this request is related to */ - application = findApplicationInstance(request); + application = findApplicationInstance(request, requestType); if (application == null) { return; } @@ -167,6 +168,7 @@ public abstract class AbstractApplicationPortlet implements Portlet, } } catch (final Throwable e) { // TODO Handle exceptions + e.printStackTrace(); } finally { // Notifies transaction end if (application != null) { @@ -178,8 +180,8 @@ public abstract class AbstractApplicationPortlet implements Portlet, private void serveStaticResources(ResourceRequest request, ResourceResponse response) { - // TODO Auto-generated method stub - + // TODO Implement me! + throw new UnsupportedOperationException("Not implemented yet"); } public void processAction(ActionRequest request, ActionResponse response) @@ -194,7 +196,6 @@ public abstract class AbstractApplicationPortlet implements Portlet, handleRequest(request, response); } - @Override public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException { System.out.println("AbstractApplicationPortlet.serveResource()"); @@ -204,36 +205,106 @@ public abstract class AbstractApplicationPortlet implements Portlet, private Window getApplicationWindow(PortletRequest request, PortletCommunicationManager applicationManager, Application application) throws PortletException { - // TODO Auto-generated method stub - return null; + // TODO Implement me! + throw new UnsupportedOperationException("Not implemented yet"); + } + + boolean requestCanCreateApplication(PortletRequest request, RequestType requestType) { + if (requestType == RequestType.UIDL && isRepaintAll(request)) { + return true; + } else if (requestType == RequestType.RENDER) { + return true; + } + return false; + } + + private boolean isRepaintAll(PortletRequest request) { + return (request.getParameter(Constants.URL_PARAMETER_REPAINT_ALL) != null) + && (request.getParameter(Constants.URL_PARAMETER_REPAINT_ALL).equals("1")); } private void startApplication(PortletRequest request, Application application, PortletCommunicationManager applicationManager) throws PortletException, MalformedURLException { - // TODO Auto-generated method stub + // TODO Implement me! + throw new UnsupportedOperationException("Not implemented yet"); } private void endApplication(PortletRequest request, PortletResponse response, Application application) throws IOException { - // TODO Auto-generated method stub + // TODO Implement me! + throw new UnsupportedOperationException("Not implemented yet"); } - private Application findApplicationInstance(PortletRequest request) + private Application findApplicationInstance(PortletRequest request, RequestType requestType) throws PortletException, SessionExpired, MalformedURLException { - return null; + + boolean requestCanCreateApplication = requestCanCreateApplication(request, requestType); + + /* Find an existing application for this request. */ + Application application = getExistingApplication(request, requestCanCreateApplication); + + if (application != null) { + /* + * There is an existing application. We can use this as long as the + * user not specifically requested to close or restart it. + */ + + final boolean restartApplication = (request + .getParameter(Constants.URL_PARAMETER_RESTART_APPLICATION) != null); + final boolean closeApplication = (request + .getParameter(Constants.URL_PARAMETER_CLOSE_APPLICATION) != null); + + if (restartApplication) { + closeApplication(application, request.getPortletSession(false)); + return createApplication(request); + } else if (closeApplication) { + closeApplication(application, request.getPortletSession(false)); + return null; + } else { + return application; + } + } + + // No existing application was found + + if (requestCanCreateApplication) { + return createApplication(request); + } else { + throw new SessionExpired(); + } + } + + private void closeApplication(Application application, PortletSession session) { + // TODO Implement me! + throw new UnsupportedOperationException("Not implemented yet"); + } + + private Application createApplication(PortletRequest request) + throws PortletException, MalformedURLException { + // TODO Implement me! + throw new UnsupportedOperationException("Not implemented yet"); } + private Application getExistingApplication(PortletRequest request, + boolean allowSessionCreation) throws MalformedURLException, + SessionExpired { + // TODO Implement me! + throw new UnsupportedOperationException("Not implemented yet"); + } + protected void writeAjaxPage(RenderRequest request, RenderResponse response, Window window, Application application) throws IOException, MalformedURLException, PortletException { + + System.out.println("AbstractApplicationPortlet.writeAjaxPage()"); + + response.setContentType("text/html"); final BufferedWriter page = new BufferedWriter(new OutputStreamWriter( response.getPortletOutputStream(), "UTF-8")); - response.setContentType("text/html"); - // TODO Figure out the format of resource URLs ResourceURL widgetsetURL = response.createResourceURL(); // TODO Add support for custom widgetsets. @@ -254,11 +325,10 @@ public abstract class AbstractApplicationPortlet implements Portlet, + widgetsetURL.toString() + "'><\\/script>\");\n}\n"); page.write("vaadin.vaadinConfigurations[\"" + request.getWindowID() + "\"] = {"); - page.write("portletMode: true, "); - - String pathInfo = response.createActionURL().toString(); - - page.write("pathInfo: '" + pathInfo + "', "); + page.write("appId: null, "); + page.write("usePortletURLs: true, "); + page.write("portletActionURLBase: '" + response.createActionURL().toString() + "', "); + page.write("pathInfo: null, "); // TODO Custom window if (window != application.getMainWindow()) { page.write("windowName: '" + window.getName() + "', "); diff --git a/src/com/vaadin/terminal/gwt/server/Constants.java b/src/com/vaadin/terminal/gwt/server/Constants.java index 0cf6bc5dbe..defc0a10c5 100644 --- a/src/com/vaadin/terminal/gwt/server/Constants.java +++ b/src/com/vaadin/terminal/gwt/server/Constants.java @@ -16,5 +16,11 @@ public interface Constants { public static final String DEFAULT_WIDGETSET = "com.vaadin.terminal.gwt.DefaultWidgetSet"; // public static final String AJAX_UIDL_URI = "/UIDL"; + + public static final String URL_PARAMETER_REPAINT_ALL = "repaintAll"; + + public static final String URL_PARAMETER_RESTART_APPLICATION = "restartApplication"; + + public static final String URL_PARAMETER_CLOSE_APPLICATION = "closeApplication"; } diff --git a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java index cb69836f9f..48357eb75f 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java +++ b/src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java @@ -38,7 +38,6 @@ public class PortletApplicationContext2 implements ApplicationContext, protected HashMap applicationToAjaxAppMgrMap = new HashMap(); - @Override public void addTransactionListener(TransactionListener listener) { if (listeners == null) { listeners = new LinkedList(); @@ -46,12 +45,10 @@ public class PortletApplicationContext2 implements ApplicationContext, listeners.add(listener); } - @Override public Collection getApplications() { return Collections.unmodifiableCollection(applications); } - @Override public File getBaseDirectory() { String resultPath = session.getPortletContext().getRealPath("/"); if (resultPath != null) { @@ -68,7 +65,6 @@ public class PortletApplicationContext2 implements ApplicationContext, return null; } - @Override public void removeTransactionListener(TransactionListener listener) { if (listeners != null) { listeners.remove(listener); @@ -169,7 +165,6 @@ public class PortletApplicationContext2 implements ApplicationContext, return session; } - @Override public void valueBound(HttpSessionBindingEvent event) { // We are not interested in bindings } diff --git a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManagerImpl.java b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManagerImpl.java index 302546c3c5..c8960bce3d 100644 --- a/src/com/vaadin/terminal/gwt/server/PortletCommunicationManagerImpl.java +++ b/src/com/vaadin/terminal/gwt/server/PortletCommunicationManagerImpl.java @@ -15,24 +15,21 @@ import com.vaadin.terminal.Paintable.RepaintRequestEvent; public class PortletCommunicationManagerImpl implements PortletCommunicationManager, Paintable.RepaintRequestListener, Serializable { - @Override public void repaintRequested(RepaintRequestEvent event) { - // TODO Auto-generated method stub - + // TODO Implement me! + throw new UnsupportedOperationException("Not implemented yet"); } - @Override public void handleFileUpload(ActionRequest request, ActionResponse response) throws FileUploadException, IOException { - // TODO Auto-generated method stub - + // TODO Implement me! + throw new UnsupportedOperationException("Not implemented yet"); } - @Override public void handleUIDLRequest(ActionRequest request, ActionResponse response) throws IOException, PortletException { - // TODO Auto-generated method stub - + // TODO Implement me! + throw new UnsupportedOperationException("Not implemented yet"); } }