Update of /cvsroot/displaytag/display09/site/src/org/displaytag/sample
In directory sc8-pr-cvs1:/tmp/cvs-serv26549/site/src/org/displaytag/sample

Added Files:
        DisplaySourceServlet.java ListHolder.java ListObject.java 
        LongDateWrapper.java ReportList.java ReportableListObject.java 
        TestList.java TotalWrapper.java Wrapper.java 
Log Message:
added documentation - joined documentation and samples - refactored original 
documentation pages to the new look - added build tasks for the doc/sample war - 
removed example tree (new "site" tree contains both documentation and examples)

--- NEW FILE: DisplaySourceServlet.java ---
package org.displaytag.sample;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>Servlet used to display jsp source for example pages</p>
 * @author fgiust
 * @version $Revision: 1.1 $ ($Author: fgiust $)
 */
public class DisplaySourceServlet extends HttpServlet
{

        /**
         * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest, 
HttpServletResponse)
         */
        protected void doGet(HttpServletRequest pRequest, HttpServletResponse 
pResponse)
                throws ServletException, IOException
        {

                String lJspFile= pRequest.getRequestURI();

                // lastIndexOf(".") can't be null, since the servlet is mapped to 
".source"
                lJspFile= lJspFile.substring(0, lJspFile.lastIndexOf("."));

                if (lJspFile.lastIndexOf("/") != -1)
                {
                        lJspFile= lJspFile.substring(lJspFile.lastIndexOf("/") + 1);
                }

                // only want to show sample pages, don't play with url!
                if (!lJspFile.startsWith("example-"))
                {
                        throw new ServletException("Invalid file selected: " + 
lJspFile);
                }

                String lFullName= "/jsp/" + lJspFile;

                InputStream lInputStream= 
getServletContext().getResourceAsStream(lFullName);

                if (lInputStream == null)
                {
                        throw new ServletException("Unable to find JSP file: " + 
lJspFile);
                }

                pResponse.setContentType("text/html");

                PrintWriter lOut= pResponse.getWriter();

                lOut.println(
                        "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
                                + 
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>");
                lOut.println("<html xmlns=\"http://www.w3.org/1999/xhtml\"; 
xml:lang=\"en\" lang=\"en\">");
                lOut.println("<head>");
                lOut.println("<title>");
                lOut.println("source for " + lJspFile);
                lOut.println("</title>");
                lOut.println("<meta http-equiv=\"content-type\" content=\"text/html; 
charset=ISO-8859-1\" />");
                lOut.println("</head>");
                lOut.println("<body>");
                lOut.println("<pre>");
                for (int lChar= lInputStream.read(); lChar != -1; lChar= 
lInputStream.read())
                {
                        if (lChar == '<')
                        {
                                lOut.print("&lt;");
                        }
                        else
                        {
                                lOut.print((char) lChar);
                        }
                }
                lOut.println("</pre>");
                lOut.println("</body>");
                lOut.println("</html>");
        }

}

--- NEW FILE: ListHolder.java ---
package org.displaytag.sample;

import java.util.List;

/**
 * One line description of what this class does.
 *
 * More detailed class description, including examples of usage if applicable.
 * @author epesh
 * @version $Revision: 1.1 $ ($Author: fgiust $)
 */
public class ListHolder extends Object
{
        /**
         * Field myList
         */
        private List mList;

        /**
         * Constructor for ListHolder
         */
        public ListHolder()
        {
                mList= new TestList(15);
        }

        /**
         * Method getList
         * @return List
         */
        public List getList()
        {
                return mList;
        }
}

--- NEW FILE: ListObject.java ---
package org.displaytag.sample;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.StringTokenizer;

import org.apache.commons.lang.StringUtils;

/**
 * Just a test class that returns columns of data that are useful for testing
 * out the ListTag class and ListColumn class.
 *
 * More detailed class description, including examples of usage if applicable.
 * @author epesh
 * @version $Revision: 1.1 $ ($Author: fgiust $)
 */
public class ListObject extends Object
{
        /**
         * Field rnd
         */
        private static Random rnd= new Random();
        /**
         * Field words
         */
        private static List lWords= null;

