comparison src/de/mpiwg/itgroup/eSciDoc/foxridge/IndexMetaIterator.java @ 10:ad5c0748bd08

minor
author dwinter
date Mon, 20 Aug 2012 12:53:45 +0200
parents b6cf6462d709
children
comparison
equal deleted inserted replaced
9:b6cf6462d709 10:ad5c0748bd08
22 import java.io.FileInputStream; 22 import java.io.FileInputStream;
23 import java.io.IOException; 23 import java.io.IOException;
24 import java.util.ArrayList; 24 import java.util.ArrayList;
25 import java.util.Enumeration; 25 import java.util.Enumeration;
26 import java.util.Iterator; 26 import java.util.Iterator;
27 import java.util.List;
27 import java.util.Stack; 28 import java.util.Stack;
28 import java.util.Vector; 29 import java.util.Vector;
29 30
30 31
31 32
49 private File currentFolder; 50 private File currentFolder;
50 private Stack<String> stack; 51 private Stack<String> stack;
51 private ArrayList<String>filter; //Array of paths which shouldn'T be indexed 52 private ArrayList<String>filter; //Array of paths which shouldn'T be indexed
52 53
53 public IndexMetaIterator(File rootFolder) throws IOException{ 54 public IndexMetaIterator(File rootFolder) throws IOException{
54 55
55 filter = new ArrayList<String>(); 56 filter = new ArrayList<String>();
56 filter.add("/mpiwg/online/permanent/SudanRockArt"); // TODO: make this configurable 57 filter.add("/mpiwg/online/permanent/SudanRockArt"); // TODO: make this configurable
57 58
58 this.rootFolder=rootFolder; 59 this.rootFolder=rootFolder;
59 this.currentFolder=rootFolder; 60 this.currentFolder=rootFolder;
60 this.stack = new Stack<String>(); 61 this.stack = new Stack<String>();
61 62
62 for (String f:rootFolder.list()){ 63 for (String f:rootFolder.list()){
63 String fn = rootFolder.getCanonicalPath()+"/"+f; 64 String fn = rootFolder.getCanonicalPath()+"/"+f;
64 if (!filter.contains(fn)){ 65 if (!filter.contains(fn)){
65 if (!f.equals("")){ // FIXME some filesystems (sshfs?) gives empty filenames if the path contains special characters. 66 if (!f.equals("")){ // FIXME some filesystems (sshfs?) gives empty filenames if the path contains special characters.
66 stack.push(fn);} 67 stack.push(fn);}
80 public ECHOObject next() { 81 public ECHOObject next() {
81 // TODO Auto-generated method stub 82 // TODO Auto-generated method stub
82 String nextFile = stack.pop(); 83 String nextFile = stack.pop();
83 while(!nextFile.endsWith(".meta") && !stack.isEmpty()){ 84 while(!nextFile.endsWith(".meta") && !stack.isEmpty()){
84 System.out.println("CHECK_________"+nextFile); 85 System.out.println("CHECK_________"+nextFile);
85 86
86 87
87 if(!nextFile.endsWith("pageimg") & !nextFile.endsWith("pages") & !nextFile.endsWith("pagesHi") & !nextFile.endsWith("pagesLo") 88 if(!nextFile.endsWith("pageimg") & !nextFile.endsWith("pages") & !nextFile.endsWith("pagesHi") & !nextFile.endsWith("pagesLo")
88 & !nextFile.endsWith("pageimg")){ //skip pageimg 89 & !nextFile.endsWith("pageimg")){ //skip pageimg
89 90
90 File nf = new File(nextFile); 91 File nf = new File(nextFile);
91 92
92 if(nf.isDirectory()){ 93 if(nf.isDirectory()){
93 for (String f:nf.list()){ 94 String[] filesInDirectory=nf.list();
94 String fn; 95 if (filesInDirectory != null){
95 try { 96 for (String f:filesInDirectory){
96 if (!f.startsWith(".")){ 97 String fn;
97 fn = nf.getCanonicalPath()+"/"+f; 98 try {
98 if (!filter.contains(fn)){ 99 if (!f.startsWith(".")){
99 if (!f.equals("")) {// FIXME some filesystems (sshfs?) gives empty filenames if the path contains special characters. 100 fn = nf.getCanonicalPath()+"/"+f;
100 stack.push(fn);} 101 if (!filter.contains(fn)){
101 else { 102 if (!f.equals("")) {// FIXME some filesystems (sshfs?) gives empty filenames if the path contains special characters.
102 Logger.getLogger("notAddedFilesLogger").info("Folder -" +fn+" contains files with characters I cannot read!" ); 103 stack.push(fn);}
104 else {
105 Logger.getLogger("notAddedFilesLogger").info("Folder -" +fn+" contains files with characters I cannot read!" );
106 }
107
103 } 108 }
104 109 }
110 } catch (IOException e) {
111 // TODO Auto-generated catch block
112 e.printStackTrace();
105 } 113 }
106 } 114
107 } catch (IOException e) {
108 // TODO Auto-generated catch block
109 e.printStackTrace();
110 } 115 }
111
112 } 116 }
113 } 117 }
114 } 118 }
115 119
116 nextFile = stack.pop(); 120 nextFile = stack.pop();
117 121
118 } 122 }
119 if (!nextFile.endsWith(".meta")) //der letzte Eintrag muss noch gretrennt getestet werden. 123 if (!nextFile.endsWith(".meta")) //der letzte Eintrag muss noch gretrennt getestet werden.
120 nextFile = null; 124 nextFile = null;
121 System.out.println("FOUND:"+nextFile); 125 System.out.println("FOUND:"+nextFile);
122 try { 126 try {
134 } 138 }
135 return null; 139 return null;
136 } 140 }
137 141
138 private ECHOObject createECHOObject(File nextFile) throws Exception { 142 private ECHOObject createECHOObject(File nextFile) throws Exception {
139 143
140 //Document doc = new SAXBuilder().build(nextFile); 144 //Document doc = new SAXBuilder().build(nextFile);
141 try{ 145 try{
142 FoxridgeRessource er = new FoxridgeRessource(nextFile.getParentFile().getName(),nextFile.getParentFile().getAbsolutePath(),null); 146 FoxridgeRessource er = new FoxridgeRessource(nextFile.getParentFile().getName(),nextFile.getParentFile().getAbsolutePath(),null);
143 147
144 er.metaData = er.correctML(nextFile.getAbsolutePath()); 148 er.metaData = er.correctML(nextFile.getAbsolutePath());
145 //er.pid=er.getPid(); //TODO: not needed any more? 149 //er.pid=er.getPid(); //TODO: not needed any more?
146 er.echoUrl=er.metaData; //TODO find a better solution, what to present here, z.b. texttool-tag auswerten. 150 er.echoUrl=er.metaData; //TODO find a better solution, what to present here, z.b. texttool-tag auswerten.
147 return er; 151 return er;
148 } catch (Exception e) { 152 } catch (Exception e) {
149 // TODO Auto-generated catch block 153 // TODO Auto-generated catch block
150 e.printStackTrace(); 154 e.printStackTrace();
151 throw new Exception(); 155 throw new Exception();
152 } 156 }
153 } 157 }
154 @Override 158 @Override
155 public void remove() { 159 public void remove() {
156 // TODO Auto-generated method stub 160 // TODO Auto-generated method stub
157 161
158 } 162 }
159 163
160 164
161 165
162 } 166 }
163 167
164 168
165 169