1 2 12 package com.versant.core.common; 13 14 import javax.xml.parsers.SAXParserFactory ; 15 import javax.xml.parsers.SAXParser ; 16 17 import com.versant.core.common.BindingSupportImpl; 18 19 22 public class JaxpUtils { 23 24 private static final String SAX_PARSER_FACTORY_SYSPROP = "versant.SAXParserFactory"; 25 private static final String SAX_PARSER_FACTORY_SYSPROP_OLD = "jdogenie.SAXParserFactory"; 26 27 30 public static SAXParserFactory getSAXParserFactory() { 31 String parserFactoryName = System.getProperty(SAX_PARSER_FACTORY_SYSPROP); 32 if (parserFactoryName == null) { 33 parserFactoryName = System.getProperty(SAX_PARSER_FACTORY_SYSPROP_OLD); 34 } 35 SAXParserFactory parserFactory = null; 36 if (parserFactoryName != null) { 37 try { 38 Class cls = Class.forName(parserFactoryName); 39 parserFactory = (SAXParserFactory )cls.newInstance(); 40 } catch (Throwable t) { 41 throw BindingSupportImpl.getInstance().runtime("Unable to create SAXParserFactory '" + 42 parserFactoryName + "': " + t, t); 43 } 44 System.out.println("Versant Open Access: Using " + parserFactory); 45 } else { 46 parserFactory = SAXParserFactory.newInstance(); 47 } 48 parserFactory.setValidating(false); 49 parserFactory.setNamespaceAware(false); 50 return parserFactory; 51 } 52 53 57 public static SAXParser createSAXParser(SAXParserFactory parserFactory) { 58 try { 59 return parserFactory.newSAXParser(); 60 } catch (Throwable t) { 61 throw BindingSupportImpl.getInstance().runtime( 62 "Unable to create SAXParser from factory: " + parserFactory + "\n" + 63 "Versant Open Access requires a JAXP 1.1 compliant parser. If this is not possible\n" + 64 "in your environment (e.g. WebLogic 6.0) try invoking java with\n" + 65 "-D" + SAX_PARSER_FACTORY_SYSPROP + "=<name of SAXParserFactory> to bypass JAXP\n" + 66 t, t); 67 } 68 } 69 70 } 71 | Popular Tags |