View Javadoc

    1   /**
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package net.sourceforge.pmd.lang.xml;
    5
    6   import java.io.Writer;
    7
    8   import net.sf.saxon.sxpath.IndependentContext;
    9   import net.sourceforge.pmd.lang.AbstractLanguageVersionHandler;
    10  import net.sourceforge.pmd.lang.Parser;
    11  import net.sourceforge.pmd.lang.ParserOptions;
    12  import net.sourceforge.pmd.lang.VisitorStarter;
    13  import net.sourceforge.pmd.lang.XPathHandler;
    14  import net.sourceforge.pmd.lang.ast.Node;
    15  import net.sourceforge.pmd.lang.ast.xpath.DocumentNavigator;
    16  import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
    17  import net.sourceforge.pmd.lang.xml.ast.DumpFacade;
    18  import net.sourceforge.pmd.lang.xml.ast.XmlNode;
    19  import net.sourceforge.pmd.lang.xml.rule.XmlRuleViolationFactory;
    20
    21  import org.jaxen.Navigator;
    22
    23  /**
    24   * Implementation of LanguageVersionHandler for the XML.
    25   */
    26  public class XmlHandler extends AbstractLanguageVersionHandler {
    27
    28      @Override
    29      public XPathHandler getXPathHandler() {
    30  	return new XPathHandler() {
    31  	    public void initialize() {
    32  	    }
    33
    34  	    public void initialize(IndependentContext context) {
    35  	    }
    36
    37  	    public Navigator getNavigator() {
    38  		return new DocumentNavigator();
    39  	    }
    40  	};
    41      }
    42
    43      public RuleViolationFactory getRuleViolationFactory() {
    44  	return XmlRuleViolationFactory.INSTANCE;
    45      }
    46
    47      @Override
    48      public ParserOptions getDefaultParserOptions() {
    49  	return new XmlParserOptions();
    50      }
    51
    52      public Parser getParser(ParserOptions parserOptions) {
    53  	return new XmlParser(parserOptions);
    54      }
    55
    56      @Override
    57      public VisitorStarter getDumpFacade(final Writer writer, final String prefix, final boolean recurse) {
    58  	return new VisitorStarter() {
    59  	    public void start(Node rootNode) {
    60  		new DumpFacade().initializeWith(writer, prefix, recurse, (XmlNode) rootNode);
    61  	    }
    62  	};
    63      }
    64  }