1 22 23 24 package org.xquark.xquery.metadata; 25 26 import java.util.Collection ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 30 import org.xml.sax.SAXException ; 31 import org.xml.sax.helpers.AttributesImpl ; 32 import org.xquark.schema.Schema; 33 import org.xquark.schema.SchemaReader; 34 import org.xquark.util.DefaultXMLReader; 35 import org.xquark.xpath.XTreeReader; 36 37 38 public class MetaHandler 39 extends DefaultXMLReader { 40 private static final String RCSRevision = "$Revision: 1.1 $"; 41 private static final String RCSName = "$Name: $"; 42 43 private MetaDataImpl metadata = null; 44 private MetaWrapper metawrapper = null; 45 private MetaCollection metacollection = null; 46 private AttributesImpl atts = new AttributesImpl (); 47 private String label = "ipo"; 48 49 public MetaHandler(MetaDataImpl metadata) { this.metadata = metadata; } 50 51 public MetaHandler(MetaWrapper metawrapper) { this.metawrapper = metawrapper; } 52 53 public MetaHandler(MetaCollection metacollection) { this.metacollection = metacollection; } 54 55 58 public void parse(String systemId) throws SAXException , java.io.IOException { 59 if (metacollection != null) { browseMetaCollection(metacollection); } 60 else { 61 if (metawrapper != null) { browseMetaWrapper(metawrapper); } 62 else { 63 if (metadata != null) { browseMetaData(metadata); } 64 } 65 } 66 } 67 68 public void browseMetaCollection(MetaCollection metacollection) throws SAXException , java.io.IOException { 69 atts.addAttribute("", "name", "", "CDATA", metacollection.getCollectionName()); 70 contentHandler.startElement("", "collection", "", atts); 71 atts.clear() ; 72 XTreeReader reader = new XTreeReader(metacollection.getXTree()); 73 reader.setFeature(XTreeReader.FRAGMENT_FEATURE, true) ; 74 reader.setContentHandler(contentHandler) ; 75 reader.parse(""); 76 contentHandler.endElement("", "collection", ""); 77 } 78 79 public void startPrint(String sourcename, String label) throws SAXException , java.io.IOException { 80 contentHandler.startDocument() ; 81 82 atts.addAttribute("xmlns", "xsi", "", "CDATA", "http://www.w3.org/2001/XMLSchema-instance"); 83 atts.addAttribute("xmlns", label, "", "CDATA", "http://www.xquark.org/WRAPPERMETADATA"); 84 atts.addAttribute("xsi", "schemaLocation", "", "CDATA", "http://www.xquark.org/XMLDBC/Metadata XMLDBCMetaData.xsd"); 85 atts.addAttribute("", "source", "", "CDATA", sourcename); 86 contentHandler.startElement(label, "metadata", "", atts); 87 88 atts.clear() ; 89 90 contentHandler.startElement("", "schemas", "", atts); 91 Collection schemas; 92 93 if (metawrapper != null) { 94 schemas = metawrapper.getMetaData().getSchemaManager().getSchemas(); 95 } 96 else { 97 schemas = metadata.getSchemaManager().getSchemas(); 98 } 99 100 if (schemas != null) { 101 for (Iterator iterator = schemas.iterator(); iterator.hasNext();) { 102 Schema schema = (Schema)iterator.next(); 103 if (schema == null) { 104 continue; 105 } 106 String namespace = schema.getNamespace(); 107 if (namespace.startsWith("http://www.w3.org")) { 108 continue; 109 } 110 SchemaReader schemaReader = new SchemaReader(null); 112 schemaReader.setContentHandler(contentHandler) ; 113 schemaReader.parse(schema, false); 114 } 116 } 117 118 contentHandler.endElement("", "schemas", ""); 119 } 120 121 private void endPrint(String label) throws SAXException , java.io.IOException { 122 contentHandler.endElement(label, "metadata", ""); 123 } 124 125 public void browseMetaWrapper(MetaWrapper metawrapper) throws SAXException , java.io.IOException { 126 startPrint(metawrapper.getSourceName(), label); 127 atts.clear() ; 128 contentHandler.startElement("", "collections", "", atts); 129 Iterator values = metawrapper.getMetaCollections().values().iterator(); 130 131 while (values.hasNext()) { 132 MetaCollection metacollection = (MetaCollection)values.next(); 133 browseMetaCollection(metacollection); 134 } 135 136 contentHandler.endElement("", "collections", ""); 137 endPrint(label); 138 } 139 140 public void browseMetaData(MetaDataImpl metadata) throws SAXException , java.io.IOException { 141 atts.clear() ; 142 startPrint("ACCESSOR-SOURCE", label); 143 contentHandler.startElement("", "collections", "", atts); 144 145 for (Iterator e = metadata.getMetaWrappers().values().iterator(); e.hasNext();) { 146 MetaWrapper wrapperi = (MetaWrapper)e.next(); 147 HashMap metacollections = wrapperi.getMetaCollections(); 148 Iterator values = metacollections.values().iterator(); 149 150 while (values.hasNext()) { 151 MetaCollection metacollection = (MetaCollection)values.next(); 152 browseMetaCollection(metacollection); 153 } 154 } 155 156 contentHandler.endElement("", "collections", ""); 157 endPrint(label); 158 } 159 160 } 161 162 163 164 | Popular Tags |