/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.solr.common.util;

import org.slf4j.Logger;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.TransformerException;
import javax.xml.stream.Location;
import javax.xml.stream.XMLReporter;

public final class XMLErrorLogger implements ErrorHandler,ErrorListener,XMLReporter {
  
  private final Logger log;

  public XMLErrorLogger(Logger log) {
    this.log = log;
  }
  
  // ErrorHandler
  
	public void warning(SAXParseException e) {
		log.warn("XML parse warning in \""+e.getSystemId()+"\", line "+e.getLineNumber()+", column "+e.getColumnNumber()+": "+e.getMessage());
	}

	public void error(SAXParseException e) throws SAXException {
		throw e;
	}

	public void fatalError(SAXParseException e) throws SAXException {
		throw e;
	}
  
  // ErrorListener
  
	public void warning(TransformerException e) {
		log.warn(e.getMessageAndLocation());
	}

	public void error(TransformerException e) throws TransformerException {
		throw e;
	}

	public void fatalError(TransformerException e) throws TransformerException {
		throw e;
	}
  
  // XMLReporter
  
  public void report(String message, String errorType, Object relatedInformation, Location loc) {
		log.warn("XML parse warning in \""+loc.getSystemId()+"\", line "+loc.getLineNumber()+", column "+loc.getColumnNumber()+": "+message);
  }
  
}

@@ -1214,18 +1214,16 @@
 orter %7B%0A
-  
 %0A  priva
@@ -1306,18 +1306,16 @@
 og;%0A  %7D%0A
-  
 %0A  // Er
@@ -1325,20 +1325,19 @@
 Handler%0A
+%0A
   
-%0A%09
 public v
@@ -1363,34 +1363,36 @@
 eException e) %7B%0A
-%09%09
+    
 log.warn(%22XML pa
@@ -1506,29 +1506,31 @@
 Message());%0A
-%09%7D%0A%0A%09
+  %7D%0A%0A  
 public void 
@@ -1570,34 +1570,36 @@
  SAXException %7B%0A
-%09%09
+    
 throw e;%0A%09%7D%0A%0A%09pu
@@ -1583,37 +1583,39 @@
  %7B%0A    throw e;%0A
-%09%7D%0A%0A%09
+  %7D%0A%0A  
 public void fata
@@ -1656,34 +1656,36 @@
  SAXException %7B%0A
-%09%09
+    
 throw e;%0A%09%7D%0A  %0A 
@@ -1673,29 +1673,28 @@
    throw e;%0A
-%09%7D%0A
   
+%7D%0A
 %0A  // ErrorL
@@ -1705,12 +1705,11 @@
 ner%0A
+%0A
   
-%0A%09
 publ
@@ -1746,26 +1746,28 @@
 eption e) %7B%0A
-%09%09
+    
 log.warn(e.g
@@ -1791,21 +1791,23 @@
 ion());%0A
-%09%7D%0A%0A%09
+  %7D%0A%0A  
 public v
@@ -1862,34 +1862,36 @@
 rmerException %7B%0A
-%09%09
+    
 throw e;%0A%09%7D%0A%0A%09pu
@@ -1887,13 +1887,15 @@
  e;%0A
-%09%7D%0A%0A%09
+  %7D%0A%0A  
 publ
@@ -1967,18 +1967,20 @@
 ption %7B%0A
-%09%09
+    
 throw e;
@@ -1984,13 +1984,12 @@
  e;%0A
-%09%7D%0A
   
+%7D%0A
 %0A  /
@@ -2002,18 +2002,16 @@
 eporter%0A
-  
 %0A  publi
@@ -2105,45 +2105,155 @@
 ) %7B%0A
-%09%09log.warn(%22XML parse warning in %5C%22%22+
+    final StringBuilder sb = new StringBuilder(%22XML parser reported %22).append(errorType);%0A    if (loc !=  null) %7B%0A      sb.append(%22 in %5C%22%22).append(
 loc.
@@ -2257,33 +2257,41 @@
 oc.getSystemId()
-+
+).append(
 %22%5C%22, line %22+loc.
@@ -2285,17 +2285,34 @@
 , line %22
-+
+)%0A        .append(
 loc.getL
@@ -2314,33 +2314,41 @@
 .getLineNumber()
-+
+).append(
 %22, column %22+loc.
@@ -2342,17 +2342,25 @@
 column %22
-+
+).append(
 loc.getC
@@ -2376,29 +2376,78 @@
 er()
-+%22: %22+message
+);%0A    %7D%0A    log.warn(sb.append(%22: %22).append(message).toString()
 );%0A  %7D%0A
-  
 %0A%7D%0A

Fix possible NPE, fix indent