        /**
         * Field mId
         */
        private int mId= -1;

        /**
         * Field name
         */
        private String mName;
        /**
         * Field email
         */
        private String mEmail;
        /**
         * Field date
         */
        private Date mDate;
        /**
         * Field money
         */
        private double mMoney;
        /**
         * Field description
         */
        private String mDescription;
        /**
         * Field longDescription
         */
        private String mLongDescription;
        /**
         * Field status
         */
        private String mStatus;
        /**
         * Field url
         */
        private String mUrl;

        /**
         * sub list to test nested tables
         */
        private ArrayList mSubList;

        /**
         * Constructor for ListObject
         */
        public ListObject()
        {
                setupRandomData();
        }

        /**
         * Method getId
         * @return int
         */
        public int getId()
        {
                return mId;
        }

        /**
         * Method setID
         * @param pId int
         */
        public void setID(int pId)
        {
                mId= pId;
        }

        /**
         * Method getName
         * @return String
         */
        public String getName()
        {
                return mName;
        }

        /**
         * Method getEmail
         * @return String
         */
        public String getEmail()
        {
                return mEmail;
        }

        /**
         * Method setEmail
         * @param pEmail String
         */
        public void setEmail(String pEmail)
        {
                mEmail= pEmail;
        }

        /**
         * Method getDate
         * @return Date
         */
        public Date getDate()
        {
                return mDate;
        }

        /**
         * Method getMoney
         * @return double
         */
        public double getMoney()
        {
                return mMoney;
        }

        /**
         * Method getDescription
         * @return String
         */
        public String getDescription()
        {
                return mDescription;
        }

        /**
         * Method getLongDescription
         * @return String
         */
        public String getLongDescription()
        {
                return mLongDescription;
        }

        /**
         * Method getStatus
         * @return String
         */
        public String getStatus()
        {
                return mStatus;
        }

        /**
         * Method getUrl
         * @return String
         */
        public String getUrl()
        {
                return mUrl;
        }

        /**
         * Method getNullValue
         * @return String
         */
        public String getNullValue()
        {
                return null;
        }

        /**
         * Method toString
         * @return String
         */
        public String toString()
        {
                return "ListObject(" + mId + ")";
        }

        /**
         * Method toDetailedString
         * @return String
         */
        public String toDetailedString()
        {
                return "ID:          "
                        + mId
                        + "\n"
                        + "Name:        "
                        + mName
                        + "\n"
                        + "Email:       "
                        + mEmail
                        + "\n"
                        + "Date:        "
                        + mDate
                        + "\n"
                        + "Money:       "
                        + mMoney
                        + "\n"
                        + "Description: "
                        + mDescription
                        + "\n"
                        + "Status:      "
                        + mStatus
                        + "\n"
                        + "URL:         "
                        + mUrl
                        + "\n";
        }

        /**
         * Method setupRandomData
         */
        public void setupRandomData()
        {
                mId= rnd.nextInt(99998) + 1;
                mMoney= (rnd.nextInt(999998) + 1) / 100;

                String lFirst= getRandomWord();
                String lLast= getRandomWord();

                mName= StringUtils.capitalise(lFirst) + " " + 
StringUtils.capitalise(lLast);

                mEmail= lFirst + "-" + lLast + "@" + getRandomWord() + ".com";

                Calendar lCalendar= Calendar.getInstance();
                lCalendar.add(Calendar.DATE, 365 - rnd.nextInt(730));
                mDate= lCalendar.getTime();

                mDescription= getRandomWord() + " " + getRandomWord() + "...";

                mLongDescription=
                        getRandomWord()
                                + " "
                                + getRandomWord()
                                + " "
                                + getRandomWord()
                                + " "
                                + getRandomWord()
                                + " "
                                + getRandomWord()
                                + " "
                                + getRandomWord()
                                + " "
                                + getRandomWord()
                                + " "
                                + getRandomWord()
                                + " "
                                + getRandomWord()
                                + " "
                                + getRandomWord()
                                + " "
                                + getRandomWord();

                mStatus= getRandomWord().toUpperCase();

                // added sublist for testing of nested tables
                mSubList= new ArrayList();
                mSubList.add(new SubListItem(getRandomWord(), getRandomWord() + "@" + 
getRandomWord() + ".com"));
                mSubList.add(new SubListItem(getRandomWord(), getRandomWord() + "@" + 
getRandomWord() + ".com"));
                mSubList.add(new SubListItem(getRandomWord(), getRandomWord() + "@" + 
getRandomWord() + ".com"));

                mUrl= "http://www."; + lLast + ".org/";
        }

