Commit f5cf0be3 authored by Ivan Dages's avatar Ivan Dages
Browse files

file names conversion

parent ed090b33
package fr.ill.ics.n3d.io;
import java.util.HashMap;
import fr.ill.ics.n3d.model.Component;
/**
* @author dages
*
*/
public class AsciiStringConverter {
private static final HashMap<Character, String> conversion = new HashMap<>();
static {
conversion.put(' ', "_");
conversion.put('à', "a");
conversion.put('ä', "a");
conversion.put('é', "e");
conversion.put('è', "e");
conversion.put('ê', "e");
conversion.put('ë', "e");
conversion.put('ï', "i");
conversion.put('î', "i");
conversion.put('ì', "i");
conversion.put('ö', "o");
conversion.put('ô', "o");
conversion.put('ò', "o");
conversion.put('ù', "u");
conversion.put('ü', "u");
conversion.put('û', "u");
conversion.put('ñ', "n");
conversion.put('ç', "c");
conversion.put('À', "A");
conversion.put('Ä', "A");
conversion.put('É', "E");
conversion.put('È', "E");
conversion.put('Ê', "E");
conversion.put('Ë', "E");
conversion.put('Ï', "I");
conversion.put('Î', "I");
conversion.put('Ì', "I");
conversion.put('Ö', "O");
conversion.put('Ô', "O");
conversion.put('Ò', "O");
conversion.put('Ù', "U");
conversion.put('Ü', "U");
conversion.put('Û', "U");
conversion.put('Ú', "U");
conversion.put('Ñ', "N");
conversion.put('Ç', "C");
conversion.put('<', "leftchevron");
conversion.put('>', "rightchevron");
conversion.put('\"', "doublequote");
conversion.put('\'', "quote");
conversion.put('&', "ampersand");
conversion.put('@', "at");
conversion.put('#', "sharp");
conversion.put('~', "tilde");
conversion.put('`', "backquote");
conversion.put('\\', "backslash");
conversion.put('^', "circumflex");
conversion.put('¨', "umlaut");
conversion.put('$', "dollar");
conversion.put('€', "euro");
conversion.put('£', "pound");
conversion.put('¤', "currency");
conversion.put('µ', "mu");
conversion.put('²', "squared");
conversion.put('§', "paragraph");
conversion.put('%', "percent");
conversion.put('=', "equals");
conversion.put('°', "degree");
conversion.put('(', "leftparenthesis");
conversion.put(')', "rightperenthesis");
conversion.put('[', "leftsquarebracket");
conversion.put(']', "rightsquarebracket");
conversion.put('{', "leftcurlybracket");
conversion.put('}', "rightcurlybracket");
}
/**
* Default constructor.
*/
public AsciiStringConverter() {
}
public String convert(String value) {
String result = new String(value);
for (Character c : conversion.keySet()) {
result = result.replace(c.toString(), conversion.get(c));
}
return result;
}
}
/**
*
*/
package fr.ill.ics.n3d.io;
import java.util.HashMap;
import fr.ill.ics.n3d.model.Component;
import fr.ill.ics.n3d.model.Model;
/**
* @author dages
*
*/
public class NameConverter {
/** Mapping between old file names (keys) and new file names (values). */
private HashMap<String, String> fileNameConversion;
/** Mapping between old names (keys) and new names (values). */
private HashMap<String, String> nameConversion;
/**
* Default constructor.
*/
public NameConverter() {
this.fileNameConversion = new HashMap<>();
this.nameConversion = new HashMap<>();
}
public void convert(Model model) {
this.fileNameConversion.clear();
this.nameConversion.clear();
AsciiStringConverter ascii = new AsciiStringConverter();
model.setName(ascii.convert(model.getName()));
convert(model.getRoot(), ascii);
}
private void convert(Component component, AsciiStringConverter ascii) {
String convertedFileName = ascii.convert(component.getFileName());
String newFileName = new String(convertedFileName);
// for (int i = 0 ; this.fileNameConversion.containsKey(newFileName) ; i++, newFileName = convertedFileName+"--"+Integer.toString(i));
String convertedName = ascii.convert(component.getName());
String newName = new String(convertedName);
// for (int i = 0 ; this.nameConversion.containsKey(newName) ; i++, newName = convertedName+"--"+Integer.toString(i));
this.fileNameConversion.put(component.getFileName(), newFileName);
component.setFileName(newFileName);
this.nameConversion.put(component.getName(), newName);
component.setName(newName);
for (Component child : component.getChildren()) {
convert(child, ascii);
}
}
public String newFileName(String oldFileName) {
return this.fileNameConversion.get(oldFileName);
}
public String newName(String oldName) {
return this.nameConversion.get(oldName);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "NameConverter [\nfileNameConversion=" + fileNameConversion + ",\n nameConversion=" + nameConversion + "\n]";
}
}
......@@ -188,6 +188,13 @@ public class Nomad3DImporter {
component.setWall(wall.equals("True"));
}
// TODO test
AsciiStringConverter asciiConverter = new AsciiStringConverter();
if (name.contains("&")) {
System.out.println("ASCII converter : " + name + " --> " + asciiConverter.convert(name));
System.out.println("ASCII converter : " + fileName + " --> " + asciiConverter.convert(fileName));
}
readComponentConfigurations(eComponent, component);
Element eMaterial = (Element)eComponent.getElementsByTagName("Material").item(0);
......
......@@ -888,6 +888,7 @@ public class Component {
} catch (Exception e) {
Logger.getLogger("nomad-3d").severe("Error loading file \"" + stlFile.getPath() + "\" in directory \""
+ model.getDirectoryPath() + "\" : \n" + e.getMessage() + "\n");
e.printStackTrace();
return null;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment