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