        /**
         * Method getRandomWord
         * @return String
         */
        public String getRandomWord()
        {
                if (lWords == null)
                {
                        setupWordBase();
                }

                return ((String) lWords.get(rnd.nextInt(lWords.size()))).toLowerCase();
        }

        /**
         * Method setupWordBase
         */
        public void setupWordBase()
        {
                String lLoremIpsum=
                        "Lorem ipsum dolor sit amet consetetur sadipscing elitr sed 
diam nonumy "
                                + "eirmod tempor invidunt ut labore et dolore magna 
aliquyam erat sed diam "
                                + "voluptua At vero eos et accusam et justo duo 
dolores et ea rebum Stet "
                                + "clita kasd gubergren no sea takimata sanctus est 
Lorem ipsum dolor sit "
                                + "amet Lorem ipsum dolor sit amet consetetur 
sadipscing elitr sed diam "
                                + "nonumy eirmod tempor invidunt ut labore et dolore 
magna aliquyam erat "
                                + "sed diam voluptua At vero eos et accusam et justo 
duo dolores et ea "
                                + "rebum Stet clita kasd gubergren no sea takimata 
sanctus est Lorem "
                                + "ipsum dolor sit amet Lorem ipsum dolor sit amet 
consetetur sadipscing "
                                + "elitr sed diam nonumy eirmod tempor invidunt ut 
labore et dolore magna "
                                + "aliquyam erat sed diam voluptua At vero eos et 
accusam et justo duo "
                                + "dolores et ea rebum Stet clita kasd gubergren no 
sea takimata sanctus "
                                + "est Lorem ipsum dolor sit amet "
                                + "Duis autem vel eum iriure dolor in hendrerit in 
vulputate velit esse "
                                + "molestie consequat vel illum dolore eu feugiat 
nulla facilisis at vero "
                                + "eros et accumsan et iusto odio dignissim qui 
blandit praesent luptatum "
                                + "zzril delenit augue duis dolore te feugait nulla 
facilisi Lorem ipsum "
                                + "dolor sit amet consectetuer adipiscing elit sed 
diam nonummy nibh "
                                + "euismod tincidunt ut laoreet dolore magna aliquam 
erat volutpat "
                                + "Ut wisi enim ad minim veniam quis nostrud exerci 
tation ullamcorper "
                                + "suscipit lobortis nisl ut aliquip ex ea commodo 
consequat Duis autem "
                                + "vel eum iriure dolor in hendrerit in vulputate 
velit esse molestie "
                                + "consequat vel illum dolore eu feugiat nulla 
facilisis at vero eros et "
                                + "accumsan et iusto odio dignissim qui blandit 
praesent luptatum zzril "
                                + "delenit augue duis dolore te feugait nulla 
facilisi";

                lWords= new ArrayList();
                StringTokenizer lTokenizer= new StringTokenizer(lLoremIpsum);
                while (lTokenizer.hasMoreTokens())
                {
                        String lWord= lTokenizer.nextToken();
                        lWords.add(lWord);
                }
        }

        /**
         * Returns the subList.
         * @return ArrayList
         */
        public ArrayList getSubList()
        {
                return mSubList;
        }

        /**
         * <p>Inner class used in testing nested tables</p>
         */
        public class SubListItem
        {

