You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2008/02/14 00:20:33 UTC

svn commit: r627611 - /wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/PropertiesFactory.java

Author: ivaynberg
Date: Wed Feb 13 15:20:29 2008
New Revision: 627611

URL: http://svn.apache.org/viewvc?rev=627611&view=rev
Log:
cleaned up code in #load()

Modified:
    wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/PropertiesFactory.java

Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/PropertiesFactory.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/PropertiesFactory.java?rev=627611&r1=627610&r2=627611&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/PropertiesFactory.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/resource/PropertiesFactory.java Wed Feb 13 15:20:29 2008
@@ -105,33 +105,40 @@
 	{
 		// Check the cache
 		Properties properties = (Properties)propertiesCache.get(path);
-		if (properties != null)
+
+		if (properties == null)
 		{
-			// Return null, if no resource stream was found
-			if (properties == Properties.EMPTY_PROPERTIES)
+			// If not in the cache than try to load properties
+			IResourceStream stream = application.getResourceSettings()
+				.getResourceStreamLocator()
+				.locate(clazz, path);
+			if (stream != null)
 			{
-				properties = null;
+				// Load the properties from the stream
+				properties = loadPropertiesFileAndWatchForChanges(path, stream);
 			}
-			return properties;
-		}
 
-		// If not in the cache than try to load the resource stream
-		IResourceStream stream = application.getResourceSettings().getResourceStreamLocator()
-				.locate(clazz, path);
-		if (stream != null)
-		{
-			// Load the properties from the stream
-			properties = loadPropertiesFileAndWatchForChanges(path, stream);
-			if (properties != null)
+
+			// Cache the lookup
+			if (properties == null)
+			{
+				// Could not locate properties, store a placeholder
+				propertiesCache.put(path, Properties.EMPTY_PROPERTIES);
+			}
+			else
 			{
 				propertiesCache.put(path, properties);
-				return properties;
 			}
+
+		}
+
+		if (properties == Properties.EMPTY_PROPERTIES)
+		{
+			// Translate empty properties placeholder to null prior to returning
+			properties = null;
 		}
 
-		// Add a placeholder to the cache. Null is not a valid value to add.
-		propertiesCache.put(path, Properties.EMPTY_PROPERTIES);
-		return null;
+		return properties;
 	}
 
 	/**
@@ -144,7 +151,7 @@
 	 * @return The map of loaded resources
 	 */
 	private synchronized Properties loadPropertiesFile(final String key,
-			final IResourceStream resourceStream)
+		final IResourceStream resourceStream)
 	{
 		// Make sure someone else didn't load our resources while we were
 		// waiting for the synchronized lock on the method
@@ -167,15 +174,14 @@
 				try
 				{
 					// Get the InputStream
-					BufferedInputStream in = new BufferedInputStream(resourceStream
-							.getInputStream());
+					BufferedInputStream in = new BufferedInputStream(
+						resourceStream.getInputStream());
 
 					// Determine if resource is a XML File
 					boolean loadAsXml = false;
 					if (resourceStream instanceof IFixedLocationResourceStream)
 					{
-						String location = ((IFixedLocationResourceStream)resourceStream)
-								.locationAsString();
+						String location = ((IFixedLocationResourceStream)resourceStream).locationAsString();
 						if (location != null)
 						{
 							String ext = Strings.lastPathComponent(location, '.').toLowerCase();
@@ -239,11 +245,11 @@
 	 * @return The map of loaded resources
 	 */
 	private final Properties loadPropertiesFileAndWatchForChanges(final String key,
-			final IResourceStream resourceStream)
+		final IResourceStream resourceStream)
 	{
 		// Watch file modifications
 		final ModificationWatcher watcher = application.getResourceSettings().getResourceWatcher(
-				true);
+			true);
 		if (watcher != null)
 		{
 			watcher.add(resourceStream, new IChangeListener()
@@ -251,7 +257,7 @@
 				public void onChange()
 				{
 					log.info("A properties files has changed. Removing all entries " +
-							"from the cache. Resource: " + resourceStream);
+						"from the cache. Resource: " + resourceStream);
 
 					// Clear the whole cache as associated localized files may
 					// be affected and may need reloading as well.
@@ -272,7 +278,7 @@
 						catch (Throwable ex)
 						{
 							log.error("PropertiesReloadListener has thrown an exception: " +
-									ex.getMessage());
+								ex.getMessage());
 						}
 					}
 				}