001package com.nimbusds.openid.connect.sdk;
002
003
004import org.apache.commons.lang3.StringUtils;
005
006import com.nimbusds.oauth2.sdk.ParseException;
007
008
009/**
010 * Enumeration of the display types for authentication and consent UIs. This
011 * class is immutable.
012 *
013 * <p>Related specifications:
014 *
015 * <ul>
016 *     <li>OpenID Connect Messages 1.0, section 2.1.1.
017 * </ul>
018 *
019 * @author Vladimir Dzhuvinov
020 */
021public enum Display {
022
023
024        /**
025         * Full user-agent page view (default).
026         */
027        PAGE,
028        
029        
030        /**
031         * Popup user-agent window. The popup user-agent window should be 450 
032         * pixels wide and 500 pixels tall. 
033         */
034        POPUP,
035        
036        
037        /**
038         * Device that leverages a touch interface. The authorisation server 
039         * may attempt to detect the touch device and further customise the 
040         * interface.
041         */
042        TOUCH,
043        
044        
045        /**
046         * Feature phone.
047         */
048        WAP;
049
050
051        /**
052         * Gets the default display type.
053         *
054         * @return The default display type ({@link #PAGE}).
055         */
056        public static Display getDefault() {
057        
058                return PAGE;
059        }
060        
061        
062        /**
063         * Returns the string identifier of this display type.
064         *
065         * @return The string identifier.
066         */
067        @Override
068        public String toString() {
069        
070                return super.toString().toLowerCase();
071        }
072        
073        
074        /**
075         * Parses a display type.
076         *
077         * @param s The string to parse. If the string is {@code null} or empty
078         *          the {@link #getDefault} display type will be returned.
079         *
080         * @return The display type.
081         *
082         * @throws ParseException If the parsed string doesn't match a display 
083         *                        type.
084         */
085        public static Display parse(final String s)
086                throws ParseException {
087        
088                if (StringUtils.isBlank(s))
089                        return getDefault();
090                
091                if (s.equals("page"))
092                        return PAGE;
093                        
094                if (s.equals("popup"))
095                        return POPUP;
096                        
097                if (s.equals("touch"))
098                        return TOUCH;
099                        
100                if (s.equals("wap"))
101                        return WAP;
102                        
103                throw new ParseException("Unknown display type: " + s);
104        }
105}