| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package net.sf.antcontrib.inifile; |
| 17 |
|
| 18 |
import java.io.IOException; |
| 19 |
import java.io.Writer; |
| 20 |
import java.util.*; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class IniSection |
| 32 |
implements IniPart |
| 33 |
{ |
| 34 |
private String name; |
| 35 |
private List properties; |
| 36 |
private Map propertyMap; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public IniSection() |
| 42 |
{ |
| 43 |
super(); |
| 44 |
this.propertyMap = new HashMap(); |
| 45 |
this.properties = new ArrayList(); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public IniSection(String name) |
| 54 |
{ |
| 55 |
this(); |
| 56 |
this.name = name; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public List getProperties() |
| 65 |
{ |
| 66 |
return properties; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public String getName() |
| 74 |
{ |
| 75 |
return name; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public void setName(String name) |
| 84 |
{ |
| 85 |
this.name = name; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public IniProperty getProperty(String name) |
| 93 |
{ |
| 94 |
return (IniProperty)propertyMap.get(name); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public void setProperty(IniProperty property) |
| 102 |
{ |
| 103 |
IniProperty prop = (IniProperty)propertyMap.get(property.getName()); |
| 104 |
if (prop != null) |
| 105 |
{ |
| 106 |
int idx = properties.indexOf(prop); |
| 107 |
properties.set(idx, property); |
| 108 |
} |
| 109 |
else |
| 110 |
{ |
| 111 |
properties.add(property); |
| 112 |
} |
| 113 |
|
| 114 |
propertyMap.put(property.getName(), property); |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
public void removeProperty(String name) |
| 122 |
{ |
| 123 |
IniProperty prop = (IniProperty)propertyMap.get(name); |
| 124 |
if (prop != null) |
| 125 |
{ |
| 126 |
int idx = properties.indexOf(prop); |
| 127 |
properties.remove(idx); |
| 128 |
propertyMap.remove(name); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
public void write(Writer writer) |
| 134 |
throws IOException |
| 135 |
{ |
| 136 |
writer.write("[" + name + "]"); |
| 137 |
writer.write(System.getProperty("line.separator")); |
| 138 |
Iterator it = properties.iterator(); |
| 139 |
IniProperty prop = null; |
| 140 |
while (it.hasNext()) |
| 141 |
{ |
| 142 |
prop = (IniProperty)it.next(); |
| 143 |
prop.write(writer); |
| 144 |
writer.write(System.getProperty("line.separator")); |
| 145 |
} |
| 146 |
} |
| 147 |
} |