AttributeListImpl.java
3.06 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
/*
* Decompiled with CFR 0_118.
*/
package com.day.crx.packaging.impl.proxy;
import com.day.crx.packaging.impl.proxy.AttributeList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
class AttributeListImpl
implements AttributeList {
private final Map<String, Value> attributes = new LinkedHashMap<String, Value>();
private boolean modified;
AttributeListImpl() {
}
public void addAttribute(String name, String value, char quoteChar) {
this.attributes.put(name.toLowerCase(), new Value(quoteChar, value));
}
public void addAttribute(String name, char quoteChar) {
this.attributes.put(name.toLowerCase(), null);
}
public void reset() {
this.attributes.clear();
this.modified = false;
}
@Override
public int attributeCount() {
return this.attributes.size();
}
@Override
public Iterator<String> attributeNames() {
return this.attributes.keySet().iterator();
}
@Override
public boolean containsAttribute(String name) {
return this.attributes.containsKey(name.toLowerCase());
}
@Override
public String getValue(String name) {
Value value = this.getValueEx(name);
if (value != null) {
return value.value;
}
return null;
}
@Override
public char getQuoteChar(String name) {
Value value = this.getValueEx(name);
if (value != null) {
return value.quoteChar;
}
return '\u0000';
}
@Override
public String getQuotedValue(String name) {
Value value = this.getValueEx(name);
if (value != null) {
return value.toString();
}
return null;
}
@Override
public void setValue(String name, String value) {
if (value == null) {
this.removeValue(name);
} else {
Value old = this.getValueEx(name);
if (old == null) {
this.addAttribute(name, value, '\"');
this.modified = true;
} else if (!old.value.equals(value)) {
this.addAttribute(name, value, old.quoteChar);
this.modified = true;
}
}
}
@Override
public void removeValue(String name) {
this.attributes.remove(name.toLowerCase());
this.modified = true;
}
@Override
public boolean isModified() {
return this.modified;
}
protected Value getValueEx(String name) {
return this.attributes.get(name.toLowerCase());
}
static class Value {
public final char quoteChar;
public final String value;
private String stringRep;
public Value(char quoteChar, String value) {
this.quoteChar = quoteChar;
this.value = value;
}
public String toString() {
if (this.stringRep == null) {
this.stringRep = "" + this.quoteChar + this.value + this.quoteChar;
}
return this.stringRep;
}
}
}