1 3 19 20 package com.sun.org.apache.xml.internal.resolver.readers; 21 22 import java.util.Vector ; 23 import com.sun.org.apache.xml.internal.resolver.Catalog; 24 import com.sun.org.apache.xml.internal.resolver.Resolver; 25 import com.sun.org.apache.xml.internal.resolver.CatalogEntry; 26 import com.sun.org.apache.xml.internal.resolver.CatalogException; 27 28 import org.xml.sax.*; 29 import org.w3c.dom.*; 30 31 42 public class ExtendedXMLCatalogReader extends OASISXMLCatalogReader { 43 44 public static final String extendedNamespaceName = "http://nwalsh.com/xcatalog/1.0"; 45 46 58 public void startElement (String namespaceURI, 59 String localName, 60 String qName, 61 Attributes atts) 62 throws SAXException { 63 64 boolean inExtension = inExtensionNamespace(); 68 69 super.startElement(namespaceURI, localName, qName, atts); 70 71 int entryType = -1; 72 Vector entryArgs = new Vector (); 73 74 if (namespaceURI != null && extendedNamespaceName.equals(namespaceURI) 75 && !inExtension) { 76 78 if (atts.getValue("xml:base") != null) { 79 String baseURI = atts.getValue("xml:base"); 80 entryType = Catalog.BASE; 81 entryArgs.add(baseURI); 82 baseURIStack.push(baseURI); 83 84 debug.message(4, "xml:base", baseURI); 85 86 try { 87 CatalogEntry ce = new CatalogEntry(entryType, entryArgs); 88 catalog.addEntry(ce); 89 } catch (CatalogException cex) { 90 if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { 91 debug.message(1, "Invalid catalog entry type", localName); 92 } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { 93 debug.message(1, "Invalid catalog entry (base)", localName); 94 } 95 } 96 97 entryType = -1; 98 entryArgs = new Vector (); 99 } else { 100 baseURIStack.push(baseURIStack.peek()); 101 } 102 103 if (localName.equals("uriSuffix")) { 104 if (checkAttributes(atts, "suffix", "uri")) { 105 entryType = Resolver.URISUFFIX; 106 entryArgs.add(atts.getValue("suffix")); 107 entryArgs.add(atts.getValue("uri")); 108 109 debug.message(4, "uriSuffix", 110 atts.getValue("suffix"), 111 atts.getValue("uri")); 112 } 113 } else if (localName.equals("systemSuffix")) { 114 if (checkAttributes(atts, "suffix", "uri")) { 115 entryType = Resolver.SYSTEMSUFFIX; 116 entryArgs.add(atts.getValue("suffix")); 117 entryArgs.add(atts.getValue("uri")); 118 119 debug.message(4, "systemSuffix", 120 atts.getValue("suffix"), 121 atts.getValue("uri")); 122 } 123 } else { 124 debug.message(1, "Invalid catalog entry type", localName); 126 } 127 128 if (entryType >= 0) { 129 try { 130 CatalogEntry ce = new CatalogEntry(entryType, entryArgs); 131 catalog.addEntry(ce); 132 } catch (CatalogException cex) { 133 if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { 134 debug.message(1, "Invalid catalog entry type", localName); 135 } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { 136 debug.message(1, "Invalid catalog entry", localName); 137 } 138 } 139 } 140 } 141 } 142 143 144 public void endElement (String namespaceURI, 145 String localName, 146 String qName) 147 throws SAXException { 148 149 super.endElement(namespaceURI, localName, qName); 150 151 boolean inExtension = inExtensionNamespace(); 154 155 int entryType = -1; 156 Vector entryArgs = new Vector (); 157 158 if (namespaceURI != null 159 && (extendedNamespaceName.equals(namespaceURI)) 160 && !inExtension) { 161 162 String popURI = (String ) baseURIStack.pop(); 163 String baseURI = (String ) baseURIStack.peek(); 164 165 if (!baseURI.equals(popURI)) { 166 entryType = catalog.BASE; 167 entryArgs.add(baseURI); 168 169 debug.message(4, "(reset) xml:base", baseURI); 170 171 try { 172 CatalogEntry ce = new CatalogEntry(entryType, entryArgs); 173 catalog.addEntry(ce); 174 } catch (CatalogException cex) { 175 if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { 176 debug.message(1, "Invalid catalog entry type", localName); 177 } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { 178 debug.message(1, "Invalid catalog entry (rbase)", localName); 179 } 180 } 181 } 182 } 183 } 184 } 185 | Popular Tags |