1 package info.magnolia.cms.core.ie.filters; 2 3 import org.xml.sax.Attributes ; 4 import org.xml.sax.SAXException ; 5 import org.xml.sax.XMLReader ; 6 import org.xml.sax.helpers.AttributesImpl ; 7 import org.xml.sax.helpers.XMLFilterImpl ; 8 9 10 13 public class MagnoliaV2Filter extends XMLFilterImpl { 14 15 18 private int inMetadataElement; 19 20 private boolean skipNode; 21 22 private boolean skipProperty; 23 24 28 public MagnoliaV2Filter(XMLReader parent) { 29 super(parent); 30 } 31 32 35 public void endElement(String uri, String localName, String qName) throws SAXException { 36 37 if (inMetadataElement > 0) { 38 inMetadataElement--; 39 } 40 41 if (skipNode && "sv:node".equals(qName)) { 42 skipNode = false; 43 return; 44 } 45 46 if (skipProperty) { 47 if ("sv:property".equals(qName)) { 48 skipProperty = false; 49 } 50 return; 51 } 52 53 super.endElement(uri, localName, qName); 54 } 55 56 59 public void characters(char[] ch, int start, int length) throws SAXException { 60 super.characters(ch, start, length); 63 } 65 66 69 public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { 70 71 if (inMetadataElement > 0) { 72 inMetadataElement++; 73 } 74 75 String svname = atts.getValue("sv:name"); 76 77 if ("sv:node".equals(qName) && "MetaData".equals(svname)) { 78 inMetadataElement++; 79 } 80 81 if (inMetadataElement > 0) { 82 if ("sv:node".equals(qName) && "jcr:content".equals(svname)) { 85 skipNode = true; 86 return; 87 } 88 if ("sv:property".equals(qName) 89 && ("sequenceposition".equals(svname) || "jcr:primaryType".equals(svname) || "jcr:isCheckedOut" 90 .equals(svname))) { 91 skipProperty = true; 92 return; 93 } 94 if ("sv:property".equals(qName) 95 && ("Data".equals(svname) || "template".equals(svname) || "authorid".equals(svname) || "title" 96 .equals(svname))) { 97 atts = new AttributesImpl (); 98 ((AttributesImpl ) atts).addAttribute(uri, "name", "sv:name", uri, "mgnl:" + svname); 99 ((AttributesImpl ) atts).addAttribute(uri, "type", "sv:type", uri, "String"); 100 } 101 102 else if ("sv:property".equals(qName) && ("creationdate".equals(svname) || "lastmodified".equals(svname))) { 103 atts = new AttributesImpl (); 104 ((AttributesImpl ) atts).addAttribute(uri, "name", "sv:name", uri, "mgnl:" + svname); 105 ((AttributesImpl ) atts).addAttribute(uri, "type", "sv:type", uri, "Date"); 106 } 107 108 } 109 110 super.startElement(uri, localName, qName, atts); 111 112 if ("sv:node".equals(qName) && "MetaData".equals(svname)) { 113 114 119 String atturi = atts.getURI(0); 120 AttributesImpl atts2 = new AttributesImpl (); 121 atts2.addAttribute(uri, "name", "sv:name", atturi, "jcr:primaryType"); 122 atts2.addAttribute(uri, "type", "sv:type", atturi, "Name"); 123 124 super.startElement(uri, "property", "sv:property", atts2); 125 super.startElement(uri, "value", "sv:value", new AttributesImpl ()); 126 super.characters(new char[]{'m', 'g', 'n', 'l', ':', 'm', 'e', 't', 'a', 'D', 'a', 't', 'a'}, 0, 13); 127 super.endElement(uri, "value", "sv:value"); 128 super.endElement(uri, "property", "sv:property"); 129 } 130 } 131 } | Popular Tags |