source: trunk/gli/src/org/greenstone/gatherer/cdm/SubcollectionIndex.java@ 9302

Last change on this file since 9302 was 9161, checked in by mdewsnip, 19 years ago

Made the "assign partitions" tab in the "Partition Indexes" section look a lot like the "Search Indexes" pane.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 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 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.cdm;
28
29import java.util.*;
30import org.greenstone.gatherer.DebugStream;
31import org.greenstone.gatherer.util.StaticStrings;
32import org.greenstone.gatherer.util.Utility;
33import org.greenstone.gatherer.util.XMLTools;
34import org.w3c.dom.*;
35
36/** This class encapsulates a single indexing pair.
37 * @author John Thompson, Greenstone Digital Library, University of Waikato
38 * @version 2.4
39 */
40public class SubcollectionIndex
41 implements Comparable, DOMProxyListEntry {
42
43 private ArrayList sources = null;
44 /** The element this index is based upon. */
45 private Element element = null;
46 /** The unique, if cryptic, identifier of an index. */
47 private String id = null;
48
49 /** Default constructor, which should only be used during DOMProxyListModel creation. */
50 public SubcollectionIndex() {
51 }
52
53 /** Constructor. */
54 public SubcollectionIndex(Element element) {
55 this.element = element;
56 }
57
58 public SubcollectionIndex(Object[] raw_sources) {
59 this.sources = new ArrayList();
60 // Create a new element
61 Document document = CollectionDesignManager.collect_config.document;
62 element = document.createElement(CollectionConfiguration.INDEX_ELEMENT);
63 // For each source add a content element
64 int size = raw_sources.length;
65 for(int i = 0; i < size; i++) {
66 Subcollection subcollection = (Subcollection) raw_sources[i];
67 String subcollection_name = subcollection.getName();
68 sources.add(subcollection_name);
69 Element content_element = document.createElement(CollectionConfiguration.CONTENT_ELEMENT);
70 content_element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, subcollection_name);
71 element.appendChild(content_element);
72 content_element = null;
73 }
74 document = null;
75 }
76
77 /** Method to compare two indexes.
78 * @param object The other index as an <strong>Object</strong>.
79 * @return An <i>int</i> which indicates how the indexes compare.
80 * @see java.lang.String
81 */
82 public int compareTo(Object object) {
83 return getID().compareTo(((SubcollectionIndex)object).getID());
84 }
85
86 public DOMProxyListEntry create(Element element) {
87 return new SubcollectionIndex(element);
88 }
89
90 /** Method to test for the equality of two indexes.
91 * @param object The other index as an <strong>Object</strong>.
92 * @return A <i>boolean</i> which is <i>true</i> if the two indexes are equal, <i>false</i> otherwise.
93 */
94 public boolean equals(Object object) {
95 return (compareTo(object) == 0);
96 }
97
98 public Element getElement() {
99 return element;
100 }
101
102 public String getID() {
103 if(id == null) {
104 StringBuffer id_buffer = new StringBuffer();
105 // Write data information. Retrieve each of the content sources and add them in a comma separated list.
106 ArrayList sources = getSources();
107 int sources_size = sources.size();
108 for(int i = 0; i < sources_size; i++) {
109 id_buffer.append((String)sources.get(i));
110 id_buffer.append(StaticStrings.COMMA_CHARACTER);
111 }
112 sources = null;
113 id = id_buffer.substring(0, id_buffer.length() - 1);
114 }
115 return id;
116 }
117
118 /** Retrieve the sources of this index.
119 * @return the sources as an ArrayList
120 */
121 public ArrayList getSources() {
122 if(sources == null) {
123 sources = new ArrayList();
124 NodeList content_elements = element.getElementsByTagName(CollectionConfiguration.CONTENT_ELEMENT);
125 int content_elements_length = content_elements.getLength();
126 for(int i = 0; i < content_elements_length; i++) {
127 Element content_element = (Element) content_elements.item(i);
128 sources.add(content_element.getAttribute(CollectionConfiguration.NAME_ATTRIBUTE));
129 }
130 content_elements = null;
131 Collections.sort(sources);
132 }
133 return sources;
134 }
135
136 public boolean isAssigned() {
137 return (element != null && !element.getAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE).equals(CollectionConfiguration.FALSE_STR));
138 }
139
140 public void setAssigned(boolean assigned) {
141 if(element != null) {
142 element.setAttribute(CollectionConfiguration.ASSIGNED_ATTRIBUTE, (assigned ? CollectionConfiguration.TRUE_STR : CollectionConfiguration.FALSE_STR));
143 }
144 }
145
146 public void setElement(Element element) {
147 this.element = element;
148 this.id = null;
149 this.sources = null;
150 }
151
152 /** Method to set the sources for this index which can only be used for the default index.
153 * @param sources an ArrayList of source names
154 */
155 public void setSources(ArrayList sources) {
156 if(element != null) {
157 // Erase old sources
158 XMLTools.clear(element);
159 // For each entry in the sources array add a new content element.
160 int size = sources.size();
161 for(int i = 0; i < size; i++) {
162 Element content_element = element.getOwnerDocument().createElement(CollectionConfiguration.CONTENT_ELEMENT);
163 content_element.setAttribute(CollectionConfiguration.NAME_ATTRIBUTE, (String) sources.get(i));
164 element.appendChild(content_element);
165 content_element = null;
166 }
167 this.id = null; // Regenerate ID.
168 this.sources = sources;
169 }
170 }
171
172 /** Method to turn this object into a string representation ready to be placed in the collection configuration file.
173 * @return A <strong>String</strong> containing the information of this class.
174 */
175 public String toString() {
176 String id = getID();
177 StringBuffer text = new StringBuffer(id);
178 CollectionMeta metadatum = CollectionDesignManager.collectionmeta_manager.getMetadatum(StaticStrings.STOP_CHARACTER + id, false);
179 if(metadatum != null) {
180 text.append(" \"");
181 text.append(metadatum.getValue(CollectionMeta.TEXT));
182 text.append("\"");
183 }
184 return text.toString();
185 }
186}
Note: See TracBrowser for help on using the repository browser.