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