source: trunk/greenstone3-extensions/gs3build/src/org/greenstone/gsdl3/gs3build/doctypes/RecogniserManager.java@ 12188

Last change on this file since 12188 was 12188, checked in by kjdon, 18 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
1package org.greenstone.gsdl3.gs3build.doctypes;
2
3import org.greenstone.gsdl3.gs3build.FileCrawlObserver;
4
5import java.io.File;
6import java.net.URL;
7
8import org.greenstone.gsdl3.gs3build.util.URLTools;
9
10public class RecogniserManager implements FileCrawlObserver
11{
12 RecogniserInterface list[];
13 int used;
14 int size;
15 DocumentList docList;
16 public RecogniserManager(DocumentList documentList)
17 { this.list = new RecogniserInterface[10];
18 this.used = 0;
19 this.size = 10;
20 this.docList = documentList;
21 }
22
23 /**
24 * Add a recogniser to this manager
25 */
26 public RecogniserInterface addRecogniser(String documentType)
27 {
28 ClassLoader loader = ClassLoader.getSystemClassLoader();
29 java.lang.Class thisClass = null;
30 try {
31 thisClass = loader.loadClass("org.greenstone.gsdl3.gs3build.doctypes." + documentType + "Recogniser");
32 Object instance = thisClass.newInstance();
33 this.addRecogniser((RecogniserInterface) instance);
34 return (RecogniserInterface)instance;
35 }
36 catch (ClassNotFoundException ex) {
37 System.err.println(ex);
38 return null;
39 }
40 catch (InstantiationException instEx) {
41 System.err.println(instEx);
42 }
43 catch (IllegalAccessException accEx) {
44 System.err.println(accEx);
45 }
46 return null;
47 }
48
49 /**
50 *
51 */
52 public void addRecogniser(RecogniserInterface recogniser)
53 {
54 recogniser.setListRepository(this.docList);
55 this.ensureCapacity(this.used + 1);
56
57 this.list[this.used] = recogniser;
58 this.used ++;
59 }
60
61 public void processFile(URL url)
62 { boolean result;
63
64 for (int r = 0; r < this.used; r ++)
65 { if (list[r].parseDocument(url)) {
66 break;
67 }
68 }
69 }
70
71 public void processFile(File file)
72 {
73 System.err.println("processing file "+file.getPath());
74 URL url = URLTools.getFileURL(file);
75
76 if (url != null)
77 { this.processFile(url);
78 }
79 }
80
81 private void ensureCapacity(int size)
82 { while (size >= this.size)
83 { RecogniserInterface newList [] = new RecogniserInterface[this.size*2];
84 this.size *= 2;
85 System.arraycopy(this.list, 0, newList, 0, this.size);
86 this.list = newList;
87 }
88 }
89}
Note: See TracBrowser for help on using the repository browser.