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. 011 * 012 * <p>Related specifications: 013 * 014 * <ul> 015 * <li>OpenID Connect Core 1.0, section 3.1.2.1. 016 * </ul> 017 */ 018public enum Display { 019 020 021 /** 022 * Full user-agent page view (default). 023 */ 024 PAGE, 025 026 027 /** 028 * Popup user-agent window. The popup User Agent window should be of an 029 * appropriate size for a login-focused dialog and should not obscure 030 * the entire window that it is popping up over. 031 */ 032 POPUP, 033 034 035 /** 036 * Device that leverages a touch interface. The authorisation server 037 * may attempt to detect the touch device and further customise the 038 * interface. 039 */ 040 TOUCH, 041 042 043 /** 044 * Feature phone. 045 */ 046 WAP; 047 048 049 /** 050 * Gets the default display type. 051 * 052 * @return The default display type ({@link #PAGE}). 053 */ 054 public static Display getDefault() { 055 056 return PAGE; 057 } 058 059 060 /** 061 * Returns the string identifier of this display type. 062 * 063 * @return The string identifier. 064 */ 065 @Override 066 public String toString() { 067 068 return super.toString().toLowerCase(); 069 } 070 071 072 /** 073 * Parses a display type. 074 * 075 * @param s The string to parse. If the string is {@code null} or empty 076 * the {@link #getDefault} display type will be returned. 077 * 078 * @return The display type. 079 * 080 * @throws ParseException If the parsed string doesn't match a display 081 * type. 082 */ 083 public static Display parse(final String s) 084 throws ParseException { 085 086 if (StringUtils.isBlank(s)) 087 return getDefault(); 088 089 if (s.equals("page")) 090 return PAGE; 091 092 if (s.equals("popup")) 093 return POPUP; 094 095 if (s.equals("touch")) 096 return TOUCH; 097 098 if (s.equals("wap")) 099 return WAP; 100 101 throw new ParseException("Unknown display type: " + s); 102 } 103}