001: // /////////////////////////////
002: // Makumba, Makumba tag library
003: // Copyright (C) 2000-2003 http://www.makumba.org
004: //
005: // This library is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU Lesser General Public
007: // License as published by the Free Software Foundation; either
008: // version 2.1 of the License, or (at your option) any later version.
009: //
010: // This library is distributed in the hope that it will be useful,
011: // but WITHOUT ANY WARRANTY; without even the implied warranty of
012: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: // Lesser General Public License for more details.
014: //
015: // You should have received a copy of the GNU Lesser General Public
016: // License along with this library; if not, write to the Free Software
017: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: //
019: // -------------
020: // $Id: RecordFormatter.java 1688 2007-09-25 12:54:46Z manuel_gay $
021: // $Name$
022: /////////////////////////////////////
023:
024: package org.makumba.commons.formatters;
025:
026: import java.io.Serializable;
027: import java.util.Dictionary;
028:
029: import org.makumba.DataDefinition;
030: import org.makumba.FieldDefinition;
031:
032: /**
033: * Generic formatter of Makumba data. Depending on the data type, calls specific formatters an applies them for each
034: * field of a record.
035: *
036: * @author Cristian Bogdan
037: * @author Rudolf Mayer
038: * @version $Id: RecordFormatter.java 1688 2007-09-25 12:54:46Z manuel_gay $
039: */
040:
041: public class RecordFormatter implements Serializable {
042:
043: public static final String FORMATTERS = "org.makumba.formatters";
044:
045: public DataDefinition dd;
046:
047: public String[] expr;
048:
049: protected transient FieldFormatter[] formatterArray;
050:
051: public RecordFormatter() {
052: }
053:
054: private static final long serialVersionUID = 1L;
055:
056: public RecordFormatter(DataDefinition dd, java.util.Hashtable names) {
057: this .dd = dd;
058: initFormatters();
059:
060: expr = new String[dd.getFieldNames().size()];
061:
062: for (int i = 0; i < dd.getFieldNames().size(); i++) {
063: expr[i] = (String) names.get(dd.getFieldDefinition(i)
064: .getName());
065: }
066: }
067:
068: protected String applyParameters(FieldFormatter ff,
069: Dictionary formatParams, String s) {
070: return s;
071: }
072:
073: public String format(int i, Object value, Dictionary formatParams) {
074: formatterArray[i].checkParams(this , i, formatParams);
075: return applyParameters(formatterArray[i], formatParams,
076: formatterArray[i].format(this , i, value, formatParams));
077: }
078:
079: protected void initFormatters() {
080: formatterArray = new FieldFormatter[dd.getFieldNames().size()];
081: for (int i = 0; i < dd.getFieldNames().size(); i++) {
082: FieldDefinition fd = dd.getFieldDefinition(i);
083: switch (fd.getIntegerType()) {
084: case FieldDefinition._ptr:
085: case FieldDefinition._ptrRel:
086: case FieldDefinition._ptrOne:
087: case FieldDefinition._ptrIndex:
088: formatterArray[i] = ptrFormatter.getInstance();
089: break;
090: case FieldDefinition._intEnum:
091: formatterArray[i] = intEnumFormatter.getInstance();
092: break;
093: case FieldDefinition._date:
094: formatterArray[i] = dateFormatter.getInstance();
095: break;
096: case FieldDefinition._dateCreate:
097: case FieldDefinition._dateModify:
098: formatterArray[i] = timestampFormatter.getInstance();
099: break;
100: default:
101: formatterArray[i] = FieldFormatter.getInstance();
102: }
103: }
104: }
105: }
|