Author: hoang_to
Date: 2011-05-27 00:40:37 -0400 (Fri, 27 May 2011)
New Revision: 6571
Modified:
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfigListener.java
Log:
GTNPORTAL-1905: Use Stax to parse PortalConfig 's configuration
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-27
02:16:32 UTC (rev 6570)
+++
portal/branches/stax-integration/component/portal/src/main/java/org/exoplatform/portal/config/NewPortalConfigListener.java 2011-05-27
04:40:37 UTC (rev 6571)
@@ -35,6 +35,7 @@
import org.exoplatform.portal.config.stax.PageNavigationStAXParser;
import org.exoplatform.portal.config.stax.PageSetStAXParser;
import org.exoplatform.portal.config.stax.PageStAXParser;
+import org.exoplatform.portal.config.stax.PortalConfigStAXParser;
import org.exoplatform.portal.config.stax.StAXElement;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
@@ -337,6 +338,7 @@
}
}
+ @Deprecated
public void initPortletPreferencesDB(NewPortalConfig config) throws Exception
{
for (String owner : config.getPredefinedOwner())
@@ -353,9 +355,9 @@
try
{
String type = config.getOwnerType();
- PortalConfig pconfig = getConfig(config, owner, type, PortalConfig.class);
+ StaxNavigator<StAXElement> staxNavigator = buildStAXNavigator(config,
owner, type);
- if (pconfig == null)
+ if (staxNavigator == null)
{
// Ensure that the PortalConfig has been defined
// The PortalConfig could be empty if the related PortalConfigListener
@@ -371,11 +373,12 @@
return;
}
- // We use that owner value because it may have been fixed for group names
- owner = pconfig.getName();
+ PortalConfig pconfig = new PortalConfigStAXParser(staxNavigator).parseXML();
+ String fixedOwnerName = fixOwnerName(type, owner);
+ pconfig.setType(type);
+ pconfig.setName(fixedOwnerName);
- //
- PortalConfig currentPortalConfig = dataStorage_.getPortalConfig(type, owner);
+ PortalConfig currentPortalConfig = dataStorage_.getPortalConfig(type,
fixedOwnerName);
if (currentPortalConfig == null)
{
dataStorage_.create(pconfig);
@@ -406,19 +409,19 @@
}
String ownerType = config.getOwnerType();
+ String fixedOnwerId = fixOwnerName(ownerType, owner);
ArrayList<Page> list = pageSet.getPages();
for (Page page : list)
{
page.setOwnerType(ownerType);
- page.setOwnerId(owner);
+ page.setOwnerId(fixedOnwerId);
dataStorage_.create(page);
}
}
public void createPageNavigation(NewPortalConfig config, String owner) throws
Exception
{
- //PageNavigation navigation = getConfig(config, owner, "navigation",
PageNavigation.class);
- StaxNavigator<StAXElement> staxNavigator = buildStAXNavigator(config, owner,
"navigation.xml");
+ StaxNavigator<StAXElement> staxNavigator = buildStAXNavigator(config, owner,
"navigation");
if (staxNavigator == null)
{
return;
@@ -427,12 +430,13 @@
PageNavigation navigation = new
PageNavigationStAXParser(staxNavigator).parseXML();
if(navigation.getOwnerType() == null)
{
- navigation.setOwnerType(config.getOwnerType());
+ navigation.setOwnerType(config.getOwnerType());
}
if(navigation.getOwnerId() == null)
{
- navigation.setOwnerId(owner);
+ //Call to fixOwnerName to fix '/' trouble
+ navigation.setOwnerId(fixOwnerName(navigation.getOwnerType(), owner));
}
PageNavigation currentNavigation =
dataStorage_.getPageNavigation(navigation.getOwner());
@@ -455,6 +459,7 @@
}
}
+ @Deprecated
public void createPortletPreferences(NewPortalConfig config, String owner) throws
Exception
{
PortletPreferencesSet portletSet = getConfig(config, owner,
"portlet-preferences", PortletPreferencesSet.class);
@@ -469,6 +474,7 @@
}
}
+
private final Pattern OWNER_PATTERN = Pattern.compile("@owner@");
/**
@@ -549,7 +555,6 @@
{
String ownerType = config.getOwnerType();
-
String pathToConfigFile;
if(owner.charAt(0) == '/')
@@ -563,6 +568,20 @@
String xml = getDefaultConfig(config.getTemplateLocation(), pathToConfigFile);
+ if (xml == null)
+ {
+ boolean isTemplate = (config.getTemplateName() != null &&
config.getTemplateName().trim().length() > 0);
+ if (isTemplate)
+ {
+ pathToConfigFile = "/" + ownerType + "/template/" +
config.getTemplateName() + "/" + fileName + ".xml";
+ xml = getDefaultConfig(config.getTemplateLocation(), pathToConfigFile);
+ if (xml != null)
+ {
+ xml = OWNER_PATTERN.matcher(xml).replaceAll(owner);
+ }
+ }
+ }
+
if(xml == null)
{
return null;