001/*
002 * oauth2-oidc-sdk
003 *
004 * Copyright 2012-2016, Connect2id Ltd and contributors.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use
007 * this file except in compliance with the License. You may obtain a copy of the
008 * License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software distributed
013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
015 * specific language governing permissions and limitations under the License.
016 */
017
018package com.nimbusds.openid.connect.sdk;
019
020
021import com.nimbusds.oauth2.sdk.ParseException;
022import com.nimbusds.oauth2.sdk.util.StringUtils;
023
024
025/**
026 * Enumeration of the display types for authentication and consent UIs.
027 *
028 * <p>Related specifications:
029 *
030 * <ul>
031 *     <li>OpenID Connect Core 1.0, section 3.1.2.1.
032 * </ul>
033 */
034public enum Display {
035
036
037        /**
038         * Full user-agent page view (default).
039         */
040        PAGE,
041        
042        
043        /**
044         * Popup user-agent window. The popup User Agent window should be of an
045         * appropriate size for a login-focused dialog and should not obscure
046         * the entire window that it is popping up over.
047         */
048        POPUP,
049        
050        
051        /**
052         * Device that leverages a touch interface. The authorisation server 
053         * may attempt to detect the touch device and further customise the 
054         * interface.
055         */
056        TOUCH,
057        
058        
059        /**
060         * Feature phone.
061         */
062        WAP;
063
064
065        /**
066         * Gets the default display type.
067         *
068         * @return The default display type ({@link #PAGE}).
069         */
070        public static Display getDefault() {
071        
072                return PAGE;
073        }
074        
075        
076        /**
077         * Returns the string identifier of this display type.
078         *
079         * @return The string identifier.
080         */
081        @Override
082        public String toString() {
083        
084                return super.toString().toLowerCase();
085        }
086        
087        
088        /**
089         * Parses a display type.
090         *
091         * @param s The string to parse. If the string is {@code null} or empty
092         *          the {@link #getDefault} display type will be returned.
093         *
094         * @return The display type.
095         *
096         * @throws ParseException If the parsed string doesn't match a display 
097         *                        type.
098         */
099        public static Display parse(final String s)
100                throws ParseException {
101        
102                if (StringUtils.isBlank(s))
103                        return getDefault();
104                
105                if (s.equals("page"))
106                        return PAGE;
107                        
108                if (s.equals("popup"))
109                        return POPUP;
110                        
111                if (s.equals("touch"))
112                        return TOUCH;
113                        
114                if (s.equals("wap"))
115                        return WAP;
116                        
117                throw new ParseException("Unknown display type: " + s);
118        }
119}