1 19 package org.netbeans.modules.xml.catalog.impl; 20 21 import java.awt.Image ; 22 import java.lang.reflect.*; 23 import java.util.*; 24 import java.io.Serializable ; 25 26 import org.xml.sax.*; 27 28 import org.openide.util.Lookup; 29 import org.openide.xml.EntityCatalog; 30 import org.openide.filesystems.*; 31 32 import org.netbeans.modules.xml.catalog.spi.*; 33 import java.io.IOException ; 34 35 43 public class SystemCatalogReader implements EntityResolver, CatalogReader, Serializable { 44 45 46 private static final long serialVersionUID = -6353123780493006631L; 47 48 49 public SystemCatalogReader() { 50 } 51 52 55 public Iterator getPublicIDs() { 56 57 HashSet set = new HashSet(); 58 boolean found = false; 59 60 62 FileObject root = Repository.getDefault ().getDefaultFileSystem().findResource("xml/entities"); 63 Enumeration en = root.getChildren(true); 64 while (en.hasMoreElements()) { 65 FileObject next = (FileObject) en.nextElement(); 66 if (next.isData()) { 67 Object hint = next.getAttribute("hint.originalPublicID"); 68 if (hint instanceof String ) { 69 set.add(hint); 70 found = true; 71 } else { 72 } 74 } 75 } 76 77 79 Lookup.Template templ = new Lookup.Template(EntityCatalog.class); 80 Lookup.Result res = Lookup.getDefault().lookup(templ); 81 82 Iterator it = res.allInstances().iterator(); 83 while (it.hasNext()) { 84 EntityCatalog next = (EntityCatalog) it.next(); 85 86 try { 87 88 Field uriMapF = next.getClass().getDeclaredField("id2uri"); if (uriMapF == null) continue; 91 92 uriMapF.setAccessible(true); 93 found = true; 94 95 Map uris = (Map) uriMapF.get(next); 96 if (uris != null) { 97 set.addAll(uris.keySet()); 98 } 99 } catch (NoSuchFieldException ex) { 100 } catch (IllegalAccessException ex) { 102 } catch (IllegalArgumentException ex) { 104 } 106 } 107 108 return (found == false) ? null : set.iterator(); 109 } 110 111 112 115 public String getSystemID(String publicId) { 116 117 try { 118 EntityResolver sysResolver = EntityCatalog.getDefault(); 119 120 if (sysResolver == null) return null; 121 122 InputSource in = sysResolver.resolveEntity(publicId, null); 123 if (in == null) return null; 124 125 return in.getSystemId(); 126 127 } catch (java.io.IOException ex) { 128 return null; 129 } catch (SAXException ex) { 130 return null; 131 } 132 } 133 134 137 public void refresh() { 138 } 139 140 141 145 public void addCatalogListener(CatalogListener l) { 146 throw new UnsupportedOperationException (); 147 } 148 149 153 public void removeCatalogListener(CatalogListener l) { 154 throw new UnsupportedOperationException (); 155 } 156 157 160 public boolean equals(Object obj) { 161 if (obj == null) return false; 162 return getClass().equals(obj.getClass()); 163 } 164 165 public int hashCode() { 166 return getClass().hashCode(); 167 } 168 169 172 public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { 173 return EntityCatalog.getDefault().resolveEntity(publicId, systemId); 174 } 175 176 180 public String resolveURI(String name) { 181 return null; 182 } 183 187 public String resolvePublic(String publicId) { 188 return null; 189 } 190 191 } 192 | Popular Tags |