source: trunk/gli/src/org/greenstone/gatherer/gems/AttributeContainer.java@ 12659

Last change on this file since 12659 was 12659, checked in by kjdon, 18 years ago

a new base class for MetadataSetInfo and MetadataElementModel as they share a lot of code

  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 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: 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 */
38package org.greenstone.gatherer.gems;
39
40import org.greenstone.gatherer.Configuration;
41
42import 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 */
49public 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 = atts;
89 }
90
91 public String [] getLanguageDependentAttributeNames() {
92 return language_dependent_attribute_names;
93 }
94 public ArrayList getLanguageDependentAttributes(){
95 return language_dependent_attributes;
96 }
97
98 public void setLangDependAttributes(ArrayList lda){
99 language_dependent_attributes = lda;
100 }
101
102
103 protected ArrayList getAllLanguages(){
104 ArrayList langs = new ArrayList();
105
106 for(int i=0;i<language_dependent_attributes.size();i++){
107 Attribute attr = (Attribute) language_dependent_attributes.get(i);
108 if (!langs.contains(attr.getLanguage()) && !attr.getLanguage().trim().equals("")){
109 langs.add(attr.getLanguage());
110 }
111 }
112
113 return langs;
114 }
115
116 public int languageExists(String lang){
117 for(int i=0;i<language_dependent_attributes.size();i++){
118 Attribute attr = (Attribute) language_dependent_attributes.get(i);
119 if (attr.getLanguage().trim().equals(lang.trim())){
120 return i;
121 }
122 }
123
124 return -1;
125 }
126
127 protected Attribute getAttributeByName(String name){
128 for(int i=0;i<attributes.size();i++){
129 Attribute attr = (Attribute) attributes.get(i);
130 if (attr.getName() != null && attr.getName().trim().equals(name.trim())){
131 return attr;
132 }
133 }
134
135 return null;
136 }
137
138 protected Attribute getAttributeByNameAndLanguage(String name, String lang){
139 for(int i=0;i<language_dependent_attributes.size();i++){
140 Attribute attr = (Attribute) language_dependent_attributes.get(i);
141 if (attr.getName() != null || attr.getLanguage()!=null){
142 if (attr.getName().trim().equals(name.trim()) && (attr.getLanguage().trim().equals(lang.trim()))){
143 return attr;
144 }
145 }
146 }
147
148 return null;
149
150 }
151
152 protected ArrayList getAttributesByLanguage(String lang){
153 ArrayList attrs = new ArrayList();
154
155 for(int i=0;i<language_dependent_attributes.size();i++){
156 Attribute attr = (Attribute) language_dependent_attributes.get(i);
157 if (!attr.getLanguage().trim().equals("") && attr.getLanguage().trim().equals(lang)){
158 attrs.add(attr);
159 }
160 }
161
162 return attrs;
163 }
164
165 protected boolean isAttributeRequired(String name) {
166 for(int i=0;i<required_attribute_names.length;i++){
167 if (name.equals(required_attribute_names[i])) return true;
168 }
169 return false;
170
171 }
172
173 protected boolean isLangDependentAttributeRequired(String name) {
174 for(int i=0;i<language_dependent_attribute_names.length;i++){
175 if (name.equals(language_dependent_attribute_names[i])) return true;
176 }
177 return false;
178
179 }
180
181}
Note: See TracBrowser for help on using the repository browser.