Revision 989 org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.lib/org.gvsig.scripting.lib.impl/src/main/java/org/gvsig/scripting/impl/AbstractUnit.java
AbstractUnit.java | ||
---|---|---|
4 | 4 |
import java.beans.PropertyChangeListener; |
5 | 5 |
import java.io.File; |
6 | 6 |
import java.io.IOException; |
7 |
import java.util.ArrayList; |
|
7 | 8 |
import java.util.HashMap; |
8 | 9 |
import java.util.HashSet; |
9 | 10 |
import java.util.List; |
10 | 11 |
import java.util.Map; |
11 | 12 |
import java.util.Set; |
12 |
import java.util.logging.Level; |
|
13 | 13 |
|
14 | 14 |
import org.ini4j.Ini; |
15 | 15 |
import org.slf4j.Logger; |
16 | 16 |
import org.slf4j.LoggerFactory; |
17 | 17 |
import org.apache.commons.io.FilenameUtils; |
18 | 18 |
import org.apache.commons.lang3.BooleanUtils; |
19 |
import org.apache.commons.lang3.StringUtils; |
|
19 | 20 |
import org.gvsig.scripting.ScriptingFolder; |
20 | 21 |
import org.gvsig.scripting.ScriptingManager; |
21 | 22 |
import org.gvsig.scripting.ScriptingUnit; |
... | ... | |
158 | 159 |
@Override |
159 | 160 |
public void setId(String id) { |
160 | 161 |
firePropertyChangeListener("id", id, this.id); |
161 |
if (this instanceof ScriptingFolder) { |
|
162 |
this.id = id; |
|
163 |
} else { |
|
164 |
this.id = FilenameUtils.getBaseName(id); |
|
165 |
} |
|
162 |
this.id = FilenameUtils.getBaseName(id); |
|
166 | 163 |
} |
167 | 164 |
|
168 | 165 |
@Override |
... | ... | |
176 | 173 |
return this.parent; |
177 | 174 |
} |
178 | 175 |
|
179 |
private String toStringNotNull(String s) { |
|
180 |
if (s == null) { |
|
181 |
return ""; |
|
176 |
public String getUserPath() { |
|
177 |
List<String> parts = new ArrayList<>(); |
|
178 |
ScriptingUnit unit = this; |
|
179 |
while( unit!=null ) { |
|
180 |
parts.add(0, unit.getName()); |
|
181 |
unit = unit.getParent(); |
|
182 | 182 |
} |
183 |
return s;
|
|
183 |
return String.join("/", parts);
|
|
184 | 184 |
} |
185 |
|
|
185 |
|
|
186 | 186 |
protected void save(Ini prefs) { |
187 |
prefs.put("Unit", "type", toStringNotNull(this.getTypeName()));
|
|
187 |
prefs.put("Unit", "type", StringUtils.defaultString(this.getTypeName()));
|
|
188 | 188 |
prefs.put("Unit", "name", this.getName()); |
189 |
prefs.put("Unit", "description", toStringNotNull(this.getDescription()));
|
|
190 |
prefs.put("Unit", "createdBy", toStringNotNull(this.getCreatedBy()));
|
|
191 |
prefs.put("Unit", "version", toStringNotNull(this.getVersion()));
|
|
189 |
prefs.put("Unit", "description", StringUtils.defaultString(this.getDescription()));
|
|
190 |
prefs.put("Unit", "createdBy", StringUtils.defaultString(this.getCreatedBy()));
|
|
191 |
prefs.put("Unit", "version", StringUtils.defaultString(this.getVersion()));
|
|
192 | 192 |
|
193 | 193 |
if( this.properties!=null ) { |
194 | 194 |
for (Map.Entry<String, String> property : properties.entrySet()) { |
... | ... | |
202 | 202 |
} catch (IOException e) { |
203 | 203 |
File f = prefs.getFile(); |
204 | 204 |
String fname = (f == null) ? "(null)" : f.getAbsolutePath(); |
205 |
logger.warn("Can't save inf file '" + fname + "'."); |
|
205 |
String msg = "Can't save inf file '" + fname + "'."; |
|
206 |
logger.warn(msg); |
|
207 |
throw new RuntimeException(msg, e); |
|
206 | 208 |
} |
207 | 209 |
|
208 | 210 |
} |
Also available in: Unified diff