Revision 1095
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/persistence/impl/AbstractPersistentState.java | ||
---|---|---|
832 | 832 |
} |
833 | 833 |
} |
834 | 834 |
|
835 |
public void derelativizeFiles(File rootFolder) {
|
|
836 |
PersistentContext context = this.getContext();
|
|
837 |
URI cwd = new File(System.getProperty("user.dir")).toURI();
|
|
835 |
public void derelativizeFiles(File rootFolder) {
|
|
836 |
PersistentContext context = this.getContext();
|
|
837 |
//URI cwd = new File(System.getProperty("user.dir")).toURI();
|
|
838 | 838 |
|
839 |
Iterator statesIterator = context.iterator();
|
|
840 |
String className = null;
|
|
839 |
Iterator statesIterator = context.iterator();
|
|
840 |
String className = null;
|
|
841 | 841 |
|
842 |
while (statesIterator.hasNext()) {
|
|
843 |
PersistentState aState = (PersistentState) statesIterator.next();
|
|
844 |
try {
|
|
845 |
className = aState.getTheClassName();
|
|
846 |
} catch (Throwable e) {
|
|
847 |
className = "Unknown";
|
|
848 |
}
|
|
849 |
try {
|
|
850 |
DynStruct definition = aState.getDefinition();
|
|
851 |
DynField[] fields = definition.getDynFields();
|
|
852 |
for( int i=0; i<fields.length; i++) {
|
|
853 |
DynField field = fields[i];
|
|
854 |
if (field.getType() == DataTypes.FILE
|
|
855 |
|| field.getType() == DataTypes.FOLDER) {
|
|
856 |
try {
|
|
857 |
File value = aState.getFile(field.getName());
|
|
858 |
value = FileTools.derelativizeFile(rootFolder, value);
|
|
859 |
aState.set(field.getName(), value);
|
|
860 |
} catch (PersistenceException e) {
|
|
861 |
logger.warn(
|
|
862 |
"Can't fix field '" + field.getName()
|
|
863 |
+ "' for class '"
|
|
864 |
+ definition.getName() + "'.", e);
|
|
865 |
}
|
|
866 |
} else if (field.getType() == DataTypes.URL) {
|
|
867 |
try {
|
|
868 |
URL value = aState.getURL(field.getName());
|
|
869 |
if ("FILE".equalsIgnoreCase(value.getProtocol())) {
|
|
870 |
if (!value.getFile().startsWith("/")){
|
|
871 |
File file = new File(value.getPath());
|
|
872 |
file = FileTools.derelativizeFile(rootFolder, file);
|
|
842 |
while (statesIterator.hasNext()) {
|
|
843 |
PersistentState aState = (PersistentState) statesIterator.next();
|
|
844 |
try {
|
|
845 |
className = aState.getTheClassName();
|
|
846 |
} catch (Throwable e) {
|
|
847 |
className = "Unknown";
|
|
848 |
}
|
|
849 |
try {
|
|
850 |
DynStruct definition = aState.getDefinition();
|
|
851 |
DynField[] fields = definition.getDynFields();
|
|
852 |
for (int i = 0; i < fields.length; i++) {
|
|
853 |
DynField field = fields[i];
|
|
854 |
if (field.getType() == DataTypes.FILE
|
|
855 |
|| field.getType() == DataTypes.FOLDER) {
|
|
856 |
try {
|
|
857 |
File value = aState.getFile(field.getName());
|
|
858 |
value = FileTools.derelativizeFile(rootFolder, value);
|
|
859 |
aState.set(field.getName(), value);
|
|
860 |
} catch (PersistenceException e) {
|
|
861 |
logger.warn(
|
|
862 |
"Can't fix field '" + field.getName()
|
|
863 |
+ "' for class '"
|
|
864 |
+ definition.getName() + "'.", e);
|
|
865 |
}
|
|
866 |
} else if (field.getType() == DataTypes.URL) {
|
|
867 |
try {
|
|
868 |
URL value = aState.getURL(field.getName());
|
|
869 |
if ("FILE".equalsIgnoreCase(value.getProtocol())) {
|
|
870 |
if (!value.getFile().startsWith("/")) {
|
|
871 |
File file = FileUtils.toFile(value);
|
|
872 |
file = FileTools.derelativizeFile(rootFolder, file);
|
|
873 | 873 |
value = file.toURI().toURL(); |
874 |
aState.set(field.getName(), value);
|
|
875 |
}
|
|
876 |
}
|
|
877 |
} catch (PersistenceException e) {
|
|
878 |
// do nothing
|
|
879 |
} catch (MalformedURLException e) {
|
|
880 |
// do nothing
|
|
881 |
}
|
|
874 |
aState.set(field.getName(), value);
|
|
875 |
}
|
|
876 |
}
|
|
877 |
} catch (PersistenceException e) {
|
|
878 |
// do nothing
|
|
879 |
} catch (MalformedURLException e) {
|
|
880 |
// do nothing
|
|
881 |
} |
|
882 | 882 |
|
883 |
} else if (field.getType() == DataTypes.URI) { |
|
884 |
try { |
|
885 |
URI value = aState.getURI(field.getName()); |
|
886 |
if (value.getScheme() == null || "FILE".equalsIgnoreCase(value.getScheme())) { |
|
887 |
if (!value.getPath().startsWith("/")){ |
|
888 |
File file = new File(value.getPath()); |
|
889 |
file = FileTools.derelativizeFile(rootFolder, file); |
|
890 |
aState.set(field.getName(), file.toURI()); |
|
891 |
} |
|
892 |
} |
|
893 |
} catch (PersistenceException e) { |
|
894 |
// do nothing |
|
895 |
} |
|
896 |
} |
|
897 |
} |
|
898 |
}catch (RuntimeException e) { |
|
899 |
logger.info("Can't fix relative paths in " + className, e); |
|
900 |
} |
|
901 |
} |
|
902 |
} |
|
883 |
} else if (field.getType() == DataTypes.URI) { |
|
884 |
try { |
|
885 |
URI value = aState.getURI(field.getName()); |
|
886 |
if (value.getScheme() == null || "FILE".equalsIgnoreCase(value.getScheme())) { |
|
887 |
if (!value.getPath().startsWith("/")) { |
|
888 |
File file = FileUtils.toFile(value.toURL()); |
|
889 |
file = FileTools.derelativizeFile(rootFolder, file); |
|
890 |
aState.set(field.getName(), file.toURI()); |
|
891 |
} |
|
892 |
} |
|
893 |
} catch (PersistenceException e) { |
|
894 |
// do nothing |
|
895 |
} catch (MalformedURLException ex) { |
|
896 |
// do nothing |
|
897 |
} |
|
898 |
} |
|
899 |
} |
|
900 |
} catch (RuntimeException e) { |
|
901 |
logger.info("Can't fix relative paths in " + className, e); |
|
902 |
} |
|
903 |
} |
|
904 |
} |
|
903 | 905 |
|
904 | 906 |
|
905 | 907 |
} |
Also available in: Unified diff