Changeset 8701 for trunk/gsdl3/src/java/org
- Timestamp:
- 2004-11-30T11:14:39+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSDescriptiveSet.java
r8461 r8701 27 27 28 28 public class METSDescriptiveSet 29 { Map children; 30 Map childrenById; 31 DescriptiveIdentifierFactory identifierFactory; 32 33 class DescriptiveIdentifierFactory extends AbstractIdentifierFactory 34 { public DescriptiveIdentifierFactory() 35 { super("DM"); 36 } 37 } 38 39 public METSDescriptiveSet() 40 { this.children = new HashMap(); 41 this.childrenById = new HashMap(); 42 43 this.identifierFactory = new DescriptiveIdentifierFactory(); 44 45 this.createDescriptive("default"); 46 } 47 48 /** 49 * Create a new descriptive child, adding it automatically to this descriptive set. 50 * 51 * @param <code>String</code> a name to describe the descriptive set. 52 */ 53 public METSDescriptive createDescriptive(String name) 54 { METSDescriptive descriptive = new METSDescriptive(this.identifierFactory.getNextIdentifier(), name); 55 56 this.children.put(name, descriptive); 57 this.childrenById.put(descriptive.getID(), descriptive); 58 return descriptive; 59 } 60 61 /** 62 * Add a descriptive item to this set. 63 * 64 * @param <code>METSDescriptive</code> the descriptive set 65 */ 66 public void addDescriptive(METSDescriptive metadata) 67 { // insert the item into both maps... 68 this.children.put(metadata.getName(), metadata); 69 this.childrenById.put(metadata.getID(), metadata); 70 71 // when a descriptive block is added, check that it hasn't been used before... 72 //this.identifierFactory.noteIdentifier(metadata.getID()); 73 this.identifierFactory.noteIdentifier(metadata.getName()); 74 } 75 76 /** 77 * Get a descriptive item by its name(GROUPID in METS file) 78 */ 79 public METSDescriptive getDescriptive(String name) 80 { return (METSDescriptive) this.children.get(name); 81 } 82 83 /** 84 * Get a descriptive item by its identifier 85 */ 86 public METSDescriptive getDescriptiveById(String id) 87 { return (METSDescriptive) this.childrenById.get(id); 88 } 89 90 public void addNamespace(String descriptiveName, METSNamespace namespace) 91 { METSDescriptive descriptive = this.getDescriptive(descriptiveName); 92 if (descriptive != null) 93 { descriptive.addNamespace(namespace); 94 } 95 } 96 97 public METSNamespace getNamespace(String descriptiveName, String namespace) 98 { METSDescriptive descriptive = this.getDescriptive(descriptiveName); 99 if (descriptive != null) 100 { return descriptive.getNamespace(namespace); 101 } 102 return null; 103 } 104 105 public METSNamespace getOpenNamespace(String descriptiveName, String namespace) 106 { METSDescriptive descriptive = this.getDescriptive(descriptiveName); 107 108 if (descriptive != null) 109 { return descriptive.getOpenNamespace(namespace); 110 } 111 return null; 112 } 113 114 public void addMetadata(String descriptiveName, String namespace, String label, String value) 115 { METSDescriptive descriptive = this.getDescriptive(descriptiveName); 116 117 if (descriptive != null) 118 { descriptive.addMetadata(namespace, label, value); 119 } 120 } 121 122 public void setMetadata(String descriptiveName, String namespace, String label, String value) 123 { METSDescriptive descriptive = this.getDescriptive(descriptiveName); 124 125 if (descriptive != null) 126 { descriptive.setMetadata(namespace, label, value); 127 } 128 } 129 130 public void removeMetadata(String descriptiveName, String namespace, String label) 131 { METSDescriptive descriptive = this.getDescriptive(descriptiveName); 132 133 if (descriptive != null) 134 { descriptive.removeMetadata(namespace, label); 135 } 136 } 137 138 public void removeAllMetadata(String namespace, String label) 139 { Iterator descriptiveIter = this.children.values().iterator(); 140 141 while (descriptiveIter.hasNext()) { 142 METSDescriptive descriptive = (METSDescriptive) descriptiveIter.next(); 143 144 descriptive.removeMetadata(namespace, label); 145 } 146 } 147 148 public List getMetadata(String descriptiveName, String namespace, String label) 149 { METSDescriptive descriptive = this.getDescriptive(descriptiveName); 150 151 if (descriptive != null) 152 { return descriptive.getMetadata(namespace, label); 153 } 154 return null; 155 } 156 157 public void write(PrintWriter writer) 158 { Iterator groups = this.children.values().iterator(); 159 160 while (groups.hasNext()) 161 { METSDescriptive group = (METSDescriptive) groups.next(); 162 163 group.write(writer); 164 } 165 } 166 167 168 public boolean writeSQL(DocumentInterface document, GS3SQLConnection connection) 169 { Iterator groups = this.children.values().iterator(); 170 171 while (groups.hasNext()) 172 { METSDescriptive group = (METSDescriptive) groups.next(); 173 174 if (!group.writeSQL(document, connection)) 175 { return false; 176 } 177 } 178 return true; 179 } 180 /* 181 public static METSDescriptiveSet parseXML(NodeList fileSecs) 182 { 183 METSDescriptiveSet set = new METSDescriptiveSet(); 184 185 for (int g = 0; g < fileSecs.getLength(); g ++) { 186 // Schema schema = new Schema(schemas.item(s)); 187 METSDescriptive metadata = METSDescriptive.parseXML((Element) fileSecs.item(g)); 188 set.addDescriptive(metadata); 189 } 190 return set; 191 } 192 */ 29 { 30 Map children; 31 Map childrenById; 32 DescriptiveIdentifierFactory identifierFactory; 33 34 class DescriptiveIdentifierFactory extends AbstractIdentifierFactory 35 { 36 public DescriptiveIdentifierFactory() 37 { 38 super("DM"); 39 } 40 } 41 42 public METSDescriptiveSet() 43 { 44 this.children = new HashMap(); 45 this.childrenById = new HashMap(); 46 47 this.identifierFactory = new DescriptiveIdentifierFactory(); 48 49 this.createDescriptive("default"); 50 } 51 52 /** 53 * Create a new descriptive child, adding it automatically to this descriptive set. 54 * 55 * @param <code>String</code> a name to describe the descriptive set. 56 */ 57 public METSDescriptive createDescriptive(String name) 58 { 59 METSDescriptive descriptive = new METSDescriptive(this.identifierFactory.getNextIdentifier(), name); 60 61 this.children.put(name, descriptive); 62 this.childrenById.put(descriptive.getID(), descriptive); 63 return descriptive; 64 } 65 66 /** 67 * Add a descriptive item to this set. 68 * 69 * @param <code>METSDescriptive</code> the descriptive set 70 */ 71 public void addDescriptive(METSDescriptive metadata) 72 { 73 // insert the item into both maps... 74 this.children.put(metadata.getName(), metadata); 75 this.childrenById.put(metadata.getID(), metadata); 76 77 // when a descriptive block is added, check that it hasn't been used before... 78 //this.identifierFactory.noteIdentifier(metadata.getID()); 79 this.identifierFactory.noteIdentifier(metadata.getName()); 80 } 81 82 /** 83 * Get a descriptive item by its name(GROUPID in METS file) 84 */ 85 public METSDescriptive getDescriptive(String name) 86 { 87 88 return (METSDescriptive) this.children.get(name); 89 } 90 91 /** 92 * Get a descriptive item by its identifier 93 */ 94 public METSDescriptive getDescriptiveById(String id) 95 { 96 return (METSDescriptive) this.childrenById.get(id); 97 } 98 99 public void addNamespace(String descriptiveName, METSNamespace namespace) 100 { 101 METSDescriptive descriptive = this.getDescriptive(descriptiveName); 102 if (descriptive != null){ 103 descriptive.addNamespace(namespace); 104 } 105 } 106 107 public METSNamespace getNamespace(String descriptiveName, String namespace) 108 { 109 METSDescriptive descriptive = this.getDescriptive(descriptiveName); 110 if (descriptive != null){ 111 return descriptive.getNamespace(namespace); 112 } 113 return null; 114 } 115 116 public METSNamespace getOpenNamespace(String descriptiveName, String namespace) 117 { 118 METSDescriptive descriptive = this.getDescriptive(descriptiveName); 119 120 if (descriptive != null){ 121 return descriptive.getOpenNamespace(namespace); 122 } 123 return null; 124 } 125 126 public void addMetadata(String descriptiveName, String namespace, String label, String value) 127 { 128 METSDescriptive descriptive = this.getDescriptive(descriptiveName); 129 130 if (descriptive != null){ 131 descriptive.addMetadata(namespace, label, value); 132 } 133 } 134 135 public void setMetadata(String descriptiveName, String namespace, String label, String value) 136 { 137 METSDescriptive descriptive = this.getDescriptive(descriptiveName); 138 139 if (descriptive != null){ 140 descriptive.setMetadata(namespace, label, value); 141 } 142 } 143 144 public void removeMetadata(String descriptiveName, String namespace, String label) 145 { 146 METSDescriptive descriptive = this.getDescriptive(descriptiveName); 147 148 if (descriptive != null){ 149 descriptive.removeMetadata(namespace, label); 150 } 151 } 152 153 public void removeAllMetadata(String namespace, String label) 154 { 155 Iterator descriptiveIter = this.children.values().iterator(); 156 157 while (descriptiveIter.hasNext()) { 158 METSDescriptive descriptive = (METSDescriptive) descriptiveIter.next(); 159 160 descriptive.removeMetadata(namespace, label); 161 } 162 } 163 164 public List getMetadata(String descriptiveName, String namespace, String label) 165 { 166 METSDescriptive descriptive = this.getDescriptive(descriptiveName); 167 168 if (descriptive != null){ 169 return descriptive.getMetadata(namespace, label); 170 } 171 return null; 172 } 173 174 public void write(PrintWriter writer) 175 { 176 Iterator groups = this.children.values().iterator(); 177 178 while (groups.hasNext()){ 179 METSDescriptive group = (METSDescriptive) groups.next(); 180 181 group.write(writer); 182 } 183 } 184 185 186 public boolean writeSQL(DocumentInterface document, GS3SQLConnection connection) 187 { 188 Iterator groups = this.children.values().iterator(); 189 190 while (groups.hasNext()){ 191 METSDescriptive group = (METSDescriptive) groups.next(); 192 193 if (!group.writeSQL(document, connection)){ 194 return false; 195 } 196 } 197 return true; 198 } 193 199 194 200 /* public static METSDescriptiveSet parseXML(NodeList dmdSecs) … … 201 207 String ID = dmdNode.getAttribute("ID"); 202 208 String label = dmdNode.getAttribute("GROUPID"); 203 System.err.println("###Label="+label); 204 209 205 210 if (label.equals("1")) { 206 thisDescriptive = set.getDescriptive("default"); 207 System.err.println("####thisDescriptiveDefault=" + thisDescriptive); 211 thisDescriptive = set.getDescriptive("default"); 208 212 } else { 209 thisDescriptive = new METSDescriptive(ID, label); 210 System.err.println("####thisDescriptive=" + thisDescriptive); 211 } 212 213 thisDescriptive = new METSDescriptive(ID, label); 214 } 215 213 216 METSDescriptive metadata = METSDescriptive.parseXML((Element) dmdSecs.item(g), thisDescriptive); 214 217 215 218 set.addDescriptive(metadata); 216 219 } 217 return set; 218 }*/ 220 return set; 221 }*/ 222 219 223 public static METSDescriptiveSet parseXML(NodeList dmdSecs) 220 224 { … … 226 230 set.addDescriptive(metadata); 227 231 } 228 229 232 230 233 System.err.println("******** Away to do transfer!!!!!!"); … … 234 237 METSDescriptive opo_metadata = set.getDescriptive("1.1"); 235 238 METSDescriptive default_metadata = set.getDescriptive("default"); 236 239 237 240 if (top_level_metadata != null) { 238 241 if (default_metadata != null) { … … 248 251 return set; 249 252 } 250 251 public static METSDescriptiveSet readSQL(DocumentInterface document, GS3SQLConnection connection)252 {253 254 255 256 257 258 259 260 261 262 263 264 265 266 METSDescriptive descriptive = METSDescriptive.readSQL(document, connection, resultSet);267 if (descriptive != null) {268 set.addDescriptive(descriptive);269 }270 else {271 System.out.println("Null descriptive");272 }273 274 275 276 277 278 279 280 281 }253 254 public static METSDescriptiveSet readSQL(DocumentInterface document, GS3SQLConnection connection) 255 { 256 METSDescriptiveSet set = new METSDescriptiveSet(); 257 258 GS3SQLSelect select = new GS3SQLSelect("metadata"); 259 select.addField("*"); 260 GS3SQLWhereItem whereItem = new GS3SQLWhereItem("DocID", "=", document.getID().toString()); 261 select.setWhere(new GS3SQLWhere(whereItem)); 262 connection.execute(select.toString()); 263 264 // start going through the matching metadata blocks 265 try { 266 ResultSet resultSet = connection.getResultSet(); 267 resultSet.first(); 268 do { 269 METSDescriptive descriptive = METSDescriptive.readSQL(document, connection, resultSet); 270 if (descriptive != null) { 271 set.addDescriptive(descriptive); 272 } 273 else { 274 System.out.println("Null descriptive"); 275 } 276 } while (resultSet.next()); 277 } 278 catch (SQLException sqlEx) { 279 System.out.println(sqlEx); 280 System.exit(1); 281 } 282 283 return set; 284 } 282 285 } 283 286
Note:
See TracChangeset
for help on using the changeset viewer.