[gatein-commits] gatein SVN: r8733 - in epp/portal/branches/EPP_5_2_Branch/component/portal/src: test/java/org/exoplatform/portal/mop/management/binding/xml and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Jun 20 11:33:40 EDT 2012


Author: hfnukal
Date: 2012-06-20 11:33:39 -0400 (Wed, 20 Jun 2012)
New Revision: 8733

Modified:
   epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java
   epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/Element.java
   epp/portal/branches/EPP_5_2_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/management/binding/xml/PageMarshallerTest.java
   epp/portal/branches/EPP_5_2_Branch/component/portal/src/test/resources/org/exoplatform/portal/mop/management/pages-loaded.xml
Log:
Bug 807279 - Support WSRP applications for Export/Import

Modified: epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java	2012-06-20 11:49:26 UTC (rev 8732)
+++ epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/AbstractMarshaller.java	2012-06-20 15:33:39 UTC (rev 8733)
@@ -34,6 +34,7 @@
 import org.exoplatform.portal.config.model.Page;
 import org.exoplatform.portal.config.model.PageBody;
 import org.exoplatform.portal.config.model.TransientApplicationState;
+import org.exoplatform.portal.pom.spi.wsrp.WSRP;
 import org.gatein.common.xml.stax.writer.StaxWriter;
 import org.gatein.common.xml.stax.writer.WritableValueTypes;
 import org.exoplatform.portal.pom.data.ModelDataStorage;
@@ -76,7 +77,7 @@
          }
          else if (ApplicationType.WSRP_PORTLET == type)
          {
-            throw new XMLStreamException("WSRP portlet marshalling not supported.");
+            marshalWsrpApplication(writer, safeCast(application, WSRP.class));
          }
       }
       else if (modelObject instanceof Page)
@@ -282,74 +283,30 @@
       writer.writeEndElement(); // End of portlet-application
    }
 
-   protected Application<Portlet> unmarshalPortletApplication(StaxNavigator<Element> navigator) throws XMLStreamException
+   protected Application<?> unmarshalPortletApplication(StaxNavigator<Element> navigator) throws XMLStreamException
    {
-      requiresChild(navigator, Element.PORTLET);
-      ApplicationState<Portlet> state = unmarshalPortletApplicationState(navigator.fork());
-
-      Application<Portlet> portlet = new Application<Portlet>(ApplicationType.PORTLET);
-      portlet.setState(state);
-
-      boolean showInfoBarParsed = false;
-
-      Element current = navigator.sibling();
-      while (current != null)
+      Application<?> application;
+      switch (navigator.child())
       {
-         switch (current)
-         {
-            case THEME:
-               portlet.setTheme(navigator.getContent());
-               current = navigator.sibling();
-               break;
-            case TITLE:
-               portlet.setTitle(navigator.getContent());
-               current = navigator.sibling();
-               break;
-            case ACCESS_PERMISSIONS:
-               portlet.setAccessPermissions(unmarshalAccessPermissions(navigator, true));
-               current = navigator.sibling();
-               break;
-            case SHOW_INFO_BAR:
-               portlet.setShowInfoBar(parseRequiredContent(navigator, ValueType.BOOLEAN));
-               showInfoBarParsed = true;
-               current = navigator.sibling();
-               break;
-            case SHOW_APPLICATION_STATE:
-               portlet.setShowApplicationState(navigator.parseContent(ValueType.BOOLEAN));
-               current = navigator.sibling();
-               break;
-            case SHOW_APPLICATION_MODE:
-               portlet.setShowApplicationMode(navigator.parseContent(ValueType.BOOLEAN));
-               current = navigator.sibling();
-               break;
-            case DESCRIPTION:
-               portlet.setDescription(navigator.getContent());
-               current = navigator.sibling();
-               break;
-            case ICON:
-               portlet.setIcon(navigator.getContent());
-               current = navigator.sibling();
-               break;
-            case WIDTH:
-               portlet.setWidth(navigator.getContent());
-               current = navigator.sibling();
-               break;
-            case HEIGHT:
-               portlet.setHeight(navigator.getContent());
-               current = navigator.sibling();
-               break;
-            case UNKNOWN:
-               throw unknownElement(navigator);
-            default:
-               throw unexpectedElement(navigator);
-         }
+         case PORTLET:
+            ApplicationState<Portlet> state = unmarshalPortletApplicationState(navigator.fork());
+            Application<Portlet> portlet = new Application<Portlet>(ApplicationType.PORTLET);
+            portlet.setState(state);
+            application = portlet;
+            break;
+         case WSRP:
+            ApplicationState<WSRP> wsrpState = unmarshalWsrpApplicationState(navigator.fork());
+            Application<WSRP> wsrp = new Application<WSRP>(ApplicationType.WSRP_PORTLET);
+            wsrp.setState(wsrpState);
+            application = wsrp;
+            break;
+         case UNKNOWN:
+            throw unexpectedElement(navigator);
+         default:
+            throw unexpectedElement(navigator);
       }
 
-      //TODO: We should raise this exception as soon as we know so location is accurate
-      if (portlet.getAccessPermissions() == null) throw expectedElement(navigator, Element.ACCESS_PERMISSIONS);
-      if (!showInfoBarParsed) throw expectedElement(navigator, Element.SHOW_INFO_BAR);
-
-      return portlet;
+      return unmarshalApplication(navigator, application);
    }
 
    private ApplicationState<Portlet> unmarshalPortletApplicationState(StaxNavigator<Element> navigator) throws XMLStreamException
