]> source.dussan.org Git - vaadin-framework.git/commitdiff
Work-In-Progress
authorPetter Holmström <petter.holmstrom@itmill.com>
Fri, 30 Oct 2009 12:57:44 +0000 (12:57 +0000)
committerPetter Holmström <petter.holmstrom@itmill.com>
Fri, 30 Oct 2009 12:57:44 +0000 (12:57 +0000)
svn changeset:9510/svn branch:portlet_2.0

src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
src/com/vaadin/terminal/gwt/server/Constants.java
src/com/vaadin/terminal/gwt/server/PortletApplicationContext2.java
src/com/vaadin/terminal/gwt/server/PortletCommunicationManagerImpl.java

index 10278e6537dfeaad58f02e57c9c23a8f2efbb483..ac04468975e92ac235d84d7a2fbbfab44aadac14 100644 (file)
@@ -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() + "', ");
index 0cf6bc5dbe0a3ffe2eae452f2e71911fba5bb127..defc0a10c54025645fd694eb6b4c8fcf00840f29 100644 (file)
@@ -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";
 
 }
index cb69836f9ff4eec94ac90450c3e510ba28df1882..48357eb75fa4eed8d8ea5d11b69d02a0e6d3fe63 100644 (file)
@@ -38,7 +38,6 @@ public class PortletApplicationContext2 implements ApplicationContext,
 
     protected HashMap<Application, PortletCommunicationManager> applicationToAjaxAppMgrMap = new HashMap<Application, PortletCommunicationManager>();
 
-    @Override
     public void addTransactionListener(TransactionListener listener) {
         if (listeners == null) {
             listeners = new LinkedList<TransactionListener>();
@@ -46,12 +45,10 @@ public class PortletApplicationContext2 implements ApplicationContext,
         listeners.add(listener);
     }
 
-    @Override
     public Collection<Application> 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
     }
index 302546c3c5e40f213385f1c87ed62a193176aa42..c8960bce3dc71d6b7922bd275e5ab159020afba9 100644 (file)
@@ -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");
     }
 
 }