1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.internal.util;
18 
19 import android.annotation.NonNull;
20 
21 import org.xmlpull.v1.XmlPullParser;
22 import org.xmlpull.v1.XmlPullParserException;
23 
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.Reader;
27 import java.util.Objects;
28 
29 /**
30  * Wrapper which delegates all calls through to the given {@link XmlPullParser}.
31  */
32 public class XmlPullParserWrapper implements XmlPullParser {
33     private final XmlPullParser mWrapped;
34 
XmlPullParserWrapper(@onNull XmlPullParser wrapped)35     public XmlPullParserWrapper(@NonNull XmlPullParser wrapped) {
36         mWrapped = Objects.requireNonNull(wrapped);
37     }
38 
setFeature(String name, boolean state)39     public void setFeature(String name, boolean state) throws XmlPullParserException {
40         mWrapped.setFeature(name, state);
41     }
42 
getFeature(String name)43     public boolean getFeature(String name) {
44         return mWrapped.getFeature(name);
45     }
46 
setProperty(String name, Object value)47     public void setProperty(String name, Object value) throws XmlPullParserException {
48         mWrapped.setProperty(name, value);
49     }
50 
getProperty(String name)51     public Object getProperty(String name) {
52         return mWrapped.getProperty(name);
53     }
54 
setInput(Reader in)55     public void setInput(Reader in) throws XmlPullParserException {
56         mWrapped.setInput(in);
57     }
58 
setInput(InputStream inputStream, String inputEncoding)59     public void setInput(InputStream inputStream, String inputEncoding)
60             throws XmlPullParserException {
61         mWrapped.setInput(inputStream, inputEncoding);
62     }
63 
getInputEncoding()64     public String getInputEncoding() {
65         return mWrapped.getInputEncoding();
66     }
67 
defineEntityReplacementText(String entityName, String replacementText)68     public void defineEntityReplacementText(String entityName, String replacementText)
69             throws XmlPullParserException {
70         mWrapped.defineEntityReplacementText(entityName, replacementText);
71     }
72 
getNamespaceCount(int depth)73     public int getNamespaceCount(int depth) throws XmlPullParserException {
74         return mWrapped.getNamespaceCount(depth);
75     }
76 
getNamespacePrefix(int pos)77     public String getNamespacePrefix(int pos) throws XmlPullParserException {
78         return mWrapped.getNamespacePrefix(pos);
79     }
80 
getNamespaceUri(int pos)81     public String getNamespaceUri(int pos) throws XmlPullParserException {
82         return mWrapped.getNamespaceUri(pos);
83     }
84 
getNamespace(String prefix)85     public String getNamespace(String prefix) {
86         return mWrapped.getNamespace(prefix);
87     }
88 
getDepth()89     public int getDepth() {
90         return mWrapped.getDepth();
91     }
92 
getPositionDescription()93     public String getPositionDescription() {
94         return mWrapped.getPositionDescription();
95     }
96 
getLineNumber()97     public int getLineNumber() {
98         return mWrapped.getLineNumber();
99     }
100 
getColumnNumber()101     public int getColumnNumber() {
102         return mWrapped.getColumnNumber();
103     }
104 
isWhitespace()105     public boolean isWhitespace() throws XmlPullParserException {
106         return mWrapped.isWhitespace();
107     }
108 
getText()109     public String getText() {
110         return mWrapped.getText();
111     }
112 
getTextCharacters(int[] holderForStartAndLength)113     public char[] getTextCharacters(int[] holderForStartAndLength) {
114         return mWrapped.getTextCharacters(holderForStartAndLength);
115     }
116 
getNamespace()117     public String getNamespace() {
118         return mWrapped.getNamespace();
119     }
120 
getName()121     public String getName() {
122         return mWrapped.getName();
123     }
124 
getPrefix()125     public String getPrefix() {
126         return mWrapped.getPrefix();
127     }
128 
isEmptyElementTag()129     public boolean isEmptyElementTag() throws XmlPullParserException {
130         return mWrapped.isEmptyElementTag();
131     }
132 
getAttributeCount()133     public int getAttributeCount() {
134         return mWrapped.getAttributeCount();
135     }
136 
getAttributeNamespace(int index)137     public String getAttributeNamespace(int index) {
138         return mWrapped.getAttributeNamespace(index);
139     }
140 
getAttributeName(int index)141     public String getAttributeName(int index) {
142         return mWrapped.getAttributeName(index);
143     }
144 
getAttributePrefix(int index)145     public String getAttributePrefix(int index) {
146         return mWrapped.getAttributePrefix(index);
147     }
148 
getAttributeType(int index)149     public String getAttributeType(int index) {
150         return mWrapped.getAttributeType(index);
151     }
152 
isAttributeDefault(int index)153     public boolean isAttributeDefault(int index) {
154         return mWrapped.isAttributeDefault(index);
155     }
156 
getAttributeValue(int index)157     public String getAttributeValue(int index) {
158         return mWrapped.getAttributeValue(index);
159     }
160 
getAttributeValue(String namespace, String name)161     public String getAttributeValue(String namespace, String name) {
162         return mWrapped.getAttributeValue(namespace, name);
163     }
164 
getEventType()165     public int getEventType() throws XmlPullParserException {
166         return mWrapped.getEventType();
167     }
168 
next()169     public int next() throws XmlPullParserException, IOException {
170         return mWrapped.next();
171     }
172 
nextToken()173     public int nextToken() throws XmlPullParserException, IOException {
174         return mWrapped.nextToken();
175     }
176 
require(int type, String namespace, String name)177     public void require(int type, String namespace, String name)
178             throws XmlPullParserException, IOException {
179         mWrapped.require(type, namespace, name);
180     }
181 
nextText()182     public String nextText() throws XmlPullParserException, IOException {
183         return mWrapped.nextText();
184     }
185 
nextTag()186     public int nextTag() throws XmlPullParserException, IOException {
187         return mWrapped.nextTag();
188     }
189 }
190