You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by me...@apache.org on 2009/01/05 21:46:34 UTC
svn commit: r731703 - in /incubator/jspwiki/trunk: ./ etc/i18n/
src/com/ecyrd/jspwiki/ tests/com/ecyrd/jspwiki/
Author: metskem
Date: Mon Jan 5 12:46:34 2009
New Revision: 731703
URL: http://svn.apache.org/viewvc?rev=731703&view=rev
Log:
3.0.0-svn-46 JSPWIKI-460 - Add current time stamp to WikiVariables (requested by NicolaFischer)
Modified:
incubator/jspwiki/trunk/ChangeLog
incubator/jspwiki/trunk/etc/i18n/CoreResources.properties
incubator/jspwiki/trunk/etc/i18n/CoreResources_nl.properties
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/VariableManager.java
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/VariableManagerTest.java
Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=731703&r1=731702&r2=731703&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Mon Jan 5 12:46:34 2009
@@ -1,4 +1,10 @@
-2009-01-03 Harry Metske <me...@apache.org>
+2009-01-05 Harry Metske <me...@apache.org>
+
+ * 3.0.0-svn-46
+
+ * JSPWIKI-460 - Add current time stamp to WikiVariables (requested by NicolaFischer)
+
+2009-01-05 Harry Metske <me...@apache.org>
* 3.0.0-svn-45
Modified: incubator/jspwiki/trunk/etc/i18n/CoreResources.properties
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/etc/i18n/CoreResources.properties?rev=731703&r1=731702&r2=731703&view=diff
==============================================================================
--- incubator/jspwiki/trunk/etc/i18n/CoreResources.properties (original)
+++ incubator/jspwiki/trunk/etc/i18n/CoreResources.properties Mon Jan 5 12:46:34 2009
@@ -208,6 +208,8 @@
varmgr.authenticated=authenticated
varmgr.asserted=asserted
varmgr.anonymous=anonymous
+varmgr.dateformat.invalid=No valid dateformat was provided:
+varmgr.dateformat.noformat=No dateformat was provided.
###############################################################################
## Default Resource Bundle file for the Stripes Framework. Values should be
Modified: incubator/jspwiki/trunk/etc/i18n/CoreResources_nl.properties
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/etc/i18n/CoreResources_nl.properties?rev=731703&r1=731702&r2=731703&view=diff
==============================================================================
--- incubator/jspwiki/trunk/etc/i18n/CoreResources_nl.properties (original)
+++ incubator/jspwiki/trunk/etc/i18n/CoreResources_nl.properties Mon Jan 5 12:46:34 2009
@@ -208,6 +208,8 @@
varmgr.authenticated=geauthenticeerd
varmgr.asserted=aangenomen identiteit
varmgr.anonymous=anoniem
+varmgr.dateformat.invalid=ongeldig datum formaat opgegeven:
+varmgr.dateformat.noformat=geen datum formaat opgegeven.
######################################################################
#
Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java?rev=731703&r1=731702&r2=731703&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Mon Jan 5 12:46:34 2009
@@ -77,7 +77,7 @@
* <p>
* If the build identifier is empty, it is not added.
*/
- public static final String BUILD = "45";
+ public static final String BUILD = "46";
/**
* This is the generic version string you should use
Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/VariableManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/VariableManager.java?rev=731703&r1=731702&r2=731703&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/VariableManager.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/VariableManager.java Mon Jan 5 12:46:34 2009
@@ -22,6 +22,7 @@
import java.lang.reflect.Method;
import java.security.Principal;
+import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
@@ -333,6 +334,36 @@
return s;
}
}
+
+ //
+ // handle the timestamp variable ( example: timestamp=yyyy-MM-dd)
+ //
+
+ if( varName.startsWith( "timeStamp" ) )
+ {
+ StringTokenizer tok = new StringTokenizer( varName, "=" );
+ int numTokens = tok.countTokens();
+ if( numTokens != 2 )
+ {
+ return context.getBundle( InternationalizationManager.CORE_BUNDLE ).getString( "varmgr.dateformat.noformat" );
+ }
+
+ @SuppressWarnings( "unused" )
+ String ignoreFirstToken = tok.nextToken();
+ String dateFormatString = tok.nextToken();
+
+ SimpleDateFormat dateFormat = null;
+ try
+ {
+ dateFormat = new SimpleDateFormat( dateFormatString );
+ return dateFormat.format( new Date( System.currentTimeMillis() ) );
+ }
+ catch( RuntimeException e )
+ {
+ return context.getBundle( InternationalizationManager.CORE_BUNDLE ).getString( "varmgr.dateformat.invalid" )
+ + dateFormatString;
+ }
+ }
//
// Final defaults for some known quantities.
Modified: incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/VariableManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/VariableManagerTest.java?rev=731703&r1=731702&r2=731703&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/VariableManagerTest.java (original)
+++ incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/VariableManagerTest.java Mon Jan 5 12:46:34 2009
@@ -22,6 +22,8 @@
package com.ecyrd.jspwiki;
import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.Properties;
import junit.framework.Test;
@@ -190,6 +192,24 @@
assertEquals( "Testing {}, {{{}", res );
}
+ public void testTimeStamp() throws Exception
+ {
+ // Yes I know there is a tiny chance that this fails if the minute
+ // passes by between here and the "new Date" in VariableManager
+ String format = "dd.MM.yyyy HH:mm";
+ SimpleDateFormat df = new SimpleDateFormat( format );
+ String dateString = df.format( new Date() );
+
+ String res = m_variableManager.expandVariables( m_context, ">>>>>{$timeStamp=" + format + "}<<<<<" );
+ assertEquals( ">>>>>" + dateString + "<<<<<", res );
+
+ res = m_variableManager.expandVariables( m_context, ">>>>>{$timeStamp}<<<<<" );
+ assertEquals( ">>>>>No dateformat was provided. <<<<<", res );
+
+ res = m_variableManager.expandVariables( m_context, ">>>>>{$timeStamp=" + format + "INVALIDFORMAT}<<<<<" );
+ assertEquals( ">>>>>No valid dateformat was provided: dd.MM.yyyy HH:mmINVALIDFORMAT<<<<<", res );
+ }
+
public static Test suite()
{
return new TestSuite( VariableManagerTest.class );