| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
package org.apache.tapestry5.corelib.pages; |
| 16 | |
|
| 17 | |
import org.apache.tapestry5.MarkupWriter; |
| 18 | |
import org.apache.tapestry5.Renderable; |
| 19 | |
import org.apache.tapestry5.annotations.Environmental; |
| 20 | |
import org.apache.tapestry5.internal.TapestryInternalUtils; |
| 21 | |
import org.apache.tapestry5.ioc.annotations.Inject; |
| 22 | |
import org.apache.tapestry5.services.PropertyOutputContext; |
| 23 | |
|
| 24 | |
import java.text.DateFormat; |
| 25 | |
import java.util.Locale; |
| 26 | |
|
| 27 | 8 | public class PropertyDisplayBlocks |
| 28 | |
{ |
| 29 | |
@Environmental |
| 30 | |
private PropertyOutputContext context; |
| 31 | |
|
| 32 | |
@Inject |
| 33 | |
private Locale locale; |
| 34 | |
|
| 35 | 2 | private final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale); |
| 36 | |
|
| 37 | |
public String getConvertedEnumValue() |
| 38 | |
{ |
| 39 | 292 | Enum value = (Enum) context.getPropertyValue(); |
| 40 | |
|
| 41 | 292 | if (value == null) return null; |
| 42 | |
|
| 43 | 292 | return TapestryInternalUtils.getLabelForEnum(context.getMessages(), value); |
| 44 | |
} |
| 45 | |
|
| 46 | |
public DateFormat getDateFormat() |
| 47 | |
{ |
| 48 | 2 | return dateFormat; |
| 49 | |
} |
| 50 | |
|
| 51 | |
public PropertyOutputContext getContext() |
| 52 | |
{ |
| 53 | 8 | return context; |
| 54 | |
} |
| 55 | |
|
| 56 | |
public Renderable getPasswordRenderer() |
| 57 | |
{ |
| 58 | 6 | return new Renderable() |
| 59 | |
{ |
| 60 | 6 | public void render(MarkupWriter writer) |
| 61 | |
{ |
| 62 | |
|
| 63 | 6 | Object value = context.getPropertyValue(); |
| 64 | |
|
| 65 | 6 | int length = value == null ? 0 : value.toString().length(); |
| 66 | |
|
| 67 | 6 | for (int i = 0; i < length; i++) writer.write("*"); |
| 68 | 6 | } |
| 69 | |
}; |
| 70 | |
} |
| 71 | |
} |