                /**
                 * Field mName
                 */
                private String mName;
                /**
                 * Field mEmail
                 */
                private String mEmail;

                /**
                 * Constructor for SubListItem
                 * @param pName String
                 * @param pEmail String
                 */
                public SubListItem(String pName, String pEmail)
                {
                        mName= pName;
                        mEmail= pEmail;
                }

                /**
                 * Returns the name.
                 * @return String
                 */
                public String getName()
                {
                        return mName;
                }

                /**
                 * Returns the email.
                 * @return String
                 */
                public String getEmail()
                {
                        return mEmail;
                }

        }

}

--- NEW FILE: LongDateWrapper.java ---
package org.displaytag.sample;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.displaytag.decorator.ColumnDecorator;

/**
 * @author epesh
 * @version $Revision: 1.1 $ ($Author: fgiust $)
 */
public class LongDateWrapper extends ColumnDecorator
{
        /**
         * Field sdf
         */
        private DateFormat mDateFormat= new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

        /**
         * Method decorate
         * @param pColumnValue Object
         * @return String
         */
        public String decorate(Object pColumnValue)
        {
                Date lDate= (Date) pColumnValue;
                return mDateFormat.format(lDate);
        }
}

--- NEW FILE: ReportList.java ---
package org.displaytag.sample;

import java.util.ArrayList;
import java.util.Collections;

/**
 * Just a utility class for testing out the table and column tags.
 *
 * This List fills itself with objects and sorts them as though it where pulling
 * data from a report.  This list is used to show the various report oriented
 * examples (such as grouping, callbacks, and data exports).
 * @author epesh
 * @version $Revision: 1.1 $ ($Author: fgiust $)
 */
public class ReportList extends ArrayList
{
        /**
         * Creats a TestList that is filled with 20 ReportableListObject suitable for 
testing
         */
        public ReportList()
        {
                super();

                for (int lCount= 0; lCount < 20; lCount++)
                {
                        add(new ReportableListObject());
                }

                Collections.sort(this);
        }

        /**
         * Creates a TestList that is filled with [size] ReportableListObject suitable 
for
         * testing.
         * @param pSize int
         */
        public ReportList(int pSize)
        {
                super();

                for (int lCount= 0; lCount < pSize; lCount++)
                {
                        add(new ReportableListObject());
                }

                Collections.sort(this);
        }
}

--- NEW FILE: ReportableListObject.java ---
package org.displaytag.sample;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.StringTokenizer;

/**
 * A test class that has data that looks more like information that comes back
 * in a report...
 * @author epesh
 * @version $Revision: 1.1 $ ($Author: fgiust $)
 */
public class ReportableListObject extends Object implements Comparable
{
        /**
         * Field rnd
         */
        private static Random mRandom= new Random();
        /**
         * Field words
         */
        private static List mWords= null;

        /**
         * Field city
         */
        private String mCity;

        /**
         * Field project
         */
        private String mProject;

        /**
         * Field task
         */
        private String mTask;

        /**
         * Field amount
         */
        private double mAmount;

        /**
         * Constructor for ReportableListObject
         */
        public ReportableListObject()
        {
                setupRandomData();
        }

        /**
         * Method getCity
         * @return String
         */
        public String getCity()
        {
                return mCity;
        }

        /**
         * Method setCity
         * @param pCity String
         */
        public void setCity(String pCity)
        {
                mCity= pCity;
        }

        /**
         * Method getProject
         * @return String
         */
        public String getProject()
        {
                return mProject;
        }

        /**
         * Method setProject
         * @param pProject String
         */
        public void setProject(String pProject)
        {
                mProject= pProject;
        }

        /**
         * Method getTask
         * @return String
         */
        public String getTask()
        {
                return mTask;
        }

        /**
         * Method setTask
         * @param pTask String
         */
        public void setTask(String pTask)
        {
                mTask= pTask;
        }

        /**
         * Method getAmount
         * @return double
         */
        public double getAmount()
        {
                return mAmount;
        }

