1 20 21 package org.apache.directory.ldapstudio.valueeditors.time; 22 23 24 import java.text.DateFormat ; 25 import java.text.ParseException ; 26 import java.text.SimpleDateFormat ; 27 import java.util.Date ; 28 29 import org.apache.directory.ldapstudio.browser.core.model.IValue; 30 import org.apache.directory.ldapstudio.valueeditors.AbstractInPlaceStringValueEditor; 31 32 33 43 public class InPlaceGeneralizedTimeValueEditor extends AbstractInPlaceStringValueEditor 44 { 45 46 58 public String getDisplayValue( IValue value ) 59 { 60 String displayValue = super.getDisplayValue( value ); 61 62 if ( !showRawValues() ) 63 { 64 DateFormat ldapFormat = new SimpleDateFormat ( "yyyyMMddHHmmssZ" ); 65 DateFormat activeDirectoryFormat = new SimpleDateFormat ( "yyyyMMddHHmmss'.'SSSZ" ); 66 DateFormat targetFormat = DateFormat.getDateTimeInstance( DateFormat.MEDIUM, DateFormat.LONG ); 67 68 String s = displayValue; 69 if ( s.matches( "[\\.0-9]+Z" ) ) 70 { 71 s = s.replaceAll( "Z", "GMT" ); 72 } 73 74 try 75 { 76 Date date = ldapFormat.parse( s ); 77 displayValue = targetFormat.format( date ) + " (" + displayValue + ")"; 78 } 79 catch ( ParseException e1 ) 80 { 81 try 82 { 83 Date date = activeDirectoryFormat.parse( s ); 84 displayValue = targetFormat.format( date ) + " (" + displayValue + ")"; 85 } 86 catch ( ParseException e2 ) 87 { 88 } 89 } 90 } 91 92 return displayValue; 93 } 94 95 } 96 | Popular Tags |