You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gc...@apache.org on 2012/02/06 21:24:39 UTC

svn commit: r1241154 - in /myfaces/trinidad/trunk/trinidad-api/src/main: java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts

Author: gcrawford
Date: Mon Feb  6 20:24:39 2012
New Revision: 1241154

URL: http://svn.apache.org/viewvc?rev=1241154&view=rev
Log:
TRINIDAD-2199 Improve Date Time Converters to detect invalid 12 hour pattern

Reverting this, we should not be changing the pattern the user gave us.

Modified:
    myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java
    myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java?rev=1241154&r1=1241153&r2=1241154&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/convert/DateTimeConverter.java Mon Feb  6 20:24:39 2012
@@ -844,152 +844,14 @@ public class DateTimeConverter extends j
   {
     Object patternObj = _facesBean.getProperty(_PATTERN_KEY);
     String pattern = ComponentUtils.resolveString(patternObj);
-         
+
     if (pattern != null && pattern.trim().isEmpty())
     {
       return null;
-      
-    }
-    //check if pattern is already in map , if not then parse it and cache in map
-    String fixedPattern = _PATTERNS_MAP.get(pattern);
-          
-    if(fixedPattern == null)
-    {
-      fixedPattern = checkAndFixPattern(pattern);
-      //cache the pattern in the map
-      _PATTERNS_MAP.put(pattern , fixedPattern) ;  
     }
-          
-    return fixedPattern;
-  }
-  /**
-  * <p>Return and validate the  pattern to be used .Currently only pattern
-  * we are validating is a 12 hour clock.</p>
-  */
-  public String checkAndFixPattern(String pattern) 
-  {
-    pattern = fix12HourPattern(pattern) ;
+
     return pattern;
   }
-  
-  /**
-  * <p>Validating a pattern with 12 hour clock
-  * check if pattern is 12 hour clock and doesnot have  
-  * am/pm format then add an "a" at the end of the pattern  
-  * so that in 12 hour clock user is able to see am/pm.</p>
-  */ 
-  public static String fix12HourPattern(String pattern)
-  {
-    boolean is12HourClock = false;
-    boolean isAmPmPresent = false;
-    int lastIndexOfTime = -1;
-    boolean inQuotes = false;
-      
-    if (pattern != null && pattern.indexOf("h") != -1)
-    {
-      int currCharIndex = 0;
-      int patternLen = pattern.length();
-          
-      for (; currCharIndex < patternLen; currCharIndex++)
-      {
-        char currChar = pattern.charAt(currCharIndex);
-        
-        switch (currChar)
-        {
-          case 'a':
-          if (!inQuotes)
-          {
-            // it already has am/pm in it
-            isAmPmPresent = true;
-          }
-          break;
-          
-          case 'h':
-          if (!inQuotes)
-          {
-            // save the location of the last h and we are in 12 hour clock pattern
-            is12HourClock = true;
-            lastIndexOfTime = currCharIndex;
-          }
-          break;
-  
-          case 'm':
-          if (!inQuotes)
-          {
-            // save the location of the last m
-            lastIndexOfTime = currCharIndex;
-          }
-          break;
-          
-          case 's':
-          if (!inQuotes)
-          {
-            // save the location of the last s
-            lastIndexOfTime = currCharIndex;
-          }
-          break;
-  
-          case '\'':
-          if (inQuotes)
-          {
-            int nextCharIndex = currCharIndex + 1;
-            
-            if ((nextCharIndex < patternLen) &&('\'' == pattern.charAt(nextCharIndex)))
-            {
-              // this is just an escaped quote, so ignore
-              currCharIndex++;
-            }
-            else
-            {
-              // no longer quoted
-              inQuotes = false;
-            }
-  
-          }
-          else
-          {
-            // we're now in quotes
-            inQuotes = true;
-          }
-          // fall through
-          default:
-          {
-  
-          }
-  
-        }
-  
-      }
-      // if we are in 12 hour clock and am/pm is not there, we will append an 'a' to pattern
-      
-      if(is12HourClock && !isAmPmPresent)
-      {
-        StringBuffer newFormatPattern = new StringBuffer(patternLen + 2);
-        // append everything from the orginal string before lastIndexOfTime
-        newFormatPattern.append(pattern.substring(0, lastIndexOfTime + 1));
-        newFormatPattern.append(" a");
-        // append everything from the orginal string after lastIndexOfTime
-        // where we appended
-  
-        if (lastIndexOfTime + 1 < patternLen)
-        {
-          newFormatPattern.append(pattern.substring(lastIndexOfTime + 1,
-                                                                patternLen));
-        }
-        String formattedPattern = newFormatPattern.toString();
-        if(_LOG.isWarning())
-          {
-            _LOG.warning("PATTERN_HAS_12HOURCLOCK_BUT_NO_AM/PM" ,new Object[]{pattern, formattedPattern} );
-          }
-           
-        pattern = formattedPattern;
-      }  
-       
-    }
-  
-    return pattern;      
-  
-  }
 
   /**
    * <p>Set the <code>TimeZone</code> used to interpret a time value.</p>
@@ -2122,7 +1984,6 @@ public class DateTimeConverter extends j
     new HashMap<Locale, List<String>>();
   private static final List<String> _US_CONVENIENCE_PATTERNS =
     Arrays.asList("MMMM dd, yy", "MMMM/dd/yy", "dd-MMMM-yy");
-  private static final  Map<String, String> _PATTERNS_MAP = new HashMap<String, String>();
 
   static
   {

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts?rev=1241154&r1=1241153&r2=1241154&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts Mon Feb  6 20:24:39 2012
@@ -480,9 +480,6 @@
 <!-- ROWKEY_NOT_RESET  -->
 <resource key="ROWKEY_NOT_RESET">row key might not be reset correctly at the end of the request. Component ID: {0} ViewId: {1}</resource>
 
-<!-- PATTERN_HAS_12HOURCLOCK_BUT_NO_AM/PM -->
-<resource key="PATTERN_HAS_12HOURCLOCK_BUT_NO_AM/PM">Pattern "{0}" uses a lower case 'h' for a 12 hour clock, but there is no 'a', so it does not show am/pm. Going forward pattern "{1}" will be used instead. If this pattern is not acceptable please fix your pattern to either use 'H' for a 24 hour clock, or add an 'a' to the pattern to show am/pm.</resource> 
-
 <!-- COLLECTION_CHANGE_TEARDOWN  -->
 <resource key="COLLECTION_CHANGE_TEARDOWN">The component change that was on the stack is not the required one to properly tear down the context of this component. The component tree is in an invalid state and further errors may result. Component ID: {0} Invalid component change: {1}</resource>