package net.sf.jasperreports.engine.xml;

import javax.xml.parsers.ParserConfigurationException;
import net.sf.jasperreports.engine.JRRuntimeException;
import net.sf.jasperreports.engine.util.JRProperties;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.RuleSet;
import org.apache.commons.digester.RuleSetBase;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class JRXmlTemplateDigesterFactory implements ErrorHandler {
  protected static final String PATTERN_ROOT = "jasperTemplate";
  
  protected static final String PATTERN_INCLUDED_TEMPLATE = "jasperTemplate/template";
  
  protected static final String PATTERN_STYLE = "jasperTemplate/style";
  
  protected static final String PATTERN_STYLE_PEN = "jasperTemplate/style/pen";
  
  protected static final String PATTERN_BOX = "jasperTemplate/style/box";
  
  protected static final String PATTERN_BOX_PEN = "jasperTemplate/style/box/pen";
  
  protected static final String PATTERN_BOX_TOP_PEN = "jasperTemplate/style/box/topPen";
  
  protected static final String PATTERN_BOX_LEFT_PEN = "jasperTemplate/style/box/leftPen";
  
  protected static final String PATTERN_BOX_BOTTOM_PEN = "jasperTemplate/style/box/bottomPen";
  
  protected static final String PATTERN_BOX_RIGHT_PEN = "jasperTemplate/style/box/rightPen";
  
  private static final JRXmlTemplateDigesterFactory instance = new JRXmlTemplateDigesterFactory();
  
  private final RuleSet rules = readRuleSet();
  
  static Class class$net$sf$jasperreports$engine$JRSimpleTemplate;
  
  static Class class$net$sf$jasperreports$engine$xml$JRTemplateStyleFactory;
  
  static Class class$net$sf$jasperreports$engine$JRStyle;
  
  static Class class$net$sf$jasperreports$engine$xml$JRPenFactory$Style;
  
  static Class class$net$sf$jasperreports$engine$xml$JRBoxFactory;
  
  static Class class$net$sf$jasperreports$engine$xml$JRPenFactory$Box;
  
  static Class class$net$sf$jasperreports$engine$xml$JRPenFactory$Top;
  
  static Class class$net$sf$jasperreports$engine$xml$JRPenFactory$Left;
  
  static Class class$net$sf$jasperreports$engine$xml$JRPenFactory$Bottom;
  
  static Class class$net$sf$jasperreports$engine$xml$JRPenFactory$Right;
  
  public static JRXmlTemplateDigesterFactory instance() {
    return instance;
  }
  
  protected RuleSet readRuleSet() {
    return (RuleSet)new RuleSetBase() {
        private final JRXmlTemplateDigesterFactory this$0;
        
        public void addRuleInstances(Digester digester) {
          digester.addObjectCreate("jasperTemplate", (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$JRSimpleTemplate == null) ? (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$JRSimpleTemplate = JRXmlTemplateDigesterFactory.class$("net.sf.jasperreports.engine.JRSimpleTemplate")) : JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$JRSimpleTemplate);
          digester.addCallMethod("jasperTemplate/template", "addIncludedTemplate", 0);
          digester.addFactoryCreate("jasperTemplate/style", (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRTemplateStyleFactory == null) ? (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRTemplateStyleFactory = JRXmlTemplateDigesterFactory.class$("net.sf.jasperreports.engine.xml.JRTemplateStyleFactory")) : JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRTemplateStyleFactory);
          digester.addSetNext("jasperTemplate/style", "addStyle", ((JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$JRStyle == null) ? (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$JRStyle = JRXmlTemplateDigesterFactory.class$("net.sf.jasperreports.engine.JRStyle")) : JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$JRStyle).getName());
          digester.addFactoryCreate("jasperTemplate/style/pen", ((JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Style == null) ? (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Style = JRXmlTemplateDigesterFactory.class$("net.sf.jasperreports.engine.xml.JRPenFactory$Style")) : JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Style).getName());
          digester.addFactoryCreate("jasperTemplate/style/box", ((JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRBoxFactory == null) ? (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRBoxFactory = JRXmlTemplateDigesterFactory.class$("net.sf.jasperreports.engine.xml.JRBoxFactory")) : JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRBoxFactory).getName());
          digester.addFactoryCreate("jasperTemplate/style/box/pen", ((JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Box == null) ? (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Box = JRXmlTemplateDigesterFactory.class$("net.sf.jasperreports.engine.xml.JRPenFactory$Box")) : JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Box).getName());
          digester.addFactoryCreate("jasperTemplate/style/box/topPen", ((JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Top == null) ? (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Top = JRXmlTemplateDigesterFactory.class$("net.sf.jasperreports.engine.xml.JRPenFactory$Top")) : JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Top).getName());
          digester.addFactoryCreate("jasperTemplate/style/box/leftPen", ((JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Left == null) ? (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Left = JRXmlTemplateDigesterFactory.class$("net.sf.jasperreports.engine.xml.JRPenFactory$Left")) : JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Left).getName());
          digester.addFactoryCreate("jasperTemplate/style/box/bottomPen", ((JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Bottom == null) ? (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Bottom = JRXmlTemplateDigesterFactory.class$("net.sf.jasperreports.engine.xml.JRPenFactory$Bottom")) : JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Bottom).getName());
          digester.addFactoryCreate("jasperTemplate/style/box/rightPen", ((JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Right == null) ? (JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Right = JRXmlTemplateDigesterFactory.class$("net.sf.jasperreports.engine.xml.JRPenFactory$Right")) : JRXmlTemplateDigesterFactory.class$net$sf$jasperreports$engine$xml$JRPenFactory$Right).getName());
        }
      };
  }
  
  static Class class$(String x0) {
    try {
      return Class.forName(x0);
    } catch (ClassNotFoundException x1) {
      throw (new NoClassDefFoundError()).initCause(x1);
    } 
  }
  
  public JRXmlDigester createDigester() {
    JRXmlDigester digester = new JRXmlDigester();
    try {
      configureDigester(digester);
    } catch (SAXException e) {
      throw new JRRuntimeException(e);
    } catch (ParserConfigurationException e) {
      throw new JRRuntimeException(e);
    } 
    return digester;
  }
  
  protected void configureDigester(Digester digester) throws SAXException, ParserConfigurationException {
    boolean validating = JRProperties.getBooleanProperty("net.sf.jasperreports.compiler.xml.validation");
    digester.setErrorHandler(this);
    digester.setValidating(validating);
    digester.setFeature("http://xml.org/sax/features/validation", validating);
    digester.addRuleSet(this.rules);
  }
  
  public void error(SAXParseException exception) throws SAXException {
    throw exception;
  }
  
  public void fatalError(SAXParseException exception) throws SAXException {
    throw exception;
  }
  
  public void warning(SAXParseException exception) throws SAXException {
    throw exception;
  }
}
