source: trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/metadata/METSNamespace.java@ 5800

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

Adding gs3build

  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1package org.greenstone.gsdl3.gs3build.metadata;
2
3import java.io.PrintWriter;
4
5import java.util.List;
6
7import org.greenstone.gsdl3.gs3build.util.GS3SQLConnection;
8import org.greenstone.gsdl3.gs3build.database.*;
9
10/**
11 * Implement a single namespace
12 */
13
14public abstract class METSNamespace
15{
16 protected String type; // the type of the metadata
17 protected String otherType; // if a non-standard type, then...
18 protected String name; // e.g. "DC" for Dublin Core
19 protected METSLocation location; // the location of the corresponding file
20 protected String group; // the group of metadata namespaces to which
21 // this namespace belongs
22 protected String id; // the ID for this namespace
23
24 public METSNamespace(String name)
25 { this.name = name;
26 this.location = null;
27 this.group = null;
28 this.id = null;
29 }
30
31 public METSNamespace(String name, METSLocation location)
32 { this.location = location;
33 this.name = name;
34 this.group = null;
35 this.id = null;
36 }
37
38 /**
39 * Get the name of the namespace...
40 *
41 * @return <code>String</code> the name of the namespace
42 */
43 public String getName()
44 { return this.name;
45 }
46
47 /**
48 * Get the group of namespaces to which this namespace belongs.
49 *
50 * @return <code>String</code> the name of the namespace group
51 */
52 public String getGroup()
53 { return this.group;
54 }
55
56 /**
57 * Set the group of namespaces to which this namespace belongs.
58 *
59 * @param <code>String</code> the name of the namespace group
60 */
61 public void setGroup(String group)
62 { this.group = group;
63 }
64
65 /**
66 * Get the ID for this namespace.
67 *
68 * @return <code>String</code> the id of the namespace
69 */
70 public String getID()
71 { return this.id;
72 }
73
74 /**
75 * Set the id of this namespace.
76 *
77 * @param <code>String</code> the name of the namespace group
78 */
79 public void setID(String id)
80 { this.id = id;
81 }
82
83 /**
84 * <p>Indicate whether this namespace is open to being changed or not.</p>
85 * <p>Metadata which is created from a distinct file cannot be changed,
86 * only those which have no associated file can be modified.
87 *
88 * @return <code>boolean</code> whether this namespace can be altered.
89 */
90 public boolean isEditable()
91 { return (this.location == null);
92 }
93
94 public abstract boolean addMetadata(String label, String value);
95 public abstract boolean setMetadata(String label, String value);
96 public abstract boolean removeMetadata(String label);
97 public abstract boolean removeMetadata(String label, String value);
98 public abstract List getMetadata(String label);
99 public abstract boolean write(PrintWriter writer);
100 // public abstract boolean writeSQL(GS3SQLConnection connection);
101
102 /**
103 * Write out the metadata to an SQL database through a <code>GS3SQLConnection</code>.
104 *
105 * @param <code>GS3SQLConnection</code> the SQL database to use.
106 */
107 public boolean writeSQL(int parentId, GS3SQLConnection connection)
108 {
109 GS3SQLInsert insert = new GS3SQLInsert("namespaces");
110
111 if (this.id != null) {
112 insert.addValue("NamespaceID", this.id);
113 }
114
115 if (this.location != null) {
116 insert.addValue("fileLoc", this.location.getLocation().toString());
117 insert.addValue("fileType", "URL");
118 }
119 else {
120 // no location stuff
121 }
122 insert.addValue("MetadataRef", Integer.toString(parentId), GS3SQLField.INTEGER_TYPE);
123 insert.addValue("NamespaceType", this.name);
124
125 // System.out.println(insert.toString());
126 connection.execute(insert.toString());
127
128 return true;
129 }
130}
Note: See TracBrowser for help on using the repository browser.