001    /*
002     * This program is free software; you can redistribute it and/or modify
003     * it under the terms of the GNU General Public License as published by
004     * the Free Software Foundation; version 2 of the License.
005     *
006     * This program is distributed in the hope that it will be useful,
007     * but WITHOUT ANY WARRANTY; without even the implied warranty of
008     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
009     * GNU General Public License for more details.
010     *
011     * You should have received a copy of the GNU General Public License along
012     * with this program; if not, write to the Free Software Foundation, Inc.,
013     * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
014     */
015    package org.tastybug.bugwerk.bugtrail.widget.ticket;
016    
017    import org.tastybug.bugwerk.blueprint.model.BaseData;
018    import org.tastybug.bugwerk.blueprint.model.Ticket;
019    
020    /**
021     * This HTML helper class creates HTML tables summarizing the base ticket properties.
022     * <br>
023     * 
024     * <hr>
025     * Copyright 2006 Philipp Bartsch.<br>
026     * <a href="http://www.tastybug.com">www.tastybug.com</a><br>
027     * <hr>
028     * Created on Feb 8, 2006<br>
029     * @author Philipp Bartsch, philipp.bartsch{at}tastybug{dot}com</a>
030     */
031    public class HTMLFactory {
032        
033        private static  final String NEW_LINE = System.getProperty("line.separator");
034    
035        /**
036         * Returns a HTML table listing the base properties of <code>ticket</code> including
037         * the incident count.
038         * 
039         * @param ticket    the ticket
040         * @return          the HTML table
041         */
042        public static String createTicketHTMLRepresentation (Ticket ticket) {
043    
044            final StringBuffer body = new StringBuffer();
045            
046            body.append(   "<html>" + NEW_LINE
047                         + "<body>" + NEW_LINE);
048            
049            // table header
050            body.append("<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" width=\"100%\">" + NEW_LINE);    
051            
052            body.append(getTableRow(BaseData.ProjectName.KEY,
053                                    "<b>" + (ticket == null ? " --" : ticket.getProjectName()) + "</b>",
054                                    true));                         
055            
056            body.append(getTableRow(BaseData.Component.KEY,
057                                    (ticket == null ? " --" : ticket.getComponent()),
058                                    true)); 
059            body.append(getTableRow(BaseData.Signature.KEY,
060                                    (ticket == null ? " --" : ticket.getSignature()),
061                                    true)); 
062            body.append(getTableRow("Incidents",
063                                    (ticket == null ? " --" : ticket.getIncidentCount() + ""),
064                                    true)); 
065    
066            body.append(getTableRow(Ticket.State.KEY,
067                                    (ticket == null ? " --" :  (ticket.getState() != null ? ticket.getState() : "<i>none</i>")),
068                                    false)); 
069            body.append(getTableRow(BaseData.Type.KEY,
070                                    (ticket == null ? " --" : (ticket.getType() != null? ticket.getType() : "<i>none</i>")),
071                                    false)); 
072    
073            // table tail
074            body.append("</table>"+ NEW_LINE + "<br clear=\"all\">" + NEW_LINE );       
075            // finished             
076    
077            // close html document
078            body.append(  "</body>"
079                        + "</html>");
080            return body.toString();
081        }
082    
083        /**
084         * Returns a eyecandy table row.
085         * 
086         * @param   key       the inserted key
087         * @param   value     the inserted value
088         * @param   highlight specifies wheter to highlight the row label with a
089         *                    blue or the standard grey background
090         * @return  the row (html code)
091         */ 
092        public static final String getTableRow (final String  key,
093                                                final String  value,
094                                                final boolean highlight) {
095            return   "<tr>" + NEW_LINE +
096                         "<td valign=\"top\"" + NEW_LINE +
097                             "align=\"right\"" + NEW_LINE +
098                             "bgColor=\"" + (highlight
099                                             ? "#3399ff\">"
100                                             : "SILVER\">") + NEW_LINE +
101                                 "<font face=\"Arial\" size=\"-2\">" +
102                                 key + "&nbsp;" +
103                                 "</font>" +
104                                 NEW_LINE +
105                         "</td>" + NEW_LINE +
106                         "<td width=\"5\">" + NEW_LINE +
107                             "&nbsp;" + NEW_LINE +         
108                         "</td>" + NEW_LINE +
109                         "<td valign=\"top\">" + NEW_LINE +
110                         "<font face=\"Arial\" size=\"-2\">" +
111                         value +
112                         "</font>" +
113                         "</td>" + NEW_LINE +
114                     "</tr>" + NEW_LINE;                                                                      
115        }
116    }