Initial commit for AAI-UI(sparky-backend)
[aai/sparky-be.git] / src / main / java / org / openecomp / sparky / synchronizer / MyErrorHandler.java
1 /**
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 package org.openecomp.sparky.synchronizer;
27
28 import java.io.PrintWriter;
29
30 import org.xml.sax.ErrorHandler;
31 import org.xml.sax.SAXException;
32 import org.xml.sax.SAXParseException;
33
34 /**
35  * The Class MyErrorHandler.
36  */
37 public class MyErrorHandler implements ErrorHandler {
38
39   /** Error handler output goes here. */
40   private PrintWriter out;
41
42   /**
43    * Instantiates a new my error handler.
44    *
45    * @param out the out
46    */
47   public MyErrorHandler(PrintWriter out) {
48     this.out = out;
49   }
50
51   /**
52    * Returns a string describing parse exception details.
53    *
54    * @param spe the spe
55    * @return the parses the exception info
56    */
57   private String getParseExceptionInfo(SAXParseException spe) {
58     String systemId = spe.getSystemId();
59     if (systemId == null) {
60       systemId = "null";
61     }
62     String info = "URI=" + systemId + " Line=" + spe.getLineNumber() + ": " + spe.getMessage();
63     return info;
64   }
65
66   // The following methods are standard SAX ErrorHandler methods.
67   // See SAX documentation for more info.
68
69   /* (non-Javadoc)
70    * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
71    */
72   @Override
73   public void warning(SAXParseException spe) throws SAXException {
74     out.println("Warning: " + getParseExceptionInfo(spe));
75   }
76
77   /* (non-Javadoc)
78    * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
79    */
80   @Override
81   public void error(SAXParseException spe) throws SAXException {
82     String message = "Error: " + getParseExceptionInfo(spe);
83     throw new SAXException(message);
84   }
85
86   /* (non-Javadoc)
87    * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
88    */
89   @Override
90   public void fatalError(SAXParseException spe) throws SAXException {
91     String message = "Fatal Error: " + getParseExceptionInfo(spe);
92     throw new SAXException(message);
93   }
94 }