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: Katherine Don, New Zealand Digital Library Project,
|
---|
11 | * University of Waikato
|
---|
12 | *
|
---|
13 | * <BR><BR>
|
---|
14 | *
|
---|
15 | * Copyright (C) 2006 New Zealand Digital Library Project
|
---|
16 | *
|
---|
17 | * <BR><BR>
|
---|
18 | *
|
---|
19 | * This program is free software; you can redistribute it and/or modify
|
---|
20 | * it under the terms of the GNU General Public License as published by
|
---|
21 | * the Free Software Foundation; either version 2 of the License, or
|
---|
22 | * (at your option) any later version.
|
---|
23 | *
|
---|
24 | * <BR><BR>
|
---|
25 | *
|
---|
26 | * This program is distributed in the hope that it will be useful,
|
---|
27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
29 | * GNU General Public License for more details.
|
---|
30 | *
|
---|
31 | * <BR><BR>
|
---|
32 | *
|
---|
33 | * You should have received a copy of the GNU General Public License
|
---|
34 | * along with this program; if not, write to the Free Software
|
---|
35 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
36 | *########################################################################
|
---|
37 | */
|
---|
38 | package org.greenstone.gatherer.gems;
|
---|
39 |
|
---|
40 | import org.greenstone.gatherer.Configuration;
|
---|
41 |
|
---|
42 | import java.util.ArrayList;
|
---|
43 |
|
---|
44 |
|
---|
45 | /** this is used as a base class for MetadataSetInfo and MetadataElementModel
|
---|
46 | * Both of thesee have some attributes which are language independent, and
|
---|
47 | * some which are language dependent
|
---|
48 | */
|
---|
49 | public class AttributeContainer {
|
---|
50 |
|
---|
51 | protected ArrayList attributes;
|
---|
52 | protected ArrayList language_dependent_attributes;
|
---|
53 |
|
---|
54 | String [] required_attribute_names = null;
|
---|
55 | String [] language_dependent_attribute_names = null;
|
---|
56 |
|
---|
57 | public AttributeContainer() {}
|
---|
58 | public AttributeContainer(String [] required_atts, String []lang_dependent_atts) {
|
---|
59 |
|
---|
60 | attributes = new ArrayList();
|
---|
61 | language_dependent_attributes = new ArrayList();
|
---|
62 |
|
---|
63 | if (required_atts != null) {
|
---|
64 | required_attribute_names = required_atts;
|
---|
65 | for(int i=0;i<required_atts.length;i++){
|
---|
66 | String reName = required_atts[i];
|
---|
67 | Attribute attr = new Attribute(reName,"",true);
|
---|
68 | attributes.add(attr);
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | if (lang_dependent_atts != null) {
|
---|
73 | language_dependent_attribute_names = lang_dependent_atts;
|
---|
74 | for(int i=0;i<lang_dependent_atts.length;i++){
|
---|
75 | String reName = lang_dependent_atts[i];
|
---|
76 | Attribute attr = new Attribute(reName,"",Configuration.getLanguage(),true);
|
---|
77 | language_dependent_attributes.add(attr);
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | }
|
---|
82 |
|
---|
83 | public ArrayList getAttributes(){
|
---|
84 | return attributes;
|
---|
85 | }
|
---|
86 |
|
---|
87 | public void setAttributes(ArrayList atts) {
|
---|
88 | attributes.clear();
|
---|
89 | attributes = atts;
|
---|
90 | }
|
---|
91 |
|
---|
92 | public String [] getLanguageDependentAttributeNames() {
|
---|
93 | return language_dependent_attribute_names;
|
---|
94 | }
|
---|
95 | public ArrayList getLanguageDependentAttributes(){
|
---|
96 | return language_dependent_attributes;
|
---|
97 | }
|
---|
98 |
|
---|
99 | public void setLanguageDependentAttributes(ArrayList lda){
|
---|
100 | language_dependent_attributes.clear();
|
---|
101 | language_dependent_attributes = lda;
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | protected ArrayList getAllLanguages(){
|
---|
106 | ArrayList langs = new ArrayList();
|
---|
107 |
|
---|
108 | for(int i=0;i<language_dependent_attributes.size();i++){
|
---|
109 | Attribute attr = (Attribute) language_dependent_attributes.get(i);
|
---|
110 | if (!langs.contains(attr.getLanguage()) && !attr.getLanguage().trim().equals("")){
|
---|
111 | langs.add(attr.getLanguage());
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | return langs;
|
---|
116 | }
|
---|
117 |
|
---|
118 | public int languageExists(String lang){
|
---|
119 | for(int i=0;i<language_dependent_attributes.size();i++){
|
---|
120 | Attribute attr = (Attribute) language_dependent_attributes.get(i);
|
---|
121 | if (attr.getLanguage().trim().equals(lang.trim())){
|
---|
122 | return i;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | return -1;
|
---|
127 | }
|
---|
128 |
|
---|
129 | protected Attribute getAttributeByName(String name){
|
---|
130 | for(int i=0;i<attributes.size();i++){
|
---|
131 | Attribute attr = (Attribute) attributes.get(i);
|
---|
132 | if (attr.getName() != null && attr.getName().trim().equals(name.trim())){
|
---|
133 | return attr;
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | return null;
|
---|
138 | }
|
---|
139 |
|
---|
140 | protected Attribute getAttributeByNameAndLanguage(String name, String lang){
|
---|
141 | for(int i=0;i<language_dependent_attributes.size();i++){
|
---|
142 | Attribute attr = (Attribute) language_dependent_attributes.get(i);
|
---|
143 | if (attr.getName() != null || attr.getLanguage()!=null){
|
---|
144 | if (attr.getName().trim().equals(name.trim()) && (attr.getLanguage().trim().equals(lang.trim()))){
|
---|
145 | return attr;
|
---|
146 | }
|
---|
147 | }
|
---|
148 | }
|
---|
149 |
|
---|
150 | return null;
|
---|
151 |
|
---|
152 | }
|
---|
153 |
|
---|
154 | protected ArrayList getAttributesByLanguage(String lang){
|
---|
155 | ArrayList attrs = new ArrayList();
|
---|
156 |
|
---|
157 | for(int i=0;i<language_dependent_attributes.size();i++){
|
---|
158 | Attribute attr = (Attribute) language_dependent_attributes.get(i);
|
---|
159 | if (!attr.getLanguage().trim().equals("") && attr.getLanguage().trim().equals(lang)){
|
---|
160 | attrs.add(attr);
|
---|
161 | }
|
---|
162 | }
|
---|
163 |
|
---|
164 | return attrs;
|
---|
165 | }
|
---|
166 |
|
---|
167 | protected boolean isAttributeRequired(String name) {
|
---|
168 | for(int i=0;i<required_attribute_names.length;i++){
|
---|
169 | if (name.equals(required_attribute_names[i])) return true;
|
---|
170 | }
|
---|
171 | return false;
|
---|
172 |
|
---|
173 | }
|
---|
174 |
|
---|
175 | protected boolean isLangDependentAttributeRequired(String name) {
|
---|
176 | for(int i=0;i<language_dependent_attribute_names.length;i++){
|
---|
177 | if (name.equals(language_dependent_attribute_names[i])) return true;
|
---|
178 | }
|
---|
179 | return false;
|
---|
180 |
|
---|
181 | }
|
---|
182 |
|
---|
183 | }
|
---|