1 /* 2 * Copyright (c) 2011-2022, jcabi.com 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 1) Redistributions of source code must retain the above 8 * copyright notice, this list of conditions and the following 9 * disclaimer. 2) Redistributions in binary form must reproduce the above 10 * copyright notice, this list of conditions and the following 11 * disclaimer in the documentation and/or other materials provided 12 * with the distribution. 3) Neither the name of the jcabi.com nor 13 * the names of its contributors may be used to endorse or promote 14 * products derived from this software without specific prior written 15 * permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 19 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 20 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 28 * OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 package com.jcabi.w3c; 31 32 import com.jcabi.log.Logger; 33 import lombok.EqualsAndHashCode; 34 35 /** 36 * Validation defect (error or warning) produced by {@link ValidationResponse}. 37 * 38 * <p>Objects of this class are immutable and thread-safe. 39 * 40 * @see <a href="http://validator.w3.org/docs/api.html">W3C API</a> 41 * @since 0.1 42 * @checkstyle LineLength (2 lines) 43 */ 44 @EqualsAndHashCode(of = { "iline", "icolumn", "isource", "iexplanation", "msg", "imessage" }) 45 public final class Defect { 46 47 /** 48 * Line. 49 */ 50 private final transient int iline; 51 52 /** 53 * Column. 54 */ 55 private final transient int icolumn; 56 57 /** 58 * Source line. 59 */ 60 private final transient String isource; 61 62 /** 63 * Explanation. 64 */ 65 private final transient String iexplanation; 66 67 /** 68 * Message id. 69 */ 70 private final transient String msg; 71 72 /** 73 * The message. 74 */ 75 private final transient String imessage; 76 77 /** 78 * Protected ctor, to be called only from this package. 79 * @param line Line number 80 * @param column Column number 81 * @param source Source line 82 * @param explanation The explanation 83 * @param mid ID of the message 84 * @param message Message text 85 * @checkstyle ParameterNumber (5 lines) 86 */ 87 Defect(final int line, final int column, final String source, 88 final String explanation, final String mid, 89 final String message) { 90 this.iline = line; 91 this.icolumn = column; 92 this.isource = source.trim(); 93 this.iexplanation = explanation.trim(); 94 this.msg = mid.trim(); 95 this.imessage = message.trim(); 96 } 97 98 @Override 99 public String toString() { 100 return Logger.format( 101 "[%d:%d] \"%s\", \"%s\", \"%s\", \"%s\"", 102 this.iline, 103 this.icolumn, 104 this.isource, 105 this.iexplanation, 106 this.msg, 107 this.imessage 108 ); 109 } 110 111 /** 112 * Line number, where the defect was found. 113 * @return Line number 114 */ 115 public int line() { 116 return this.iline; 117 } 118 119 /** 120 * Column number inside the line. 121 * @return Column number 122 */ 123 public int column() { 124 return this.icolumn; 125 } 126 127 /** 128 * Source line, as quoted by W3C validator. 129 * @return Full text of the source line 130 */ 131 public String source() { 132 return this.isource; 133 } 134 135 /** 136 * Explanation of the problem. 137 * @return Text 138 */ 139 public String explanation() { 140 return this.iexplanation; 141 } 142 143 /** 144 * Message ID, according to W3C API. 145 * @return The ID 146 */ 147 public String messageId() { 148 return this.msg; 149 } 150 151 /** 152 * Text of the message. 153 * @return The message returned by W3C server 154 */ 155 public String message() { 156 return this.imessage; 157 } 158 159 }