001package biweekly.property; 002 003import java.util.Arrays; 004import java.util.Collection; 005 006import biweekly.ICalVersion; 007 008/* 009 Copyright (c) 2013-2015, Michael Angstadt 010 All rights reserved. 011 012 Redistribution and use in source and binary forms, with or without 013 modification, are permitted provided that the following conditions are met: 014 015 1. Redistributions of source code must retain the above copyright notice, this 016 list of conditions and the following disclaimer. 017 2. Redistributions in binary form must reproduce the above copyright notice, 018 this list of conditions and the following disclaimer in the documentation 019 and/or other materials provided with the distribution. 020 021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 022 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 023 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 024 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 025 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 026 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 027 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 028 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 029 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 030 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 031 */ 032 033/** 034 * <p> 035 * Defines the level of sensitivity of the iCalendar data. If not specified, the 036 * data should be considered "public". 037 * </p> 038 * 039 * <p> 040 * <b>Code sample (creating):</b> 041 * 042 * <pre class="brush:java"> 043 * VEvent event = new VEvent(); 044 * event.setClassification(Classification.public_()); 045 * </pre> 046 * 047 * </p> 048 * 049 * <p> 050 * <b>Code sample (retrieving):</b> 051 * 052 * <pre class="brush:java"> 053 * ICalendar ical = ... 054 * VEvent event = ical.getEvents().get(0); 055 * 056 * Classification classification = event.getClassification(); 057 * if (classification.isPublic()) { 058 * ... 059 * } else if (classification.isPrivate()){ 060 * ... 061 * } else if (classification.isConfidential()){ 062 * ... 063 * } 064 * </pre> 065 * 066 * </p> 067 * @author Michael Angstadt 068 * @see <a href="http://tools.ietf.org/html/rfc5545#page-82">RFC 5545 p.82-3</a> 069 * @see <a href="http://tools.ietf.org/html/rfc2445#page-79">RFC 2445 070 * p.79-80</a> 071 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.28-9</a> 072 */ 073public class Classification extends EnumProperty { 074 private static final String PUBLIC = "PUBLIC"; 075 private static final String PRIVATE = "PRIVATE"; 076 private static final String CONFIDENTIAL = "CONFIDENTIAL"; 077 078 /** 079 * Creates a new classification property. Use the static factory methods to 080 * create a property with a standard classification level. 081 * @param classification the classification level (e.g. "PUBLIC") 082 */ 083 public Classification(String classification) { 084 super(classification); 085 } 086 087 /** 088 * Creates a "public" classification property. 089 * @return the property 090 */ 091 public static Classification public_() { 092 return create(PUBLIC); 093 } 094 095 /** 096 * Determines if the classification level is "public". 097 * @return true if it's "public", false if not 098 */ 099 public boolean isPublic() { 100 return is(PUBLIC); 101 } 102 103 /** 104 * Creates a "private" classification property. 105 * @return the property 106 */ 107 public static Classification private_() { 108 return create(PRIVATE); 109 } 110 111 /** 112 * Determines if the classification level is "private". 113 * @return true if it's "private", false if not 114 */ 115 public boolean isPrivate() { 116 return is(PRIVATE); 117 } 118 119 /** 120 * Creates a "confidential" classification property. 121 * @return the property 122 */ 123 public static Classification confidential() { 124 return create(CONFIDENTIAL); 125 } 126 127 /** 128 * Determines if the classification level is "confidential". 129 * @return true if it's "confidential", false if not 130 */ 131 public boolean isConfidential() { 132 return is(CONFIDENTIAL); 133 } 134 135 private static Classification create(String classification) { 136 return new Classification(classification); 137 } 138 139 @Override 140 protected Collection<String> getStandardValues(ICalVersion version) { 141 return Arrays.asList(PUBLIC, PRIVATE, CONFIDENTIAL); 142 } 143}