001package biweekly.io; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import biweekly.Messages; 007import biweekly.Warning; 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 The views and conclusions contained in the software and documentation are those 034 of the authors and should not be interpreted as representing official policies, 035 either expressed or implied, of the FreeBSD Project. 036 */ 037 038/** 039 * Records vCard parse warnings. 040 * @author Michael Angstadt 041 */ 042public class ParseWarnings { 043 private final List<String> warnings = new ArrayList<String>(); 044 045 /** 046 * Adds a parse warning. 047 * @param line the line number or null if unknown 048 * @param propertyName the property name or null if N/A 049 * @param code the message code from the resource bundle 050 * @param args the message arguments 051 */ 052 public void add(Integer line, String propertyName, int code, Object... args) { 053 Warning warning = Warning.parse(code, args); 054 add(line, propertyName, warning); 055 } 056 057 /** 058 * Adds a parse warning. 059 * @param line the line number or null if unknown 060 * @param propertyName the property name or null if N/A 061 * @param message the warning message 062 */ 063 public void add(Integer line, String propertyName, Warning message) { 064 if (line == null && propertyName == null) { 065 warnings.add(message.toString()); 066 return; 067 } 068 069 String key; 070 if (line == null && propertyName != null) { 071 key = "parse.prop"; 072 } else if (line != null && propertyName == null) { 073 key = "parse.line"; 074 } else { 075 key = "parse.lineWithProp"; 076 } 077 078 String warning = Messages.INSTANCE.getMessage(key, line, propertyName, message); 079 warnings.add(warning); 080 } 081 082 /** 083 * Creates a copy of this warnings list. 084 * @return the copy 085 */ 086 public List<String> copy() { 087 return new ArrayList<String>(warnings); 088 } 089 090 /** 091 * Clears the warnings list. 092 */ 093 public void clear() { 094 warnings.clear(); 095 } 096}