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 | * Copyright (C) 2022 New Zealand Digital Library Project
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
23 | *########################################################################
|
---|
24 | */
|
---|
25 | package org.greenstone.gatherer.cdm;
|
---|
26 |
|
---|
27 | import org.greenstone.gatherer.Gatherer;
|
---|
28 | import org.greenstone.gatherer.Configuration;
|
---|
29 | import org.greenstone.gatherer.util.Codec;
|
---|
30 | import org.greenstone.gatherer.util.StaticStrings;
|
---|
31 | import org.greenstone.gatherer.util.XMLTools;
|
---|
32 | import org.w3c.dom.*;
|
---|
33 |
|
---|
34 |
|
---|
35 | /** This class encapsulates a single search metadata assignment, which constitutes a name, language and value and type
|
---|
36 | */
|
---|
37 | public class SearchMeta
|
---|
38 | extends CollectionMeta {
|
---|
39 |
|
---|
40 | public static final String TYPE_INDEX = "index";
|
---|
41 | public static final String TYPE_LEVEL = "level";
|
---|
42 | public static final String TYPE_PARTITION = "partition";
|
---|
43 | public static final String TYPE_LANGUAGE = "language";
|
---|
44 | public static final String TYPE_SORT = "sort";
|
---|
45 | public static final String TYPE_FACET = "facet";
|
---|
46 |
|
---|
47 | // gs2 all meta have the same type, as there is currently no distinction in
|
---|
48 | // config file
|
---|
49 | public static final String TYPE_SEARCH = "search";
|
---|
50 |
|
---|
51 | // public SearchMeta() {
|
---|
52 | //}
|
---|
53 | /** Constructor.
|
---|
54 | * @param element the Element from which we will determine metadata details
|
---|
55 | */
|
---|
56 | public SearchMeta(Element element) {
|
---|
57 | this.element = element;
|
---|
58 | }
|
---|
59 |
|
---|
60 | public SearchMeta(String name) {
|
---|
61 | System.err.println("error calling new search meta with only a name");
|
---|
62 | }
|
---|
63 | /** Constructor to create a new piece of metadata given its name. */
|
---|
64 | public SearchMeta(String name, String type) {
|
---|
65 | this(name, type, Configuration.getLanguage());
|
---|
66 | }
|
---|
67 |
|
---|
68 | /** Constructor to create a new piece of metadata given its name. */
|
---|
69 | public SearchMeta(String name, String type, String language) {
|
---|
70 | element = CollectionConfiguration.createElement(StaticStrings.SEARCHMETADATA_ELEMENT);
|
---|
71 | element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
|
---|
72 | element.setAttribute(StaticStrings.LANGUAGE_ATTRIBUTE, language);
|
---|
73 | element.setAttribute(StaticStrings.ASSIGNED_ATTRIBUTE, StaticStrings.FALSE_STR);
|
---|
74 | if (Gatherer.GS3) {
|
---|
75 | element.setAttribute(StaticStrings.TYPE_ATTRIBUTE, type);
|
---|
76 | } else {
|
---|
77 | element.setAttribute(StaticStrings.TYPE_ATTRIBUTE, TYPE_SEARCH);
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | /** Constructor to create a new piece of metadata given its name. */
|
---|
82 | public SearchMeta(String name, String type, String language, boolean dummy) {
|
---|
83 | this(name, type, language);
|
---|
84 | this.dummy = dummy;
|
---|
85 | }
|
---|
86 |
|
---|
87 | /** Method to compare two collection metadata objects to calculate their respective ordering.
|
---|
88 | * @param object the other metadata to compare to, as an Object
|
---|
89 | * @return an int which is less than 0 if this object proceeds the given object, 0 if they are equal and greater than 0 otherwise.
|
---|
90 | * @see org.greenstone.gatherer.cdm.Language
|
---|
91 | */
|
---|
92 | // todo this soesn't look at type
|
---|
93 | public int compareTo(Object object) {
|
---|
94 | return toString().compareTo(object.toString());
|
---|
95 | }
|
---|
96 |
|
---|
97 | /** Factory constructor. */
|
---|
98 | public DOMProxyListEntry create(Element element) {
|
---|
99 | return new SearchMeta(element);
|
---|
100 | }
|
---|
101 |
|
---|
102 | /** Method to compare two collection metadata objects for equality.
|
---|
103 | * @param object The other metadata to compare to, as an <strong>Object</strong>.
|
---|
104 | * @return A <i>boolean</i> value of <i>true</i> if the object are equal, <i>false</i> otherwise.
|
---|
105 | */
|
---|
106 | public boolean equals(Object object) {
|
---|
107 | return (compareTo(object) == 0);
|
---|
108 | }
|
---|
109 |
|
---|
110 |
|
---|
111 | public void setType(String type) {
|
---|
112 | if(element != null) {
|
---|
113 | if (Gatherer.GS3) {
|
---|
114 | element.setAttribute(StaticStrings.TYPE_ATTRIBUTE, type);
|
---|
115 | } else {
|
---|
116 | element.setAttribute(StaticStrings.TYPE_ATTRIBUTE, TYPE_SEARCH);
|
---|
117 | }
|
---|
118 | }
|
---|
119 | }
|
---|
120 | public String getType() {
|
---|
121 | if (element != null) {
|
---|
122 |
|
---|
123 | return element.getAttribute(StaticStrings.TYPE_ATTRIBUTE);
|
---|
124 | }
|
---|
125 | return null;
|
---|
126 | }
|
---|
127 | public boolean hasType() {
|
---|
128 | return element.hasAttribute(StaticStrings.TYPE_ATTRIBUTE);
|
---|
129 | }
|
---|
130 | /** Method to print out this class as it would appear within the collection configuration file.
|
---|
131 | * @return A <strong>String</strong> containing the text value of this class.
|
---|
132 | */
|
---|
133 | /** what is this used for???? */
|
---|
134 | public String toString() {
|
---|
135 | if(text == null) {
|
---|
136 | text = "searchmeta ["+getType()+"] [l="+getLanguage()+"] \""+getName()+"\"";
|
---|
137 | }
|
---|
138 | // text = CollectCfgReadWrite.toString(element); // this puts a dot in now. don't want that. but it also adds the language
|
---|
139 | // if (text.equals("")){
|
---|
140 | // text = getName();
|
---|
141 | // }
|
---|
142 | // }
|
---|
143 | return text;
|
---|
144 | }
|
---|
145 | }
|
---|