001 /*
002 Copyright (c) 1996-2012, Damon Hart-Davis
003 All rights reserved.
004
005 Redistribution and use in source and binary forms, with or without
006 modification, are permitted provided that the following conditions are
007 met:
008
009 * Redistributions of source code must retain the above copyright
010 notice, this list of conditions and the following disclaimer.
011
012 * Redistributions in binary form must reproduce the above copyright
013 notice, this list of conditions and the following disclaimer in the
014 documentation and/or other materials provided with the
015 distribution.
016
017 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
018 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
019 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
020 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
021 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
022 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
023 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
024 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
025 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
026 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
027 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028 */
029
030 package org.hd.d.pg2k.webSvr.util;
031
032 import javax.servlet.http.HttpServletRequest;
033
034 /**
035 * Created by IntelliJ IDEA.
036 * User: Damon Hart-Davis
037 * Date: 02-Nov-2003
038 * Time: 20:52:36
039 */
040
041 /**A utilities class to support page skins.
042 * Many skin-specific overrides from the default values are accessed
043 * from the page-level (PageContext) properties via constants
044 * and methods here.
045 * <p>
046 * Default skin/UI methods are also defined here.
047 */
048 public final class PageSkinUtils
049 {
050 /**Prevent creation of an instance. */
051 private PageSkinUtils() { }
052
053 /**Main background colour for catalogue and other generic pages. */
054 public static final String GENERIC_BG_COLOUR = "white";
055 /**Quoted (if necessary) version of GENERIC_BG_COLOUR for HTML attributes; computed once per run. */
056 public static final String GENERIC_BG_COLOUR_QUOTED = GENERIC_BG_COLOUR;
057 /**Main text colour for architrave headings for catalogue and other generic pages. */
058 public static final String GENERIC_AH_COLOUR = "navy";
059 /**Quoted (if necessary) version of GENERIC_AH_COLOUR for HTML attributes; computed once per run. */
060 public static final String GENERIC_AH_COLOUR_QUOTED = GENERIC_AH_COLOUR;
061 /**Main background colour for architrave headings for catalogue and other generic pages. */
062 public static final String GENERIC_ABG_COLOUR = "#ffffcc"; // "yellow";
063 /**Quoted (if necessary) version of GENERIC_ABG_COLOUR for HTML attributes; computed once per run. */
064 public static final String GENERIC_ABG_COLOUR_QUOTED = "\"" + GENERIC_ABG_COLOUR + "\"";
065 /**Columns in table for "generic"/default skin. */
066 public static final int GENERIC_TABLE_COLS = 4;
067 /**Width of chisled border for thumbnails in generic layout. */
068 public static final int GENERIC_TN_BORDER_WIDTH_PIXELS = 5; // Decorative border width for thumbnail tables.
069
070 /**Nominal generic page width (pixels).
071 * Up to 2003/02/19 was 600 as per http://news.bbc.co.uk/
072 * but since then, we too have increased to (just under) 800
073 * with the aim of avoiding horizontal scrolling on an actual 800-pixel screen.
074 */
075 public static final int GENERIC_WIDTH_PX = 784;
076
077 /**Max width of a contact-strip / lightbox section on a normal page in pixels; strictly positive.
078 * Defaults to a little short of the full available width...
079 */
080 public static final int MAX_LIGHTBOX_WIDTH_PX = (PageSkinUtils.GENERIC_WIDTH_PX*95)/100;
081
082 /**Width of a tower column containing wide/mixed skyscraper ads, in pixels; strictly positive.
083 * Since tower ads are typically 120 or 160 pixels,
084 * this should be 160 + padding.
085 */
086 public static final int TOWER_COL_WIDTH_PX = 170;
087
088 /**Width of a tower column containing narrow skyscraper ads, in pixels; strictly positive.
089 * Since narrow tower ads are 120 pixels,
090 * this should be 120 + padding.
091 */
092 public static final int TOWER_NARROW_COL_WIDTH_PX = 130;
093
094 /**Attribute in PageContext used to hold non-default alternate background colour.
095 * Essentially private to getAltBgColour() and setAltBgColour().
096 */
097 private static final String _gABC_PROP_NAME = "_gABC";
098
099 /**Sets the alternate background colour for the current skin for the current request.
100 * Must be a value unquoted HTML colour name or value,
101 * eg <code>white</code> or <code>#fffff</code>.
102 * <p>
103 * The colour passed can be null to restore the default value,
104 * ie remove any override.
105 */
106 public static void setAltBgColour(final HttpServletRequest request, final String colour)
107 {
108 if(colour == null)
109 {
110 request.removeAttribute(_gABC_PROP_NAME);
111 return;
112 }
113 request.setAttribute(_gABC_PROP_NAME, colour);
114 }
115
116 /**Gets the alternate background colour for the current skin for the current request; never null.
117 * This gets an unquoted HTML colour name or value,
118 * eg white or #fffff.
119 * <p>
120 * This may need to be quoted to be used as an attribute value.
121 * <p>
122 * This defaults to the normal value,
123 * but can be overridden for the current JSP page (in the PageContext)
124 * with a call to setAltBgColour().
125 */
126 public static String getAltBgColour(final HttpServletRequest request)
127 {
128 final Object o = request.getAttribute(_gABC_PROP_NAME);
129 if(o instanceof String) { return((String) o); }
130 return(GENERIC_ABG_COLOUR);
131 }
132 }