public AtcParser(File source) throws FileNotFoundException {
input = new BufferedReader(new FileReader(source));
}
public ArrayList<DirectoryVidalAtcItem> read() throws IOException, ClipsException {
DirectoryVidalAtc dir = (DirectoryVidalAtc) DirectoryLocator.getDirectory(DirectoryVidalAtc.class, false);
ArrayList<DirectoryVidalAtcItem> res = new ArrayList<DirectoryVidalAtcItem>();
DirectoryVidalAtcItem stack[] = new DirectoryVidalAtcItem[10];
int stackPos = -1;
String line = input.readLine();
while (line != null) {
if (!line.trim().isEmpty()) {
int pos = line.indexOf('\t');
String code = line.substring(0, pos);
line = line.substring(pos + 1);
int lvl = 0;
while (line.charAt(lvl) == ' ') {
lvl += 1;
}
line = line.substring(lvl);
lvl = lvl/3;
DirectoryVidalAtcItem parent;
if (lvl-1 >= 0) {
parent = stack[lvl-1];
} else {
parent = null;
}
if (lvl > stackPos + 1) {
System.err.println("Ошибка структуры файла");
break;
}
ClassificationAtcDetails details = new ClassificationAtcDetails();
details.title = line;
if (parent != null) {
details.groupCode = code.substring(parent.getGroupCode().length());
parent.getGroupCode();
} else {
details.groupCode = code;
}
DirectoryVidalAtcItem newItem = new DirectoryVidalAtcItem(details);
System.out.println("["+code+"][" + line + "]" + lvl);
if (parent != null) {
System.out.println(parent+"->>>>>"+newItem);
parent.getItems().append(newItem);
} else {
System.out.println("root->>>>>"+newItem);
dir.getItems().append(newItem);
}
stackPos = lvl;
stack[stackPos] = newItem;
}