Update of /cvsroot/displaytag/display09/src/org/apache/taglibs/display/model
In directory sc8-pr-cvs1:/tmp/cvs-serv22073/src/org/apache/taglibs/display/model
Added Files:
Anchor.java Cell.java Column.java ColumnIterator.java
HeaderCell.java Href.java HtmlAttributeMap.java
MultipleHtmlAttribute.java Row.java RowIterator.java
TableModel.java TagConstants.java
Log Message:
--- NEW FILE: Anchor.java ---
package org.apache.taglibs.display.model;
import java.util.HashMap;
/**
* Anchor object used to output an html link (an <a> tag)
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public class Anchor
{
/**
* href
*/
private Href mHref;
/**
* link body text
*/
private String mLinkText;
/**
* HashMap containing all the html attributes
*/
private HashMap mAttributeMap= new HtmlAttributeMap();
/**
* Creates a new anchor with the supplied body text
* @param pLinkText String body text
*/
public Anchor(String pLinkText)
{
mLinkText= pLinkText;
}
/**
* Creates a new Anchor whit the supplied Href
* @param pHref Href
*/
public Anchor(Href pHref)
{
mHref= pHref;
}
/**
* Constructor for Anchor
* @param pHref Href
* @param pLinkText String link body
*/
public Anchor(Href pHref, String pLinkText)
{
mHref= pHref;
mLinkText= pLinkText;
}
/**
* setter for anchor href
* @param pHref Href
*/
public void setHref(Href pHref)
{
mHref= pHref;
}
/**
* setter for link body text
* @param pLinkText String
*/
public void setText(String pLinkText)
{
mLinkText= pLinkText;
}
/**
* Method setClass
* @param pClass String
*/
public void setClass(String pClass)
{
mAttributeMap.put(TagConstants.ATTRIBUTE_CLASS, pClass);
}
/**
* Method setStyle
* @param pStyle String
*/
public void setStyle(String pStyle)
{
mAttributeMap.put(TagConstants.ATTRIBUTE_STYLE, pStyle);
}
/**
* Method setTitle
* @param pTitle String
*/
public void setTitle(String pTitle)
{
mAttributeMap.put(TagConstants.ATTRIBUTE_TITLE, pTitle);
}
/**
* Method getHrefString
* @return String
*/
private String getHrefString()
{
if (mHref == null)
{
return "";
}
return " href=\"" + mHref.toString() + "\"";
}
/**
* Method getOpenTag
* @return String
*/
public String getOpenTag()
{
// shortcut for links with no attributes
if (mAttributeMap.size() == 0)
{
return TagConstants.TAG_OPEN + TagConstants.TAGNAME_ANCHOR +
getHrefString() + TagConstants.TAG_CLOSE;
}
// append all attributes
StringBuffer lBuffer= new StringBuffer();
lBuffer.append(TagConstants.TAG_OPEN).append(TagConstants.TAGNAME_ANCHOR).append(getHrefString());
lBuffer.append(mAttributeMap);
lBuffer.append(TagConstants.TAG_CLOSE);
return lBuffer.toString();
}
/**
* Method getCloseTag
* @return String
*/
public String getCloseTag()
{
return TagConstants.TAG_OPENCLOSING + TagConstants.TAGNAME_ANCHOR +
TagConstants.TAG_CLOSE;
}
/**
* Method toString
* @return String
*/
public String toString()
{
return getOpenTag() + mLinkText + getCloseTag();
}
}
--- NEW FILE: Cell.java ---
package org.apache.taglibs.display.model;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public class Cell implements Comparable
{
/**
* Logger
*/
private static Log mLog= LogFactory.getLog(Cell.class);
/**
* empty cell object. Use as placeholder for empty cell to avoid useless
object creation
*/
public static final Cell EMPTY_CELL= new Cell();
/**
* Field mStaticValue
*/
private Object mStaticValue;
/**
* Creates a new empty cell
*/
private Cell()
{
}
/**
* Creates a cell with a static value
* @param pStaticValue Object value of the Cell object
*/
public Cell(Object pStaticValue)
{
mStaticValue= pStaticValue;
}
/**
* get the static value for the cell
* @return the Object value of mStaticValue.
*/
public Object getStaticValue()
{
return mStaticValue;
}
/**
* set the static value of the cell
* @param pStaticValue - the new value for mStaticValue
*/
public void setStaticValue(Object pStaticValue)
{
mStaticValue= pStaticValue;
}
/**
* Method toString
* @return String
*/
public String toString()
{
return "[Cell {value=" + mStaticValue + "}]";
}
/**
* Compare the Cell value to another Cell (to the value included) or to the
object
* @param pObj Object
* @return int
* @see java.lang.Comparable#compareTo(Object)
*/
public int compareTo(Object pObj)
{
if (mStaticValue == null)
{
return -1;
}
if (pObj instanceof Cell)
{
return ((Comparable) mStaticValue).compareTo(((Cell)
pObj).getStaticValue());
}
else
{
return ((Comparable) mStaticValue).compareTo(pObj);
}
}
}
--- NEW FILE: Column.java ---
package org.apache.taglibs.display.model;
import java.lang.reflect.InvocationTargetException;
import java.util.StringTokenizer;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.taglibs.display.util.LinkUtil;
/**
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public class Column
{
/**
* logger
*/
private static Log mLog= LogFactory.getLog(Column.class);
/**
* Field mParentRow
*/
private Row mParentRow;
/**
* Field mHeaderCell
*/
private HeaderCell mHeaderCell;
/**
* Field mCell
*/
private Cell mCell;
/**
* Constructor for Column
* @param pColumnTag HeaderCell
* @param pCell Cell
* @param pParentRow Row
*/
public Column(HeaderCell pColumnTag, Cell pCell, Row pParentRow)
{
mHeaderCell= pColumnTag;
mParentRow= pParentRow;
mCell= pCell;
}
/**
* Method getValue
* @param pDecorated boolean
* @return Object
* @throws NoSuchMethodException if method not found in bean
* @throws InvocationTargetException if method in bean returned an exception
* @throws IllegalAccessException if method not valid in bean
*/
public Object getValue(boolean pDecorated)
throws NoSuchMethodException, InvocationTargetException,
IllegalAccessException
{
if (mCell.getStaticValue() != null)
{
return mCell.getStaticValue();
}
Object lObject= null;
if (pDecorated && (mParentRow.getParentTable().getTableDecorator() !=
null))
{
try
{
lObject=
PropertyUtils.getProperty(
mParentRow.getParentTable().getTableDecorator(),
mHeaderCell.getBeanPropertyName());
}
catch (IllegalAccessException ex)
{
// doesn't matter, check object and skip decorator
}
catch (InvocationTargetException ex)
{
// doesn't matter, check object and skip decorator
}
catch (NoSuchMethodException ex)
{
// doesn't matter, check object and skip decorator
}
}
if (lObject == null)
{
lObject= PropertyUtils.getProperty(mParentRow.getObject(),
mHeaderCell.getBeanPropertyName());
}
if (pDecorated && (mHeaderCell.getColumnDecorator() != null))
{
lObject= mHeaderCell.getColumnDecorator().decorate(lObject);
}
if (lObject == null || lObject.equals("null"))
{
if (!mHeaderCell.getShowNulls())
{
lObject= "";
}
}
return lObject;
}
/**
* Method getOpenTag
* @return String
*/
public String getOpenTag()
{
return mHeaderCell.getOpenTag();
}
/**
* Method getCloseTag
* @return String
*/
public String getCloseTag()
{
return mHeaderCell.getCloseTag();
}
/**
* Method getChoppedAndLinkedValue
* @return String
* @throws NoSuchMethodException if method not found in bean
* @throws InvocationTargetException if method in bean returned an exception
* @throws IllegalAccessException if method not valid in bean
*/
public String getChoppedAndLinkedValue()
throws NoSuchMethodException, InvocationTargetException,
IllegalAccessException
{
Object lValue= getValue(true);
// String to hold what's left over after value is chopped
String lLeftover= "";
boolean lChopped= false;
String lTempValue= "";
if (lValue != null)
{
lTempValue= lValue.toString();
}
// trim the string if a maxLength or maxWords is defined
if (mHeaderCell.getMaxLength() > 0 && lTempValue.length() >
mHeaderCell.getMaxLength())
{
lLeftover= "..." +
lTempValue.substring(mHeaderCell.getMaxLength(), lTempValue.length());
lValue= lTempValue.substring(0, mHeaderCell.getMaxLength()) +
"...";
lChopped= true;
}
else if (mHeaderCell.getMaxWords() > 0)
{
StringBuffer lBuffer= new StringBuffer();
StringTokenizer lTokenizer= new StringTokenizer(lTempValue);
int lTokensNum= lTokenizer.countTokens();
if (lTokensNum > mHeaderCell.getMaxWords())
{
int lWordsCount= 0;
while (lTokenizer.hasMoreTokens() && (lWordsCount <
mHeaderCell.getMaxWords()))
{
lBuffer.append(lTokenizer.nextToken() + " ");
lWordsCount++;
}
lLeftover= "..." +
lTempValue.substring(lBuffer.length(), lTempValue.length());
lBuffer.append("...");
lValue= lBuffer;
lChopped= true;
}
}
// Are we supposed to set up a link to the data being displayed
// in this column...
if (mHeaderCell.getAutoLink())
{
lValue= LinkUtil.autoLink(lValue.toString());
}
/*if (mColumnTag.getHref() != null) {
Anchor lAtag = new Anchor(mColumnTag.getHref(), value.toString());
// if value has been chopped, add leftover as title
if (chopped) {
lAtag.setTitle(leftover);
}
value = lAtag.toString();
}*/
if (lValue != null)
{
return lValue.toString();
}
return null;
}
/**
* Method getGroup
* @return int
*/
public int getGroup()
{
return mHeaderCell.getGroup();
}
/**
* Method toString
* @return String
*/
public String toString()
{
return "[Column HeaderCell=" + mHeaderCell + " Cell=" + mCell + "]";
}
}
--- NEW FILE: ColumnIterator.java ---
package org.apache.taglibs.display.model;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public class ColumnIterator
{
/**
* Field mLog
*/
private static Log mLog= LogFactory.getLog(ColumnIterator.class);
/**
* Field mParentRow
*/
private Row mParentRow;
/**
* Field mHeaderIterator
*/
private Iterator mHeaderIterator;
/**
* Field mCellIterator
*/
private Iterator mCellIterator;
/**
* Constructor for ColumnIterator
* @param pColumns List
* @param pParentRow Row
*/
public ColumnIterator(List pColumns, Row pParentRow)
{
mHeaderIterator= pColumns.iterator();
mCellIterator= pParentRow.getCellList().iterator();
mParentRow= pParentRow;
}
/**
* Method hasNext
* @return boolean
*/
public boolean hasNext()
{
return mHeaderIterator.hasNext();
}
/**
* Method nextColumn
* @return Column
*/
public Column nextColumn()
{
return new Column((HeaderCell) mHeaderIterator.next(), (Cell)
mCellIterator.next(), mParentRow);
}
/**
* Method toString
* @return String
*/
public String toString()
{
return "[ColumnIterator]";
}
}
--- NEW FILE: HeaderCell.java ---
package org.apache.taglibs.display.model;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.taglibs.display.decorator.ColumnDecorator;
import org.apache.taglibs.display.util.HtmlTagUtil;
/**
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public class HeaderCell
{
/**
* logger
*/
private static Log mLog= LogFactory.getLog(HeaderCell.class);
/**
* Map containing the html tag attributes for cells (td)
*/
private Map mHtmlAttributes;
/**
* Map containing the html tag attributes for header cells (td)
*/
private Map mHeaderAttributes;
/**
* column title
*/
private String mTitle;
/**
* is the column sortable?
*/
private boolean mSortable;
/**
* ColumnDecorator
*/
private ColumnDecorator mColumnDecorator;
/**
* column number
*/
private int mColumnNumber;
/**
* is the column sorted?
*/
private boolean mAlreadySorted;
/**
* property name to look up in the bean
*/
private String mBeanPropertyName;
/**
* show null values?
*/
private boolean mShowNulls;
/**
* max length of cell content
*/
private int mMaxLength;
/**
* autolink url?
*/
private boolean mAutoLink;
/**
* group the column?
*/
private int mGroup;
/**
*
* @return the int value of mGroup.
*/
public int getGroup()
{
return mGroup;
}
/**
*
* @param pGroup - the new value for mGroup
*/
public void setGroup(int pGroup)
{
mGroup= pGroup;
}
/**
*
* @return true if mAutoLink is set to true.
*/
public boolean getAutoLink()
{
return mAutoLink;
}
/**
*
* @param pAutoLink - the new value for mAutoLink
*/
public void setAutoLink(boolean pAutoLink)
{
mAutoLink= pAutoLink;
}
/**
*
* @return the int value of mMaxLengtht.
*/
public int getMaxLength()
{
return mMaxLength;
}
/**
*
* @param pMaxLength - the new value for mMaxLength
*/
public void setMaxLength(int pMaxLength)
{
mMaxLength= pMaxLength;
}
/**
* Field mMaxWords
*/
private int mMaxWords;
/**
*
* @return the int value of mMaxWords.
*/
public int getMaxWords()
{
return mMaxWords;
}
/**
*
* @param pMaxWords - the new value for mMaxWords
*/
public void setMaxWords(int pMaxWords)
{
mMaxWords= pMaxWords;
}
/**
*
* @return true if mShowNulls is set to true.
*/
public boolean getShowNulls()
{
return mShowNulls;
}
/**
*
* @param pShowNulls - the new value for mShowNulls
*/
public void setShowNulls(boolean pShowNulls)
{
mShowNulls= pShowNulls;
}
/**
*
* @return the String value of mBeanPropertyName.
*/
public String getBeanPropertyName()
{
return mBeanPropertyName;
}
/**
*
* @param pBeanPropertyName - the new value for mBeanPropertyName
*/
public void setBeanPropertyName(String pBeanPropertyName)
{
mBeanPropertyName= pBeanPropertyName;
}
/**
*
* @return true if mAlreadySorted is set to true.
*/
public boolean isAlreadySorted()
{
return mAlreadySorted;
}
/**
*
*/
public void setAlreadySorted()
{
mAlreadySorted= true;
}
/**
*
* @return the int value of mColumnNumber.
*/
public int getColumnNumber()
{
return mColumnNumber;
}
/**
*
* @param pColumnNumber - the new value for mColumnNumber
*/
public void setColumnNumber(int pColumnNumber)
{
mColumnNumber= pColumnNumber;
}
/**
*
* @return the ColumnDecorator value of mColumnDecorator.
*/
public ColumnDecorator getColumnDecorator()
{
return mColumnDecorator;
}
/**
*
* @param pColumnDecorator - the new value for mColumnDecorator
*/
public void setColumnDecorator(ColumnDecorator pColumnDecorator)
{
mColumnDecorator= pColumnDecorator;
}
/**
*
* @return true if mSortable is set to true.
*/
public boolean getSortable()
{
return mSortable;
}
/**
*
* @param pSortable - the new value for mSortable
*/
public void setSortable(boolean pSortable)
{
mSortable= pSortable;
}
/**
*
* @return the Object value of mValue.
*/
public String getTitle()
{
return mTitle;
}
/**
*
* @param pValue - the new value for mValue
*/
public void getTitle(String pValue)
{
mTitle= pValue;
}
/**
*
* @return the Map value of mHtmlAttributes.
*/
public Map getHtmlAttributes()
{
return mHtmlAttributes;
}
/**
*
* @param pHtmlAttributes - the new value for mHtmlAttributes
*/
public void setHtmlAttributes(Map pHtmlAttributes)
{
mHtmlAttributes= pHtmlAttributes;
}
/**
*
* @return the Map value of mHeaderAttributes.
*/
public Map getHeaderAttributes()
{
return mHeaderAttributes;
}
/**
*
* @param pHeaderAttributes - the new value for mHtmlAttributes
*/
public void setHeaderAttributes(Map pHeaderAttributes)
{
mHeaderAttributes= pHeaderAttributes;
}
/**
* add a css class to the html "class" attribute
* @param pClass String
*/
public void addHeaderClass(String pClass)
{
Object lClassAttributes=
mHeaderAttributes.get(TagConstants.ATTRIBUTE_CLASS);
if (lClassAttributes == null)
{
mHeaderAttributes.put(TagConstants.ATTRIBUTE_CLASS, new
MultipleHtmlAttribute(pClass));
}
else
{
((MultipleHtmlAttribute)
lClassAttributes).addAttributeValue(pClass);
}
}
/**
* return the open tag for a cell
* @return String
*/
public String getOpenTag()
{
return HtmlTagUtil.createOpenTagString(TagConstants.TAGNAME_COLUMN,
mHtmlAttributes);
}
/**
* return the open tag for a column header
* @return String
*/
public String getHeaderOpenTag()
{
return
HtmlTagUtil.createOpenTagString(TagConstants.TAGNAME_COLUMN_HEADER, mHeaderAttributes);
}
/**
* return the closing tag for a cell
* @return String
*/
public String getCloseTag()
{
return TagConstants.TAG_OPENCLOSING + TagConstants.TAGNAME_COLUMN +
TagConstants.TAG_CLOSE;
}
/**
* return the closing tag for a column header
* @return String
*/
public String getHeaderCloseTag()
{
return TagConstants.TAG_OPENCLOSING +
TagConstants.TAGNAME_COLUMN_HEADER + TagConstants.TAG_CLOSE;
}
/**
* Method toString
* @return String in the follwing format: "[HeaderCell title=" + mTitle + "
property=" + mBeanPropertyName + "]"
*/
public String toString()
{
return "[HeaderCell title=" + mTitle + " property=" +
mBeanPropertyName + "]";
}
}
--- NEW FILE: Href.java ---
package org.apache.taglibs.display.model;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import org.apache.commons.lang.StringUtils;
/**
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public class Href
{
/**
* Field mBaseUrl
*/
private String mBaseUrl;
/**
* Field mParameters
*/
private HashMap mParameters;
/**
* Constructor for Href
* @param pBaseUrl String
*/
public Href(String pBaseUrl)
{
mParameters= new HashMap();
if (pBaseUrl.indexOf("?") == -1)
{
// simple url, no parameters
mBaseUrl= pBaseUrl;
}
else
{
// the Url already has parameters, put them in the parameter
Map
StringTokenizer lTokenizer= new StringTokenizer(pBaseUrl, "?");
// base url (before "?")
mBaseUrl= lTokenizer.nextToken();
if (lTokenizer.hasMoreTokens())
{
StringTokenizer lParamTokenizer= new
StringTokenizer(lTokenizer.nextToken(), "&");
// split parameters (key=value)
while (lParamTokenizer.hasMoreTokens())
{
// split key and value ...
String[] lKeyValue=
StringUtils.split(lParamTokenizer.nextToken(), "=");
// ... and add it to the map
mParameters.put(lKeyValue[0], lKeyValue[1]);
}
}
}
}
/**
* Constructor for Href
* @param pHref Href
*/
public Href(Href pHref)
{
mBaseUrl= pHref.getBaseUrl();
mParameters= pHref.getParameterMap();
}
/**
* Method addParameter
* @param pName String
* @param pValue Object
*/
public void addParameter(String pName, Object pValue)
{
mParameters.put(pName, pValue);
}
/**
* Method addParameter
* @param pName String
* @param pValue int
*/
public void addParameter(String pName, int pValue)
{
mParameters.put(pName, new Integer(pValue));
}
/**
* Method getParameterMap
* @return HashMap
*/
public HashMap getParameterMap()
{
return (HashMap) mParameters.clone();
}
/**
* Method setParameterMap
* @param pMap HashMap
*/
public void setParameterMap(HashMap pMap)
{
mParameters= pMap;
}
/**
* Method getBaseUrl
* @return String
*/
public String getBaseUrl()
{
return mBaseUrl;
}
/**
* toString: output the full url with parameters
* @return String
*/
public String toString()
{
// no parameters? simply return the base Url
if (mParameters.size() == 0)
{
return mBaseUrl;
}
StringBuffer lBuffer= new StringBuffer(30);
lBuffer.append(mBaseUrl).append('?');
Set lParameterSet= mParameters.entrySet();
Iterator lIterator= lParameterSet.iterator();
while (lIterator.hasNext())
{
Map.Entry lEntry= (Map.Entry) lIterator.next();
lBuffer.append(lEntry.getKey()).append('=').append(lEntry.getValue());
if (lIterator.hasNext())
{
lBuffer.append("&");
}
}
return lBuffer.toString();
}
}
--- NEW FILE: HtmlAttributeMap.java ---
package org.apache.taglibs.display.model;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* Extends Map providing only a different toString() method
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public class HtmlAttributeMap extends HashMap
{
/**
* Attribute value delimiter
*/
private static final char DELIMITER= '"';
/**
* character between name and value
*/
private static final char EQUALS= '=';
/**
* space before any attribute
*/
private static final char SPACE= ' ';
/**
* toString method: returns attributes in the format:
* attributename="attributevalue" attr2="attrValue2" ...
* @return String representation of the HtmlAttributeMap
*/
public String toString()
{
// buffer extimated in number of attributes * 30
StringBuffer lBuffer= new StringBuffer(size() * 30);
// get the entrySet
Set lEntrySet= entrySet();
Iterator lIterator= lEntrySet.iterator();
// iterates on attributes
while (lIterator.hasNext())
{
Map.Entry lEntry= (Map.Entry) lIterator.next();
// append a new atribute
lBuffer.append(SPACE).append(lEntry.getKey()).append(EQUALS).append(DELIMITER).append(
lEntry.getValue()).append(
DELIMITER);
}
// return
return lBuffer.toString();
}
}
--- NEW FILE: MultipleHtmlAttribute.java ---
package org.apache.taglibs.display.model;
import java.util.HashSet;
import java.util.Iterator;
import org.apache.commons.lang.StringUtils;
/**
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public class MultipleHtmlAttribute implements Cloneable
{
/** HashSet containing splitted attribute values **/
private HashSet mAttributeSet;
/**
* Constructor for MultipleHtmlAttribute
* @param pAttributeValue String
*/
public MultipleHtmlAttribute(String pAttributeValue)
{
// split initial attribute
String[] lAttributes= StringUtils.split(pAttributeValue);
addAllAttributesFromArray(lAttributes);
}
/**
* Constructor for MultipleHtmlAttribute
* @param pAttributes Object[]
*/
private MultipleHtmlAttribute(Object[] pAttributes)
{
addAllAttributesFromArray(pAttributes);
}
/**
* add attributes from an array
* @param pAttributes Object[] Array containing attributes
*/
private void addAllAttributesFromArray(Object[] pAttributes)
{
// number of attributes to add
int lLength= pAttributes.length;
// create new HashSet with correct size
mAttributeSet= new HashSet(lLength);
// add all the splitted attributes
for (int lCounter= 0; lCounter < lLength; lCounter++)
{
// don't add if empty
if (!"".equals(pAttributes[lCounter]) )
{
mAttributeSet.add(pAttributes[lCounter]);
}
}
}
/**
* return the list of attributes separated by a space
* @return String
*/
public String toString()
{
StringBuffer lBuffer= new StringBuffer();
Iterator lIterator= mAttributeSet.iterator();
while (lIterator.hasNext())
{
// apend next value
lBuffer.append(lIterator.next());
if (lIterator.hasNext())
{
// append a space if there are more
lBuffer.append(" ");
}
}
return lBuffer.toString();
}
/**
* Method addAttributeValue
* @param pAttributeValue String
*/
public void addAttributeValue(String pAttributeValue)
{
// don't add if empty
if (!"".equals(pAttributeValue))
{
mAttributeSet.add(pAttributeValue);
}
}
/**
* Method clone
* @return Object
*/
protected Object clone()
{
// creates a totally new object
return new MultipleHtmlAttribute(mAttributeSet.toArray());
}
}
--- NEW FILE: Row.java ---
package org.apache.taglibs.display.model;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public class Row
{
/**
* Field mLog
*/
private static Log mLog= LogFactory.getLog(Row.class);
/**
* Field mRowObject
*/
private Object mRowObject;
/**
* Field mStaticCells
*/
private List mStaticCells;
/**
* Field mRowNumber
*/
private int mRowNumber;
/**
* Field mTableModel
*/
private TableModel mTableModel;
/**
*
* @param pRowNumber - the new value for mRowNumber
*/
public void setRowNumber(int pRowNumber)
{
mRowNumber= pRowNumber;
}
/**
*
* @return true if isOddRow is set to true.
*/
public boolean isOddRow()
{
return (mRowNumber % 2 == 0);
}
/**
* Method getRowNumber
* @return int
*/
public int getRowNumber()
{
return mRowNumber;
}
/**
* Constructor for Row
* @param pRowObject Object
* @param pRowNumber int
*/
public Row(Object pRowObject, int pRowNumber)
{
mRowObject= pRowObject;
mRowNumber= pRowNumber;
mStaticCells= new ArrayList();
}
/**
* Method addCell
* @param pCell Cell
*/
public void addCell(Cell pCell)
{
// mLog.debug("adding cell " + pCell + " to collection " +
mStaticCells);
mStaticCells.add(pCell);
}
/**
* Method getCellList
* @return List
*/
public List getCellList()
{
return mStaticCells;
}
/**
* Method getObject
* @return Object
*/
public Object getObject()
{
return mRowObject;
}
/**
* Method toString
* @return String
*/
public String toString()
{
return mRowObject.toString();
}
/**
* Method getColumnIterator
* @param pColumns List
* @return ColumnIterator
*/
public ColumnIterator getColumnIterator(List pColumns)
{
return new ColumnIterator(pColumns, this);
}
/**
* Method setParentTable
* @param pTableModel TableModel
*/
protected void setParentTable(TableModel pTableModel)
{
mTableModel= pTableModel;
}
/**
* Method getParentTable
* @return TableModel
*/
protected TableModel getParentTable()
{
return mTableModel;
}
}
--- NEW FILE: RowIterator.java ---
package org.apache.taglibs.display.model;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.taglibs.display.decorator.TableDecorator;
/**
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public class RowIterator
{
/**
* Logger
*/
private static Log mLog= LogFactory.getLog(RowIterator.class);
/**
* List contaning CellHeader objects
*/
private List mColumns;
/**
* internal iterator for Rows
*/
private Iterator mIterator;
/**
* row number counter
*/
private int mCount;
/**
* reference to the table TableDecorator
*/
private TableDecorator mTableDecorator;
/**
* Constructor for RowIterator
* @param pRowList List containing Row objects
* @param pColumns List containing CellHeader objects
* @param pTableDecorator TableDecorator
*/
protected RowIterator(List pRowList, List pColumns, TableDecorator
pTableDecorator)
{
mIterator= pRowList.iterator();
mColumns= pColumns;
mCount= 0;
mTableDecorator= pTableDecorator;
}
/**
* Method hasNext
* @return boolean true if a new row
*/
public boolean hasNext()
{
return mIterator.hasNext();
}
/**
* return the next row object
* @return Row
*/
public Row next()
{
int lRowNumber= mCount++;
if (mLog.isDebugEnabled())
{
mLog.debug("RowIterator.next() row number=" + lRowNumber);
}
Object lObject= mIterator.next();
Row lRow= (Row) lObject;
lRow.setRowNumber(lRowNumber);
if (mTableDecorator != null)
{
mTableDecorator.initRow(lRow.getObject(), lRowNumber,
lRowNumber);
}
return lRow;
}
}
--- NEW FILE: TableModel.java ---
package org.apache.taglibs.display.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.taglibs.display.decorator.TableDecorator;
import org.apache.taglibs.display.util.RowCellSorter;
import org.apache.taglibs.display.util.RowSorter;
/**
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public class TableModel
{
/**
* Field mLog
*/
private static Log mLog= LogFactory.getLog(TableModel.class);
/** list of HeaderCell **/
private List mHeaderCellList;
/** full list (contains Row objects) **/
private List mRowListFull;
/** list of data to be displayed in page **/
private List mRowListPage;
/** sort order = ascending? **/
private boolean mSortOrderAscending= true;
/** sort full List? (false sort only displayed page) **/
private boolean mSortFullTable= true;
/**
* index of the sorted column (-1 if the table is not sorted)
*/
private int mSortColumn= -1;
/** Table decorator **/
private TableDecorator mTableDecorator;
/**
* Constructor for TableModel
*/
public TableModel()
{
mRowListFull= new ArrayList(20);
mHeaderCellList= new ArrayList(20);
}
/**
* get the full list
* @return the full list containing Row objects
*/
public List getRowListFull()
{
return mRowListFull;
}
/**
* get the partial (paginated) list
* @return the partial list to display in page (contains Row objects)
*/
public List getRowListPage()
{
return mRowListPage;
}
/**
* add a Row object to the table
* @param pRow Row
*/
public void addRow(Row pRow)
{
pRow.setParentTable(this);
mLog.debug("adding row");
mRowListFull.add(pRow);
}
/**
* set the sort full table property. If true the full list is sorted,
* if false sorting is applied only to the displayed sublist
* @param pSortFullTable boolean
*/
public void setSortFullTable(boolean pSortFullTable)
{
mSortFullTable= pSortFullTable;
}
/**
* return the sort full table property
* @return boolean true if sorting is applied to the full list
*/
public boolean isSortFullTable()
{
return mSortFullTable;
}
/**
* return the sort order of the page
* @return true if sort order is ascending
*/
public boolean isSortOrderAscending()
{
return mSortOrderAscending;
}
/**
* set the sort order of the list
* @param pSortOrderAscending true to sort in ascending order
*/
public void setSortOrderAscending(boolean pSortOrderAscending)
{
mSortOrderAscending= pSortOrderAscending;
}
/**
*
* @param pRowListPage - the new value for mRowListPage
*/
public void setRowListPage(List pRowListPage)
{
mRowListPage= pRowListPage;
}
/**
* getter for the Table Decorator
* @return TableDecorator
*/
public TableDecorator getTableDecorator()
{
return mTableDecorator;
}
/**
* setter for the table decorator
* @param pTableDecorator - the TableDecorator object
*/
public void setTableDecorator(TableDecorator pTableDecorator)
{
mTableDecorator= pTableDecorator;
}
/**
* return true if the table is sorted
* @return boolean true if the table is sorted
*/
public boolean isSorted()
{
return (mSortColumn != -1);
}
/**
* return the HeaderCell for the sorted column
* @return HeaderCell
*/
public HeaderCell getSortedColumnHeader()
{
if (mSortColumn < 0 || (mSortColumn > (mHeaderCellList.size() - 1)))
{
return null;
}
return (HeaderCell) mHeaderCellList.get(mSortColumn);
}
/**
* return the number of columns in the table
* @return int number of columns
*/
public int getNumberOfColumns()
{
return mHeaderCellList.size();
}
/**
* return true is the table has no columns
* @return boolean
*/
public boolean isEmpty()
{
return (mHeaderCellList.size() == 0);
}
/**
* return the index of the sorted column
* @return index of the sorted column or -1 if the table is not sorted
*/
public int getSortedColumnNumber()
{
return mSortColumn;
}
/**
* set the sorted column index
* @param pSortColumn - the index of the sorted column
*/
public void setSortedColumnNumber(int pSortColumn)
{
mSortColumn= pSortColumn;
}
/**
* Method addColumnHeader
* @param pHeaderCell HeaderCell
*/
public void addColumnHeader(HeaderCell pHeaderCell)
{
if (mSortColumn == mHeaderCellList.size())
{
pHeaderCell.setAlreadySorted();
}
pHeaderCell.setColumnNumber(mHeaderCellList.size());
mHeaderCellList.add(pHeaderCell);
}
/**
* Method getHeaderCellList
* @return List
*/
public List getHeaderCellList()
{
return mHeaderCellList;
}
/**
* returns a RowIterator on the requested (full|page) list
* @return RowIterator
* @see org.apache.taglibs.display.model.RowIterator
*/
public RowIterator getRowIterator()
{
return new RowIterator(mRowListPage, mHeaderCellList, mTableDecorator);
}
/**
* returns a RowIterator on the _full_ list. Needed for export views
* @return RowIterator
* @see org.apache.taglibs.display.model.RowIterator
*/
public RowIterator getFullListRowIterator()
{
return new RowIterator(mRowListFull, mHeaderCellList, mTableDecorator);
}
/**
* Method sortRowList
* @param pList List
*/
private void sortRowList(List pList)
{
mLog.debug("sortRowList()");
if (isSorted())
{
HeaderCell lSortedHeaderCell= getSortedColumnHeader();
// If it is an explicit value, then sort by that, otherwise
sort by
// the property...
if (lSortedHeaderCell.getBeanPropertyName() != null)
{
Collections.sort(
pList,
new
RowSorter(lSortedHeaderCell.getBeanPropertyName(), getTableDecorator(),
mSortOrderAscending));
}
else if (mSortColumn != -1 && mSortColumn <
mHeaderCellList.size())
{
Collections.sort(pList, new RowCellSorter(mSortColumn,
mSortOrderAscending));
}
}
}
/**
* sort the list displayed in page
*/
public void sortPageList()
{
mLog.debug("sortFullData()");
sortRowList(mRowListPage);
}
/**
* sort the full list of data
*/
public void sortFullList()
{
mLog.debug("sort FullData");
sortRowList(mRowListFull);
}
}
--- NEW FILE: TagConstants.java ---
package org.apache.taglibs.display.model;
/**
* @author fgiust
* @version $Revision: 1.1 $ ($Author: fgiust $)
*/
public interface TagConstants
{
/**
* Field TAG_OPEN
*/
public static final String TAG_OPEN= "\n<";
/**
* Field TAG_OPENCLOSING
*/
public static final String TAG_OPENCLOSING= "</";
/**
* Field TAG_CLOSE
*/
public static final String TAG_CLOSE= ">";
/**
* Field TAGNAME_ANCHOR
*/
public static final String TAGNAME_ANCHOR= "a";
/**
* Field TABLE_TAG_NAME
*/
public static final String TABLE_TAG_NAME= "table";
/**
* Field TAGNAME_COLUMN
*/
public static final String TAGNAME_COLUMN= "td";
/**
* Field TAGNAME_COLUMN_HEADER
*/
public static final String TAGNAME_COLUMN_HEADER= "th";
/**
* Field TAGNAME_TABLE_HEAD
*/
public static final String TAGNAME_TABLE_HEAD= "thead";
/**
* Field TAGNAME_TABLE_BODY
*/
public static final String TAGNAME_TABLE_BODY= "tbody";
/**
* Field TAGNAME_TABLE_FOOTER
*/
public static final String TAGNAME_TABLE_FOOTER= "tfooter";
/**
* Field ATTRIBUTE_RULES
*/
public static final String ATTRIBUTE_RULES= "rules";
/**
* Field ATTRIBUTE_BGCOLOR
*/
public static final String ATTRIBUTE_BGCOLOR= "bgcolor";
/**
* Field ATTRIBUTE_FRAME
*/
public static final String ATTRIBUTE_FRAME= "frame";
/**
* Field ATTRIBUTE_HEIGHT
*/
public static final String ATTRIBUTE_HEIGHT= "height";
/**
* Field ATTRIBUTE_HSPACE
*/
public static final String ATTRIBUTE_HSPACE= "hspace";
/**
* Field ATTRIBUTE_WIDTH
*/
public static final String ATTRIBUTE_WIDTH= "width";
/**
* Field ATTRIBUTE_BORDER
*/
public static final String ATTRIBUTE_BORDER= "border";
/**
* Field ATTRIBUTE_CELLSPACING
*/
public static final String ATTRIBUTE_CELLSPACING= "cellspacing";
/**
* Field ATTRIBUTE_CELLPADDING
*/
public static final String ATTRIBUTE_CELLPADDING= "cellpadding";
/**
* Field ATTRIBUTE_ALIGN
*/
public static final String ATTRIBUTE_ALIGN= "align";
/**
* Field ATTRIBUTE_BACKGROUND
*/
public static final String ATTRIBUTE_BACKGROUND= "background";
/**
* Field ATTRIBUTE_SUMMARY
*/
public static final String ATTRIBUTE_SUMMARY= "summary";
/**
* Field ATTRIBUTE_VSPACE
*/
public static final String ATTRIBUTE_VSPACE= "vspace";
/**
* Field ATTRIBUTE_CLASS
*/
public static final String ATTRIBUTE_CLASS= "class";
/**
* Field ATTRIBUTE_ID
*/
public static final String ATTRIBUTE_ID= "id";
/**
* Field ATTRIBUTE_STYLE
*/
public static final String ATTRIBUTE_STYLE= "style";
/**
* Field ATTRIBUTE_TITLE
*/
public static final String ATTRIBUTE_TITLE= "title";
/**
* Field ATTRIBUTE_VALIGN
*/
public static final String ATTRIBUTE_VALIGN= "valign";
/**
* Field ATTRIBUTE_NOWRAP
*/
public static final String ATTRIBUTE_NOWRAP= "nowrap";
}
-------------------------------------------------------
This SF.NET email is sponsored by: eBay
Great deals on office technology -- on eBay now! Click here:
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
displaytag-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-devel