Author: pete
Date: Thu Jun 30 13:35:50 2011
New Revision: 1141533
URL: http://svn.apache.org/viewvc?rev=1141533&view=rev
Log:
WICKET-3852 make PropertiesFactory easier to use outside of wicket scope
Added:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/IPropertiesFactoryContext.java
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/PropertiesFactory.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/IResourceSettings.java
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/def/ResourceSettings.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/XmlPageTest.java
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/resource/loader/ComponentStringResourceLoaderTest.java
Added:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/IPropertiesFactoryContext.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/IPropertiesFactoryContext.java?rev=1141533&view=auto
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/IPropertiesFactoryContext.java
(added)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/IPropertiesFactoryContext.java
Thu Jun 30 13:35:50 2011
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.resource;
+
+import org.apache.wicket.Localizer;
+import org.apache.wicket.util.resource.locator.IResourceStreamLocator;
+import org.apache.wicket.util.watch.IModificationWatcher;
+
+/**
+ * environment required for properties factory
+ *
+ * @author Peter Ertl
+ *
+ * @since 1.5
+ */
+public interface IPropertiesFactoryContext
+{
+ /**
+ * Get the application's localizer.
+ *
+ * to modify the way Wicket resolves keys to localized messages you can
+ * add custom resource loaders to the list returned by
+ * {@link
org.apache.wicket.settings.IResourceSettings#getStringResourceLoaders()}.
+ *
+ * @return The application wide localizer instance
+ */
+ Localizer getLocalizer();
+
+ /**
+ * @return Resource locator for this application
+ */
+ IResourceStreamLocator getResourceStreamLocator();
+
+ /**
+ * @param start
+ * boolean if the resource watcher should be started if not
already started.
+ *
+ * @return Resource watcher with polling frequency determined by
setting, or null if no polling
+ * frequency has been set.
+ */
+ IModificationWatcher getResourceWatcher(boolean start);
+}
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/PropertiesFactory.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/PropertiesFactory.java?rev=1141533&r1=1141532&r2=1141533&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/PropertiesFactory.java
(original)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/resource/PropertiesFactory.java
Thu Jun 30 13:35:50 2011
@@ -25,7 +25,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import org.apache.wicket.Application;
import org.apache.wicket.settings.IResourceSettings;
import org.apache.wicket.util.io.IOUtils;
import org.apache.wicket.util.listener.IChangeListener;
@@ -60,8 +59,8 @@ public class PropertiesFactory implement
/** Cache for all property files loaded */
private final Map<String, Properties> propertiesCache =
newPropertiesCache();
- /** This is necessary since the ModificationWatcher runs in a separate
thread */
- private final Application application;
+ /** Provides the environment for properties factory */
+ private final IPropertiesFactoryContext context;
/** List of Properties Loader */
private final List<IPropertiesLoader> propertiesLoader;
@@ -69,17 +68,16 @@ public class PropertiesFactory implement
/**
* Construct.
*
- * @param application
- * Application for this properties factory.
+ * @param context
+ * context for properties factory
*/
- public PropertiesFactory(final Application application)
+ public PropertiesFactory(final IPropertiesFactoryContext context)
{
- this.application = application;
-
- propertiesLoader = new ArrayList<IPropertiesLoader>();
- propertiesLoader.add(new
IsoPropertiesFilePropertiesLoader("properties"));
- propertiesLoader.add(new
UtfPropertiesFilePropertiesLoader("utf8.properties", "utf-8"));
- propertiesLoader.add(new
XmlFilePropertiesLoader("properties.xml"));
+ this.context = context;
+ this.propertiesLoader = new ArrayList<IPropertiesLoader>();
+ this.propertiesLoader.add(new
IsoPropertiesFilePropertiesLoader("properties"));
+ this.propertiesLoader.add(new
UtfPropertiesFilePropertiesLoader("utf8.properties", "utf-8"));
+ this.propertiesLoader.add(new
XmlFilePropertiesLoader("properties.xml"));
}
/**
@@ -124,7 +122,7 @@ public class PropertiesFactory implement
}
// clear the localizer cache as well
- application.getResourceSettings().getLocalizer().clearCache();
+ context.getLocalizer().clearCache();
}
/**
@@ -142,8 +140,6 @@ public class PropertiesFactory implement
if (properties == null)
{
- IResourceSettings resourceSettings =
application.getResourceSettings();
-
Iterator<IPropertiesLoader> iter =
propertiesLoader.iterator();
while ((properties == null) && iter.hasNext())
{
@@ -151,7 +147,7 @@ public class PropertiesFactory implement
String fullPath = path +
loader.getFileExtension();
// If not in the cache than try to load
properties
- IResourceStream resourceStream =
resourceSettings.getResourceStreamLocator()
+ IResourceStream resourceStream =
context.getResourceStreamLocator()
.locate(clazz, fullPath);
if (resourceStream == null)
{
@@ -159,7 +155,7 @@ public class PropertiesFactory implement
}
// Watch file modifications
- final IModificationWatcher watcher =
resourceSettings.getResourceWatcher(true);
+ final IModificationWatcher watcher =
context.getResourceWatcher(true);
if (watcher != null)
{
addToWatcher(path, resourceStream,
watcher);
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/IResourceSettings.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/IResourceSettings.java?rev=1141533&r1=1141532&r2=1141533&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/IResourceSettings.java
(original)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/IResourceSettings.java
Thu Jun 30 13:35:50 2011
@@ -27,6 +27,7 @@ import org.apache.wicket.markup.html.Pac
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
import org.apache.wicket.resource.IPropertiesFactory;
+import org.apache.wicket.resource.IPropertiesFactoryContext;
import org.apache.wicket.resource.loader.IStringResourceLoader;
import org.apache.wicket.util.file.IFileUploadCleaner;
import org.apache.wicket.util.file.IResourceFinder;
@@ -73,7 +74,7 @@ import org.apache.wicket.util.watch.IMod
*
* @author Igor Vaynberg (ivaynberg)
*/
-public interface IResourceSettings
+public interface IResourceSettings extends IPropertiesFactoryContext
{
/**
* Adds a resource factory to the list of factories to consult when
generating resources
@@ -107,17 +108,6 @@ public interface IResourceSettings
Duration getDefaultCacheDuration();
/**
- * Get the application's localizer.
- *
- * to modify the way Wicket resolves keys to localized messages you can
- * add custom resource loaders to the list returned by
- * {@link
org.apache.wicket.settings.IResourceSettings#getStringResourceLoaders()}.
- *
- * @return The application wide localizer instance
- */
- Localizer getLocalizer();
-
- /**
* Gets the {@link PackageResourceGuard package resource guard}.
*
* @return The package resource guard
@@ -153,20 +143,6 @@ public interface IResourceSettings
Duration getResourcePollFrequency();
/**
- * @return Resource locator for this application
- */
- IResourceStreamLocator getResourceStreamLocator();
-
- /**
- * @param start
- * boolean if the resource watcher should be started if not
already started.
- *
- * @return Resource watcher with polling frequency determined by
setting, or null if no polling
- * frequency has been set.
- */
- IModificationWatcher getResourceWatcher(boolean start);
-
- /**
* @return mutable list of all available string resource loaders
*/
List<IStringResourceLoader> getStringResourceLoaders();
Modified:
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/def/ResourceSettings.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/def/ResourceSettings.java?rev=1141533&r1=1141532&r2=1141533&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/def/ResourceSettings.java
(original)
+++
wicket/trunk/wicket-core/src/main/java/org/apache/wicket/settings/def/ResourceSettings.java
Thu Jun 30 13:35:50 2011
@@ -192,7 +192,7 @@ public class ResourceSettings implements
{
if (propertiesFactory == null)
{
- propertiesFactory = new
PropertiesFactory(Application.get());
+ propertiesFactory = new PropertiesFactory(this);
}
return propertiesFactory;
}
Modified:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/XmlPageTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/XmlPageTest.java?rev=1141533&r1=1141532&r2=1141533&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/XmlPageTest.java
(original)
+++
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/markup/html/basic/XmlPageTest.java
Thu Jun 30 13:35:50 2011
@@ -87,7 +87,7 @@ public class XmlPageTest extends WicketT
*/
public MyPropertiesFactory(Application application)
{
- super(application);
+ super(application.getResourceSettings());
getPropertiesLoaders().clear();
getPropertiesLoaders().add(new
IsoPropertiesFilePropertiesLoader("properties"));
Modified:
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/resource/loader/ComponentStringResourceLoaderTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-core/src/test/java/org/apache/wicket/resource/loader/ComponentStringResourceLoaderTest.java?rev=1141533&r1=1141532&r2=1141533&view=diff
==============================================================================
---
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/resource/loader/ComponentStringResourceLoaderTest.java
(original)
+++
wicket/trunk/wicket-core/src/test/java/org/apache/wicket/resource/loader/ComponentStringResourceLoaderTest.java
Thu Jun 30 13:35:50 2011
@@ -18,10 +18,10 @@ package org.apache.wicket.resource.loade
import java.util.Map;
-import org.apache.wicket.Application;
import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.WicketTestCase;
import org.apache.wicket.resource.IPropertiesFactory;
+import org.apache.wicket.resource.IPropertiesFactoryContext;
import org.apache.wicket.resource.IsoPropertiesFilePropertiesLoader;
import org.apache.wicket.resource.Properties;
import org.apache.wicket.resource.PropertiesFactory;
@@ -64,7 +64,7 @@ public class ComponentStringResourceLoad
{
// Avoid the conflict by limiting the search for properties
files
// to *.properties
- IPropertiesFactory myFac = new
MyPropertiesFactory(tester.getApplication());
+ IPropertiesFactory myFac = new
MyPropertiesFactory(tester.getApplication().getResourceSettings());
tester.getApplication().getResourceSettings().setPropertiesFactory(myFac);
executeTest(TestPage_1.class, "TestPageExpectedResult_1.xml");
@@ -75,7 +75,7 @@ public class ComponentStringResourceLoad
*/
public void testDisabledCache() throws Exception
{
- IPropertiesFactory myFac = new
DisabledCachePropertiesFactory(tester.getApplication());
+ IPropertiesFactory myFac = new
DisabledCachePropertiesFactory(tester.getApplication().getResourceSettings());
tester.getApplication().getResourceSettings().setPropertiesFactory(myFac);
executeTest(TestPage_1.class, "TestPageExpectedResult_1.xml");
@@ -90,12 +90,12 @@ public class ComponentStringResourceLoad
{
/**
* Construct.
- *
- * @param application
+ *
+ * @param context
*/
- public MyPropertiesFactory(Application application)
+ public MyPropertiesFactory(IPropertiesFactoryContext context)
{
- super(application);
+ super(context);
getPropertiesLoaders().clear();
getPropertiesLoaders().add(new
IsoPropertiesFilePropertiesLoader("properties"));
@@ -110,11 +110,11 @@ public class ComponentStringResourceLoad
/**
* Construct.
*
- * @param application
+ * @param context
*/
- public DisabledCachePropertiesFactory(Application application)
+ public DisabledCachePropertiesFactory(IPropertiesFactoryContext
context)
{
- super(application);
+ super(context);
}
/**