You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2009/01/28 06:34:43 UTC
svn commit: r738372 - in /incubator/jspwiki/trunk:
src/com/ecyrd/jspwiki/ui/migrator/BundleMigrator.java
src/com/ecyrd/jspwiki/util/CommentedProperties.java
tests/com/ecyrd/jspwiki/util/CommentedPropertiesTest.java
Author: ajaquith
Date: Wed Jan 28 05:34:42 2009
New Revision: 738372
URL: http://svn.apache.org/viewvc?rev=738372&view=rev
Log:
Checked in BundleMigrator, which makes it easier to move, rename, or delete resource bundle messages across a range of property files with a single command. This necessitated changes to CommentedProperties, because it was not properly parsing multi-line messages.
Modified:
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/migrator/BundleMigrator.java
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/CommentedProperties.java
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/CommentedPropertiesTest.java
Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/migrator/BundleMigrator.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/migrator/BundleMigrator.java?rev=738372&r1=738371&r2=738372&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/migrator/BundleMigrator.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/ui/migrator/BundleMigrator.java Wed Jan 28 05:34:42 2009
@@ -16,11 +16,11 @@
{
private final Map<Locale, File> m_bundleFiles = new HashMap<Locale, File>();
- private final Map<Locale, Properties> m_bundleProps = new HashMap<Locale, Properties>();
+ private final Map<Locale, CommentedProperties> m_bundleProps = new HashMap<Locale, CommentedProperties>();
private final File m_baseFile;
- private Properties m_baseProps;
+ private CommentedProperties m_baseProps;
/**
* Constructs a new Bundle whose base file name is supplied. During
@@ -75,7 +75,7 @@
* will be returned
* @return the file
*/
- public Properties getProperties( Locale locale )
+ public CommentedProperties getProperties( Locale locale )
{
return locale == null ? m_baseProps : m_bundleProps.get( locale );
}
@@ -91,7 +91,7 @@
// Now load one for each Locale
for( Map.Entry<Locale, File> entry : m_bundleFiles.entrySet() )
{
- Properties props = new CommentedProperties();
+ CommentedProperties props = new CommentedProperties();
props.load( new FileInputStream( entry.getValue() ) );
m_bundleProps.put( entry.getKey(), props );
}
@@ -110,7 +110,7 @@
// Now store each Locale's file
for( Map.Entry<Locale, File> entry : m_bundleFiles.entrySet() )
{
- Properties props = m_bundleProps.get( entry.getKey() );
+ CommentedProperties props = m_bundleProps.get( entry.getKey() );
props.store( new FileOutputStream( entry.getValue() ), null );
}
}
@@ -172,10 +172,13 @@
// Load the source and target bundles
m_source.load();
target.load();
+ String msg = "Copied from " + m_source.m_baseFile.getPath() + ".";
// Copy the base property file's key first
- Properties props = target.getProperties( null );
- props.put( key, value );
+ CommentedProperties props = target.getProperties( null );
+ String comment = props.getComment( key );
+ comment = comment == null ? msg : comment + ". " + msg;
+ props.setProperty( key, value, comment );
// Copy the key for each locale file
Collection<Locale> locales = m_source.getLocales();
@@ -188,7 +191,9 @@
props = target.getProperties( locale );
if( props != null )
{
- props.put( key, value );
+ comment = props.getComment( key );
+ comment = comment == null ? msg : comment + ". " + msg;
+ props.setProperty( key, value, comment );
}
}
}
@@ -237,7 +242,7 @@
m_source.load();
// Rename the base property file's key first
- Properties props = m_source.getProperties( null );
+ CommentedProperties props = m_source.getProperties( null );
props.remove( key );
// Remove the key from each locale file
@@ -277,11 +282,14 @@
// Load the source bundle
m_source.load();
+ String msg = "Formerly named " + key + ".";
// Rename the base property file's key first
- Properties props = m_source.getProperties( null );
+ CommentedProperties props = m_source.getProperties( null );
+ String comment = props.getComment( key );
+ comment = comment == null ? msg : comment + ". " + msg;
props.remove( key );
- props.put( newKey, value );
+ props.setProperty( newKey, value, comment );
// Rename the key in each locale file
Collection<Locale> locales = m_source.getLocales();
@@ -291,8 +299,10 @@
value = props.getProperty( key );
if( value != null )
{
+ comment = props.getComment( key );
+ comment = comment == null ? msg : comment + ". " + msg;
props.remove( key );
- props.put( newKey, value );
+ props.setProperty( newKey, value, comment );
}
}
Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/CommentedProperties.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/CommentedProperties.java?rev=738372&r1=738371&r2=738372&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/CommentedProperties.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/util/CommentedProperties.java Wed Jan 28 05:34:42 2009
@@ -157,11 +157,14 @@
private void printProperty( StringBuilder b, Object key, Object value )
{
+ // Escape any linebreak characters in the value string
+ String pattern = " *[\\n\\r]+";
+ String valueString = value.toString().replaceAll( pattern, " \\\\" + m_br );
b.append( key.toString() );
b.append( ' ' );
b.append( '=' );
b.append( ' ' );
- b.append( value.toString() );
+ b.append( valueString );
b.append( m_br );
}
Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/CommentedPropertiesTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/CommentedPropertiesTest.java?rev=738372&r1=738371&r2=738372&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/CommentedPropertiesTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/util/CommentedPropertiesTest.java Wed Jan 28 05:34:42 2009
@@ -71,6 +71,33 @@
assertTrue( m_props.toString().indexOf( "newProp = newValue2" ) != -1 );
}
+ public void testSetMultilineProperty() throws Exception
+ {
+ CommentedProperties props = new CommentedProperties();
+ props.put( "foo", "This is a\r\nmultiline\nproperty\rwith 4 lines." );
+ File outFile = createFile( "test2.properties" );
+ OutputStream out = new FileOutputStream( outFile );
+ props.store( out, null );
+
+ // Make sure that the line was escaped properly
+ String cr = System.getProperty( "line.separator" );
+ String propString = props.toString();
+ assertEquals( "foo = This is a \\" + cr +"multiline \\" + cr + "property \\" + cr + "with 4 lines.\n", propString );
+
+ // Reload and make sure the property is parsed in as 1 line
+ props = new CommentedProperties();
+ InputStream in = CommentedPropertiesTest.class.getClassLoader().getResourceAsStream( "test2.properties" );
+ props.load( in );
+ assertEquals( "This is a multiline property with 4 lines.", props.get( "foo" ) );
+
+ // Delete the test file
+ File file = getFile( "test2.properties" );
+ if( file != null && file.exists() )
+ {
+ file.delete();
+ }
+ }
+
public void testGetComment()
{
String cr = System.getProperty( "line.separator" );