4
|
1 package de.mpiwg.itgroup.indexMeta2RDF;
|
|
2
|
|
3
|
|
4 /*
|
|
5 * Copyright 2000-2004 The Apache Software Foundation
|
|
6 *
|
|
7 * Licensed under the Apache License, Version 2.0 (the "License");
|
|
8 * you may not use this file except in compliance with the License.
|
|
9 * You may obtain a copy of the License at
|
|
10 *
|
|
11 * http://www.apache.org/licenses/LICENSE-2.0
|
|
12 *
|
|
13 * Unless required by applicable law or agreed to in writing, software
|
|
14 * distributed under the License is distributed on an "AS IS" BASIS,
|
|
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16 * See the License for the specific language governing permissions and
|
|
17 * limitations under the License.
|
|
18 *
|
|
19 */
|
|
20
|
|
21 import java.io.File;
|
|
22 import java.io.FileInputStream;
|
|
23 import java.io.IOException;
|
|
24 import java.util.ArrayList;
|
|
25 import java.util.Enumeration;
|
|
26 import java.util.Iterator;
|
|
27 import java.util.List;
|
|
28 import java.util.Stack;
|
|
29 import java.util.Vector;
|
|
30
|
|
31
|
|
32
|
|
33 import org.apache.log4j.Logger;
|
|
34 import org.jdom.Document;
|
|
35 import org.jdom.JDOMException;
|
|
36 import org.jdom.input.SAXBuilder;
|
|
37
|
|
38
|
|
39 /**
|
|
40 * An iterator which iterates through the contents of a java directory. The
|
|
41 * iterator should be created with the directory at the root of the Java
|
|
42 * namespace.
|
|
43 *
|
|
44 */
|
|
45 public class IndexMetaIterator implements Iterator<String> {
|
|
46
|
|
47 private File rootFolder;
|
|
48 private File currentFolder;
|
|
49 private Stack<String> stack;
|
|
50 private ArrayList<String>filter; //Array of paths which shouldn'T be indexed
|
|
51
|
|
52 public IndexMetaIterator(File rootFolder) throws IOException{
|
|
53
|
|
54 filter = new ArrayList<String>();
|
|
55 filter.add("/mpiwg/online/permanent/SudanRockArt"); // TODO: make this configurable
|
|
56
|
|
57 this.rootFolder=rootFolder;
|
|
58 this.currentFolder=rootFolder;
|
|
59 this.stack = new Stack<String>();
|
|
60
|
|
61 for (String f:rootFolder.list()){
|
|
62 String fn = rootFolder.getCanonicalPath()+"/"+f;
|
|
63 if (!filter.contains(fn)){
|
|
64 if (!f.equals("")){ // FIXME some filesystems (sshfs?) gives empty filenames if the path contains special characters.
|
|
65 stack.push(fn);}
|
|
66 else {
|
|
67 Logger.getLogger("notAddedFilesLogger").info("Folder -" +fn+" contains files with charakters I cannot read!" );
|
|
68 }
|
|
69 }
|
|
70 }
|
|
71 }
|
|
72 @Override
|
|
73 public boolean hasNext() {
|
|
74 // TODO Auto-generated method stub
|
|
75 return !stack.isEmpty();
|
|
76 }
|
|
77
|
|
78 @Override
|
|
79 public String next() {
|
|
80 // TODO Auto-generated method stub
|
|
81 String nextFile = stack.pop();
|
|
82 while(!nextFile.endsWith(".meta") && !stack.isEmpty()){
|
|
83 System.out.println("CHECK_________"+nextFile);
|
|
84
|
|
85
|
|
86 if(!nextFile.endsWith("pageimg")){ //skip pageimg
|
|
87
|
|
88
|
|
89 File nf = new File(nextFile);
|
|
90
|
|
91
|
|
92 if(nf.isDirectory()){
|
|
93 String[] ls = nf.list();
|
|
94 if (ls==null){
|
|
95 return null;
|
|
96 }
|
|
97 for (String f:ls){
|
|
98 String fn;
|
|
99 try {
|
|
100 if (!f.startsWith(".")){
|
|
101 fn = nf.getCanonicalPath()+"/"+f;
|
|
102 if (!filter.contains(fn)){
|
|
103 if (!f.equals("")) {// FIXME some filesystems (sshfs?) gives empty filenames if the path contains special characters.
|
|
104 stack.push(fn);}
|
|
105 else {
|
|
106 Logger.getLogger("notAddedFilesLogger").info("Folder -" +fn+" contains files with characters I cannot read!" );
|
|
107 }
|
|
108
|
|
109 }
|
|
110 }
|
|
111 } catch (IOException e) {
|
|
112 // TODO Auto-generated catch block
|
|
113 e.printStackTrace();
|
|
114 }
|
|
115
|
|
116 }
|
|
117 }
|
|
118 }
|
|
119
|
|
120 nextFile = stack.pop();
|
|
121
|
|
122 }
|
|
123 if (!nextFile.endsWith(".meta")) //der letzte Eintrag muss noch gretrennt getestet werden.
|
|
124 nextFile = null;
|
|
125 System.out.println("FOUND:"+nextFile);
|
|
126
|
|
127 if (nextFile!=null)
|
|
128 return nextFile;
|
|
129
|
|
130 return null;
|
|
131 }
|
|
132
|
|
133
|
|
134 @Override
|
|
135 public void remove() {
|
|
136 // TODO Auto-generated method stub
|
|
137
|
|
138 }
|
|
139
|
|
140
|
|
141
|
|
142 }
|
|
143
|
|
144
|
|
145
|