1 16 17 package org.apache.cocoon.components.modules.input; 18 19 import java.text.SimpleDateFormat ; 20 import java.util.Date ; 21 import java.util.Iterator ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import java.util.Map ; 25 import java.util.Vector ; 26 27 import org.apache.avalon.framework.configuration.Configuration; 28 import org.apache.avalon.framework.configuration.ConfigurationException; 29 import org.apache.avalon.framework.thread.ThreadSafe; 30 31 40 public class DateInputModule extends AbstractInputModule implements ThreadSafe { 41 42 final static Vector returnNames; 43 static { 44 Vector tmp = new Vector (); 45 tmp.add("currentDate"); 46 returnNames = tmp; 47 } 48 49 public Object getAttribute( String name, Configuration modeConf, Map objectModel ) throws ConfigurationException { 50 51 String format = (String ) this.settings.get("format",name); 52 if (modeConf != null) { 53 format = modeConf.getAttribute("format", format); 54 format = modeConf.getChild("format").getValue(format); 56 } 57 58 if (format==null) { 59 return new Date (); 60 } else { 61 try { 62 return new SimpleDateFormat (format).format(new Date ()); 63 } catch (Exception e) { 64 return new Date (); 65 } 66 } 67 } 68 69 70 public Iterator getAttributeNames( Configuration modeConf, Map objectModel ) throws ConfigurationException { 71 72 return DateInputModule.returnNames.iterator(); 73 } 74 75 76 public Object [] getAttributeValues( String name, Configuration modeConf, Map objectModel ) 77 throws ConfigurationException { 78 79 List values = new LinkedList (); 80 values.add( this.getAttribute(name, modeConf, objectModel) ); 81 82 return values.toArray(); 83 84 } 85 86 } 87 | Popular Tags |