001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.commons.scxml.env;
018
019 import java.io.Serializable;
020
021 import org.apache.commons.logging.Log;
022 import org.apache.commons.logging.LogFactory;
023 import org.xml.sax.ErrorHandler;
024 import org.xml.sax.SAXParseException;
025
026 /**
027 * Custom error handler that logs the parsing errors in the
028 * SCXML document.
029 */
030 public class SimpleErrorHandler implements ErrorHandler, Serializable {
031
032 /** Serial version UID. */
033 private static final long serialVersionUID = 1L;
034 /** Message prefix. */
035 private static final String MSG_PREFIX = "SCXML SAX Parsing: ";
036 /** Message postfix. */
037 private static final String MSG_POSTFIX = " Correct the SCXML document.";
038
039 /** Log. */
040 private Log log = LogFactory.getLog(getClass());
041
042 /**
043 * Constructor.
044 */
045 public SimpleErrorHandler() {
046 super();
047 }
048
049 /**
050 * @see ErrorHandler#error(SAXParseException)
051 */
052 public void error(final SAXParseException exception) {
053 if (log.isErrorEnabled()) {
054 log.error(MSG_PREFIX + exception.getMessage() + MSG_POSTFIX,
055 exception);
056 }
057 }
058
059 /**
060 * @see ErrorHandler#fatalError(SAXParseException)
061 */
062 public void fatalError(final SAXParseException exception) {
063 if (log.isFatalEnabled()) {
064 log.fatal(MSG_PREFIX + exception.getMessage() + MSG_POSTFIX,
065 exception);
066 }
067 }
068
069 /**
070 * @see ErrorHandler#warning(SAXParseException)
071 */
072 public void warning(final SAXParseException exception) {
073 if (log.isWarnEnabled()) {
074 log.warn(MSG_PREFIX + exception.getMessage() + MSG_POSTFIX,
075 exception);
076 }
077 }
078 }
079