Annotation of edoc-applet/Bundle.java, revision 1.3
1.1 rogo 1: //
2: // Bundle.java
3: //
4: //
5: // Created by rogo on Thu Jan 30 2003.
6: // Copyright (c) 2001 __MyCompanyName__. All rights reserved.
7: //
8: import java.util.*;
9: import java.io.*;
10:
11: public class Bundle
12: {
13: String name="";
14: int grp=0;
15: Vector documents=new Vector();
16: Hashtable docs=new Hashtable();
17: Hashtable docsLocator=new Hashtable();
18: static Hashtable genresId=new Hashtable();
19: static Hashtable genresLabel=new Hashtable();
20: static Hashtable genresName=new Hashtable();
21:
22: static Vector genVec= new Vector();
23: public Bundle()
24: {
25:
26: }
27: public void exportToXML(File f) throws Exception
28: {
29: FileWriter fw = new FileWriter(f);
30: BufferedWriter buffr = new BufferedWriter(fw);
31: buffr.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
32: buffr.newLine();
33: buffr.write("<edoc>\n");
34: // write Documents
35: for(int j=0;j<docs.size();++j)
36: {
37: Document doc=(Document)documents.elementAt(j);
38: doc.exportToXML(buffr);
39: }
40:
41: buffr.newLine();
42: buffr.write("</edoc>");
43:
44: buffr.close();
45: fw.close();
46: }
1.3 ! rogo 47:
! 48: public void exportToXMLDownload(File f,File startFile) throws Exception
! 49: {
! 50: String fileLink="";// to save original fileLink
! 51: FileWriter fw = new FileWriter(f);
! 52: BufferedWriter buffr = new BufferedWriter(fw);
! 53: buffr.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
! 54: buffr.newLine();
! 55: buffr.write("<edoc>\n");
! 56: // write Documents
! 57: for(int j=0;j<docs.size();++j)
! 58: {
! 59: Document doc=(Document)documents.elementAt(j);
! 60: if(doc.fileLink!="")
! 61: {
! 62:
! 63: fileLink=doc.fileLink;
! 64: doc.fileLink=startFile.getAbsolutePath()+"/images/"+doc.fileName;
! 65: doc.modified = new File(doc.fileLink).lastModified();
! 66: // System.out.println(doc.fileLink);
! 67: } else fileLink="";
! 68: doc.exportToXML(buffr);
! 69: doc.fileLink=fileLink;
! 70: }
! 71:
! 72: buffr.newLine();
! 73: buffr.write("</edoc>");
! 74:
! 75: buffr.close();
! 76: fw.close();
! 77: }
1.1 rogo 78: static class Document
79: {
80: int docID=0;
81: int ver=0;
82: String title = "";
83: String type = ""; // edoc Type e.g. Archimedes Image Collection
84: String locator="";
85: String comment="";
86: String placeofevent="";
87: int fileID=0;
88: int fileVer=0;
89: String fileName="";
90: String mimeType="";
91: String md5cs="";
92: int size=0;
93: String fileLink="";
94: Hashtable metaTags = new Hashtable();
1.2 rogo 95: long modified = System.currentTimeMillis();
1.3 ! rogo 96: boolean downloadAgain = false;
1.1 rogo 97: static int lastDocID=0;
98: public Document()
99: {
100: docID=++lastDocID;
101: }
102: public Document(int docID,int ver,String title,String locator,String comment,String placeofevent,int fileID,int fileVer,String fileName,String mimeType,String md5cs, int size, String fileLink)
103: {
104: this.docID=docID;
105: this.ver=ver;
106: this.title=title;
107: this.locator=locator;
108: this.comment=comment;
109: this.placeofevent=placeofevent;
110: this.fileID=fileID;
111: this.fileVer=fileVer;
112: this.fileName=fileName;
113: this.mimeType=mimeType;
114: this.md5cs=md5cs;
115: this.size=size;
116: this.fileLink=fileLink;
117: }
118: public void addData(String key,String value)
119: {
120: //System.out.println(key+" "+value);
121: // known tags
122: if(key.equals("docID"))
123: docID = Integer.parseInt(value);
124: else if(key.equals("ver"))
125: ver = Integer.parseInt(value);
126: else if(key.equals("title"))
127: {
128: title=value;
129: metaTags.put(key,value);
130: }
131: else if(key.equals("type"))
132: type=value;
133: else if(key.equals("locator")||key.equals("locater")) // wrong Typing in interface
134: {
135: locator=value;
136: // temporarly because of typing error
137: metaTags.put("locator",value);
138: }
139: else if(key.equals("comment"))
140: {
141: comment=value;
142: metaTags.put(key,value);
143: }
144: else if(key.equals("placeofevent"))
145: {
146: placeofevent=value;
147: metaTags.put(key,value);
148: }
149: else if(key.equals("fileID"))
150: fileID = Integer.parseInt(value);
151: else if(key.equals("fileVer"))
152: fileVer = Integer.parseInt(value);
153: else if(key.equals("filename"))
154: fileName=value;
155: else if(key.equals("mimetype"))
156: mimeType=value;
157: else if(key.equals("md5cs"))
158: md5cs=value;
159: else if(key.equals("size"))
160: size=Integer.parseInt(value);
161: else if(key.equals("filelink"))
162: fileLink=value;
1.2 rogo 163: else if(key.equals("lastmodified"))
164: {
165: modified = Long.parseLong(value);
166: }
1.1 rogo 167: // end of known tags
168: else
169: metaTags.put(key,value);
1.2 rogo 170: //if(key.equals("docaffs")) System.out.println(value);
1.1 rogo 171: }
172: public void removeData(String key)
173: {
174: metaTags.remove(key);
175: }
176: public void exportToXML(BufferedWriter buffr) throws Exception
177: {
178: buffr.write(" <doc id = \""+docID+"\" ver = \""+ver+"\">\n");
179: buffr.write(" <type>"+type+"</type>\n");
180:
181: Enumeration en = metaTags.keys();
182: while(en.hasMoreElements())
183: {
184: String key=(String)en.nextElement();
185: buffr.write(" <"+key+">");
186: buffr.write((String)metaTags.get(key));
187: buffr.write("</"+key+">\n");
188:
189: }
190: buffr.write(" <file id = \""+fileID+"\" ver = \""+fileVer+"\">\n");
191: buffr.write(" <filename>"+fileName+"</filename>\n");
192: buffr.write(" <mimetype>"+mimeType+"</mimetype>\n");
193: buffr.write(" <md5cs>"+md5cs+"</md5cs>\n");
194: buffr.write(" <size>"+size+"</size>\n");
195: buffr.write(" <filelink>"+fileLink+"</filelink>\n");
1.2 rogo 196: buffr.write(" <lastmodified>"+modified+"</lastmodified>\n");
1.1 rogo 197: buffr.write(" </file>\n");
198: buffr.write(" </doc>\n");
199: }
200: public String toString() {
201: return "Document "+docID+" "+size;
202: }
203:
204: }
205: static class Genre
206: {
207:
208: static boolean debug=false;
209: Integer id;
210: String label="";
211: String name="";
212: String definition="";
213: public Genre() {}
214: public String toString()
215: {
216: if(debug)
217: return id+"\n"+label+"\n"+name+"\n"+definition;
218: else return id+" "+label;
219: }
220: public void addData(String key,String value)
221: {
222: //System.out.println(key+" "+value);
223: // known tags
224: if(key.equals("label"))
225: label = value;
226: else if(key.equals("name"))
227: name = value;
228: else if(key.equals("definition"))
229: definition=value;
230: }
231: }
232: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>