Author: hoang_to
Date: 2011-05-26 05:55:07 -0400 (Thu, 26 May 2011)
New Revision: 6565
Modified:
portal/branches/stax-integration/component/portal/pom.xml
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfigListener.java
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageSetStAXParser.java
portal/branches/stax-integration/packaging/tomcat/pkg/pom.xml
portal/branches/stax-integration/pom.xml
Log:
GTNPORTAL-1905: Init page using Stax
Modified: portal/branches/stax-integration/component/portal/pom.xml
===================================================================
--- portal/branches/stax-integration/component/portal/pom.xml 2011-05-26 03:27:48 UTC (rev
6564)
+++ portal/branches/stax-integration/component/portal/pom.xml 2011-05-26 09:55:07 UTC (rev
6565)
@@ -116,7 +116,6 @@
<dependency>
<groupId>org.staxnav</groupId>
<artifactId>staxnav.core</artifactId>
- <version>0.9.1-SNAPSHOT</version>
</dependency>
</dependencies>
Modified:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfigListener.java
===================================================================
---
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfigListener.java 2011-05-26
03:27:48 UTC (rev 6564)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfigListener.java 2011-05-26
09:55:07 UTC (rev 6565)
@@ -32,19 +32,28 @@
import org.exoplatform.portal.config.model.PageNode;
import org.exoplatform.portal.config.model.PortalConfig;
import org.exoplatform.portal.config.model.Page.PageSet;
+import org.exoplatform.portal.config.stax.PageSetStAXParser;
+import org.exoplatform.portal.config.stax.PageStAXParser;
+import org.exoplatform.portal.config.stax.StAXElement;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import org.jibx.runtime.*;
import org.jibx.runtime.impl.UnmarshallingContext;
+import org.staxnav.Naming;
+import org.staxnav.StaxNavigator;
+import org.staxnav.StaxNavigatorImpl;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
/**
* Created by The eXo Platform SARL Author : Tuan Nguyen
@@ -383,14 +392,24 @@
public void createPage(NewPortalConfig config, String owner) throws Exception
{
- PageSet pageSet = getConfig(config, owner, "pages", PageSet.class);
+ StaxNavigator<StAXElement> staxNavigator = buildStAXNavigator(config, owner,
"pages");
+ if(staxNavigator == null)
+ {
+ return;
+ }
+
+ PageSet pageSet = new PageSetStAXParser(staxNavigator).parseXML();
if (pageSet == null)
{
return;
}
+
+ String ownerType = config.getOwnerType();
ArrayList<Page> list = pageSet.getPages();
for (Page page : list)
{
+ page.setOwnerType(ownerType);
+ page.setOwnerId(owner);
dataStorage_.create(page);
}
}
@@ -503,6 +522,46 @@
return null;
}
+ /**
+ * Build a StaxNavigator object from configuration file
+ *
+ * @param config
+ * @param owner
+ * @param fileName
+ * @return
+ * @throws Exception
+ */
+ private StaxNavigator<StAXElement> buildStAXNavigator(NewPortalConfig config,
String owner, String fileName) throws Exception
+ {
+
+ String ownerType = config.getOwnerType();
+
+ String pathToConfigFile;
+
+ if(owner.charAt(0) == '/')
+ {
+ pathToConfigFile = "/" + ownerType + owner + "/" + fileName
+ ".xml";
+ }
+ else
+ {
+ pathToConfigFile = "/" + ownerType + "/" + owner +
"/" + fileName + ".xml";
+ }
+
+ String xml = getDefaultConfig(config.getTemplateLocation(), pathToConfigFile);
+
+ if(xml == null)
+ {
+ return null;
+ }
+ else
+ {
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new
StringReader(xml));
+
+ return new StaxNavigatorImpl<StAXElement>(new
Naming.Enumerated.Simple<StAXElement>(StAXElement.class,
StAXElement.NO_SUCH_ELEMENT), streamReader);
+ }
+ }
+
private String getDefaultConfig(String location, String path) throws Exception
{
String s = location + path;
Modified:
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 2011-05-26
03:27:48 UTC (rev 6564)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/stax/PageSetStAXParser.java 2011-05-26
09:55:07 UTC (rev 6565)
@@ -45,10 +45,16 @@
Page.PageSet pageSet = new Page.PageSet();
- for(StaxNavigator<StAXElement> pageElementNavigator :
elementNavigator.fork(StAXElement.page))
+ elementNavigator.next(StAXElement.page);
+
+ StAXElement tempElement = elementNavigator.getName();
+ while(tempElement == StAXElement.page)
{
- PageStAXParser pageStAXParser = new PageStAXParser(pageElementNavigator);
+ //Call to fork() make the elementNavigator navigate to sibling of current entry
+ PageStAXParser pageStAXParser = new PageStAXParser(elementNavigator.fork());
pageSet.getPages().add(pageStAXParser.parseXML());
+
+ tempElement = elementNavigator.getName();
}
return pageSet;
Modified: portal/branches/stax-integration/packaging/tomcat/pkg/pom.xml
===================================================================
--- portal/branches/stax-integration/packaging/tomcat/pkg/pom.xml 2011-05-26 03:27:48 UTC
(rev 6564)
+++ portal/branches/stax-integration/packaging/tomcat/pkg/pom.xml 2011-05-26 09:55:07 UTC
(rev 6565)
@@ -350,6 +350,12 @@
<artifactId>mop-spi</artifactId>
</dependency>
+ <!-- Staxnav -->
+ <dependency>
+ <groupId>org.staxnav</groupId>
+ <artifactId>staxnav.core</artifactId>
+ </dependency>
+
<!-- GateIn Captcha -->
<dependency>
<groupId>org.gatein.captcha</groupId>
Modified: portal/branches/stax-integration/pom.xml
===================================================================
--- portal/branches/stax-integration/pom.xml 2011-05-26 03:27:48 UTC (rev 6564)
+++ portal/branches/stax-integration/pom.xml 2011-05-26 09:55:07 UTC (rev 6565)
@@ -52,6 +52,7 @@
<org.gatein.mop.version>1.1.0-Beta01</org.gatein.mop.version>
<version.chromattic>1.1.0-beta2</version.chromattic>
<version.reflext>1.1.0-beta12</version.reflext>
+ <org.staxnav.version>0.9.1-SNAPSHOT</org.staxnav.version>
<jcip.version>1.0</jcip.version>
<!-- ************** -->
@@ -638,6 +639,13 @@
<version>${version.chromattic}</version>
</dependency>
+ <!-- Staxnav -->
+ <dependency>
+ <groupId>org.staxnav</groupId>
+ <artifactId>staxnav.core</artifactId>
+ <version>${org.staxnav.version}</version>
+ </dependency>
+
<!-- Picketlink -->
<dependency>
<groupId>org.picketlink.idm</groupId>