        /**
         * Method setAmount
         * @param pAmount double
         */
        public void setAmount(double pAmount)
        {
                mAmount= pAmount;
        }

        /**
         * Method toString
         * @return String
         */
        public String toString()
        {
                return "ReportableListObject(" + mCity + ":" + mProject + ":" + 
mAmount + ")";
        }

        /**
         * Method setupRandomData
         */
        public void setupRandomData()
        {
                mAmount= (mRandom.nextInt(99999) + 1) / 100;

                mCity= getRandomCity();
                mProject= getRandomProject();
                mTask= getRandomTask();
        }

        /**
         * Method getRandomCity
         * @return String
         */
        public String getRandomCity()
        {
                String lCities[]= { "Roma", "Olympia", "Neapolis", "Carthago" };

                return lCities[mRandom.nextInt(lCities.length)];
        }

        /**
         * Method getRandomProject
         * @return String
         */
        public String getRandomProject()
        {
                String lProjects[]= { "Taxes", "Arts", "Army", "Gladiators" };

                return lProjects[mRandom.nextInt(lProjects.length)];
        }

        /**
         * Method getRandomTask
         * @return String
         */
        public String getRandomTask()
        {
                if (mWords == null)
                {
                        this.setupWordBase();
                }

                return ((String) 
mWords.get(mRandom.nextInt(mWords.size()))).toLowerCase()
                        + " "
                        + ((String) 
mWords.get(mRandom.nextInt(mWords.size()))).toLowerCase()
                        + " "
                        + ((String) 
mWords.get(mRandom.nextInt(mWords.size()))).toLowerCase()
                        + " "
                        + ((String) 
mWords.get(mRandom.nextInt(mWords.size()))).toLowerCase();

        }

