You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2010/01/13 01:54:16 UTC
svn commit: r898586 - in /tapestry/tapestry5/trunk:
tapestry-core/src/main/java/org/apache/tapestry5/internal/services/
tapestry-core/src/main/java/org/apache/tapestry5/services/
tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ tapes...
Author: hlship
Date: Wed Jan 13 00:54:16 2010
New Revision: 898586
URL: http://svn.apache.org/viewvc?rev=898586&view=rev
Log:
TAP5-856: MetaDataLocatorImpl.findMeta(String, String, Class) doesn't check contributed defaults - breaks SECURE_PAGE contributions
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MetaDataLocatorImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/MetaDataLocator.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/MetaDataLocatorImplTest.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/IOCTestCase.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/SymbolObjectProviderTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MetaDataLocatorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MetaDataLocatorImpl.java?rev=898586&r1=898585&r2=898586&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MetaDataLocatorImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/MetaDataLocatorImpl.java Wed Jan 13 00:54:16 2010
@@ -1,10 +1,10 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 2010 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -31,7 +31,8 @@
private final ComponentModelSource modelSource;
- private final Map<String, Map<String, String>> defaultsByFolder = CollectionFactory.newCaseInsensitiveMap();
+ private final Map<String, Map<String, String>> defaultsByFolder = CollectionFactory
+ .newCaseInsensitiveMap();
private final Map<String, String> cache = CollectionFactory.newConcurrentMap();
@@ -40,9 +41,8 @@
String valueForKey(String key);
}
- public MetaDataLocatorImpl(SymbolSource symbolSource, TypeCoercer typeCoercer, ComponentModelSource modelSource,
- Map<String, String> configuration
- )
+ public MetaDataLocatorImpl(SymbolSource symbolSource, TypeCoercer typeCoercer,
+ ComponentModelSource modelSource, Map<String, String> configuration)
{
this.symbolSource = symbolSource;
this.typeCoercer = typeCoercer;
@@ -82,36 +82,36 @@
public <T> T findMeta(String key, final ComponentResources resources, Class<T> expectedType)
{
- String value = getSymbolExpandedValueFromCache(key,
- resources.getCompleteId() + "/" + key,
- new ValueLocator()
- {
- public String valueForKey(String key)
- {
- return locate(key, resources);
- }
- });
+ String value = getSymbolExpandedValueFromCache(key, resources.getCompleteId() + "/" + key,
+ new ValueLocator()
+ {
+ public String valueForKey(String key)
+ {
+ return locate(key, resources);
+ }
+ });
return typeCoercer.coerce(value, expectedType);
}
public <T> T findMeta(String key, final String pageName, Class<T> expectedType)
{
-
- String value = getSymbolExpandedValueFromCache(key,
- pageName + "/" + key,
- new ValueLocator()
- {
- public String valueForKey(String key)
- {
- return modelSource.getPageModel(pageName).getMeta(key);
- }
- });
+ String value = getSymbolExpandedValueFromCache(key, pageName + "/" + key,
+ new ValueLocator()
+ {
+ public String valueForKey(String key)
+ {
+ String result = modelSource.getPageModel(pageName).getMeta(key);
+
+ return result != null ? result : locateInDefaults(key, pageName);
+ }
+ });
return typeCoercer.coerce(value, expectedType);
}
- private String getSymbolExpandedValueFromCache(String key, String cacheKey, ValueLocator valueLocator)
+ private String getSymbolExpandedValueFromCache(String key, String cacheKey,
+ ValueLocator valueLocator)
{
if (cache.containsKey(cacheKey))
return cache.get(cacheKey);
@@ -140,11 +140,13 @@
{
String value = cursor.getComponentModel().getMeta(key);
- if (value != null) return value;
+ if (value != null)
+ return value;
ComponentResources next = cursor.getContainerResources();
- if (next == null) return locateInDefaults(key, cursor.getPageName());
+ if (next == null)
+ return locateInDefaults(key, cursor.getPageName());
cursor = next;
}
@@ -167,9 +169,11 @@
Map<String, String> forFolder = defaultsByFolder.get(folderKey);
- if (forFolder != null && forFolder.containsKey(key)) return forFolder.get(key);
+ if (forFolder != null && forFolder.containsKey(key))
+ return forFolder.get(key);
- if (lastSlashx < 0) break;
+ if (lastSlashx < 0)
+ break;
path = path.substring(0, lastSlashx);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/MetaDataLocator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/MetaDataLocator.java?rev=898586&r1=898585&r2=898586&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/MetaDataLocator.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/MetaDataLocator.java Wed Jan 13 00:54:16 2010
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/MetaDataLocatorImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/MetaDataLocatorImplTest.java?rev=898586&r1=898585&r2=898586&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/MetaDataLocatorImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/MetaDataLocatorImplTest.java Wed Jan 13 00:54:16 2010
@@ -1,10 +1,10 @@
-// Copyright 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2010 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
-// http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -17,6 +17,8 @@
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newMap;
+
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.services.SymbolSource;
import org.apache.tapestry5.ioc.services.TypeCoercer;
import org.apache.tapestry5.model.ComponentModel;
@@ -58,7 +60,8 @@
Map<String, String> configuration = Collections.emptyMap();
- MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
+ MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource,
+ configuration);
assertSame(locator.findMeta(key, resources, String.class), value);
@@ -76,6 +79,105 @@
}
@Test
+ public void default_to_symbol_source()
+ {
+ ComponentResources resources = mockComponentResources();
+ ComponentModel model = mockComponentModel();
+ SymbolSource symbolSource = mockSymbolSource();
+ ComponentModelSource modelSource = mockComponentModelSource();
+
+ String key = "foo.bar";
+ String value = "zaphod";
+ String completeId = "foo/Bar:baz";
+
+ train_getCompleteId(resources, completeId);
+ train_getComponentModel(resources, model);
+ train_getMeta(model, key, null);
+ train_getContainerResources(resources, null);
+ train_getPageName(resources, "foo/Bar");
+ train_valueForSymbol(symbolSource, key, value);
+
+ replay();
+
+ Map<String, String> configuration = Collections.emptyMap();
+
+ MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource,
+ configuration);
+
+ assertSame(locator.findMeta(key, resources, String.class), value);
+
+ verify();
+
+ // And check that it's cached:
+
+ train_getCompleteId(resources, completeId);
+
+ replay();
+
+ assertSame(locator.findMeta(key, resources, String.class), value);
+
+ verify();
+ }
+
+ @Test
+ public void find_by_page_name()
+ {
+ ComponentModel model = mockComponentModel();
+ SymbolSource symbolSource = mockSymbolSource();
+ ComponentModelSource modelSource = mockComponentModelSource();
+
+ String key = "foo.bar";
+ String value = "zaphod";
+ String pageName = "foo/Bar";
+
+ expect(modelSource.getPageModel(pageName)).andReturn(model);
+
+ train_getMeta(model, key, value);
+ train_expandSymbols(symbolSource, value, "*expanded*");
+
+ replay();
+
+ Map<String, String> configuration = Collections.emptyMap();
+
+ MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource,
+ configuration);
+
+ assertSame(locator.findMeta(key, pageName, String.class), "*expanded*");
+
+ verify();
+ }
+
+ @Test
+ public void not_found_by_page_name_but_found_in_configuration()
+ {
+ ComponentModel model = mockComponentModel();
+ SymbolSource symbolSource = mockSymbolSource();
+ ComponentModelSource modelSource = mockComponentModelSource();
+
+ String key = "foo.bar";
+ String value = "zaphod";
+ String pageName = "gnip/Gnop";
+
+ expect(modelSource.getPageModel(pageName)).andReturn(model);
+
+ train_getMeta(model, key, null);
+ train_expandSymbols(symbolSource, value, "*expanded*");
+
+ replay();
+
+ Map<String, String> configuration = CollectionFactory.newMap();
+
+ configuration.put("gnip:foo.bar", value);
+
+ MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource,
+ configuration);
+
+ assertSame(locator.findMeta(key, pageName, String.class), "*expanded*");
+
+ verify();
+ }
+
+ @Test
public void found_in_container()
{
ComponentResources resources = mockComponentResources();
@@ -101,7 +203,8 @@
Map<String, String> configuration = Collections.emptyMap();
- MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
+ MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource,
+ configuration);
assertSame(locator.findMeta(key, resources, String.class), value);
@@ -135,7 +238,8 @@
Map<String, String> configuration = newMap();
configuration.put(key, value);
- MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
+ MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource,
+ configuration);
assertSame(locator.findMeta(key, resources, String.class), value);
@@ -178,7 +282,8 @@
Map<String, String> configuration = newMap();
configuration.put(key.toUpperCase(), value);
- MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
+ MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource,
+ configuration);
assertSame(locator.findMeta(key, resources, String.class), value);
@@ -222,7 +327,8 @@
configuration.put(key, "xxx");
configuration.put("foo:" + key, value);
- MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
+ MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource,
+ configuration);
assertSame(locator.findMeta(key, resources, String.class), value);
@@ -261,8 +367,8 @@
Map<String, String> configuration = Collections.emptyMap();
- MetaDataLocatorImpl locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration
- );
+ MetaDataLocatorImpl locator = new MetaDataLocatorImpl(symbolSource, typeCoercer,
+ modelSource, configuration);
assertSame(locator.findMeta(key, resources, String.class), value);
@@ -286,7 +392,8 @@
}
/**
- * Makes sense to test together to ensure that the expanded value is what's fed to the type coercer.
+ * Makes sense to test together to ensure that the expanded value is what's fed to the type
+ * coercer.
*/
@Test
public void train_symbols_expanded_and_types_coerced()
@@ -310,7 +417,8 @@
Map<String, String> configuration = Collections.emptyMap();
- MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource, configuration);
+ MetaDataLocator locator = new MetaDataLocatorImpl(symbolSource, typeCoercer, modelSource,
+ configuration);
assertEquals(locator.findMeta(key, resources, Integer.class), new Integer(99));
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/IOCTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/IOCTestCase.java?rev=898586&r1=898585&r2=898586&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/IOCTestCase.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/test/IOCTestCase.java Wed Jan 13 00:54:16 2010
@@ -21,6 +21,7 @@
import org.apache.tapestry5.ioc.def.ModuleDef;
import org.apache.tapestry5.ioc.def.ServiceDef;
import org.apache.tapestry5.ioc.services.*;
+
import static org.easymock.EasyMock.isA;
import org.slf4j.Logger;
@@ -423,4 +424,9 @@
return resources;
}
+
+ protected final void train_valueForSymbol(SymbolSource symbolSource, String symbolName, String value)
+ {
+ expect(symbolSource.valueForSymbol(symbolName)).andReturn(value).atLeastOnce();
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/SymbolObjectProviderTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/SymbolObjectProviderTest.java?rev=898586&r1=898585&r2=898586&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/SymbolObjectProviderTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/SymbolObjectProviderTest.java Wed Jan 13 00:54:16 2010
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2010 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -115,9 +115,4 @@
expect(annotation.value()).andReturn(symbolName);
return annotation;
}
-
- protected final void train_valueForSymbol(SymbolSource source, String symbolName, String symbolValue)
- {
- expect(source.valueForSymbol(symbolName)).andReturn(symbolValue);
- }
}