Parses a TLD from the given resource path. @param path the TLD resource path @return the parsed tag library XML @throws IOException if an I/O error occurs @throws SAXException if a parsing error occurs
(TldResourcePath path)
| 74 | * @throws SAXException if a parsing error occurs |
| 75 | */ |
| 76 | public TaglibXml parse(TldResourcePath path) throws IOException, SAXException { |
| 77 | Thread currentThread = Thread.currentThread(); |
| 78 | ClassLoader original = currentThread.getContextClassLoader(); |
| 79 | try (InputStream is = path.openStream()) { |
| 80 | currentThread.setContextClassLoader(TldParser.class.getClassLoader()); |
| 81 | XmlErrorHandler handler = new XmlErrorHandler(); |
| 82 | digester.setErrorHandler(handler); |
| 83 | |
| 84 | TaglibXml taglibXml = new TaglibXml(); |
| 85 | digester.push(taglibXml); |
| 86 | |
| 87 | InputSource source = new InputSource(path.toExternalForm()); |
| 88 | source.setByteStream(is); |
| 89 | digester.parse(source); |
| 90 | if (!handler.getWarnings().isEmpty() || !handler.getErrors().isEmpty()) { |
| 91 | handler.logFindings(log, source.getSystemId()); |
| 92 | if (!handler.getErrors().isEmpty()) { |
| 93 | // throw the first to indicate there was an error during processing |
| 94 | throw handler.getErrors().iterator().next(); |
| 95 | } |
| 96 | } |
| 97 | return taglibXml; |
| 98 | } finally { |
| 99 | digester.reset(); |
| 100 | currentThread.setContextClassLoader(original); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Sets the class loader used for parsing. |
no test coverage detected