You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2013/08/19 14:27:01 UTC
svn commit: r1515385 - in /myfaces/tobago/trunk/tobago-core/src:
main/java/org/apache/myfaces/tobago/context/
test/java/org/apache/myfaces/tobago/internal/context/
Author: lofwyr
Date: Mon Aug 19 12:27:00 2013
New Revision: 1515385
URL: http://svn.apache.org/r1515385
Log:
TOBAGO-1298: Re-implement TobagoConfigParser
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeResources.java
myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserTest.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java?rev=1515385&r1=1515384&r2=1515385&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeImpl.java Mon Aug 19 12:27:00 2013
@@ -66,6 +66,12 @@ public class ThemeImpl implements Theme,
private String version;
+ public ThemeImpl() {
+ resources = new ThemeResources();
+ productionResources = new ThemeResources();
+ productionResources.setProduction(true);
+ }
+
public String getName() {
return name;
}
@@ -194,61 +200,33 @@ public class ThemeImpl implements Theme,
return productionResources;
}
- public void addResources(ThemeResources resources) {
- if (resources.isProduction()) {
- if (productionResources != null) {
- merge(productionResources, resources);
- } else {
- productionResources = resources.copy();
- }
+ public void addResources(ThemeResources themeResources) {
+ if (themeResources.isProduction()) {
+ productionResources.merge(themeResources);
} else {
- if (this.resources != null) {
- merge(this.resources, resources);
- } else {
- this.resources = resources.copy();
- }
+ resources.merge(themeResources);
}
}
public void init() {
- if (productionResources != null) {
- productionScripts = new String[productionResources.getScriptList().size()];
- for (int i = 0; i< productionResources.getScriptList().size(); i++) {
- productionScripts[i] = productionResources.getScriptList().get(i).getName();
- }
- productionStyles = new String[productionResources.getStyleList().size()];
- for (int i = 0; i< productionResources.getStyleList().size(); i++) {
- productionStyles[i] = productionResources.getStyleList().get(i).getName();
- }
+ productionScripts = new String[productionResources.getScriptList().size()];
+ for (int i = 0; i < productionResources.getScriptList().size(); i++) {
+ productionScripts[i] = productionResources.getScriptList().get(i).getName();
+ }
+ productionStyles = new String[productionResources.getStyleList().size()];
+ for (int i = 0; i < productionResources.getStyleList().size(); i++) {
+ productionStyles[i] = productionResources.getStyleList().get(i).getName();
+ }
+
+ scripts = new String[resources.getScriptList().size()];
+ for (int i = 0; i < resources.getScriptList().size(); i++) {
+ scripts[i] = resources.getScriptList().get(i).getName();
+ }
+ styles = new String[resources.getStyleList().size()];
+ for (int i = 0; i < resources.getStyleList().size(); i++) {
+ styles[i] = resources.getStyleList().get(i).getName();
}
- if (resources != null) {
- scripts = new String[resources.getScriptList().size()];
- for (int i = 0; i< resources.getScriptList().size(); i++) {
- scripts[i] = resources.getScriptList().get(i).getName();
- }
- styles = new String[resources.getStyleList().size()];
- for (int i = 0; i< resources.getStyleList().size(); i++) {
- styles[i] = resources.getStyleList().get(i).getName();
- }
- }
-
- }
-
- private void merge(ThemeResources resources, ThemeResources toAddResources) {
- if (resources == toAddResources) {
- return;
- }
- for (int i = toAddResources.getScriptList().size()-1; i >= 0; i--) {
- ThemeScript script = toAddResources.getScriptList().get(i);
- resources.getScriptList().remove(script);
- resources.getScriptList().add(0, script);
- }
- for (int i = toAddResources.getStyleList().size()-1; i >= 0; i--) {
- ThemeStyle style = toAddResources.getStyleList().get(i);
- resources.getStyleList().remove(style);
- resources.getStyleList().add(0, style);
- }
}
public String[] getScriptResources(boolean production) {
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeResources.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeResources.java?rev=1515385&r1=1515384&r2=1515385&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeResources.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/context/ThemeResources.java Mon Aug 19 12:27:00 2013
@@ -34,12 +34,20 @@ public final class ThemeResources implem
private List<ThemeScript> scriptList = new ArrayList<ThemeScript>();
private List<ThemeStyle> styleList = new ArrayList<ThemeStyle>();
- public ThemeResources copy() {
- ThemeResources resources = new ThemeResources();
- resources.setProduction(isProduction());
- resources.scriptList.addAll(scriptList);
- resources.styleList.addAll(styleList);
- return resources;
+ public void merge(ThemeResources toAddResources) {
+ if (this == toAddResources) {
+ return;
+ }
+ for (int i = toAddResources.getScriptList().size()-1; i >= 0; i--) {
+ ThemeScript script = toAddResources.getScriptList().get(i);
+ this.getScriptList().remove(script);
+ this.getScriptList().add(0, script);
+ }
+ for (int i = toAddResources.getStyleList().size()-1; i >= 0; i--) {
+ ThemeStyle style = toAddResources.getStyleList().get(i);
+ this.getStyleList().remove(style);
+ this.getStyleList().add(0, style);
+ }
}
public boolean isProduction() {
Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserTest.java?rev=1515385&r1=1515384&r2=1515385&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserTest.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/context/ThemeParserTest.java Mon Aug 19 12:27:00 2013
@@ -83,7 +83,8 @@ public class ThemeParserTest {
URL themeUrl = urls.nextElement();
theme3 = parser.parse(themeUrl);
Assert.assertEquals("test3", theme3.getName());
- Assert.assertNull(theme3.getResources());
+ Assert.assertEquals(0, theme3.getResources().getScriptList().size());
+ Assert.assertEquals(0, theme3.getResources().getStyleList().size());
themeBuilder.addTheme(theme3);
} else {
Assert.fail();
@@ -96,7 +97,8 @@ public class ThemeParserTest {
URL themeUrl = urls.nextElement();
theme4 = parser.parse(themeUrl);
Assert.assertEquals("test4", theme4.getName());
- Assert.assertNull(theme4.getResources());
+ Assert.assertEquals(0, theme4.getResources().getScriptList().size());
+ Assert.assertEquals(0, theme4.getResources().getStyleList().size());
themeBuilder.addTheme(theme4);
} else {
Assert.fail();