##### Coverage Report - org.apache.any23.extractor.microdata.MicrodataParserException

Classes in this File | Line Coverage | Branch Coverage | Complexity
MicrodataParserException |
0% | 0/20
0% | 0/10
| 1.6;1.6

1 |  |
     /*
2 |  |
      * Licensed to the Apache Software Foundation (ASF) under one or more
3 |  |
      * contributor license agreements.  See the NOTICE file distributed with
4 |  |
      * this work for additional information regarding copyright ownership.
5 |  |
      * The ASF licenses this file to You under the Apache License, Version 2.0
6 |  |
      * (the "License"); you may not use this file except in compliance with
7 |  |
      * the License.  You may obtain a copy of the License at
8 |  |
      *
9 |  |
      *  http://www.apache.org/licenses/LICENSE-2.0
10 |  |
      *
11 |  |
      * Unless required by applicable law or agreed to in writing, software
12 |  |
      * distributed under the License is distributed on an "AS IS" BASIS,
13 |  |
      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 |  |
      * See the License for the specific language governing permissions and
15 |  |
      * limitations under the License.
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 |  |
      * Defines an exception occurring while parsing
25 |  |
      * <i>Microdata</i>.
26 |  |
      *
27 |  |
      * @see MicrodataParser
28 |  |
      * @author Michele Mostarda (mostarda@fbk.eu)
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 |  |
     }