Author: hoang_to
Date: 2011-05-26 07:45:08 -0400 (Thu, 26 May 2011)
New Revision: 6566
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageNavigationStAXParser.java
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageNodeStAXParser.java
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageNavigation.java
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageNode.java
portal/branches/stax-integration/component/portal/src/test/resources/stax/navigation.xml
portal/branches/stax-integration/component/portal/src/test/resources/stax/node.xml
Modified:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/AbstractStAXParserFactory.java
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/StAXElement.java
Log:
GTNPORTAL-1905: Add parser for PageNode, PageNavigation and relevant JUnit tests
Modified:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/AbstractStAXParserFactory.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/AbstractStAXParserFactory.java 2011-05-26
09:55:07 UTC (rev 6565)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/AbstractStAXParserFactory.java 2011-05-26
11:45:08 UTC (rev 6566)
@@ -45,6 +45,11 @@
return (AbstractStAXParser<T>) new
GadgetWindowStAXParer(elementNavigator);
case container:
return (AbstractStAXParser<T>) new
ContainerStAXParser(elementNavigator);
+ case node:
+ return (AbstractStAXParser<T>) new
PageNodeStAXParser(elementNavigator);
+ case node_navigation:
+ return (AbstractStAXParser<T>) new
PageNavigationStAXParser(elementNavigator);
+
default:
throw new IllegalArgumentException("StAXElement " + element +
" is not associated with any subclass of ModelObject");
}
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageNavigationStAXParser.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageNavigationStAXParser.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageNavigationStAXParser.java 2011-05-26
11:45:08 UTC (rev 6566)
@@ -0,0 +1,74 @@
+/*
+ * 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.PageNavigation;
+import org.exoplatform.portal.config.model.PageNode;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/24/11
+ */
+public class PageNavigationStAXParser extends AbstractStAXParser<PageNavigation>
+{
+
+ public PageNavigationStAXParser(StaxNavigator<StAXElement> elementNavigator)
throws IllegalArgumentException
+ {
+ super(elementNavigator);
+ }
+
+ @Override
+ public PageNavigation parseXML() throws StaxNavException
+ {
+ PageNavigation pageNavigation = new PageNavigation();
+ pageNavigation.setOwnerType(getContent(elementNavigator, StAXElement.owner_type));
+ pageNavigation.setOwnerId(getContent(elementNavigator, StAXElement.owner_id));
+
+ String priority = getContent(elementNavigator, StAXElement.priority);
+ if (priority != null)
+ {
+ pageNavigation.setPriority(Integer.parseInt(priority));
+ }
+
+ elementNavigator.next(StAXElement.page_nodes);
+ elementNavigator.next(StAXElement.node);
+
+ StAXElement tempElement = elementNavigator.getName();
+
+ while (tempElement == StAXElement.node)
+ {
+ AbstractStAXParser<ModelObject> pageNodeParser =
AbstractStAXParserFactory.getParser(StAXElement.node, elementNavigator.fork());
+ PageNode childNode = (PageNode)pageNodeParser.parseXML();
+ pageNavigation.addNode(childNode);
+
+ tempElement = elementNavigator.getName();
+ }
+
+ return pageNavigation;
+ }
+
+ @Override
+ public boolean isOptional(StAXElement staxElement)
+ {
+ return true;
+ }
+}
Added:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageNodeStAXParser.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageNodeStAXParser.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageNodeStAXParser.java 2011-05-26
11:45:08 UTC (rev 6566)
@@ -0,0 +1,98 @@
+/*
+ * 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.PageNode;
+import org.exoplatform.portal.mop.Visibility;
+import org.staxnav.StaxNavException;
+import org.staxnav.StaxNavigator;
+import java.util.Date;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/24/11
+ */
+public class PageNodeStAXParser extends AbstractStAXParser<PageNode>
+{
+ public PageNodeStAXParser(StaxNavigator<StAXElement> elementNavigator) throws
IllegalArgumentException
+ {
+ super(elementNavigator);
+ }
+
+ @Override
+ public PageNode parseXML() throws StaxNavException
+ {
+ PageNode pageNode = new PageNode();
+
+ pageNode.setUri(getContent(elementNavigator, StAXElement.uri));
+ pageNode.setName(getContent(elementNavigator, StAXElement.name));
+ pageNode.setLabel(getContent(elementNavigator, StAXElement.label));
+ pageNode.setIcon(getContent(elementNavigator, StAXElement.icon));
+
+ elementNavigator.next(StAXElement.start_publication_date);
+ elementNavigator.next(StAXElement.end_publication_date);
+
+ String visibilityContent = getContent(elementNavigator, StAXElement.visibility);
+ Visibility visibility;
+ if(visibilityContent == null)
+ {
+ visibility = Visibility.DISPLAYED;
+ }
+ else
+ {
+ visibility = Visibility.valueOf(visibilityContent);
+ }
+
+ pageNode.setVisibility(visibility);
+
+ pageNode.setPageReference(getContent(elementNavigator,
StAXElement.page_reference));
+
+ elementNavigator.next(StAXElement.node);
+
+ StAXElement tempElement = elementNavigator.getName();
+ while(tempElement == StAXElement.node)
+ {
+ AbstractStAXParser<ModelObject> pageNodeParser =
AbstractStAXParserFactory.getParser(StAXElement.node, elementNavigator.fork());
+ PageNode childNode = (PageNode)pageNodeParser.parseXML();
+ pageNode.getChildren().add(childNode);
+
+ tempElement = elementNavigator.getName();
+ }
+
+ return pageNode;
+ }
+
+ @Override
+ public boolean isOptional(StAXElement staxElement)
+ {
+ switch (staxElement)
+ {
+ case label:
+ case icon:
+ case start_publication_date:
+ case end_publication_date:
+ case visibility:
+ case page_reference:
+ return true;
+ default:
+ return false;
+ }
+ }
+}
Modified:
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 2011-05-26
09:55:07 UTC (rev 6565)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/StAXElement.java 2011-05-26
11:45:08 UTC (rev 6566)
@@ -94,6 +94,30 @@
entry,
+ node_navigation,
+
+ owner_type,
+
+ owner_id,
+
+ priority,
+
+ page_nodes,
+
+ node,
+
+ uri,
+
+ label,
+
+ start_publication_date,
+
+ end_publication_date,
+
+ visibility,
+
+ page_reference,
+
NO_SUCH_ELEMENT
}
Added:
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageNavigation.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageNavigation.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageNavigation.java 2011-05-26
11:45:08 UTC (rev 6566)
@@ -0,0 +1,81 @@
+/*
+ * 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 org.exoplatform.portal.config.model.PageNavigation;
+import org.exoplatform.portal.config.model.PageNode;
+import org.exoplatform.portal.config.stax.PageNavigationStAXParser;
+import org.exoplatform.portal.config.stax.StAXElement;
+import org.exoplatform.portal.mop.Visibility;
+import org.staxnav.StaxNavigator;
+import java.util.List;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/26/11
+ */
+public class TestParsingPageNavigation extends AbstractStaxTestCase
+{
+
+ private StaxNavigator<StAXElement> elementNavigator;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ elementNavigator = createNavigator("/stax/navigation.xml");
+ }
+
+ public void testPageNavigation()
+ {
+ PageNavigationStAXParser parser = new PageNavigationStAXParser(elementNavigator);
+
+ PageNavigation navigation = parser.parseXML();
+
+ assertEquals("portal", navigation.getOwnerType());
+ assertEquals("classic", navigation.getOwnerId());
+
+ assertEquals(1, navigation.getPriority());
+
+ List<PageNode> nodes = navigation.getNodes();
+
+ PageNode pageNode = nodes.get(0);
+
+ assertEquals("home", pageNode.getUri());
+ assertEquals("home", pageNode.getName());
+ assertEquals("#{portal.classic.home}", pageNode.getLabel());
+ assertEquals(Visibility.DISPLAYED, pageNode.getVisibility());
+ assertEquals("portal::classic::homepage", pageNode.getPageReference());
+
+ pageNode = nodes.get(1);
+
+ assertEquals("sitemap", pageNode.getUri());
+ assertEquals("sitemap", pageNode.getName());
+ assertEquals("#{portal.classic.sitemap}", pageNode.getLabel());
+ assertEquals(Visibility.HIDDEN, pageNode.getVisibility());
+ assertEquals("portal::classic::sitemap", pageNode.getPageReference());
+
+ pageNode = nodes.get(2);
+
+ assertEquals("notfound", pageNode.getUri());
+ assertEquals("notfound", pageNode.getName());
+ assertEquals("NotFound", pageNode.getLabel());
+ assertEquals(Visibility.SYSTEM, pageNode.getVisibility());
+ assertNull(pageNode.getPageReference());
+ }
+}
Added:
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageNode.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageNode.java
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/test/java/org/exoplatform/portal/stax/TestParsingPageNode.java 2011-05-26
11:45:08 UTC (rev 6566)
@@ -0,0 +1,55 @@
+/*
+ * 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 org.exoplatform.portal.config.model.PageNode;
+import org.exoplatform.portal.config.stax.PageNodeStAXParser;
+import org.exoplatform.portal.config.stax.StAXElement;
+import org.exoplatform.portal.mop.Visibility;
+import org.staxnav.StaxNavigator;
+
+/**
+ * @author <a href="hoang281283(a)gmail.com">Minh Hoang TO</a>
+ * @date 5/25/11
+ */
+public class TestParsingPageNode extends AbstractStaxTestCase
+{
+
+ private StaxNavigator<StAXElement> elementNavigator;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ elementNavigator = createNavigator("/stax/node.xml");
+ }
+
+ public void testPageNode()
+ {
+ PageNodeStAXParser parser = new PageNodeStAXParser(elementNavigator);
+
+ PageNode pageNode = parser.parseXML();
+
+ assertNotNull(pageNode);
+ assertEquals("sitemap", pageNode.getUri());
+ assertEquals("sitemap", pageNode.getName());
+ assertEquals("#{portal.classic.sitemap}", pageNode.getLabel());
+ assertEquals(Visibility.HIDDEN, pageNode.getVisibility());
+ assertEquals("portal::classic::sitemap", pageNode.getPageReference());
+ }
+}
Added:
portal/branches/stax-integration/component/portal/src/test/resources/stax/navigation.xml
===================================================================
---
portal/branches/stax-integration/component/portal/src/test/resources/stax/navigation.xml
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/test/resources/stax/navigation.xml 2011-05-26
11:45:08 UTC (rev 6566)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+
+<node-navigation
+
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">
+
+ <owner-type>portal</owner-type>
+ <owner-id>classic</owner-id>
+ <priority>1</priority>
+
+ <page-nodes>
+ <node>
+ <uri>home</uri>
+ <name>home</name>
+ <label>#{portal.classic.home}</label>
+ <page-reference>portal::classic::homepage</page-reference>
+ </node>
+ <node>
+ <uri>sitemap</uri>
+ <name>sitemap</name>
+ <label>#{portal.classic.sitemap}</label>
+ <visibility>HIDDEN</visibility>
+ <page-reference>portal::classic::sitemap</page-reference>
+ </node>
+
+ <!-- NOT FOUND node -->
+ <node>
+ <uri>notfound</uri>
+ <name>notfound</name>
+ <label>NotFound</label>
+ <visibility>SYSTEM</visibility>
+ </node>
+ </page-nodes>
+</node-navigation>
Added: portal/branches/stax-integration/component/portal/src/test/resources/stax/node.xml
===================================================================
--- portal/branches/stax-integration/component/portal/src/test/resources/stax/node.xml
(rev 0)
+++
portal/branches/stax-integration/component/portal/src/test/resources/stax/node.xml 2011-05-26
11:45:08 UTC (rev 6566)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+
+<node>
+ <uri>sitemap</uri>
+ <name>sitemap</name>
+ <label>#{portal.classic.sitemap}</label>
+ <visibility>HIDDEN</visibility>
+ <page-reference>portal::classic::sitemap</page-reference>
+</node>