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.lang.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
47
48 public class VersionFilter extends XMLFilterImpl {
49
50
51
52
53 private int inVersionElement;
54
55
56
57
58
59 public VersionFilter(XMLReader parent) {
60 super(parent);
61 }
62
63 public static String[] FILTERED_PROPERTIES = new String[]{
64 "jcr:predecessors",
65 "jcr:baseVersion",
66 "jcr:versionHistory",
67 "jcr:isCheckedOut",
68 "jcr:created",
69 "mgnl:sequenceposition"
70 };
71
72 public static String[] FILTERED_NODES = new String[]{
73 "jcr:system",
74 };
75
76
77
78
79 @Override
80 public void endElement(String uri, String localName, String qName) throws SAXException {
81
82 if (inVersionElement > 0) {
83 inVersionElement--;
84 return;
85 }
86
87 super.endElement(uri, localName, qName);
88 }
89
90
91
92
93 @Override
94 public void characters(char[] ch, int start, int length) throws SAXException {
95
96 if (inVersionElement == 0) {
97 super.characters(ch, start, length);
98 }
99 }
100
101
102
103
104 @Override
105 public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
106
107 if (inVersionElement > 0) {
108 inVersionElement++;
109 return;
110 }
111 if ("sv:node".equals(qName)) {
112 String attName = atts.getValue("sv:name");
113 if (attName != null && ArrayUtils.contains(FILTERED_NODES, attName)) {
114 inVersionElement++;
115 return;
116 }
117 } else if ("sv:property".equals(qName)) {
118 String attName = atts.getValue("sv:name");
119 if (attName != null && ArrayUtils.contains(FILTERED_PROPERTIES, attName)) {
120 inVersionElement++;
121 return;
122 }
123 }
124
125 super.startElement(uri, localName, qName, atts);
126 }
127
128 }