@@ -493,6 +450,102 @@
       Application<Gadget> gadget = new Application<Gadget>(ApplicationType.GADGET);
       gadget.setState(state);
 
+      return unmarshalApplication(navigator, gadget);
+   }
+
+   private ApplicationState<Gadget> unmarshalGadgetApplicationState(StaxNavigator<Element> navigator) throws XMLStreamException
+   {
+      requiresChild(navigator, Element.GADGET_REF);
+      String gadgetRef = getRequiredContent(navigator, true);
+
+      //TODO: Implement userPref unmarshalling when gatein_objects support it
+      Gadget gadget = null;
+
+      if (navigator.next() != null)
+      {
+         throw unexpectedElement(navigator);
+      }
+
+      return new TransientApplicationState<Gadget>(gadgetRef, gadget);
+   }
+
+   protected void marshalWsrpApplication(StaxWriter<Element> writer, Application<WSRP> wsrpApplication) throws XMLStreamException
+   {
+      writer.writeStartElement(Element.PORTLET_APPLICATION);
+      
+      // Marshal application state
+      String contentId;
+      ApplicationState<WSRP> state = wsrpApplication.getState();
+      if (state instanceof TransientApplicationState)
+      {
+         TransientApplicationState<WSRP> tas = (TransientApplicationState<WSRP>) state;
+         contentId = tas.getContentId();
+      }
+      else
+      {
+         // The only way to retrieve the information if the state is not transient is if we're within the portal context
+         ExoContainer container = ExoContainerContext.getCurrentContainer();
+         if (container instanceof PortalContainer)
+         {
+            DataStorage dataStorage = (DataStorage) container.getComponentInstanceOfType(DataStorage.class);
+            try
+            {
+               contentId = dataStorage.getId(state);
+            }
+            catch (Exception e)
+            {
+               throw new XMLStreamException("Could not obtain contentId.", e);
+            }
+         }
+         else
+         {
+            throw new XMLStreamException("Cannot marshal application state " + state + " outside the context of the portal.");
+         }
+      }
+
+      writer.writeElement(Element.WSRP, contentId);
+
+      marshalApplication(writer, wsrpApplication);
+
+      writer.writeEndElement(); // end portlet-application
+   }
+
+   private ApplicationState<WSRP> unmarshalWsrpApplicationState(StaxNavigator<Element> navigator) throws XMLStreamException
+   {
+      String portletId = getRequiredContent(navigator, true);
+      if (navigator.next() != null)
+      {
+         throw unexpectedElement(navigator);
+      }
+
+      return new TransientApplicationState<WSRP>(portletId, null);
+   }
+
+   protected void marshalApplication(StaxWriter<Element> writer, Application<?> application) throws XMLStreamException
+   {
+      // Theme, Title
+      writeOptionalElement(writer, Element.THEME, application.getTheme());
+      writeOptionalElement(writer, Element.TITLE, application.getTitle());
+
+      // Access Permissions
+      marshalAccessPermissions(writer, application.getAccessPermissions());
+
+      // common application elements
+      writeOptionalElement(writer, Element.SHOW_INFO_BAR, String.valueOf(application.getShowInfoBar()));
+      writeOptionalElement(writer, Element.SHOW_APPLICATION_STATE, String.valueOf(application.getShowApplicationState()));
+      writeOptionalElement(writer, Element.SHOW_APPLICATION_MODE, String.valueOf(application.getShowApplicationMode()));
+
+      // Description, Icon
+      writeOptionalElement(writer, Element.DESCRIPTION, application.getDescription());
+      writeOptionalElement(writer, Element.ICON, application.getIcon());
+
+      // Width & Height
+      writeOptionalElement(writer, Element.WIDTH, application.getWidth());
+      writeOptionalElement(writer, Element.HEIGHT, application.getHeight());
+   }
+   
+   protected <S> Application<S> unmarshalApplication(StaxNavigator<Element> navigator, Application<S> application) throws XMLStreamException
+   {
       boolean showInfoBarParsed = false;
 
       Element current = navigator.sibling();
@@ -501,44 +554,44 @@
          switch (current)
          {
             case THEME:
-               gadget.setTheme(navigator.getContent());
+               application.setTheme(navigator.getContent());
                current = navigator.sibling();
                break;
             case TITLE:
-               gadget.setTitle(navigator.getContent());
+               application.setTitle(navigator.getContent());
                current = navigator.sibling();
                break;
             case ACCESS_PERMISSIONS:
-               gadget.setAccessPermissions(unmarshalAccessPermissions(navigator, true));
+               application.setAccessPermissions(unmarshalAccessPermissions(navigator, true));
                current = navigator.sibling();
                break;
             case SHOW_INFO_BAR:
-               gadget.setShowInfoBar(parseRequiredContent(navigator, ValueType.BOOLEAN));
+               application.setShowInfoBar(parseRequiredContent(navigator, ValueType.BOOLEAN));
                showInfoBarParsed = true;
                current = navigator.sibling();
                break;
             case SHOW_APPLICATION_STATE:
-               gadget.setShowApplicationState(navigator.parseContent(ValueType.BOOLEAN));
+               application.setShowApplicationState(navigator.parseContent(ValueType.BOOLEAN));
                current = navigator.sibling();
                break;
             case SHOW_APPLICATION_MODE:
-               gadget.setShowApplicationMode(navigator.parseContent(ValueType.BOOLEAN));
+               application.setShowApplicationMode(navigator.parseContent(ValueType.BOOLEAN));
                current = navigator.sibling();
                break;
             case DESCRIPTION:
-               gadget.setDescription(navigator.getContent());
+               application.setDescription(navigator.getContent());
                current = navigator.sibling();
                break;
             case ICON:
-               gadget.setIcon(navigator.getContent());
+               application.setIcon(navigator.getContent());
                current = navigator.sibling();
                break;
             case WIDTH:
-               gadget.setWidth(navigator.getContent());
+               application.setWidth(navigator.getContent());
                current = navigator.sibling();
                break;
             case HEIGHT:
-               gadget.setHeight(navigator.getContent());
+               application.setHeight(navigator.getContent());
                current = navigator.sibling();
                break;
             case UNKNOWN:
@@ -549,51 +602,12 @@
       }
 
       //TODO: We should raise this exception as soon as we know so location is accurate
-      if (gadget.getAccessPermissions() == null) throw expectedElement(navigator, Element.ACCESS_PERMISSIONS);
+      if (application.getAccessPermissions() == null) throw expectedElement(navigator, Element.ACCESS_PERMISSIONS);
       if (!showInfoBarParsed) throw expectedElement(navigator, Element.SHOW_INFO_BAR);
 
-      return gadget;
+      return application;
    }
 
