0
|
1 package de.mpiwg.itgroup.eSciDoc.foxridge;
|
|
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;
|
8
|
24 import java.util.ArrayList;
|
0
|
25 import java.util.Enumeration;
|
|
26 import java.util.Iterator;
|
10
|
27 import java.util.List;
|
0
|
28 import java.util.Stack;
|
|
29 import java.util.Vector;
|
|
30
|
|
31
|
|
32
|
8
|
33 import org.apache.log4j.Logger;
|
0
|
34 import org.jdom.Document;
|
|
35 import org.jdom.JDOMException;
|
|
36 import org.jdom.input.SAXBuilder;
|
|
37
|
|
38 import de.mpiwg.itgroup.eSciDoc.echoObjects.ECHOObject;
|
|
39 import de.mpiwg.itgroup.eSciDoc.echoObjects.ECHORessource;
|
|
40
|
|
41 /**
|
|
42 * An iterator which iterates through the contents of a java directory. The
|
|
43 * iterator should be created with the directory at the root of the Java
|
|
44 * namespace.
|
|
45 *
|
|
46 */
|
|
47 public class IndexMetaIterator implements Iterator<ECHOObject> {
|
|
48
|
|
49 private File rootFolder;
|
|
50 private File currentFolder;
|
8
|
51 private Stack<String> stack;
|
|
52 private ArrayList<String>filter; //Array of paths which shouldn'T be indexed
|
0
|
53
|
8
|
54 public IndexMetaIterator(File rootFolder) throws IOException{
|
10
|
55
|
8
|
56 filter = new ArrayList<String>();
|
|
57 filter.add("/mpiwg/online/permanent/SudanRockArt"); // TODO: make this configurable
|
10
|
58
|
0
|
59 this.rootFolder=rootFolder;
|
|
60 this.currentFolder=rootFolder;
|
8
|
61 this.stack = new Stack<String>();
|
10
|
62
|
8
|
63 for (String f:rootFolder.list()){
|
|
64 String fn = rootFolder.getCanonicalPath()+"/"+f;
|
|
65 if (!filter.contains(fn)){
|
|
66 if (!f.equals("")){ // FIXME some filesystems (sshfs?) gives empty filenames if the path contains special characters.
|
|
67 stack.push(fn);}
|
|
68 else {
|
|
69 Logger.getLogger("notAddedFilesLogger").info("Folder -" +fn+" contains files with charakters I cannot read!" );
|
|
70 }
|
|
71 }
|
0
|
72 }
|
|
73 }
|
|
74 @Override
|
|
75 public boolean hasNext() {
|
|
76 // TODO Auto-generated method stub
|
|
77 return !stack.isEmpty();
|
|
78 }
|
|
79
|
|
80 @Override
|
|
81 public ECHOObject next() {
|
|
82 // TODO Auto-generated method stub
|
8
|
83 String nextFile = stack.pop();
|
|
84 while(!nextFile.endsWith(".meta") && !stack.isEmpty()){
|
|
85 System.out.println("CHECK_________"+nextFile);
|
10
|
86
|
|
87
|
9
|
88 if(!nextFile.endsWith("pageimg") & !nextFile.endsWith("pages") & !nextFile.endsWith("pagesHi") & !nextFile.endsWith("pagesLo")
|
|
89 & !nextFile.endsWith("pageimg")){ //skip pageimg
|
10
|
90
|
8
|
91 File nf = new File(nextFile);
|
10
|
92
|
8
|
93 if(nf.isDirectory()){
|
10
|
94 String[] filesInDirectory=nf.list();
|
|
95 if (filesInDirectory != null){
|
|
96 for (String f:filesInDirectory){
|
|
97 String fn;
|
|
98 try {
|
|
99 if (!f.startsWith(".")){
|
|
100 fn = nf.getCanonicalPath()+"/"+f;
|
|
101 if (!filter.contains(fn)){
|
|
102 if (!f.equals("")) {// FIXME some filesystems (sshfs?) gives empty filenames if the path contains special characters.
|
|
103 stack.push(fn);}
|
|
104 else {
|
|
105 Logger.getLogger("notAddedFilesLogger").info("Folder -" +fn+" contains files with characters I cannot read!" );
|
|
106 }
|
|
107
|
8
|
108 }
|
10
|
109 }
|
|
110 } catch (IOException e) {
|
|
111 // TODO Auto-generated catch block
|
|
112 e.printStackTrace();
|
8
|
113 }
|
10
|
114
|
8
|
115 }
|
0
|
116 }
|
|
117 }
|
|
118 }
|
10
|
119
|
0
|
120 nextFile = stack.pop();
|
10
|
121
|
0
|
122 }
|
8
|
123 if (!nextFile.endsWith(".meta")) //der letzte Eintrag muss noch gretrennt getestet werden.
|
0
|
124 nextFile = null;
|
|
125 System.out.println("FOUND:"+nextFile);
|
|
126 try {
|
1
|
127 if (nextFile!=null)
|
8
|
128 return createECHOObject(new File(nextFile));
|
0
|
129 } catch (JDOMException e) {
|
|
130 // TODO Auto-generated catch block
|
|
131 e.printStackTrace();
|
|
132 } catch (IOException e) {
|
|
133 // TODO Auto-generated catch block
|
|
134 e.printStackTrace();
|
|
135 } catch (Exception e) {
|
|
136 // TODO Auto-generated catch block
|
|
137 e.printStackTrace();
|
|
138 }
|
|
139 return null;
|
|
140 }
|
|
141
|
|
142 private ECHOObject createECHOObject(File nextFile) throws Exception {
|
10
|
143
|
0
|
144 //Document doc = new SAXBuilder().build(nextFile);
|
|
145 try{
|
10
|
146 FoxridgeRessource er = new FoxridgeRessource(nextFile.getParentFile().getName(),nextFile.getParentFile().getAbsolutePath(),null);
|
|
147
|
|
148 er.metaData = er.correctML(nextFile.getAbsolutePath());
|
|
149 //er.pid=er.getPid(); //TODO: not needed any more?
|
|
150 er.echoUrl=er.metaData; //TODO find a better solution, what to present here, z.b. texttool-tag auswerten.
|
|
151 return er;
|
0
|
152 } catch (Exception e) {
|
|
153 // TODO Auto-generated catch block
|
|
154 e.printStackTrace();
|
|
155 throw new Exception();
|
|
156 }
|
|
157 }
|
|
158 @Override
|
|
159 public void remove() {
|
|
160 // TODO Auto-generated method stub
|
10
|
161
|
0
|
162 }
|
|
163
|
10
|
164
|
0
|
165
|
|
166 }
|
|
167
|
|
168
|
10
|
169
|