| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
package org.apache.any23.extractor.microdata; |
| 19 | |
|
| 20 | |
import org.apache.any23.extractor.html.DomUtils; |
| 21 | |
import org.w3c.dom.Node; |
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
public class MicrodataParserException extends Exception { |
| 31 | |
|
| 32 | |
private String errorPath; |
| 33 | |
private int[] errorLocation; |
| 34 | |
|
| 35 | |
public MicrodataParserException(String message, Node errorNode) { |
| 36 | 0 | super(message); |
| 37 | 0 | setErrorNode(errorNode); |
| 38 | 0 | } |
| 39 | |
|
| 40 | |
public MicrodataParserException(String message, Throwable cause, Node errorNode) { |
| 41 | 0 | super(message, cause); |
| 42 | 0 | setErrorNode(errorNode); |
| 43 | 0 | } |
| 44 | |
|
| 45 | |
public String getErrorPath() { |
| 46 | 0 | return errorPath; |
| 47 | |
} |
| 48 | |
|
| 49 | |
public int getErrorLocationBeginRow() { |
| 50 | 0 | return errorLocation == null ? -1 : errorLocation[0]; |
| 51 | |
} |
| 52 | |
|
| 53 | |
public int getErrorLocationBeginCol() { |
| 54 | 0 | return errorLocation == null ? -1 : errorLocation[1]; |
| 55 | |
} |
| 56 | |
|
| 57 | |
public int getErrorLocationEndRow() { |
| 58 | 0 | return errorLocation == null ? -1 : errorLocation[2]; |
| 59 | |
} |
| 60 | |
|
| 61 | |
public int getErrorLocationEndCol() { |
| 62 | 0 | return errorLocation == null ? -1 : errorLocation[3]; |
| 63 | |
} |
| 64 | |
|
| 65 | |
public String toJSON() { |
| 66 | 0 | return String.format( |
| 67 | |
"{ \"message\" : \"%s\", " + |
| 68 | |
"\"path\" : \"%s\", " + |
| 69 | |
"\"begin_row\" : %d, \"begin_col\" : %d, " + |
| 70 | |
"\"end_row\" : %d, \"end_col\" : %d }", |
| 71 | |
getMessage().replaceAll("\"", ""), |
| 72 | |
getErrorPath(), |
| 73 | |
getErrorLocationBeginRow(), |
| 74 | |
getErrorLocationBeginCol(), |
| 75 | |
getErrorLocationEndRow(), |
| 76 | |
getErrorLocationEndCol() |
| 77 | |
); |
| 78 | |
} |
| 79 | |
|
| 80 | |
@Override |
| 81 | |
public String toString() { |
| 82 | 0 | return toJSON(); |
| 83 | |
} |
| 84 | |
|
| 85 | |
protected void setErrorNode(Node n) { |
| 86 | 0 | if(n == null) { |
| 87 | 0 | errorPath = null; |
| 88 | 0 | errorLocation = null; |
| 89 | 0 | return; |
| 90 | |
} |
| 91 | |
|
| 92 | 0 | errorPath = DomUtils.getXPathForNode(n); |
| 93 | 0 | errorLocation = DomUtils.getNodeLocation(n); |
| 94 | 0 | } |
| 95 | |
|
| 96 | |
} |