        /**
         * Method setupWordBase
         */
        public void setupWordBase()
        {
                String lLoremIpsum=
                        "Lorem ipsum dolor sit amet consetetur sadipscing elitr sed 
diam nonumy "
                                + "eirmod tempor invidunt ut labore et dolore magna 
aliquyam erat sed diam "
                                + "voluptua At vero eos et accusam et justo duo 
dolores et ea rebum Stet "
                                + "clita kasd gubergren no sea takimata sanctus est 
Lorem ipsum dolor sit "
                                + "amet Lorem ipsum dolor sit amet consetetur 
sadipscing elitr sed diam "
                                + "nonumy eirmod tempor invidunt ut labore et dolore 
magna aliquyam erat "
                                + "sed diam voluptua At vero eos et accusam et justo 
duo dolores et ea "
                                + "rebum Stet clita kasd gubergren no sea takimata 
sanctus est Lorem "
                                + "ipsum dolor sit amet Lorem ipsum dolor sit amet 
consetetur sadipscing "
                                + "elitr sed diam nonumy eirmod tempor invidunt ut 
labore et dolore magna "
                                + "aliquyam erat sed diam voluptua At vero eos et 
accusam et justo duo "
                                + "dolores et ea rebum Stet clita kasd gubergren no 
sea takimata sanctus "
                                + "est Lorem ipsum dolor sit amet "
                                + "Duis autem vel eum iriure dolor in hendrerit in 
vulputate velit esse "
                                + "molestie consequat vel illum dolore eu feugiat 
nulla facilisis at vero "
                                + "eros et accumsan et iusto odio dignissim qui 
blandit praesent luptatum "
                                + "zzril delenit augue duis dolore te feugait nulla 
facilisi Lorem ipsum "
                                + "dolor sit amet consectetuer adipiscing elit sed 
diam nonummy nibh "
                                + "euismod tincidunt ut laoreet dolore magna aliquam 
erat volutpat "
                                + "Ut wisi enim ad minim veniam quis nostrud exerci 
tation ullamcorper "
                                + "suscipit lobortis nisl ut aliquip ex ea commodo 
consequat Duis autem "
                                + "vel eum iriure dolor in hendrerit in vulputate 
velit esse molestie "
                                + "consequat vel illum dolore eu feugiat nulla 
facilisis at vero eros et "
                                + "accumsan et iusto odio dignissim qui blandit 
praesent luptatum zzril "
                                + "delenit augue duis dolore te feugait nulla facilisi 
"
                                + "Nam liber tempor cum soluta nobis eleifend option 
congue nihil imperdiet "
                                + "doming id quod mazim placerat facer possim assum 
Lorem ipsum dolor sit "
                                + "amet consectetuer adipiscing elit sed diam nonummy 
nibh euismod "
                                + "tincidunt ut laoreet dolore magna aliquam erat 
volutpat Ut wisi enim ad "
                                + "minim veniam quis nostrud exerci tation ullamcorper 
suscipit lobortis "
                                + "nisl ut aliquip ex ea commodo consequat "
                                + "Duis autem vel eum iriure dolor in hendrerit in 
vulputate velit esse "
                                + "molestie consequat vel illum dolore eu feugiat 
nulla facilisis "
                                + "At vero eos et accusam et justo duo dolores et ea 
rebum Stet clita kasd "
                                + "gubergren no sea takimata sanctus est Lorem ipsum 
dolor sit amet Lorem "
                                + "ipsum dolor sit amet consetetur sadipscing elitr 
sed diam nonumy "
                                + "eirmod tempor invidunt ut labore et dolore magna 
aliquyam erat sed diam "
                                + "voluptua At vero eos et accusam et justo duo 
dolores et ea rebum Stet "
                                + "clita kasd gubergren no sea takimata sanctus est 
Lorem ipsum dolor sit "
                                + "amet Lorem ipsum dolor sit amet consetetur 
sadipscing elitr At "
                                + "accusam aliquyam diam diam dolore dolores duo 
eirmod eos erat et nonumy "
                                + "sed tempor et et invidunt justo labore Stet clita 
ea et gubergren kasd "
                                + "magna no rebum sanctus sea sed takimata ut vero 
voluptua est Lorem "
                                + "ipsum dolor sit amet Lorem ipsum dolor sit amet 
consetetur sadipscing "
                                + "elitr sed diam nonumy eirmod tempor invidunt ut 
labore et dolore magna "
                                + "aliquyam erat "
                                + "Consetetur sadipscing elitr sed diam nonumy eirmod 
tempor invidunt ut "
                                + "labore et dolore magna aliquyam erat sed diam 
voluptua At vero eos et "
                                + "accusam et justo duo dolores et ea rebum Stet clita 
kasd gubergren no "
                                + "sea takimata sanctus est Lorem ipsum dolor sit amet 
Lorem ipsum dolor "
                                + "sit amet consetetur sadipscing elitr sed diam 
nonumy eirmod tempor "
                                + "invidunt ut labore et dolore magna aliquyam erat 
sed diam voluptua At "
                                + "vero eos et accusam et justo duo dolores et ea 
rebum Stet clita kasd "
                                + "gubergren no sea takimata sanctus est Lorem ipsum 
dolor sit amet Lorem "
                                + "ipsum dolor sit amet consetetur sadipscing elitr 
sed diam nonumy "
                                + "eirmod tempor invidunt ut labore et dolore magna 
aliquyam erat sed diam "
                                + "voluptua At vero eos et accusam et justo duo 
dolores et ea rebum Stet "
                                + "clita kasd gubergren no sea takimata sanctus ";

                mWords= new ArrayList();
                StringTokenizer lTokenizer= new StringTokenizer(lLoremIpsum);
                while (lTokenizer.hasMoreTokens())
                {
                        String lWord= lTokenizer.nextToken();
                        mWords.add(lWord);
                }
        }
        /**
         * Method compareTo
         * @param pObject Object
         * @return int
         * @see java.lang.Comparable#compareTo(Object)
         */
        public int compareTo(Object pObject)
        {
                ReportableListObject lObject1= this;
                ReportableListObject lObject2= (ReportableListObject) pObject;

                if (lObject1.mCity.equals(lObject2.mCity))
                {
                        if (lObject1.mProject.equals(lObject2.mProject))
                        {
                                return (int) (lObject2.mAmount - lObject1.mAmount);
                        }
                        else
                        {
                                return lObject1.mProject.compareTo(lObject2.mProject);
                        }
                }
                else
                {
                        return lObject1.mCity.compareTo(lObject2.mCity);
                }
        }
}

--- NEW FILE: TestList.java ---
package org.displaytag.sample;

import java.util.ArrayList;
import java.util.Random;

/**
 * Just a utility class for testing out the table and column tags.
 *
 * When this class is created, it loads itself with a number of ListObjects
 * that are shown throughout the various example pages that exercise the table
 * object.  If created via the default constructor, this loads itself with 60
 * ListObjects.
 * @author epesh
 * @version $Revision: 1.1 $ ($Author: fgiust $)
 */
public class TestList extends ArrayList
{

