1 3 56 57 package org.jboss.util.xml.catalog.readers; 58 59 import java.util.Vector ; 60 61 import org.jboss.util.xml.catalog.Catalog; 62 import org.jboss.util.xml.catalog.CatalogEntry; 63 import org.jboss.util.xml.catalog.CatalogException; 64 import org.jboss.util.xml.catalog.Resolver; 65 66 import org.xml.sax.*; 67 import org.w3c.dom.*; 68 69 80 public class ExtendedXMLCatalogReader extends OASISXMLCatalogReader { 81 82 public static final String extendedNamespaceName = "http://nwalsh.com/xcatalog/1.0"; 83 84 96 public void startElement (String namespaceURI, 97 String localName, 98 String qName, 99 Attributes atts) 100 throws SAXException { 101 102 boolean inExtension = inExtensionNamespace(); 106 107 super.startElement(namespaceURI, localName, qName, atts); 108 109 int entryType = -1; 110 Vector entryArgs = new Vector (); 111 112 if (namespaceURI != null && extendedNamespaceName.equals(namespaceURI) 113 && !inExtension) { 114 116 if (atts.getValue("xml:base") != null) { 117 String baseURI = atts.getValue("xml:base"); 118 entryType = Catalog.BASE; 119 entryArgs.add(baseURI); 120 baseURIStack.push(baseURI); 121 122 debug.message(4, "xml:base", baseURI); 123 124 try { 125 CatalogEntry ce = new CatalogEntry(entryType, entryArgs); 126 catalog.addEntry(ce); 127 } catch (CatalogException cex) { 128 if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { 129 debug.message(1, "Invalid catalog entry type", localName); 130 } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { 131 debug.message(1, "Invalid catalog entry (base)", localName); 132 } 133 } 134 135 entryType = -1; 136 entryArgs = new Vector (); 137 } else { 138 baseURIStack.push(baseURIStack.peek()); 139 } 140 141 if (localName.equals("uriSuffix")) { 142 if (checkAttributes(atts, "suffix", "uri")) { 143 entryType = Resolver.URISUFFIX; 144 entryArgs.add(atts.getValue("suffix")); 145 entryArgs.add(atts.getValue("uri")); 146 147 debug.message(4, "uriSuffix", 148 atts.getValue("suffix"), 149 atts.getValue("uri")); 150 } 151 } else if (localName.equals("systemSuffix")) { 152 if (checkAttributes(atts, "suffix", "uri")) { 153 entryType = Resolver.SYSTEMSUFFIX; 154 entryArgs.add(atts.getValue("suffix")); 155 entryArgs.add(atts.getValue("uri")); 156 157 debug.message(4, "systemSuffix", 158 atts.getValue("suffix"), 159 atts.getValue("uri")); 160 } 161 } else { 162 debug.message(1, "Invalid catalog entry type", localName); 164 } 165 166 if (entryType >= 0) { 167 try { 168 CatalogEntry ce = new CatalogEntry(entryType, entryArgs); 169 catalog.addEntry(ce); 170 } catch (CatalogException cex) { 171 if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { 172 debug.message(1, "Invalid catalog entry type", localName); 173 } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { 174 debug.message(1, "Invalid catalog entry", localName); 175 } 176 } 177 } 178 } 179 } 180 181 182 public void endElement (String namespaceURI, 183 String localName, 184 String qName) 185 throws SAXException { 186 187 super.endElement(namespaceURI, localName, qName); 188 189 boolean inExtension = inExtensionNamespace(); 192 193 int entryType = -1; 194 Vector entryArgs = new Vector (); 195 196 if (namespaceURI != null 197 && (extendedNamespaceName.equals(namespaceURI)) 198 && !inExtension) { 199 200 String popURI = (String ) baseURIStack.pop(); 201 String baseURI = (String ) baseURIStack.peek(); 202 203 if (!baseURI.equals(popURI)) { 204 entryType = catalog.BASE; 205 entryArgs.add(baseURI); 206 207 debug.message(4, "(reset) xml:base", baseURI); 208 209 try { 210 CatalogEntry ce = new CatalogEntry(entryType, entryArgs); 211 catalog.addEntry(ce); 212 } catch (CatalogException cex) { 213 if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { 214 debug.message(1, "Invalid catalog entry type", localName); 215 } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { 216 debug.message(1, "Invalid catalog entry (rbase)", localName); 217 } 218 } 219 } 220 } 221 } 222 } 223 | Popular Tags |