Author: hoang_to
Date: 2011-05-12 07:24:49 -0400 (Thu, 12 May 2011)
New Revision: 6469
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/AbstractStAXParser.java
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/ContainerStAXParser.java
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageBodyStAXParser.java
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageSetStAXParser.java
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageStAXParser.java
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PortalConfigStAXParser.java
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PortletWindowStAXParser.java
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/SiteBodyStAXParser.java
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/StAXElement.java
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPage.java
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageSet.java
portal/branches/stax-integration/component/portal/src/test/resources/stax/
portal/branches/stax-integration/component/portal/src/test/resources/stax/pages.xml
portal/branches/stax-integration/component/portal/src/test/resources/stax/test-page.xml
Modified:
portal/branches/stax-integration/component/portal/pom.xml
Log:
StAX integration
Modified: portal/branches/stax-integration/component/portal/pom.xml
===================================================================
--- portal/branches/stax-integration/component/portal/pom.xml 2011-05-12 11:21:59 UTC (rev
6468)
+++ portal/branches/stax-integration/component/portal/pom.xml 2011-05-12 11:24:49 UTC (rev
6469)
@@ -113,6 +113,12 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.staxnav</groupId>
+ <artifactId>staxnav.core</artifactId>
+ <version>0.9.1-SNAPSHOT</version>
+ </dependency>
+
</dependencies>
<build>
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/AbstractStAXParser.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/AbstractStAXParser.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/AbstractStAXParser.java 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.config.stax;
+
+import org.exoplatform.portal.config.model.ModelObject;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/9/11
+ */
+public abstract class AbstractStAXParser<T extends ModelObject>
+{
+
+ protected StaxNavigator<StAXElement> elementNavigator;
+
+ public AbstractStAXParser(StaxNavigator<StAXElement> elementNavigator) throws
IllegalArgumentException
+ {
+ if(elementNavigator == null)
+ {
+ throw new IllegalArgumentException("Element navigator could not be
null");
+ }
+
+ this.elementNavigator = elementNavigator;
+ }
+
+ public abstract T parseXML() throws StaxNavException;
+
+ /** Return true if element specified by staxElement is optional to object binding **/
+ public abstract boolean isOptional(StAXElement staxElement);
+
+ protected String getContent(StaxNavigator<StAXElement> navigator, StAXElement
staxElement)
+ {
+ if(navigator.next(staxElement))
+ {
+ return navigator.getContent();
+ }
+ else if(isOptional(staxElement))
+ {
+ return "";
+ }
+ else
+ {
+ throw new StaxNavException(navigator.getLocation(), "Was expecting element
" + staxElement + " to be present at the place of " +
navigator.getName());
+ }
+
+ }
+
+}
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/ContainerStAXParser.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/ContainerStAXParser.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/ContainerStAXParser.java 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.config.stax;
+
+import org.exoplatform.portal.config.model.Container;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/9/11
+ */
+public class ContainerStAXParser extends AbstractStAXParser<Container>
+{
+
+ public ContainerStAXParser(StaxNavigator<StAXElement> elementNavigator)
+ {
+ super(elementNavigator);
+ }
+
+ @Override
+ public Container parseXML() throws StaxNavException
+ {
+ Container container = new Container();
+
+ final Set<StAXElement> childElementSet = new HashSet<StAXElement>();
+ childElementSet.add(StAXElement.portlet_application);
+ childElementSet.add(StAXElement.container);
+
+ StAXElement tempElement = elementNavigator.next(childElementSet);
+
+ while(tempElement != null)
+ {
+ switch(tempElement)
+ {
+ case container:
+ ContainerStAXParser subElementStAXParser = new
ContainerStAXParser(elementNavigator);
+ container.getChildren().add(subElementStAXParser.parseXML());
+ break;
+
+ case portlet_application:
+ PortletWindowStAXParser portletWindowStAXParser = new
PortletWindowStAXParser(elementNavigator);
+ container.getChildren().add(portletWindowStAXParser.parseXML());
+ break;
+ }
+
+ tempElement = elementNavigator.next(childElementSet);
+ }
+
+ return container;
+ }
+
+ @Override
+ public boolean isOptional(StAXElement staxElement)
+ {
+ return false; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+}
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageBodyStAXParser.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageBodyStAXParser.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageBodyStAXParser.java 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.config.stax;
+
+import org.exoplatform.portal.config.model.PageBody;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/9/11
+ */
+public class PageBodyStAXParser extends AbstractStAXParser<PageBody>
+{
+
+ public PageBodyStAXParser(StaxNavigator<StAXElement> elementNavigator) throws
IllegalArgumentException
+ {
+ super(elementNavigator);
+ }
+
+ @Override
+ public PageBody parseXML() throws StaxNavException
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ @Override
+ public boolean isOptional(StAXElement staxElement)
+ {
+ return false; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+}
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageSetStAXParser.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageSetStAXParser.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageSetStAXParser.java 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.config.stax;
+
+import org.exoplatform.portal.config.model.Page;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/9/11
+ */
+public class PageSetStAXParser
+{
+
+ private StaxNavigator<StAXElement> elementNavigator;
+
+ public PageSetStAXParser(StaxNavigator<StAXElement> elementNavigator)
+ {
+ this.elementNavigator = elementNavigator;
+ }
+
+ public Page.PageSet parseXML() throws StaxNavException
+ {
+ if(elementNavigator.getName() != StAXElement.page_set)
+ {
+ throw new StaxNavException("Expect a root element named page-set");
+ }
+
+ Page.PageSet pageSet = new Page.PageSet();
+
+ for(StaxNavigator<StAXElement> pageElementNavigator :
elementNavigator.fork(StAXElement.page))
+ {
+ PageStAXParser pageStAXParser = new PageStAXParser(pageElementNavigator);
+ pageSet.getPages().add(pageStAXParser.parseXML());
+ }
+
+ return pageSet;
+ }
+
+}
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageStAXParser.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageStAXParser.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageStAXParser.java 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.config.stax;
+
+import org.exoplatform.portal.config.model.ModelObject;
+import org.exoplatform.portal.config.model.Page;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/9/11
+ */
+public class PageStAXParser extends AbstractStAXParser<Page>
+{
+
+ public PageStAXParser(StaxNavigator<StAXElement> elementNavigator)
+ {
+ super(elementNavigator);
+ }
+
+ @Override
+ public Page parseXML() throws StaxNavException
+ {
+ Page page = new Page();
+
+ page.setName(getContent(elementNavigator, StAXElement.name));
+ page.setTitle(getContent(elementNavigator, StAXElement.title));
+
+ String factoryID = getContent(elementNavigator, StAXElement.factory_id);
+ if(factoryID.length() > 0)
+ {
+ page.setFactoryId(factoryID);
+ }
+
+ String accessPermissions = getContent(elementNavigator,
StAXElement.access_permissions);
+ if(accessPermissions.length() > 0)
+ {
+ page.setAccessPermissions(accessPermissions.split(","));
+ }
+
+ page.setEditPermission(getContent(elementNavigator, StAXElement.edit_permission));
+ page.setShowMaxWindow("true".equals(getContent(elementNavigator,
StAXElement.show_max_window)));
+
+ ArrayList<ModelObject> children = new ArrayList<ModelObject>(3);
+
+ final Set<StAXElement> modelObjectElements = new
HashSet<StAXElement>();
+ modelObjectElements.add(StAXElement.portlet_application);
+ modelObjectElements.add(StAXElement.container);
+
+ StAXElement tempElement = elementNavigator.next(modelObjectElements);
+
+ while(tempElement != null)
+ {
+ switch(tempElement)
+ {
+ case portlet_application:
+ PortletWindowStAXParser portletWindowStAXParser = new
PortletWindowStAXParser(elementNavigator);
+ children.add(portletWindowStAXParser.parseXML());
+ break;
+
+ case container:
+ ContainerStAXParser containerStAXParser = new
ContainerStAXParser(elementNavigator);
+ children.add(containerStAXParser.parseXML());
+ break;
+ }
+
+ tempElement = elementNavigator.next(modelObjectElements);
+ }
+
+ page.setChildren(children);
+
+ return page;
+ }
+
+ @Override
+ public boolean isOptional(StAXElement staxElement)
+ {
+ switch(staxElement)
+ {
+ case title:
+ case factory_id:
+ case access_permissions:
+ case edit_permission:
+ case show_max_window:
+ return true;
+
+ default:
+ return false;
+ }
+ }
+}
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PortalConfigStAXParser.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PortalConfigStAXParser.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PortalConfigStAXParser.java 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.config.stax;
+
+import org.exoplatform.portal.config.model.PortalConfig;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/9/11
+ */
+public class PortalConfigStAXParser extends AbstractStAXParser<PortalConfig>
+{
+
+ public PortalConfigStAXParser(StaxNavigator<StAXElement> elementNavigator)
throws IllegalArgumentException
+ {
+ super(elementNavigator); //To change body of overridden methods use File |
Settings | File Templates.
+ }
+
+ @Override
+ public PortalConfig parseXML() throws StaxNavException
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ @Override
+ public boolean isOptional(StAXElement staxElement)
+ {
+ return false; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+}
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PortletWindowStAXParser.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PortletWindowStAXParser.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PortletWindowStAXParser.java 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.config.stax;
+
+import org.exoplatform.portal.config.model.Application;
+import org.exoplatform.portal.config.model.TransientApplicationState;
+import org.exoplatform.portal.config.serialize.PortletApplication;
+import org.exoplatform.portal.pom.spi.portlet.Portlet;
+import org.exoplatform.portal.pom.spi.portlet.PortletBuilder;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/9/11
+ */
+public class PortletWindowStAXParser extends
AbstractStAXParser<Application<Portlet>>
+{
+
+ public PortletWindowStAXParser(StaxNavigator<StAXElement> elementNavigator)
+ {
+ super(elementNavigator);
+ }
+
+ @Override
+ public Application<Portlet> parseXML() throws StaxNavException
+ {
+ elementNavigator.next(StAXElement.portlet);
+
+ String applicationName = getContent(elementNavigator,
StAXElement.application_ref);
+ String portletName = getContent(elementNavigator, StAXElement.portlet_ref);
+
+ TransientApplicationState<Portlet> state;
+
+ if(elementNavigator.next(StAXElement.preferences))
+ {
+ PortletBuilder builder = new PortletBuilder();
+
+ while(elementNavigator.next(StAXElement.preference))
+ {
+ String preferenceName = getContent(elementNavigator, StAXElement.name);
+ String preferenceValue = getContent(elementNavigator, StAXElement.value);
+ boolean readOnly = "true".equals(getContent(elementNavigator,
StAXElement.read_only));
+
+ builder.add(preferenceName, preferenceValue, readOnly);
+ }
+
+ state = new TransientApplicationState<Portlet>(applicationName +
"/" + portletName, builder.build());
+ }
+ else
+ {
+ state = new TransientApplicationState<Portlet>(applicationName +
"/" + portletName, null);
+ }
+
+ Application<Portlet> application = Application.createPortletApplication();
+ application.setState(state);
+
+ application.setTitle(getContent(elementNavigator, StAXElement.title));
+ application.setTheme(getContent(elementNavigator, StAXElement.theme));
+ application.setAccessPermissions(getContent(elementNavigator,
StAXElement.access_permissions).split(","));
+ application.setShowInfoBar("true".equals(getContent(elementNavigator,
StAXElement.show_info_bar)));
+
application.setShowApplicationState("true".equals(getContent(elementNavigator,
StAXElement.show_application_state)));
+
application.setShowApplicationMode("true".equals(getContent(elementNavigator,
StAXElement.show_application_state)));
+ application.setDescription(getContent(elementNavigator, StAXElement.description));
+ application.setIcon(getContent(elementNavigator, StAXElement.icon));
+ application.setWidth(getContent(elementNavigator, StAXElement.width));
+ application.setHeight(getContent(elementNavigator, StAXElement.height));
+
+ return application;
+ }
+
+ @Override
+ public boolean isOptional(StAXElement staxElement)
+ {
+ switch(staxElement)
+ {
+ case preferences:
+ case theme:
+ case show_application_state:
+ case description:
+ case icon:
+ case width:
+ case height:
+ return true;
+
+ default:
+ return false;
+ }
+ }
+}
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/SiteBodyStAXParser.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/SiteBodyStAXParser.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/SiteBodyStAXParser.java 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.config.stax;
+
+import org.exoplatform.portal.config.model.SiteBody;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/9/11
+ */
+public class SiteBodyStAXParser extends AbstractStAXParser<SiteBody>
+{
+
+ public SiteBodyStAXParser(StaxNavigator<StAXElement> elementNavigator) throws
IllegalArgumentException
+ {
+ super(elementNavigator); //To change body of overridden methods use File |
Settings | File Templates.
+ }
+
+ @Override
+ public SiteBody parseXML() throws StaxNavException
+ {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ @Override
+ public boolean isOptional(StAXElement staxElement)
+ {
+ return false; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+}
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/StAXElement.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/StAXElement.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/StAXElement.java 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.config.stax;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/9/11
+ */
+public enum StAXElement
+{
+ page_set,
+
+ page,
+
+ name,
+
+ title,
+
+ factory_id,
+
+ access_permissions,
+
+ edit_permission,
+
+ show_max_window,
+
+ portlet_application,
+
+ portlet,
+
+ application_ref,
+
+ portlet_ref,
+
+ preferences,
+
+ preference,
+
+ value,
+
+ read_only,
+
+ theme,
+
+ show_info_bar,
+
+ show_application_state,
+
+ show_application_mode,
+
+ description,
+
+ icon,
+
+ width,
+
+ height,
+
+ gadget_application,
+
+ container,
+
+ portal_config,
+
+ NO_SUCH_ELEMENT
+
+}
Added:
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPage.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPage.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPage.java 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.stax;
+
+import junit.framework.TestCase;
+import org.exoplatform.portal.config.model.Application;
+import org.exoplatform.portal.config.model.ApplicationType;
+import org.exoplatform.portal.config.model.Page;
+import org.exoplatform.portal.config.stax.PageStAXParser;
+import org.exoplatform.portal.config.stax.StAXElement;
+import org.staxnav.Naming;
+import org.staxnav.StaxNavigator;
+import org.staxnav.StaxNavigatorImpl;
+import java.io.InputStream;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/11/11
+ */
+public class TestParsingPage extends TestCase
+{
+
+ private StaxNavigator<StAXElement> pageMetadata;
+
+ protected void setUp() throws Exception
+ {
+ InputStream in =
ClassLoader.getSystemClassLoader().getResourceAsStream("./stax/test-page.xml");
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+
+ XMLStreamReader streamReader = factory.createXMLStreamReader(in);
+
+ pageMetadata = new StaxNavigatorImpl<StAXElement>(new
Naming.Enumerated.Simple<StAXElement>(StAXElement.class,
StAXElement.NO_SUCH_ELEMENT), streamReader);
+ }
+
+ public void testConvertXML() throws Exception
+ {
+ PageStAXParser pageStAXParser = new PageStAXParser(pageMetadata);
+
+ Page page = pageStAXParser.parseXML();
+
+ assertNotNull(page);
+ assertEquals("homepage", page.getName());
+ assertEquals("Home Page", page.getTitle());
+
+ Application application = (Application)page.getChildren().get(0);
+
+ assertEquals(ApplicationType.PORTLET, application.getType());
+ assertEquals("Home Page portlet", application.getTitle());
+ }
+}
Added:
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageSet.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageSet.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageSet.java 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2011 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.portal.stax;
+
+import junit.framework.TestCase;
+import org.exoplatform.portal.config.model.Page;
+import org.exoplatform.portal.config.stax.PageSetStAXParser;
+import org.exoplatform.portal.config.stax.StAXElement;
+import org.staxnav.Naming;
+import org.staxnav.StaxNavigator;
+import org.staxnav.StaxNavigatorImpl;
+import java.io.InputStream;
+import java.util.List;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/12/11
+ */
+public class TestParsingPageSet extends TestCase
+{
+
+ private StaxNavigator<StAXElement> elementNavigator;
+
+ protected void setUp() throws Exception
+ {
+ InputStream in =
ClassLoader.getSystemClassLoader().getResourceAsStream("./stax/pages.xml");
+
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ XMLStreamReader streamReader = factory.createXMLStreamReader(in);
+
+ elementNavigator = new StaxNavigatorImpl<StAXElement>(new
Naming.Enumerated.Simple<StAXElement>(StAXElement.class,
StAXElement.NO_SUCH_ELEMENT), streamReader);
+ }
+
+ public void testNumberOfPage()
+ {
+ PageSetStAXParser pageSetStAXParser = new PageSetStAXParser(elementNavigator);
+
+ Page.PageSet pageSet = pageSetStAXParser.parseXML();
+
+ List<Page> pages = pageSet.getPages();
+
+ assertEquals(5, pages.size());
+ }
+}
Added:
portal/branches/stax-integration/component/portal/src/test/resources/stax/pages.xml
===================================================================
--- portal/branches/stax-integration/component/portal/src/test/resources/stax/pages.xml
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/test/resources/stax/pages.xml 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+
+<page-set
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_1
http://www.gatein.org/xml/ns/gatein_objects_1_1"
+
xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_1">
+
+ <page>
+ <name>homepage</name>
+ <title>Home Page</title>
+ <access-permissions>Everyone</access-permissions>
+ <edit-permission>*:/platform/administrators</edit-permission>
+ <portlet-application>
+ <portlet>
+ <application-ref>web</application-ref>
+ <portlet-ref>HomePagePortlet</portlet-ref>
+ <preferences>
+ <preference>
+ <name>template</name>
+
<value>system:/templates/groovy/webui/component/UIHomePagePortlet.gtmpl</value>
+ <read-only>false</read-only>
+ </preference>
+ </preferences>
+ </portlet>
+ <title>Home Page portlet</title>
+ <access-permissions>Everyone</access-permissions>
+ <show-info-bar>false</show-info-bar>
+ <show-application-state>false</show-application-state>
+ <show-application-mode>false</show-application-mode>
+ </portlet-application>
+ </page>
+
+ <page>
+ <name>groupnavigation</name>
+ <title>Group Navigation</title>
+ <access-permissions>*:/platform/users</access-permissions>
+ <edit-permission>*:/platform/administrators</edit-permission>
+ <portlet-application>
+ <portlet>
+ <application-ref>exoadmin</application-ref>
+ <portlet-ref>GroupNavigationPortlet</portlet-ref>
+ </portlet>
+ <title>Group Navigation</title>
+ <access-permissions>Everyone</access-permissions>
+ <show-info-bar>false</show-info-bar>
+ </portlet-application>
+ </page>
+
+ <page>
+ <name>portalnavigation</name>
+ <title>Portal Navigation</title>
+ <access-permissions>*:/platform/users</access-permissions>
+ <edit-permission>*:/platform/administrators</edit-permission>
+ <portlet-application>
+ <portlet>
+ <application-ref>exoadmin</application-ref>
+ <portlet-ref>PortalNavigationPortlet</portlet-ref>
+ </portlet>
+ <title>Portal Navigation</title>
+ <access-permissions>Everyone</access-permissions>
+ <show-info-bar>false</show-info-bar>
+ </portlet-application>
+ </page>
+
+ <page>
+ <name>register</name>
+ <title>Register</title>
+ <access-permissions>*:/platform/guests</access-permissions>
+ <edit-permission>*:/platform/administrators</edit-permission>
+ <portlet-application>
+ <portlet>
+ <application-ref>exoadmin</application-ref>
+ <portlet-ref>RegisterPortlet</portlet-ref>
+ </portlet>
+ <title>Register Account</title>
+ <access-permissions>*:/platform/guests</access-permissions>
+ <show-info-bar>false</show-info-bar>
+ </portlet-application>
+ </page>
+ <page>
+ <name>sitemap</name>
+ <title>Site Map</title>
+ <access-permissions>Everyone</access-permissions>
+ <edit-permission>*:/platform/administrators</edit-permission>
+ <portlet-application>
+ <portlet>
+ <application-ref>web</application-ref>
+ <portlet-ref>SiteMapPortlet</portlet-ref>
+ </portlet>
+ <title>SiteMap</title>
+ <access-permissions>Everyone</access-permissions>
+ <show-info-bar>false</show-info-bar>
+ </portlet-application>
+ </page>
+</page-set>
Added:
portal/branches/stax-integration/component/portal/src/test/resources/stax/test-page.xml
===================================================================
---
portal/branches/stax-integration/component/portal/src/test/resources/stax/test-page.xml
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/test/resources/stax/test-page.xml 2011-05-12
11:24:49 UTC (rev 6469)
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ This is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of
+ the License, or (at your option) any later version.
+
+ This software is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this software; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+
+-->
+
+<page>
+ <name>homepage</name>
+ <title>Home Page</title>
+ <access-permissions>Everyone</access-permissions>
+ <edit-permission>*:/platform/administrators</edit-permission>
+ <portlet-application>
+ <portlet>
+ <application-ref>web</application-ref>
+ <portlet-ref>HomePagePortlet</portlet-ref>
+ <preferences>
+ <preference>
+ <name>template</name>
+
<value>system:/templates/groovy/webui/component/UIHomePagePortlet.gtmpl</value>
+ <read-only>false</read-only>
+ </preference>
+ </preferences>
+ </portlet>
+ <title>Home Page portlet</title>
+ <access-permissions>Everyone</access-permissions>
+ <show-info-bar>false</show-info-bar>
+ <show-application-state>false</show-application-state>
+ <show-application-mode>false</show-application-mode>
+ </portlet-application>
+</page>
\ No newline at end of file