1 4 package info.magnolia.cms.core.ie.filters; 5 6 import org.xml.sax.Attributes ; 7 import org.xml.sax.SAXException ; 8 import org.xml.sax.XMLReader ; 9 import org.xml.sax.helpers.XMLFilterImpl ; 10 11 12 public class ImportXmlRootFilter extends XMLFilterImpl { 13 14 public boolean rootNodeFound = false; 16 17 private boolean isRootNode = false; 18 19 private boolean isPrimaryTypeProperty = false; 20 21 private boolean isPrimaryTypeValue = false; 22 23 26 private int inFilterElement; 27 28 public ImportXmlRootFilter(XMLReader parent) { 29 super(parent); 30 } 31 32 35 public void endElement(String uri, String localName, String qName) throws SAXException { 36 37 if (inFilterElement > 0) { 38 inFilterElement--; 39 return; 40 } 41 42 super.endElement(uri, localName, qName); 43 } 44 45 48 public boolean rootNodeWasFound() { 49 return rootNodeFound; 50 } 51 52 55 public void characters(char[] ch, int start, int length) throws SAXException { 56 if (inFilterElement == 0) { 58 if (this.isPrimaryTypeValue) { 60 this.isRootNode = false; 61 this.isPrimaryTypeProperty = false; 62 this.isPrimaryTypeValue = false; 63 64 super.characters("mgnl:content".toCharArray(), 0, "mgnl:content".length()); 65 } 66 else { 67 super.characters(ch, start, length); 68 } 69 } 70 } 71 72 75 80 public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { 81 if (inFilterElement > 0) { 83 inFilterElement++; 84 return; 85 } 86 87 if ("sv:node".equals(qName)) { String attName = atts.getValue("sv:name"); if ("jcr:root".equals(attName)) { 92 this.rootNodeFound = true; 93 this.isRootNode = true; 94 } 95 96 if ("jcr:system".equals(attName)) { inFilterElement++; 98 return; 99 } 100 } 101 102 if (this.isRootNode && "sv:property".equals(qName) && "jcr:primaryType".equals(atts.getValue("sv:name"))) { 104 this.isPrimaryTypeProperty = true; 105 } 106 107 if (this.isPrimaryTypeProperty && "sv:value".equals(qName)) { 108 this.isPrimaryTypeValue = true; 109 } 110 111 super.startElement(uri, localName, qName, atts); 112 } 113 } | Popular Tags |