-   private ApplicationState<Gadget> unmarshalGadgetApplicationState(StaxNavigator<Element> navigator) throws XMLStreamException
-   {
-      requiresChild(navigator, Element.GADGET_REF);
-      String gadgetRef = getRequiredContent(navigator, true);
-
-      //TODO: Implement userPref unmarshalling when gatein_objects support it
-      Gadget gadget = null;
-
-      if (navigator.next() != null)
-      {
-         throw unexpectedElement(navigator);
-      }
-
-      return new TransientApplicationState<Gadget>(gadgetRef, gadget);
-   }
-
-   protected void marshalApplication(StaxWriter<Element> writer, Application<?> application) throws XMLStreamException
-   {
-      // Theme, Title
-      writeOptionalElement(writer, Element.THEME, application.getTheme());
-      writeOptionalElement(writer, Element.TITLE, application.getTitle());
-
-      // Access Permissions
-      marshalAccessPermissions(writer, application.getAccessPermissions());
-
-      // common application elements
-      writeOptionalElement(writer, Element.SHOW_INFO_BAR, String.valueOf(application.getShowInfoBar()));
-      writeOptionalElement(writer, Element.SHOW_APPLICATION_STATE, String.valueOf(application.getShowApplicationState()));
-      writeOptionalElement(writer, Element.SHOW_APPLICATION_MODE, String.valueOf(application.getShowApplicationMode()));
-
-      // Description, Icon
-      writeOptionalElement(writer, Element.DESCRIPTION, application.getDescription());
-      writeOptionalElement(writer, Element.ICON, application.getIcon());
-
-      // Width & Height
-      writeOptionalElement(writer, Element.WIDTH, application.getWidth());
-      writeOptionalElement(writer, Element.HEIGHT, application.getHeight());
-   }
-
    protected void marshalAccessPermissions(StaxWriter<Element> writer, String[] accessPermissions) throws XMLStreamException
    {
       writeOptionalElement(writer, Element.ACCESS_PERMISSIONS, DelimitedValueType.SEMI_COLON, accessPermissions);

Modified: epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/Element.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/Element.java	2012-06-20 11:49:26 UTC (rev 8732)
+++ epp/portal/branches/EPP_5_2_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/management/binding/xml/Element.java	2012-06-20 15:33:39 UTC (rev 8733)
@@ -76,6 +76,7 @@
    PORTLET("portlet"),
    GADGET_REF("gadget-ref"),
    GADGET("gadget"),
+   WSRP("wsrp"),
    THEME("theme"),
    SHOW_INFO_BAR("show-info-bar"),
    SHOW_APPLICATION_STATE("show-application-state"),

Modified: epp/portal/branches/EPP_5_2_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/management/binding/xml/PageMarshallerTest.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/management/binding/xml/PageMarshallerTest.java	2012-06-20 11:49:26 UTC (rev 8732)
+++ epp/portal/branches/EPP_5_2_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/management/binding/xml/PageMarshallerTest.java	2012-06-20 15:33:39 UTC (rev 8733)
@@ -37,6 +37,7 @@
 import org.exoplatform.portal.pom.spi.gadget.Gadget;
 import org.exoplatform.portal.pom.spi.portlet.Portlet;
 import org.exoplatform.portal.pom.spi.portlet.Preference;
+import org.exoplatform.portal.pom.spi.wsrp.WSRP;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -292,31 +293,56 @@
       assertEquals("Everyone", Utils.join(";", container3.getAccessPermissions()));
       assertNull(container3.getFactoryId());
       {
-         // Verify site map application
+         // Verify site map  & wsrp application
          assertNotNull(container3.getChildren());
-         assertEquals(1, container3.getChildren().size());
-         ModelObject sitemapcomponent = container3.getChildren().get(0);
-         assertTrue(sitemapcomponent instanceof Application);
-         @SuppressWarnings("unchecked")
-         Application<Portlet> application = (Application<Portlet>) sitemapcomponent;
-         assertTrue(application.getType() == ApplicationType.PORTLET);
-         ApplicationState<Portlet> state = application.getState();
-         assertNotNull(state);
-         assertTrue(state instanceof TransientApplicationState);
-         TransientApplicationState<Portlet> tas = (TransientApplicationState<Portlet>) state;
-         assertEquals("web/SiteMapPortlet", tas.getContentId());
-         assertNull(tas.getContentState());
+         assertEquals(2, container3.getChildren().size());
+         {
+            ModelObject sitemapcomponent = container3.getChildren().get(0);
+            assertTrue(sitemapcomponent instanceof Application);
+            @SuppressWarnings("unchecked")
+            Application<Portlet> application = (Application<Portlet>) sitemapcomponent;
+            assertTrue(application.getType() == ApplicationType.PORTLET);
+            ApplicationState<Portlet> state = application.getState();
+            assertNotNull(state);
+            assertTrue(state instanceof TransientApplicationState);
+            TransientApplicationState<Portlet> tas = (TransientApplicationState<Portlet>) state;
+            assertEquals("web/SiteMapPortlet", tas.getContentId());
+            assertNull(tas.getContentState());
 
-         assertEquals("Default:DefaultTheme::Vista:VistaTheme::Mac:MacTheme", application.getTheme());
-         assertEquals("SiteMap", application.getTitle());
-         assertEquals("*:/platform/users", Utils.join(";", application.getAccessPermissions()));
-         assertTrue(application.getShowInfoBar());
-         assertTrue(application.getShowApplicationState());
-         assertFalse(application.getShowApplicationMode());
-         assertEquals("SiteMap", application.getDescription());
-         assertNull(application.getIcon());
-         assertNull(application.getWidth());
-         assertNull(application.getHeight());
+            assertEquals("Default:DefaultTheme::Vista:VistaTheme::Mac:MacTheme", application.getTheme());
+            assertEquals("SiteMap", application.getTitle());
+            assertEquals("*:/platform/users", Utils.join(";", application.getAccessPermissions()));
+            assertTrue(application.getShowInfoBar());
+            assertTrue(application.getShowApplicationState());
+            assertFalse(application.getShowApplicationMode());
+            assertEquals("SiteMap", application.getDescription());
+            assertNull(application.getIcon());
+            assertNull(application.getWidth());
+            assertNull(application.getHeight());
+         }
+         {
+            ModelObject wsrpcomponent = container3.getChildren().get(1);
+            assertTrue(wsrpcomponent instanceof Application);
+            @SuppressWarnings("unchecked")
+            Application<WSRP> application = (Application<WSRP>) wsrpcomponent;
+            assertTrue(application.getType() == ApplicationType.WSRP_PORTLET);
+            ApplicationState<WSRP> state = application.getState();
+            assertNotNull(state);
+            assertTrue(state instanceof TransientApplicationState);
+            TransientApplicationState<WSRP> tas = (TransientApplicationState<WSRP>) state;
+            assertEquals("selfv2./portletApplicationName.portletName", tas.getContentId());
+            assertNull(tas.getContentState());
+
+            assertEquals("WSRP", application.getTitle());
+            assertEquals("Someone", Utils.join(";", application.getAccessPermissions()));
+            assertFalse(application.getShowInfoBar());
+            assertTrue(application.getShowApplicationState());
+            assertTrue(application.getShowApplicationMode());
+            assertNull(application.getDescription());
+            assertNull(application.getIcon());
+            assertNull(application.getWidth());
+            assertNull(application.getHeight());
+         }
       }
    }
 

Modified: epp/portal/branches/EPP_5_2_Branch/component/portal/src/test/resources/org/exoplatform/portal/mop/management/pages-loaded.xml
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/component/portal/src/test/resources/org/exoplatform/portal/mop/management/pages-loaded.xml	2012-06-20 11:49:26 UTC (rev 8732)
+++ epp/portal/branches/EPP_5_2_Branch/component/portal/src/test/resources/org/exoplatform/portal/mop/management/pages-loaded.xml	2012-06-20 15:33:39 UTC (rev 8733)
@@ -117,7 +117,13 @@
                <show-application-mode>false</show-application-mode>
                <description>SiteMap</description>
             </portlet-application>
+            <portlet-application>
+               <wsrp>selfv2./portletApplicationName.portletName</wsrp>
+               <title>WSRP</title>
+               <access-permissions>Someone</access-permissions>
+               <show-info-bar>false</show-info-bar>
+            </portlet-application>
          </container>
       </container>
    </page>
-</page-set>
\ No newline at end of file
+</page-set>



More information about the gatein-commits mailing list