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