Revision 2246 tmp/org.txm.groovy.core/src/groovy/org/txm/scripts/importer/xtz/XTZImport.groovy

XTZImport.groovy (revision 2246)
36 36
	}
37 37
	
38 38
	@Override
39
	protected ArrayList<File> getTXMFilesOrder() {
39
	protected ArrayList<String> getTXMFilesOrder() {
40 40
		//System.out.println("XTZ FILES ORDER");
41 41
		if (importer == null) {
42 42
			println "no importer step, using default text order"
......
55 55
			}
56 56
		})));
57 57
	
58
		final HashMap<File, String> textorder = new HashMap<File, String>();
59
		for (File f : files) {
60
			HashMap<String, String> m = metadata.getTextMetadata(f);
61
			if (m != null && m.containsKey("textorder")) textorder[f] = m["textorder"];
58
		// fill sort data map
59
		final HashMap<String, String> textorder = new HashMap<String, String>();
60
		for (String t : metadata.keySet()) {
61
			def ti = metadata.get(t)
62
			for (org.txm.metadatas.Entry e : ti) {
63
				if ("textorder".equals(e.getId())) {
64
					textorder[t] = ti.get("textorder")
65
				}
66
			}
62 67
		}
68
		
63 69
		println "Sorting texts using 'textorder' metadata values: "+textorder
64
		Collections.sort(files, new Comparator<File>() {
65
			public int compare(File f1, File f2) {
70
		def texts = project.getTextsID();
71
		Collections.sort(texts, new Comparator<String>() {
72
			public int compare(String f1, String f2) {
66 73
				String o1 = textorder[f1];
67 74
				String o2 = textorder[f2];
68 75
				if (o1 == null && o2 == null) {
69
					return f1.getName().compareTo(f2.getName());
76
					return f1.compareTo(f2);
70 77
				} else if (o1 == null) {
71 78
					return 1
72 79
				} else if (o2 == null) {
73 80
					return -1
74 81
				} else {
75 82
					int c = o1.compareTo(o2);
76
					if (c == 0) return f1.getName().compareTo(f2.getName());
83
					if (c == 0) return f1.compareTo(f2);
77 84
					else return c;
78 85
				}
79 86
			}

Also available in: Unified diff