source: trunk/gli/src/org/greenstone/gatherer/cdm/Index.java@ 4494

Last change on this file since 4494 was 4494, checked in by jmt12, 21 years ago

2030098: Fixed translation manager and separated the Languages from the possible text fragment Translations.

  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37
38
39
40
41
42
43package org.greenstone.gatherer.cdm;
44/**************************************************************************************
45 * Title: Gatherer
46 * Description: The Gatherer: a tool for gathering and enriching a digital collection.
47 * Copyright: Copyright (c) 2001
48 * Company: The University of Waikato
49 * Written: 03/05/02
50 * Revised: 17/11/02
51 **************************************************************************************/
52import java.util.Collections;
53import java.util.Comparator;
54import java.util.Vector;
55import org.greenstone.gatherer.cdm.CollectionMeta;
56import org.greenstone.gatherer.msm.MSMUtils;
57import org.w3c.dom.Element;
58/** This class encapsulates a single indexing pair.
59 * @author John Thompson, Greenstone Digital Library, University of Waikato
60 * @version 2.2
61 */
62public class Index
63 implements Comparable {
64 /** A refernce to the main manager for access to other sub-managers. */
65 private CollectionDesignManager manager = null;
66 /** The level of this index. */
67 private int level = 0;
68 /** The sources for data this index is built apon, which are either fully qualified metadata element names or 'text'. */
69 private Vector sources = null;
70 /** An element in the index level enumeration. */
71 static public final int DOCUMENT = 0;
72 /** An element in the index level enumeration. */
73 static public final int PARAGRAPH = 1;
74 /** An element in the index level enumeration. */
75 static public final int SECTION = 2;
76 /** An values of items in the index level enumeration. */
77 static public final String LEVEL[] = {"document","paragraph","section"};
78 /** Constructor.
79 * @param level The level of this index as a <strong>String</string>.
80 * @param metadata The fully qualified name of the metadata this index is built on as a <strong>String</strong>, or <i>null</i> in which case the data defaults to "text".
81 */
82 public Index(int level, Vector sources, CollectionDesignManager manager) {
83 this.level = level;
84 this.manager = manager;
85 this.sources = sources;
86 if(this.sources == null) {
87 this.sources = new Vector();
88 this.sources.add("text");
89 }
90 }
91 /** Method to compare two indexes.
92 * @param object The other index as an <strong>Object</strong>.
93 * @return An <i>int</i> which indicates how the indexes compare.
94 * @see java.lang.String
95 */
96 public int compareTo(Object object) {
97 return toString(false).compareTo(object.toString());
98 }
99 /** Method to test for the equality of two indexes.
100 * @param object The other index as an <strong>Object</strong>.
101 * @return A <i>boolean</i> which is <i>true</i> if the two indexes are equal, <i>false</i> otherwise.
102 */
103 public boolean equals(Object object) {
104 if(compareTo(object) == 0) {
105 return true;
106 }
107 return false;
108 }
109 /** Method to get the data source of this index.
110 * @return A <strong>String</string> which is a comma separated list of either fully qualified names of an assigned metadata elements, or "text".
111 */
112 public String getData() {
113 String result = "";
114 Collections.sort(sources, new IndexComparator());
115 for(int i = 0; i < sources.size(); i++) {
116 result = result + sources.get(i).toString();
117 if(i < sources.size() - 1) {
118 result = result + ",";
119 }
120 }
121 return result;
122 }
123 /** Method to get the value of level.
124 * @return The value of level as a <strong>String</strong>.
125 */
126 public int getLevel() {
127 return level;
128 }
129 /** Method to get the value of metadata.
130 * @return The value of metadata as an <strong>Vector</strong>.
131 */
132 public Vector getMetadata() {
133 return sources;
134 }
135 /** Method to retrieve this indexes name.
136 * @return A <strong>String</strong>.
137 */
138 public String getName() {
139 if(manager != null) {
140 String name = LEVEL[level] + ":" + getData();
141 Language language = manager.languages.getDefaultLanguage();
142 CollectionMeta metadata = manager.collectionmetadatum.getMetadata(name, language, true);
143 if(metadata != null) {
144 return metadata.getValue();
145 }
146 }
147 return "";
148 }
149 /** Method to turn this object into a string representation ready to be placed in the collection configuration file.
150 * @return A <strong>String</strong> containing the information of this class.
151 */
152 public String toString() {
153 return LEVEL[level] + ":" + getData();
154 }
155 /** Retrieve a textual representation of this index.
156 * @param show_name <i>true</i> if you want the name of this index, <i>false</i> for the gsdl index reference.
157 */
158 public String toString(boolean show_name) {
159 if(show_name) {
160 return getName();
161 }
162 return LEVEL[level] + ":" + getData();
163 }
164 /** A custom comparator for comparing Indexes. */
165 private class IndexComparator
166 implements Comparator {
167 /** Method to compare two objects, which may be either indexes or strings.
168 * @param object1 One object as an <strong>Object</strong>.
169 * @param object2 Another object as an <strong>Object</strong>.
170 * @return An <i>int</i> which indicates how they compare.
171 * @see java.lang.String
172 */
173 public int compare(Object object1, Object object2) {
174 if(object1 instanceof Index && object2 instanceof Index) {
175 Index index1 = (Index)object1;
176 Index index2 = (Index)object2;
177 return index1.toString(false).compareTo(index2.toString(false));
178 }
179 else if(object1 instanceof Index) {
180 Index index = (Index) object1;
181 return index.toString(false).compareTo(object2.toString());
182 }
183 else if(object2 instanceof Index) {
184 Index index = (Index) object2;
185 return object1.toString().compareTo(index.toString(false));
186 }
187 return object1.toString().compareTo(object2.toString());
188 }
189 /** Method to test for the equality of two objects, which may be indexes or strings.
190 * @param object Another object as an <strong>Object</strong>.
191 * @return A <i>boolean</i> which is <i>true</i> if the two objects are equal, <i>false</i> otherwise.
192 */
193 public boolean equals(Object object) {
194 if(compareTo(object) == 0) {
195 return true;
196 }
197 return false;
198 }
199 }
200}
Note: See TracBrowser for help on using the repository browser.