class TemplatesParser {

    public Templates parseTemplates(Source source) throws TransformerConfigurationException, SAXException, IOException {
        InputSource inputSource = SAXSource.sourceToInputSource(source);
        if (inputSource == null) {
            throw new RuntimeException("Unable convert to Input Source");
        }

        SAXTransformerFactory saxTransformerFactory = createFeaturedSaxTransformerFactory();
        TemplatesHandler templateHandler = saxTransformerFactory.newTemplatesHandler();
        XMLReader xmlReader = XMLReaderFactory.createXMLReader();
        if (resolver != null) {
            xmlReader.setEntityResolver(resolver);
        }
        xmlReader.setContentHandler(templateHandler);

        xmlReader.parse(inputSource);

        Templates templates = templateHandler.getTemplates();
        if (templates == null) {
            throw new RuntimeException("Unable create templates from given source");
        }
        return templates;
    }

}