001package biweekly.property; 002 003import java.util.Arrays; 004import java.util.Collection; 005import java.util.Collections; 006 007import biweekly.ICalVersion; 008 009/* 010 Copyright (c) 2013-2015, Michael Angstadt 011 All rights reserved. 012 013 Redistribution and use in source and binary forms, with or without 014 modification, are permitted provided that the following conditions are met: 015 016 1. Redistributions of source code must retain the above copyright notice, this 017 list of conditions and the following disclaimer. 018 2. Redistributions in binary form must reproduce the above copyright notice, 019 this list of conditions and the following disclaimer in the documentation 020 and/or other materials provided with the distribution. 021 022 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 023 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 024 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 025 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 026 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 027 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 028 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 029 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 030 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 031 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 032 */ 033 034/** 035 * <p> 036 * Defines the type of action to invoke when an alarm is triggered. 037 * </p> 038 * 039 * <p> 040 * <b>Code sample (creating):</b> 041 * 042 * <pre class="brush:java"> 043 * Action action = Action.audio(); 044 * </pre> 045 * 046 * </p> 047 * 048 * <p> 049 * <b>Code sample (retrieving):</b> 050 * 051 * <pre class="brush:java"> 052 * ICalendar ical = ... 053 * for (VAlarm alarm : ical.getAlarms()){ 054 * Action action = alarm.getAction(); 055 * if (action.isAudio()) { 056 * ... 057 * } else if (action.isEmail()){ 058 * ... 059 * } else if (action.isDisplay()){ 060 * ... 061 * } 062 * } 063 * </pre> 064 * 065 * </p> 066 * @author Michael Angstadt 067 * @see <a href="http://tools.ietf.org/html/rfc5545#page-132">RFC 5545 068 * p.132-3</a> 069 * @see <a href="http://tools.ietf.org/html/rfc2445#page-126">RFC 2445 p.126</a> 070 */ 071public class Action extends EnumProperty { 072 private static final String AUDIO = "AUDIO"; 073 private static final String DISPLAY = "DISPLAY"; 074 private static final String EMAIL = "EMAIL"; 075 private static final String PROCEDURE = "PROCEDURE"; 076 077 /** 078 * Creates an action property. Use of this constructor is discouraged and 079 * may put the property in an invalid state. Use one of the static factory 080 * methods instead. 081 * @param value the value (e.g. "AUDIO") 082 */ 083 public Action(String value) { 084 super(value); 085 } 086 087 /** 088 * Creates an "audio" action property. 089 * @return the property 090 */ 091 public static Action audio() { 092 return create(AUDIO); 093 } 094 095 /** 096 * Determines if this property is an "audio" action. 097 * @return true if it's an "audio" action, false if not 098 */ 099 public boolean isAudio() { 100 return is(AUDIO); 101 } 102 103 /** 104 * Creates an "display" action property. 105 * @return the property 106 */ 107 public static Action display() { 108 return create(DISPLAY); 109 } 110 111 /** 112 * Determines if this property is an "display" action. 113 * @return true if it's an "display" action, false if not 114 */ 115 public boolean isDisplay() { 116 return is(DISPLAY); 117 } 118 119 /** 120 * Creates an "email" action property. 121 * @return the property 122 */ 123 public static Action email() { 124 return create(EMAIL); 125 } 126 127 /** 128 * Determines if this property is an "email" action. 129 * @return true if it's an "email" action, false if not 130 */ 131 public boolean isEmail() { 132 return is(EMAIL); 133 } 134 135 /** 136 * Creates a "procedure" action property (vCal 1.0 only). 137 * @return the property 138 */ 139 public static Action procedure() { 140 return create(PROCEDURE); 141 } 142 143 /** 144 * Determines if this property is a "procedure" action (vCal 1.0 only). 145 * @return true if it's a "procedure" action, false if not 146 */ 147 public boolean isProcedure() { 148 return is(PROCEDURE); 149 } 150 151 private static Action create(String value) { 152 return new Action(value); 153 } 154 155 @Override 156 protected Collection<String> getStandardValues(ICalVersion version) { 157 switch (version) { 158 case V1_0: 159 return Arrays.asList(AUDIO, DISPLAY, EMAIL, PROCEDURE); 160 default: 161 return Arrays.asList(AUDIO, DISPLAY, EMAIL); 162 } 163 } 164 165 @Override 166 protected Collection<ICalVersion> getValueSupportedVersions() { 167 if (value == null) { 168 return Collections.emptyList(); 169 } 170 171 if (isAudio() || isDisplay() || isEmail()) { 172 return Arrays.asList(ICalVersion.values()); 173 } 174 if (isProcedure()) { 175 return Arrays.asList(ICalVersion.V1_0); 176 } 177 178 return Collections.emptyList(); 179 } 180}