001    /*******************************************************************************
002     * Copyright (c) 2005 Gabriel Handford.
003     * All rights reserved.
004     *
005     * Contributors:
006     *    Gabriel Handford -
007     *******************************************************************************/
008    package net.sf.tacos.services.impl;
009    
010    import java.util.List;
011    
012    import net.sf.tacos.services.CategoryInfo;
013    
014    import org.apache.commons.lang.builder.EqualsBuilder;
015    import org.apache.commons.lang.builder.HashCodeBuilder;
016    import org.apache.commons.lang.builder.ToStringBuilder;
017    import org.apache.commons.lang.builder.ToStringStyle;
018    
019    /**
020     * This class describes a site map category containing page names.
021     *
022     * @author Gabriel Handford
023     */
024    public class CategoryInfoImpl implements CategoryInfo {
025    
026        private String name;
027        private List pageNames;
028        private String image;
029        private String inactiveImage;
030    
031        /**
032         * Construct named category with list of pages.
033         * @param name The category name
034         * @param pageNames List of the page names in this category
035         */
036        public CategoryInfoImpl(String name, List pageNames) {
037            this.name = name;
038            this.pageNames = pageNames;
039        }
040    
041        /**
042         * Construct named category with list of pages, active and inactive image.
043         * @param name The category name
044         * @param pageNames List of the page names in this category
045         */
046        public CategoryInfoImpl(String name, List pageNames,
047                String image, String inactiveImage) {
048            this.name = name;
049            this.pageNames = pageNames;
050            this.image = image;
051            this.inactiveImage = inactiveImage;
052        }
053        
054        /**
055         * Get category name.
056         * @return name The category name
057         */
058        public String getName() {
059            return name;
060        }
061    
062        /**
063         * Get the default page.
064         * @return The default page, or the first page, or null.
065         */
066        public String getDefaultPage() {
067            if (pageNames.size() > 0)
068                return (String)pageNames.get(0);
069            else
070                return null;
071        }
072    
073        /**
074         * Get list of pages in category.
075         * @return pageNames The page names in this category
076         */
077        public List getPageNames() {
078            return pageNames;
079        }
080    
081        /**
082         * Returns active image for category.
083         * @return
084         */
085        public String getImage()
086        {
087            return image;
088        }
089        
090        /**
091         * Returns the inactive image for category.
092         * @return
093         */
094        public String getInactiveImage()
095        {
096            return inactiveImage;
097        }
098        
099        /**
100         * @see java.lang.Object#toString()
101         */
102        public String toString() {
103            return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
104                    .append("name", this.name).append("pageNames", this.pageNames)
105                    .toString();
106        }
107    
108        /**
109         * @see java.lang.Object#equals(Object)
110         */
111        public boolean equals(Object object) {
112            if (object == this) {
113                return true;
114            }
115            if (!(object instanceof CategoryInfo)) {
116                return false;
117            }
118            CategoryInfo rhs = (CategoryInfo) object;
119            return new EqualsBuilder().append(this.name, rhs.getName())
120                    .isEquals();
121        }
122        
123        /**
124         * @see java.lang.Object#hashCode()
125         */
126        public int hashCode() {
127            return new HashCodeBuilder(1471056309, 288593091).append(this.name)
128                    .toHashCode();
129        }
130    }