001    /*****************************************************************************
002    *                             MODULE DESCRIPTION
003    ******************************************************************************
004    *
005    *      NAME:     HtmlColumn.java
006    *      LANGUAGE: Java 2
007    *      DATE:     11.02.2002
008    *      AUTHOR:   Miika Nurminen, University of Jyväskylä (JYU)
009    *      PURPOSE:  Abstraction of HTML table column
010    *
011    ******************************************************************************
012    *                  COPYRIGHT (C) Kiuru group
013    *             Limited rights granted. Please refer to license
014    *****************************************************************************/
015    
016    /*****************************************************************************
017     *                                 UPDATES
018    ******************************************************************************
019    *
020    * 11.2.2003 / mn
021    *   - Initial version
022    *
023    ******************************************************************************/
024    package kiurubeans;
025    import kotkabeans.RS2;
026    
027    /**
028     * Abstraction of HTML table column
029     *
030     * @author Miika Nurminen
031     */
032    public abstract class HtmlColumn {
033      
034      /** Holds value of property title. */
035      private String title;
036      
037      /** Holds value of property fieldName. */
038      private String fieldName;
039      
040      /** Holds value of property field. */
041      private Field field;  
042      
043      /** Creates a new instance of HtmlColumn - dummy empty constructor*/
044      public HtmlColumn() {
045      }
046      
047      /** Creates a new instance of HtmlColumn
048       * @param field related db column
049       * @param title title to be shown in th
050       */
051      public HtmlColumn(Field field,String title) {
052        assignValues(field,title);
053      }
054      
055      /** Creates a new instance of HtmlColumn 
056       * @param title title to be shown in th
057       * @param field field name of related db row
058       */
059      public HtmlColumn(String field,String title) {
060        assignValues(field,title);
061      }
062      
063      /**
064       * Assigns property values in bean 
065       *
066       * @deprecated field should be of type Field. however, htmlcombinedcolumn uses this.
067       * @see HtmlCombinedColumn
068       * @param field db field name
069       * @param title title to be shown in th
070       */
071      protected void assignValues(String field,String title) {
072        setTitle(title);
073        setFieldName(field);
074      }
075      
076      /**
077       * Assigns property values in bean.
078       *
079       * @param field information about db field
080       * @param title title to be shown in th
081       */  
082      protected void assignValues(Field field,String title) {
083        setTitle(title);
084        setField(field);
085      }
086      
087      /** Getter for property title.
088       * @return Value of property title.
089       */
090      public String getTitle() {
091        return this.title;
092      }
093      
094      /** Setter for property title.
095       * @param title New value of property title.
096       */
097      public void setTitle(String title) {
098        this.title = title;
099      }
100      
101      /** Getter for property fieldName.
102       * @return Value of property fieldName.
103       */
104      public String getFieldName() {
105        if (getField()!=null) return getField().getAlias();
106        return this.fieldName;
107      }
108      
109      /** Setter for property fieldName.
110       * @param fieldName New value of property fieldName.
111       */
112      public void setFieldName(String fieldName) {
113        this.fieldName = fieldName;
114      }
115      
116      
117      /** Getter for property field.
118       * @return Value of property field.
119       *
120       */
121      public Field getField() {
122        return this.field;
123      }
124      
125      /** Setter for property field.
126       * @param field New value of property field.
127       */
128      public void setField(Field field) {
129        this.field = field;
130      }
131      
132      
133      /** Returns current table cell data as string. Inherited classes override this.
134       * @return data to be put in <td></td>
135       * @param rs RS2 where data is retrieved.
136       */
137      public abstract String getCellData(RS2 rs);
138      
139      
140      /**
141       * Returns string value for a given db field
142       * @param rs RS2 where data is retrieved
143       * @param fieldName fieldname to seek
144       * @return string value for the field
145       */  
146      protected String getFieldValue(RS2 rs,String fieldName) {
147        try {
148          return SimpleDb.getString(rs,fieldName);
149        }
150        catch (java.lang.Exception e) {
151          return "";
152        }
153      }
154      
155      /**
156       * Returns string value for current db field
157       * @param rs RS2 where data is retrieved
158       * @return string value for the field
159       */  
160      protected String getFieldValue(RS2 rs) {
161        if (getField()==null) return getFieldValue(rs,getFieldName()); 
162        try {
163          return getField().getFieldValue(rs);
164        }
165        catch (java.lang.Exception e) {
166          return "";
167        }
168      }
169      
170      /** Returns header data. If order data is linked, returns
171       * @link if true, generates link
172       * @return data to be put in <th></th>
173       * @param link if true, generates a link
174       * @param basedocument column-independent data
175       */
176      public String getHeader(String basedocument,boolean link) {
177        if ((getTitle()==null) || (getTitle().length()==0)) return "";
178        if (link==false) return getTitle();
179        else {
180          return HtmlBean.getLink(getTitle(), basedocument+getFieldName());
181        }
182      }
183      
184    }
185    /***************************************************************************************************
186     *               COPYRIGHT (C) KIURU -PROJECT GROUP
187     *               Limited rights granted. Please refer to license.
188     **************************************************************************************************/