KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > exchange > simple > FrozenElementFilter


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.exchange.simple;
14
15 import info.magnolia.cms.core.ie.filters.VersionFilter;
16
17 import org.xml.sax.Attributes JavaDoc;
18 import org.xml.sax.SAXException JavaDoc;
19 import org.xml.sax.XMLReader JavaDoc;
20 import org.xml.sax.helpers.AttributesImpl JavaDoc;
21
22
23 /**
24  * this filter converts frozen nodes to mimic actual state of a node, this is only meant to be used while activation
25  * Taken from:
26  * @see info.magnolia.cms.core.ie.filters.VersionFilter $Id: FrozenElementFilter.java 6341 2006-09-12 09:18:27Z philipp $
27  */

28 class FrozenElementFilter extends VersionFilter {
29
30     /**
31      * if != 0 we are in the middle of a filtered element.
32      */

33     private int inVersionElement;
34
35     /**
36      * original node name
37      */

38     private String JavaDoc nodeName;
39
40     /**
41      * Instantiates a new version filter.
42      * @param parent wrapped XMLReader
43      */

44     protected FrozenElementFilter(XMLReader JavaDoc parent) {
45         super(parent);
46     }
47
48     protected void setNodeName(String JavaDoc name) {
49         this.nodeName = name;
50     }
51
52     /**
53      * @see org.xml.sax.helpers.XMLFilterImpl#endElement(String, String, String)
54      */

55     public void endElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName) throws SAXException JavaDoc {
56
57         if (inVersionElement > 0) {
58             inVersionElement--;
59             return;
60         }
61
62         super.endElement(uri, localName, qName);
63     }
64
65     /**
66      * @see org.xml.sax.helpers.XMLFilterImpl#characters(char[], int, int)
67      */

68     public void characters(char[] ch, int start, int length) throws SAXException JavaDoc {
69         // filter content
70
if (inVersionElement == 0) {
71             super.characters(ch, start, length);
72         }
73     }
74
75     /**
76      * @see org.xml.sax.helpers.XMLFilterImpl#startElement(String, String, String, org.xml.sax.Attributes)
77      */

78     public void startElement(String JavaDoc uri, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc atts) throws SAXException JavaDoc {
79
80         if (inVersionElement > 0) {
81             inVersionElement++;
82             return;
83         }
84         if ("sv:property".equals(qName)) { //$NON-NLS-1$
85
String JavaDoc attName = atts.getValue("sv:name"); //$NON-NLS-1$
86
if (attName != null) {
87                 if ("jcr:predecessors".equals(attName)
88                     || "jcr:baseVersion".equals(attName)
89                     || "jcr:primaryType".equals(attName)
90                     || "jcr:uuid".equals(attName)
91                     || "jcr:mixinTypes".equals(attName)
92                     || "jcr:isCheckedOut".equals(attName)
93                     || "jcr:created".equals(attName)
94                     || "mgnl:sequenceposition".equals(attName)
95                     || "jcr:versionHistory" //$NON-NLS-1$
96
.equals(attName)) {
97                     inVersionElement++;
98                     return;
99                 }
100                 else if ("jcr:frozenPrimaryType".equals(attName)) {
101                     AttributesImpl JavaDoc attributesImpl = new AttributesImpl JavaDoc(atts);
102                     int index = attributesImpl.getIndex("sv:name");
103                     attributesImpl.setValue(index, "jcr:primaryType");
104                     atts = attributesImpl;
105                 }
106                 else if ("jcr:frozenMixinTypes".equals(attName)) {
107                     AttributesImpl JavaDoc attributesImpl = new AttributesImpl JavaDoc(atts);
108                     int index = attributesImpl.getIndex("sv:name");
109                     attributesImpl.setValue(index, "jcr:mixinTypes");
110                     atts = attributesImpl;
111                 }
112                 else if ("jcr:frozenUuid".equals(attName)) {
113                     AttributesImpl JavaDoc attributesImpl = new AttributesImpl JavaDoc(atts);
114                     int index = attributesImpl.getIndex("sv:name");
115                     attributesImpl.setValue(index, "jcr:uuid");
116                     atts = attributesImpl;
117                 }
118             }
119         }
120         else if ("sv:node".equals(qName)) {
121             String JavaDoc attName = atts.getValue("sv:name");
122             if (attName != null) {
123                 if ("jcr:frozenNode".equals(attName)) {
124                     AttributesImpl JavaDoc attributesImpl = new AttributesImpl JavaDoc(atts);
125                     int index = attributesImpl.getIndex("sv:name");
126                     attributesImpl.setValue(index, this.nodeName);
127                     atts = attributesImpl;
128                 }
129             }
130         }
131
132         super.startElement(uri, localName, qName, atts);
133     }
134
135 }
136
Popular Tags