1 3 56 57 package org.jboss.util.xml.catalog.readers; 58 59 import java.util.Vector ; 60 import org.jboss.util.xml.catalog.Catalog; 61 import org.jboss.util.xml.catalog.CatalogEntry; 62 import org.jboss.util.xml.catalog.CatalogException; 63 import org.jboss.util.xml.catalog.helpers.PublicId; 64 65 import org.xml.sax.*; 66 67 import javax.xml.parsers.*; 68 69 80 public class XCatalogReader extends SAXCatalogReader implements SAXCatalogParser { 81 84 protected Catalog catalog = null; 85 86 87 public void setCatalog (Catalog catalog) { 88 this.catalog = catalog; 89 } 90 91 92 public Catalog getCatalog () { 93 return catalog; 94 } 95 96 97 public XCatalogReader(SAXParserFactory parserFactory) { 98 super(parserFactory); 99 } 100 101 104 105 public void setDocumentLocator (Locator locator) { 106 return; 107 } 108 109 110 public void startDocument () 111 throws SAXException { 112 return; 113 } 114 115 116 public void endDocument () 117 throws SAXException { 118 return; 119 } 120 121 133 public void startElement (String namespaceURI, 134 String localName, 135 String qName, 136 Attributes atts) 137 throws SAXException { 138 139 int entryType = -1; 140 Vector entryArgs = new Vector (); 141 142 if (localName.equals("Base")) { 143 entryType = catalog.BASE; 144 entryArgs.add(atts.getValue("HRef")); 145 146 catalog.getCatalogManager().debug.message(4, "Base", atts.getValue("HRef")); 147 } else if (localName.equals("Delegate")) { 148 entryType = catalog.DELEGATE_PUBLIC; 149 entryArgs.add(atts.getValue("PublicId")); 150 entryArgs.add(atts.getValue("HRef")); 151 152 catalog.getCatalogManager().debug.message(4, "Delegate", 153 PublicId.normalize(atts.getValue("PublicId")), 154 atts.getValue("HRef")); 155 } else if (localName.equals("Extend")) { 156 entryType = catalog.CATALOG; 157 entryArgs.add(atts.getValue("HRef")); 158 159 catalog.getCatalogManager().debug.message(4, "Extend", atts.getValue("HRef")); 160 } else if (localName.equals("Map")) { 161 entryType = catalog.PUBLIC; 162 entryArgs.add(atts.getValue("PublicId")); 163 entryArgs.add(atts.getValue("HRef")); 164 165 catalog.getCatalogManager().debug.message(4, "Map", 166 PublicId.normalize(atts.getValue("PublicId")), 167 atts.getValue("HRef")); 168 } else if (localName.equals("Remap")) { 169 entryType = catalog.SYSTEM; 170 entryArgs.add(atts.getValue("SystemId")); 171 entryArgs.add(atts.getValue("HRef")); 172 173 catalog.getCatalogManager().debug.message(4, "Remap", 174 atts.getValue("SystemId"), 175 atts.getValue("HRef")); 176 } else if (localName.equals("XMLCatalog")) { 177 } else { 179 catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName); 181 } 182 183 if (entryType >= 0) { 184 try { 185 CatalogEntry ce = new CatalogEntry(entryType, entryArgs); 186 catalog.addEntry(ce); 187 } catch (CatalogException cex) { 188 if (cex.getExceptionType() == CatalogException.INVALID_ENTRY_TYPE) { 189 catalog.getCatalogManager().debug.message(1, "Invalid catalog entry type", localName); 190 } else if (cex.getExceptionType() == CatalogException.INVALID_ENTRY) { 191 catalog.getCatalogManager().debug.message(1, "Invalid catalog entry", localName); 192 } 193 } 194 } 195 } 196 197 198 public void endElement (String namespaceURI, 199 String localName, 200 String qName) 201 throws SAXException { 202 return; 203 } 204 205 206 public void characters (char ch[], int start, int length) 207 throws SAXException { 208 return; 209 } 210 211 212 public void ignorableWhitespace (char ch[], int start, int length) 213 throws SAXException { 214 return; 215 } 216 217 218 public void processingInstruction (String target, String data) 219 throws SAXException { 220 return; 221 } 222 } 223 | Popular Tags |