source: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSStructureSet.java@ 5945

Last change on this file since 5945 was 5945, checked in by cs025, 20 years ago

Extensive additions to metadata

  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1package org.greenstone.gsdl3.gs3build.metadata;
2
3import java.io.PrintWriter;
4
5import java.util.HashMap;
6import java.util.Map;
7import java.util.List;
8import java.util.ArrayList;
9import java.util.Iterator;
10
11import java.sql.SQLException;
12import java.sql.ResultSet;
13
14import org.greenstone.gsdl3.gs3build.doctypes.DocumentInterface;
15
16import org.greenstone.gsdl3.gs3build.util.GS3SQLConnection;
17import org.greenstone.gsdl3.gs3build.database.*;
18
19public class METSStructureSet
20{ Map children;
21
22 public METSStructureSet()
23 { this.children = new HashMap();
24 }
25
26 public void addStructure(METSStructure structure)
27 { this.children.put(structure.getID(), structure);
28 }
29
30 public METSStructure getStructure(String name)
31 { return (METSStructure) this.children.get(name);
32 }
33
34 /**
35 * Find the divisions that contain a list of given files
36 *
37 * @param <code>List</code> the list of files to find...
38 * @return <code>List</code> the matching divisions.
39 */
40 public List findDivisionsForFiles(List listOfFileIdentifiers)
41 { List reply = new ArrayList();
42
43 // iterate across all the children...
44 Iterator structures = this.children.values().iterator();
45
46 while (structures.hasNext())
47 { METSStructure structure = (METSStructure) structures.next();
48
49 structure.findDivisionsForFiles(listOfFileIdentifiers, reply);
50 }
51 return reply;
52 }
53
54 /**
55 * Add a division to an indicated structure.
56 *
57 * @param <code>String</code> the structure identifier
58 * @param <code>METSDivision</code> the division to be added.
59 */
60 public void addDivision(String structureName, METSDivision division)
61 { METSStructure structure = (METSStructure) this.children.get(structureName);
62
63 if (structure != null)
64 { structure.addDivision(division);
65 }
66 }
67
68 /**
69 * Add a division to an indicated division within structure.
70 *
71 * @param <code>String</code> the structure identifier
72 * @param <code>String</code> the division identifer, within which the division
73 * is to be placed.
74 * @param <code>METSDivision</code> the division to be added.
75 */
76 public void addSubDivision(String structureName, String divisionID, METSDivision division)
77 { METSStructure structure = (METSStructure) this.children.get(structureName);
78
79 if (structure != null)
80 { structure.addSubDivision(divisionID, division);
81 }
82 }
83
84 public METSDivision getDivision(String structureName, String divisionID)
85 { METSStructure structure = (METSStructure) this.children.get(structureName);
86
87 if (structure != null)
88 { return structure.getDivision(divisionID);
89 }
90 return null;
91 }
92
93 public void write(PrintWriter writer)
94 { Iterator structures = this.children.values().iterator();
95
96 while (structures.hasNext())
97 { METSStructure group = (METSStructure) structures.next();
98
99 group.write(writer);
100 }
101 }
102
103 public boolean writeSQL(DocumentInterface document, GS3SQLConnection connection)
104 { Iterator structures = this.children.values().iterator();
105
106 while (structures.hasNext())
107 { METSStructure group = (METSStructure) structures.next();
108
109 if (!group.writeSQL(document, connection))
110 { return false;
111 }
112 }
113 return true;
114 }
115
116 public static METSStructureSet readSQL(DocumentInterface document, GS3SQLConnection connection)
117 {
118 METSStructureSet set = new METSStructureSet();
119
120 GS3SQLSelect select = new GS3SQLSelect("structure");
121 select.addField("*");
122 GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString());
123 select.setWhere(new GS3SQLWhere(whereItem));
124 connection.execute(select.toString());
125
126 // start going through the matching metadata blocks
127 try {
128 ResultSet resultSet = connection.getResultSet();
129 resultSet.first();
130 do {
131 METSStructure structure = METSStructure.readSQL(document, connection, resultSet);
132 if (structure != null) {
133 set.addStructure(structure);
134 }
135 } while (resultSet.next());
136 }
137 catch (SQLException sqlEx) {
138 System.out.println(sqlEx);
139 System.exit(1);
140 }
141
142 return set;
143 }
144
145}
Note: See TracBrowser for help on using the repository browser.