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;
|
|
24 import java.util.Enumeration;
|
|
25 import java.util.Iterator;
|
|
26 import java.util.Stack;
|
|
27 import java.util.Vector;
|
|
28
|
|
29
|
|
30
|
|
31 import org.jdom.Document;
|
|
32 import org.jdom.JDOMException;
|
|
33 import org.jdom.input.SAXBuilder;
|
|
34
|
|
35 import de.mpiwg.itgroup.eSciDoc.echoObjects.ECHOObject;
|
|
36 import de.mpiwg.itgroup.eSciDoc.echoObjects.ECHORessource;
|
|
37
|
|
38 /**
|
|
39 * An iterator which iterates through the contents of a java directory. The
|
|
40 * iterator should be created with the directory at the root of the Java
|
|
41 * namespace.
|
|
42 *
|
|
43 */
|
|
44 public class IndexMetaIterator implements Iterator<ECHOObject> {
|
|
45
|
|
46 private File rootFolder;
|
|
47 private File currentFolder;
|
|
48 private Stack<File> stack;
|
|
49
|
|
50
|
|
51 public IndexMetaIterator(File rootFolder){
|
|
52 this.rootFolder=rootFolder;
|
|
53 this.currentFolder=rootFolder;
|
|
54 this.stack = new Stack<File>();
|
|
55 for (File f:rootFolder.listFiles()){
|
|
56 stack.push(f);
|
|
57 }
|
|
58 }
|
|
59 @Override
|
|
60 public boolean hasNext() {
|
|
61 // TODO Auto-generated method stub
|
|
62 return !stack.isEmpty();
|
|
63 }
|
|
64
|
|
65 @Override
|
|
66 public ECHOObject next() {
|
|
67 // TODO Auto-generated method stub
|
|
68 File nextFile = stack.pop();
|
|
69 while(!nextFile.getName().endsWith(".meta") && !stack.isEmpty()){
|
|
70 System.out.println("CHECK_________"+nextFile.getName());
|
|
71 if(!nextFile.getName().equals("pageimg")){ //skip pageimg
|
|
72 if(nextFile.isDirectory()){
|
|
73 for (File f:nextFile.listFiles()){
|
|
74 stack.push(f);
|
|
75 }
|
|
76 }
|
|
77 }
|
|
78 nextFile = stack.pop();
|
|
79 }
|
|
80 if (!nextFile.getName().endsWith(".meta")) //der letzte Eintrag muss noch gretrennt getestet werden.
|
|
81 nextFile = null;
|
|
82 System.out.println("FOUND:"+nextFile);
|
|
83 try {
|
1
|
84 if (nextFile!=null)
|
|
85 return createECHOObject(nextFile);
|
0
|
86 } catch (JDOMException e) {
|
|
87 // TODO Auto-generated catch block
|
|
88 e.printStackTrace();
|
|
89 } catch (IOException e) {
|
|
90 // TODO Auto-generated catch block
|
|
91 e.printStackTrace();
|
|
92 } catch (Exception e) {
|
|
93 // TODO Auto-generated catch block
|
|
94 e.printStackTrace();
|
|
95 }
|
|
96 return null;
|
|
97 }
|
|
98
|
|
99 private ECHOObject createECHOObject(File nextFile) throws Exception {
|
|
100
|
|
101 //Document doc = new SAXBuilder().build(nextFile);
|
|
102 try{
|
|
103 FoxridgeRessource er = new FoxridgeRessource(nextFile.getParentFile().getName(),nextFile.getParentFile().getAbsolutePath(),null);
|
|
104
|
|
105 er.metaData = er.correctML(nextFile.getAbsolutePath());
|
|
106 er.pid=er.getPid();
|
|
107 er.echoUrl=er.metaData; //TODO find a better solution, what to present here, z.b. texttool-tag auswerten.
|
|
108 return er;
|
|
109 } catch (Exception e) {
|
|
110 // TODO Auto-generated catch block
|
|
111 e.printStackTrace();
|
|
112 throw new Exception();
|
|
113 }
|
|
114 }
|
|
115 @Override
|
|
116 public void remove() {
|
|
117 // TODO Auto-generated method stub
|
|
118
|
|
119 }
|
|
120
|
|
121
|
|
122
|
|
123 }
|
|
124
|
|
125
|
|
126
|