001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements. See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership. The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the  "License");
007     * you may not use this file except in compliance with the License.
008     * You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    /*
019     * $Id: DOMErrorHandlerImpl.java 1225426 2011-12-29 04:13:08Z mrglavas $
020     */
021    
022    package org.apache.xml.serializer.dom3;
023    
024    import org.w3c.dom.DOMError;
025    import org.w3c.dom.DOMErrorHandler;
026    
027    /**
028     * This is the default implementation of the ErrorHandler interface and is 
029     * used if one is not provided.  The default implementation simply reports
030     * DOMErrors to System.err.
031     * 
032     * @xsl.usage internal
033     */
034    final class DOMErrorHandlerImpl implements DOMErrorHandler {
035        
036        /**
037         * Default Constructor 
038         */
039        DOMErrorHandlerImpl() {
040        }
041        
042        /**
043         * Implementation of DOMErrorHandler.handleError that
044         * adds copy of error to list for later retrieval.
045         *
046         */
047        public boolean handleError(DOMError error) {
048            boolean fail = true;
049            String severity = null;
050            if (error.getSeverity() == DOMError.SEVERITY_WARNING) {
051                fail = false;
052                severity = "[Warning]";
053            } else if (error.getSeverity() == DOMError.SEVERITY_ERROR) {
054                severity = "[Error]";
055            } else if (error.getSeverity() == DOMError.SEVERITY_FATAL_ERROR) {
056                severity = "[Fatal Error]";
057            }
058            
059            System.err.println(severity + ": " + error.getMessage() + "\t");
060            System.err.println("Type : " + error.getType() + "\t" + "Related Data: "
061                    + error.getRelatedData() + "\t" + "Related Exception: "
062                    + error.getRelatedException() );
063            
064            return fail;
065        }
066    }
067