01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.staxutils;
19:
20: import javax.xml.namespace.QName;
21: import javax.xml.stream.XMLStreamException;
22: import javax.xml.stream.XMLStreamReader;
23:
24: public class PartialXMLStreamReader extends DepthXMLStreamReader {
25: private QName endTag;
26: private boolean foundEnd;
27: private int endDepth;
28: private int currentEvent;
29:
30: public PartialXMLStreamReader(XMLStreamReader r, QName endTag) {
31: super (r);
32: this .endTag = endTag;
33: currentEvent = r.getEventType();
34: }
35:
36: @Override
37: public int next() throws XMLStreamException {
38: if (!foundEnd) {
39: currentEvent = super .next();
40:
41: if (currentEvent == START_ELEMENT
42: && getName().equals(endTag)) {
43: foundEnd = true;
44: endDepth = getDepth();
45: return START_ELEMENT;
46: }
47:
48: return currentEvent;
49: } else if (endDepth > 0) {
50: endDepth--;
51: currentEvent = END_ELEMENT;
52: } else {
53: currentEvent = END_DOCUMENT;
54: }
55:
56: return currentEvent;
57: }
58:
59: @Override
60: public int getEventType() {
61: return currentEvent;
62: }
63:
64: @Override
65: public boolean hasNext() {
66: return currentEvent != END_DOCUMENT;
67: }
68:
69: }
|