Debian Codegraph @

brut.apktool/apktool-lib/src/main/java/brut/androlib/res/util/ExtMXSerializer.java

raw
1 /*
2 * Copyright (C) 2010 Ryszard Wiśniewski <[email protected]>
3 * Copyright (C) 2010 Connor Tumbleson <[email protected]>
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package brut.androlib.res.util;
18
19 import org.xmlpull.renamed.MXSerializer;
20
21 import java.io.IOException;
22 import java.io.OutputStream;
23 import java.io.Writer;
24
25 public class ExtMXSerializer extends MXSerializer implements ExtXmlSerializer {
26 @Override
27 public void startDocument(String encoding, Boolean standalone)
28 throws IOException, IllegalArgumentException, IllegalStateException {
29 super.startDocument(encoding != null ? encoding : mDefaultEncoding, standalone);
30 this.newLine();
31 }
32
33 @Override
34 protected void writeAttributeValue(String value, Writer out) throws IOException {
35 if (mIsDisabledAttrEscape) {
36 out.write(value == null ? "" : value);
37 return;
38 }
39 super.writeAttributeValue(value, out);
40 }
41
42 @Override
43 public void setOutput(OutputStream os, String encoding) throws IOException {
44 super.setOutput(os, encoding != null ? encoding : mDefaultEncoding);
45 }
46
47 @Override
48 public Object getProperty(String name) throws IllegalArgumentException {
49 if (PROPERTY_DEFAULT_ENCODING.equals(name)) {
50 return mDefaultEncoding;
51 }
52 return super.getProperty(name);
53 }
54
55 @Override
56 public void setProperty(String name, Object value) throws IllegalArgumentException, IllegalStateException {
57 if (PROPERTY_DEFAULT_ENCODING.equals(name)) {
58 mDefaultEncoding = (String) value;
59 } else {
60 super.setProperty(name, value);
61 }
62 }
63
64 @Override
65 public ExtXmlSerializer newLine() throws IOException {
66 super.out.write(lineSeparator);
67 return this;
68 }
69
70 @Override
71 public void setDisabledAttrEscape(boolean disabled) {
72 mIsDisabledAttrEscape = disabled;
73 }
74
75 private String mDefaultEncoding;
76 private boolean mIsDisabledAttrEscape = false;
77
78 }