/src/main/java/com/atlassian/bamboo/plugin/dotnet/tests/TestResultContentHandler.java
Java | 118 lines | 89 code | 18 blank | 11 comment | 1 complexity | 78d729a2d366ac39b69d6edd127a3236 MD5 | raw file
Possible License(s): BSD-3-Clause
- /*_____________________________________________________________________
- *
- * Copyright (c) 2008 Department of Immigration and Citizenship
- * _____________________________________________________________________
- */
- package com.atlassian.bamboo.plugin.dotnet.tests;
-
- import com.atlassian.bamboo.configuration.ConfigurationException;
- import com.atlassian.bamboo.configuration.DefaultElementParser;
- import com.atlassian.bamboo.configuration.ElementParser;
- import com.google.common.collect.Lists;
- import com.google.common.collect.Maps;
- import org.xml.sax.Attributes;
- import org.xml.sax.ContentHandler;
- import org.xml.sax.Locator;
- import org.xml.sax.SAXException;
-
- import java.util.Deque;
- import java.util.Map;
-
- /**
- * Reimplemented logic contained in {@link com.atlassian.bamboo.configuration.DefaultContentHandler} so that
- * we can cope with changes in the test report XML structure without causing fatal exceptions.
- *
- * @author Ross Rowe
- */
- public class TestResultContentHandler implements ContentHandler
- {
- protected static final String DEFAULT_PARSER = "org.apache.xerces.parsers.SAXParser";
- private Map<String, ElementParser> elementParsers;
- private Deque<ElementParser> currentElementParsers;
-
- public TestResultContentHandler()
- {
- this.elementParsers = Maps.newHashMap();
- this.currentElementParsers = Lists.newLinkedList();
- }
-
- protected void registerElementParser(String elementName, ElementParser elementParser)
- {
- this.elementParsers.put(elementName, elementParser);
- }
-
- @Override
- public void setDocumentLocator(Locator locator)
- {
- }
-
- @Override
- public void startDocument() throws SAXException
- {
- }
-
- @Override
- public void endDocument() throws SAXException
- {
- }
-
- @Override
- public void startPrefixMapping(String buildName, String buildName1) throws SAXException
- {
- }
-
- @Override
- public void endPrefixMapping(String buildName) throws SAXException
- {
- }
-
- @Override
- public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
- {
- if (!this.elementParsers.containsKey(localName))
- {
- registerElementParser(localName, new DefaultElementParser());
- }
-
- ElementParser elementParser = this.elementParsers.get(localName);
- elementParser.startElement(attributes);
- this.currentElementParsers.push(elementParser);
-
- }
-
- @Override
- public void endElement(String uri, String localName, String qName) throws SAXException
- {
- ElementParser elementParser = this.currentElementParsers.pop();
- try
- {
- elementParser.endElement();
- }
- catch (ConfigurationException e)
- {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void characters(char[] chars, int start, int end) throws SAXException
- {
- ElementParser elementParser = this.currentElementParsers.peek();
- elementParser.characters(chars, start, end);
- }
-
- @Override
- public void ignorableWhitespace(char[] chars, int i, int i1) throws SAXException
- {
- }
-
- @Override
- public void processingInstruction(String buildName, String buildName1) throws SAXException
- {
- }
-
- @Override
- public void skippedEntity(String buildName) throws SAXException
- {
- }
- }