1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.importexport.filters;
35
36 import org.apache.commons.lang3.ArrayUtils;
37 import org.xml.sax.Attributes;
38 import org.xml.sax.SAXException;
39 import org.xml.sax.XMLReader;
40 import org.xml.sax.helpers.XMLFilterImpl;
41
42
43
44
45
46 public class VersionFilter extends XMLFilterImpl {
47
48
49
50
51 private int inVersionElement;
52
53
54
55
56
57
58 public VersionFilter(XMLReader parent) {
59 super(parent);
60 }
61
62 public static String[] FILTERED_PROPERTIES = new String[]{
63 "jcr:predecessors",
64 "jcr:baseVersion",
65 "jcr:versionHistory",
66 "jcr:isCheckedOut",
67 "jcr:created",
68 "mgnl:sequenceposition"
69 };
70
71 public static String[] FILTERED_NODES = new String[]{
72 "jcr:system",
73 };
74
75
76
77
78 @Override
79 public void endElement(String uri, String localName, String qName) throws SAXException {
80
81 if (inVersionElement > 0) {
82 inVersionElement--;
83 return;
84 }
85
86 super.endElement(uri, localName, qName);
87 }
88
89
90
91
92 @Override
93 public void characters(char[] ch, int start, int length) throws SAXException {
94
95 if (inVersionElement == 0) {
96 super.characters(ch, start, length);
97 }
98 }
99
100
101
102
103 @Override
104 public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
105
106 if (inVersionElement > 0) {
107 inVersionElement++;
108 return;
109 }
110 if ("sv:node".equals(qName)) {
111 String attName = atts.getValue("sv:name");
112 if (attName != null && ArrayUtils.contains(FILTERED_NODES, attName)) {
113 inVersionElement++;
114 return;
115 }
116 } else if ("sv:property".equals(qName)) {
117 String attName = atts.getValue("sv:name");
118 if (attName != null && ArrayUtils.contains(FILTERED_PROPERTIES, attName)) {
119 inVersionElement++;
120 return;
121 }
122 }
123
124 super.startElement(uri, localName, qName, atts);
125 }
126
127 }