source: trunk/gli/src/org/greenstone/gatherer/metadata/MetadataElement.java@ 8622

Last change on this file since 8622 was 8231, checked in by mdewsnip, 20 years ago

Replaced all "Gatherer.config" with "Configuration".

  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/**
2 *############################################################################
3 * A component of the Greenstone Librarian Interface, part of the Greenstone
4 * digital library suite from the New Zealand Digital Library Project at the
5 * University of Waikato, New Zealand.
6 *
7 * Author: Michael Dewsnip, NZDL Project, University of Waikato, NZ
8 *
9 * Copyright (C) 2004 New Zealand Digital Library Project
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *############################################################################
25 */
26
27package org.greenstone.gatherer.metadata;
28
29
30import java.io.File;
31import org.greenstone.gatherer.Configuration;
32import org.greenstone.gatherer.util.XMLTools;
33import org.w3c.dom.*;
34
35
36/** This class represents one Metadata element */
37public class MetadataElement
38{
39 private String metadata_element_name_full = null;
40 private Element metadata_element_element = null;
41 private MetadataValueTreeModel metadata_value_tree_model = null;
42
43
44 public MetadataElement(String metadata_element_name_full, Element metadata_element_element)
45 {
46 this.metadata_element_name_full = metadata_element_name_full;
47 this.metadata_element_element = metadata_element_element;
48 this.metadata_value_tree_model = new MetadataValueTreeModel(this);
49 }
50
51
52 public MetadataValueTreeNode addMetadataValue(String metadata_value)
53 {
54 return metadata_value_tree_model.addMetadataValue(metadata_value);
55 }
56
57
58 public String getAttribute(String attribute_name, String language_code)
59 {
60 // Some extracted metadata elements may not be in ex.mds, and so have no attributes
61 if (metadata_element_element == null) {
62 return null;
63 }
64
65 Element parent_element = metadata_element_element;
66 boolean language_matches = false;
67
68 NodeList language_elements_nodelist = metadata_element_element.getElementsByTagName("Language");
69 for (int i = 0; i < language_elements_nodelist.getLength(); i++) {
70 Element current_language_element = (Element) language_elements_nodelist.item(i);
71 String current_language_element_code = current_language_element.getAttribute("code");
72 if (current_language_element_code.equals(language_code)) {
73 // Found language; use it for the next step
74 parent_element = current_language_element;
75 language_matches = true;
76 break;
77 }
78 }
79
80 NodeList attribute_elements_nodelist = parent_element.getElementsByTagName("Attribute");
81 for (int i = 0; i < attribute_elements_nodelist.getLength(); i++) {
82 Element current_attribute_element = (Element) attribute_elements_nodelist.item(i);
83 String current_attribute_element_name = current_attribute_element.getAttribute("name");
84 if (!current_attribute_element_name.equals(attribute_name)) {
85 // Move on to the next Attribute element if the name doesn't match
86 continue;
87 }
88
89 // Check if the language matches
90 String current_attribute_element_language = current_attribute_element.getAttribute("language");
91 if (language_matches || current_attribute_element_language.equals(language_code)) {
92 // Found attribute; returns its value
93 return XMLTools.getElementTextValue(current_attribute_element);
94 }
95 }
96
97 return null;
98 }
99
100
101 public String getDisplayName()
102 {
103 String metadata_element_display_name = MetadataTools.getMetadataElementAttribute(this, "identifier", Configuration.getLanguage(), "en");
104 if (metadata_element_display_name != null) {
105 return getNamespace() + "." + metadata_element_display_name;
106 }
107
108 return metadata_element_name_full;
109 }
110
111
112 public MetadataValueTreeModel getMetadataValueTreeModel()
113 {
114 return metadata_value_tree_model;
115 }
116
117
118 public MetadataValueTreeNode getMetadataValueTreeNode(String metadata_value)
119 {
120 return metadata_value_tree_model.getMetadataValueTreeNode(metadata_value);
121 }
122
123
124 public String getFullName()
125 {
126 return metadata_element_name_full;
127 }
128
129
130 public String getNamespace()
131 {
132 return MetadataTools.getMetadataSetNamespace(metadata_element_name_full);
133 }
134
135
136 public String getName()
137 {
138 return MetadataTools.getMetadataElementName(metadata_element_name_full);
139 }
140
141
142 public boolean isExtractedMetadata()
143 {
144 return getNamespace().equals(MetadataSetManager.EXTRACTED_METADATA_NAMESPACE);
145 }
146
147
148 /** This is used to display the element in the metadata value table */
149 public String toString()
150 {
151 return getDisplayName();
152 }
153
154
155 public void writeHierarchyFile(File hierarchy_file)
156 {
157 metadata_value_tree_model.writeHierarchyFile(hierarchy_file);
158 }
159}
Note: See TracBrowser for help on using the repository browser.