PageRenderTime 50ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/atlassian/bamboo/plugin/dotnet/tests/TestResultContentHandler.java

https://bitbucket.org/atlassian/bamboo-dotnet-plugin/
Java | 118 lines | 89 code | 18 blank | 11 comment | 1 complexity | 78d729a2d366ac39b69d6edd127a3236 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /*_____________________________________________________________________
  2. *
  3. * Copyright (c) 2008 Department of Immigration and Citizenship
  4. * _____________________________________________________________________
  5. */
  6. package com.atlassian.bamboo.plugin.dotnet.tests;
  7. import com.atlassian.bamboo.configuration.ConfigurationException;
  8. import com.atlassian.bamboo.configuration.DefaultElementParser;
  9. import com.atlassian.bamboo.configuration.ElementParser;
  10. import com.google.common.collect.Lists;
  11. import com.google.common.collect.Maps;
  12. import org.xml.sax.Attributes;
  13. import org.xml.sax.ContentHandler;
  14. import org.xml.sax.Locator;
  15. import org.xml.sax.SAXException;
  16. import java.util.Deque;
  17. import java.util.Map;
  18. /**
  19. * Reimplemented logic contained in {@link com.atlassian.bamboo.configuration.DefaultContentHandler} so that
  20. * we can cope with changes in the test report XML structure without causing fatal exceptions.
  21. *
  22. * @author Ross Rowe
  23. */
  24. public class TestResultContentHandler implements ContentHandler
  25. {
  26. protected static final String DEFAULT_PARSER = "org.apache.xerces.parsers.SAXParser";
  27. private Map<String, ElementParser> elementParsers;
  28. private Deque<ElementParser> currentElementParsers;
  29. public TestResultContentHandler()
  30. {
  31. this.elementParsers = Maps.newHashMap();
  32. this.currentElementParsers = Lists.newLinkedList();
  33. }
  34. protected void registerElementParser(String elementName, ElementParser elementParser)
  35. {
  36. this.elementParsers.put(elementName, elementParser);
  37. }
  38. @Override
  39. public void setDocumentLocator(Locator locator)
  40. {
  41. }
  42. @Override
  43. public void startDocument() throws SAXException
  44. {
  45. }
  46. @Override
  47. public void endDocument() throws SAXException
  48. {
  49. }
  50. @Override
  51. public void startPrefixMapping(String buildName, String buildName1) throws SAXException
  52. {
  53. }
  54. @Override
  55. public void endPrefixMapping(String buildName) throws SAXException
  56. {
  57. }
  58. @Override
  59. public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
  60. {
  61. if (!this.elementParsers.containsKey(localName))
  62. {
  63. registerElementParser(localName, new DefaultElementParser());
  64. }
  65. ElementParser elementParser = this.elementParsers.get(localName);
  66. elementParser.startElement(attributes);
  67. this.currentElementParsers.push(elementParser);
  68. }
  69. @Override
  70. public void endElement(String uri, String localName, String qName) throws SAXException
  71. {
  72. ElementParser elementParser = this.currentElementParsers.pop();
  73. try
  74. {
  75. elementParser.endElement();
  76. }
  77. catch (ConfigurationException e)
  78. {
  79. throw new RuntimeException(e);
  80. }
  81. }
  82. @Override
  83. public void characters(char[] chars, int start, int end) throws SAXException
  84. {
  85. ElementParser elementParser = this.currentElementParsers.peek();
  86. elementParser.characters(chars, start, end);
  87. }
  88. @Override
  89. public void ignorableWhitespace(char[] chars, int i, int i1) throws SAXException
  90. {
  91. }
  92. @Override
  93. public void processingInstruction(String buildName, String buildName1) throws SAXException
  94. {
  95. }
  96. @Override
  97. public void skippedEntity(String buildName) throws SAXException
  98. {
  99. }
  100. }