1 18 19 20 package org.apache.tomcat.util.digester; 21 22 import java.util.Properties ; 23 24 import javax.xml.parsers.ParserConfigurationException ; 25 import javax.xml.parsers.SAXParser ; 26 import javax.xml.parsers.SAXParserFactory ; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.xml.sax.SAXException ; 31 import org.xml.sax.SAXNotRecognizedException ; 32 33 38 39 public class GenericParser{ 40 41 44 protected static Log log = 45 LogFactory.getLog("org.apache.commons.digester.Digester.sax"); 46 47 50 private static final String JAXP_SCHEMA_SOURCE = 51 "http://java.sun.com/xml/jaxp/properties/schemaSource"; 52 53 56 protected static String JAXP_SCHEMA_LANGUAGE = 57 "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; 58 59 64 public static SAXParser newSAXParser(Properties properties) 65 throws ParserConfigurationException , 66 SAXException , 67 SAXNotRecognizedException { 68 69 SAXParserFactory factory = 70 (SAXParserFactory )properties.get("SAXParserFactory"); 71 SAXParser parser = factory.newSAXParser(); 72 String schemaLocation = (String )properties.get("schemaLocation"); 73 String schemaLanguage = (String )properties.get("schemaLanguage"); 74 75 try{ 76 if (schemaLocation != null) { 77 parser.setProperty(JAXP_SCHEMA_LANGUAGE, schemaLanguage); 78 parser.setProperty(JAXP_SCHEMA_SOURCE, schemaLocation); 79 } 80 } catch (SAXNotRecognizedException e){ 81 log.info(parser.getClass().getName() + ": " 82 + e.getMessage() + " not supported."); 83 } 84 return parser; 85 } 86 87 } | Popular Tags |