001package ezvcard.io; 002 003import java.util.ArrayList; 004import java.util.List; 005 006import ezvcard.VCardVersion; 007 008/* 009 Copyright (c) 2012-2023, 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 The views and conclusions contained in the software and documentation are those 033 of the authors and should not be interpreted as representing official policies, 034 either expressed or implied, of the FreeBSD Project. 035 */ 036 037/** 038 * Stores information used during the parsing of a vCard. 039 * @author Michael Angstadt 040 */ 041public class ParseContext { 042 private VCardVersion version; 043 private List<ParseWarning> warnings = new ArrayList<>(); 044 private Integer lineNumber; 045 private String propertyName; 046 047 /** 048 * Gets the version of the vCard being parsed. 049 * @return the vCard version 050 */ 051 public VCardVersion getVersion() { 052 return version; 053 } 054 055 /** 056 * Sets the version of the vCard being parsed. 057 * @param version the vCard version 058 */ 059 public void setVersion(VCardVersion version) { 060 this.version = version; 061 } 062 063 /** 064 * Gets the line number the parser is currently on. 065 * @return the line number or null if not applicable 066 */ 067 public Integer getLineNumber() { 068 return lineNumber; 069 } 070 071 /** 072 * Sets the line number the parser is currently on. 073 * @param lineNumber the line number or null if not applicable 074 */ 075 public void setLineNumber(Integer lineNumber) { 076 this.lineNumber = lineNumber; 077 } 078 079 /** 080 * Gets the name of the property that the parser is currently parsing. 081 * @return the property name (e.g. "FN") or null if not applicable 082 */ 083 public String getPropertyName() { 084 return propertyName; 085 } 086 087 /** 088 * Sets the name of the property that the parser is currently parsing. 089 * @param propertyName the property name (e.g. "FN") or null if not 090 * applicable 091 */ 092 public void setPropertyName(String propertyName) { 093 this.propertyName = propertyName; 094 } 095 096 /** 097 * Adds a parse warning. 098 * @param code the warning code 099 * @param args the warning message arguments 100 */ 101 public void addWarning(int code, Object... args) { 102 //@formatter:off 103 warnings.add(new ParseWarning.Builder(this) 104 .message(code, args) 105 .build()); 106 //@formatter:on 107 } 108 109 /** 110 * Adds a parse warning. 111 * @param message the warning message 112 */ 113 public void addWarning(String message) { 114 //@formatter:off 115 warnings.add(new ParseWarning.Builder(this) 116 .message(message) 117 .build()); 118 //@formatter:on 119 } 120 121 /** 122 * Gets the parse warnings. 123 * @return the parse warnings 124 */ 125 public List<ParseWarning> getWarnings() { 126 return warnings; 127 } 128}