1 19 20 package org.openide.loaders; 21 22 23 import java.io.IOException ; 24 import java.util.Iterator ; 25 import javax.xml.parsers.*; 26 import org.netbeans.modules.openide.loaders.RuntimeCatalog; 27 import org.openide.util.Exceptions; 28 import org.openide.util.Lookup; 29 import org.openide.xml.*; 30 import org.xml.sax.*; 31 32 38 class XMLDataObjectImpl extends Object { 39 40 41 42 static DocumentBuilder makeBuilder(boolean validate) throws IOException , SAXException { 43 44 DocumentBuilder builder; 45 DocumentBuilderFactory factory; 46 47 try { 50 factory = DocumentBuilderFactory.newInstance(); 51 factory.setValidating(validate); 52 factory.setNamespaceAware(false); 53 } catch (FactoryConfigurationError err) { 54 notifyFactoryErr(err, "javax.xml.parsers.DocumentBuilderFactory"); throw err; 56 } 57 58 try { 59 builder = factory.newDocumentBuilder(); 60 } catch (ParserConfigurationException ex) { 61 SAXException sex = new SAXException("Configuration exception."); sex.initCause(ex); 63 Exceptions.attachLocalizedMessage(sex, 64 "Can not create a DOM builder!\nCheck javax.xml.parsers.DocumentBuilderFactory property and the builder library presence on classpath."); throw sex; 66 } 67 68 return builder; 69 } 70 71 @Deprecated 72 static Parser makeParser(boolean validate) { 73 74 try { 75 return new org.xml.sax.helpers.XMLReaderAdapter (XMLUtil.createXMLReader(validate)); 76 } catch (SAXException ex) { 77 notifyNewSAXParserEx(ex); 78 return null; 79 } 80 81 } 82 83 84 static XMLReader makeXMLReader(boolean validating, boolean namespaces) { 85 86 try { 87 return XMLUtil.createXMLReader(validating,namespaces); 88 } catch (SAXException ex) { 89 notifyNewSAXParserEx(ex); 90 return null; 91 } 92 93 } 94 95 96 private static void notifyNewSAXParserEx (Exception ex) { 97 Exceptions.attachLocalizedMessage(ex, 98 "Can not create a SAX parser!\nCheck javax.xml.parsers.SAXParserFactory property features and the parser library presence on classpath."); Exceptions.printStackTrace(ex); 100 } 101 102 103 private static void notifyFactoryErr(Error err, String property) { 104 Exceptions.attachLocalizedMessage(err, 105 "Can not create a factory!\nCheck " + 106 property + 107 " property and the factory library presence on classpath."); Exceptions.printStackTrace(err); 109 } 110 111 static synchronized void registerCatalogEntry(String publicId, String uri) { 113 Iterator it = Lookup.getDefault().lookupAll(EntityCatalog.class).iterator(); 114 while (it.hasNext()) { 115 Object o = it.next(); 116 if (o instanceof RuntimeCatalog) { 117 ((RuntimeCatalog) o).registerCatalogEntry(publicId, uri); 118 return; 119 } 120 } 121 assert false; 122 } 123 124 } 125 | Popular Tags |