        /**
         * Creats a TestList that is filled with 60 ListObjects suitable for testing
         */
        public TestList()
        {
                super();

                for (int lCount= 0; lCount < 60; lCount++)
                {
                        add(new ListObject());
                }
        }

        /**
         * Creates a TestList that is filled with [size] ListObjects suitable for
         * testing.
         * @param pSize int
         */
        public TestList(int pSize)
        {
                super();

                for (int lCount= 0; lCount < pSize; lCount++)
                {
                        add(new ListObject());
                }
        }

        /**
         * Constructor for TestList
         * @param pDuplicates boolean
         * @param pSize int
         */
        public TestList(boolean pDuplicates, int pSize)
        {
                super();

                // generate a random number between 1 and 3 and duplicate that many 
number of times.
                for (int lCount= 0; lCount < pSize; lCount++)
                {

                        ListObject lObject1= new ListObject();
                        ListObject lObject2= new ListObject();
                        ListObject lObject3= new ListObject();

                        int lRandom= new Random().nextInt(3);
                        for (int lCount2= 0; lCount2 <= lRandom; lCount2++)
                        {
                                add(lObject1);

                        }

                        lObject1.setID(lObject2.getId());

                        lRandom= new Random().nextInt(3);
                        for (int lCount2= 0; lCount2 <= lRandom; lCount2++)
                        {
                                add(lObject1);
                                add(lObject2);

                        }

                        lObject1.setEmail(lObject3.getEmail());

                        lRandom= new java.util.Random().nextInt(3);
                        for (int lCount2= 0; lCount2 <= lRandom; lCount2++)
                        {
                                add(lObject1);
                        }
                }
        }
        
        /**
         * Method getItem. Returns a ListObject using get(index) from the Array
         * @param pIndex int
         * @return ListObject
         */
        public ListObject getItem(int pIndex)
        {
                return (ListObject)super.get(pIndex);
        }

}

--- NEW FILE: TotalWrapper.java ---
package org.displaytag.sample;

import java.util.List;

import org.displaytag.decorator.TableDecorator;

/**
 * This decorator only does a summing of different groups in the reporting
 * style examples...
 * @author epesh
 * @version $Revision: 1.1 $ ($Author: fgiust $)
 */
public class TotalWrapper extends TableDecorator
{
        /**
         * Field cityTotal
         */
        private double mCityTotal= 0;
        /**
         * Field grandTotal
         */
        private double mGrandTotal= 0;

