Java tutorial
/* * * * Copyright (C) 2007 Pingtel Corp., certain elements licensed under a Contributor Agreement. * Contributors retain copyright to elements licensed under a Contributor Agreement. * Licensed to the User under the LGPL license. * * $ */ package org.sipfoundry.sipxconfig.components; import java.text.FieldPosition; import java.text.Format; import java.text.ParsePosition; import org.apache.commons.lang.StringUtils; import org.apache.hivemind.Messages; /** * Tapestry enabled formatter for new java Enums */ public class NewEnumFormat<E extends Enum<E>> extends Format { private Messages m_messages; private String m_prefixSeparator = "."; private String m_prefix = StringUtils.EMPTY; public void setMessages(Messages messages) { m_messages = messages; } public void setPrefix(String prefix) { m_prefix = prefix; } public void setPrefixSeparator(String prefixSeparator) { m_prefixSeparator = prefixSeparator; } public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos_) { E e = (E) obj; if (m_messages == null) { toAppendTo.append(e.toString()); } else { String key = m_prefix + m_prefixSeparator + e.toString(); toAppendTo.append(m_messages.getMessage(key)); } return toAppendTo; } public Object parseObject(String source, ParsePosition pos) { throw new UnsupportedOperationException(); } }