-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathSAXUtils.java
More file actions
157 lines (118 loc) · 6.66 KB
/
SAXUtils.java
File metadata and controls
157 lines (118 loc) · 6.66 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package org.anddev.andengine.util;
import org.xml.sax.Attributes;
/**
* (c) 2010 Nicolas Gramlich
* (c) 2011 Zynga Inc.
*
* @author Nicolas Gramlich
* @since 22:02:09 - 21.07.2010
*/
public class SAXUtils {
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
// ===========================================================
// Constructors
// ===========================================================
private SAXUtils() {}
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
// ===========================================================
// Methods
// ===========================================================
public static String getAttribute(final Attributes pAttributes, final String pAttributeName, final String pDefaultValue) {
final String value = pAttributes.getValue("", pAttributeName);
return (value != null) ? value : pDefaultValue;
}
public static String getAttributeOrThrow(final Attributes pAttributes, final String pAttributeName) {
final String value = pAttributes.getValue("", pAttributeName);
if(value != null) {
return value;
} else {
throw new IllegalArgumentException("No value found for attribute: '" + pAttributeName + "'");
}
}
public static boolean getBooleanAttribute(final Attributes pAttributes, final String pAttributeName, final boolean pDefaultValue) {
final String value = pAttributes.getValue("", pAttributeName);
return (value != null) ? Boolean.parseBoolean(value) : pDefaultValue;
}
public static boolean getBooleanAttributeOrThrow(final Attributes pAttributes, final String pAttributeName) {
return Boolean.parseBoolean(SAXUtils.getAttributeOrThrow(pAttributes, pAttributeName));
}
public static byte getByteAttribute(final Attributes pAttributes, final String pAttributeName, final byte pDefaultValue) {
final String value = pAttributes.getValue("", pAttributeName);
return (value != null) ? Byte.parseByte(value) : pDefaultValue;
}
public static byte getByteAttributeOrThrow(final Attributes pAttributes, final String pAttributeName) {
return Byte.parseByte(SAXUtils.getAttributeOrThrow(pAttributes, pAttributeName));
}
public static short getShortAttribute(final Attributes pAttributes, final String pAttributeName, final short pDefaultValue) {
final String value = pAttributes.getValue("", pAttributeName);
return (value != null) ? Short.parseShort(value) : pDefaultValue;
}
public static short getShortAttributeOrThrow(final Attributes pAttributes, final String pAttributeName) {
return Short.parseShort(SAXUtils.getAttributeOrThrow(pAttributes, pAttributeName));
}
public static int getIntAttribute(final Attributes pAttributes, final String pAttributeName, final int pDefaultValue) {
final String value = pAttributes.getValue("", pAttributeName);
return (value != null) ? Integer.parseInt(value) : pDefaultValue;
}
public static int getIntAttributeOrThrow(final Attributes pAttributes, final String pAttributeName) {
return Integer.parseInt(SAXUtils.getAttributeOrThrow(pAttributes, pAttributeName));
}
public static long getLongAttribute(final Attributes pAttributes, final String pAttributeName, final long pDefaultValue) {
final String value = pAttributes.getValue("", pAttributeName);
return (value != null) ? Long.parseLong(value) : pDefaultValue;
}
public static long getLongAttributeOrThrow(final Attributes pAttributes, final String pAttributeName) {
return Long.parseLong(SAXUtils.getAttributeOrThrow(pAttributes, pAttributeName));
}
public static float getFloatAttribute(final Attributes pAttributes, final String pAttributeName, final float pDefaultValue) {
final String value = pAttributes.getValue("", pAttributeName);
return (value != null) ? Float.parseFloat(value) : pDefaultValue;
}
public static float getFloatAttributeOrThrow(final Attributes pAttributes, final String pAttributeName) {
return Float.parseFloat(SAXUtils.getAttributeOrThrow(pAttributes, pAttributeName));
}
public static double getDoubleAttribute(final Attributes pAttributes, final String pAttributeName, final double pDefaultValue) {
final String value = pAttributes.getValue("", pAttributeName);
return (value != null) ? Double.parseDouble(value) : pDefaultValue;
}
public static double getDoubleAttributeOrThrow(final Attributes pAttributes, final String pAttributeName) {
return Double.parseDouble(SAXUtils.getAttributeOrThrow(pAttributes, pAttributeName));
}
public static void appendAttribute(final StringBuilder pStringBuilder, final String pName, final boolean pValue) {
SAXUtils.appendAttribute(pStringBuilder, pName, String.valueOf(pValue));
}
public static void appendAttribute(final StringBuilder pStringBuilder, final String pName, final byte pValue) {
SAXUtils.appendAttribute(pStringBuilder, pName, String.valueOf(pValue));
}
public static void appendAttribute(final StringBuilder pStringBuilder, final String pName, final short pValue) {
SAXUtils.appendAttribute(pStringBuilder, pName, String.valueOf(pValue));
}
public static void appendAttribute(final StringBuilder pStringBuilder, final String pName, final int pValue) {
SAXUtils.appendAttribute(pStringBuilder, pName, String.valueOf(pValue));
}
public static void appendAttribute(final StringBuilder pStringBuilder, final String pName, final long pValue) {
SAXUtils.appendAttribute(pStringBuilder, pName, String.valueOf(pValue));
}
public static void appendAttribute(final StringBuilder pStringBuilder, final String pName, final float pValue) {
SAXUtils.appendAttribute(pStringBuilder, pName, String.valueOf(pValue));
}
public static void appendAttribute(final StringBuilder pStringBuilder, final String pName, final double pValue) {
SAXUtils.appendAttribute(pStringBuilder, pName, String.valueOf(pValue));
}
public static void appendAttribute(final StringBuilder pStringBuilder, final String pName, final String pValue) {
pStringBuilder.append(' ').append(pName).append('=').append('\"').append(pValue).append('\"');
}
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}