        /**
         * After every row completes we evaluate to see if we should be drawing a
         * new total line and summing the results from the previous group.
         * @return String
         */
        public String finishRow()
        {
                int lListindex= ((List)getObject()).indexOf(this.getObject());
                ReportableListObject lReportableObject= (ReportableListObject) 
this.getObject();
                String lNextCity= "";

                mCityTotal += lReportableObject.getAmount();
                mGrandTotal += lReportableObject.getAmount();

                if (lListindex == ((List)getObject()).size() - 1)
                {
                        lNextCity= "XXXXXX"; // Last row hack, it's only a demo 
folks...
                }
                else
                {
                        lNextCity= ((ReportableListObject) 
((List)getObject()).get(lListindex + 1)).getCity();
                }

                StringBuffer lBuffer= new StringBuffer(1000);

                // City subtotals...
                if (!lNextCity.equals(lReportableObject.getCity()))
                {
                        lBuffer.append("\n<tr>\n<td>&nbsp;</td><td>&nbsp;</td><td><hr 
noshade size=\"1\"></td>");
                        lBuffer.append("\n<td>&nbsp;</td></tr>");

                        lBuffer.append("\n<tr><td>&nbsp;</td>");
                        lBuffer.append("\n<td align=\"right\"><b>" + 
lReportableObject.getCity() + " Total:</b></td>\n<td><b>");
                        lBuffer.append(mCityTotal);
                        lBuffer.append("</b></td>\n<td>&nbsp;</td>\n</tr>");
                        lBuffer.append("\n<tr>\n<td 
colspan=\"4\">&nbsp;\n</td>\n</tr>");

                        mCityTotal= 0;
                }

                // Grand totals...
                if (getViewIndex() == ((List)getObject()).size() - 1)
                {
                        lBuffer.append("<tr><td colspan=\"4\"><hr noshade 
size=\"1\"></td></tr>");
                        lBuffer.append("<tr><td>&nbsp;</td>");
                        lBuffer.append("<td align=\"right\"><b>Grand 
Total:</b></td><td><b>");
                        lBuffer.append(mGrandTotal);
                        lBuffer.append("</b></td><td>&nbsp;</td></tr>");
                }

                return lBuffer.toString();
        }

}

--- NEW FILE: Wrapper.java ---
package org.displaytag.sample;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;

import org.displaytag.decorator.TableDecorator;

/**
 * This class is a decorator of the TestObjects that we keep in our List.  This
 * class provides a number of methods for formatting data, creating dynamic
 * links, and exercising some aspects of the display:table API functionality
 * @author epesh
 * @version $Revision: 1.1 $ ($Author: fgiust $)
 */
public class Wrapper extends TableDecorator
{
        /**
         * Field datefmt
         */
        private SimpleDateFormat mDateFormat= null;
        /**
         * Field moneyfmt
         */
        private DecimalFormat mMoneyFormat= null;

        /**
         * Creates a new Wrapper decorator who's job is to reformat some of the
         * data located in our TestObject's.
         */

        public Wrapper()
        {
                super();

                // Formats for displaying dates and money.

                this.mDateFormat= new SimpleDateFormat("MM/dd/yy");
                this.mMoneyFormat= new DecimalFormat("$ #,###,###.00");
        }

        /**
         * Method getNullValue
         * @return String
         */
        public String getNullValue()
        {
                return null;
        }

        /**
         * Returns the date as a String in MM/dd/yy format
         * @return String
         */

        public String getDate()
        {
                return this.mDateFormat.format(((ListObject) 
this.getObject()).getDate());
        }

        /**
         * Returns the money as a String in $ #,###,###.00 format
         * @return String
         */

        public String getMoney()
        {
                return this.mMoneyFormat.format(((ListObject) 
this.getObject()).getMoney());
        }

        /**
         * Returns the TestObject's ID as a hyperlink that the person can click on
         * and "drill down" for more details.
         * @return String
         */
        public String getLink1()
        {
                ListObject lObject= (ListObject) getObject();
                int lIndex= getListIndex();

                return "<a href=\"details.jsp?index=" + lIndex + "\">" + 
lObject.getId() + "</a>";
        }

        /**
         * Returns an "action bar" of sorts that allow the user to perform various
         * actions on the TestObject based on it's id.
         * @return String
         */
        public String getLink2()
        {
                ListObject lObject= (ListObject)getObject();
                int lId= lObject.getId();

                return "<a href=\"details.jsp?id="
                        + lId
                        + "&action=view\">View</a> | "
                        + "<a href=\"details.jsp?id="
                        + lId
                        + "&action=edit\">Edit</a> | "
                        + "<a href=\"details.jsp?id="
                        + lId
                        + "&action=delete\">Delete</a>";
        }
}




-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
displaytag-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/displaytag-devel

Reply via email to