Mercurial > hg > eSciDocImport
comparison src/de/mpiwg/itgroup/eSciDoc/foxridge/IndexMetaIterator.java @ 0:c6929e63b0b8
first import
author | dwinter |
---|---|
date | Wed, 24 Nov 2010 16:52:07 +0100 |
parents | |
children | 6b0267cb40ed |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c6929e63b0b8 |
---|---|
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 { | |
84 return createECHOObject(nextFile); | |
85 } catch (JDOMException e) { | |
86 // TODO Auto-generated catch block | |
87 e.printStackTrace(); | |
88 } catch (IOException e) { | |
89 // TODO Auto-generated catch block | |
90 e.printStackTrace(); | |
91 } catch (Exception e) { | |
92 // TODO Auto-generated catch block | |
93 e.printStackTrace(); | |
94 } | |
95 return null; | |
96 } | |
97 | |
98 private ECHOObject createECHOObject(File nextFile) throws Exception { | |
99 | |
100 //Document doc = new SAXBuilder().build(nextFile); | |
101 try{ | |
102 FoxridgeRessource er = new FoxridgeRessource(nextFile.getParentFile().getName(),nextFile.getParentFile().getAbsolutePath(),null); | |
103 | |
104 er.metaData = er.correctML(nextFile.getAbsolutePath()); | |
105 er.pid=er.getPid(); | |
106 er.echoUrl=er.metaData; //TODO find a better solution, what to present here, z.b. texttool-tag auswerten. | |
107 return er; | |
108 } catch (Exception e) { | |
109 // TODO Auto-generated catch block | |
110 e.printStackTrace(); | |
111 throw new Exception(); | |
112 } | |
113 } | |
114 @Override | |
115 public void remove() { | |
116 // TODO Auto-generated method stub | |
117 | |
118 } | |
119 | |
120 | |
121 | |
122 } | |
123 | |
124 | |
125 |