View Javadoc
1   /*
2    * Copyright 2001-2009 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package org.apache.juddi.v3.client.i18n;
18  
19  import java.util.List;
20  
21  import org.uddi.api_v3.Address;
22  import org.uddi.api_v3.Description;
23  import org.uddi.api_v3.Name;
24  /** 
25   * Returns the entity in the proper language. If no language is specified
26   * or if no language is matched return the value of the first entity in the list.
27   */
28  public class EntityForLang {
29  	
30  	public static Name getName(List<Name> entityList, String lang) {
31  		
32  		if (entityList.size()==0) {
33  			Name name = new Name();
34  			name.setValue("");
35  			name.setLang(lang);
36  			entityList.add(name);
37  		}
38  		if (lang==null) return entityList.get(0);
39  		for (Name entity : entityList) {
40  			if (lang.equalsIgnoreCase(entity.getLang())) {
41  				return entity;
42  			}
43  		}
44  		return entityList.get(0);
45  	}
46  	
47  	public static Address getAddress(List<Address> entityList, String lang) {
48  		
49  		if (entityList.size()==0) {
50  			Address address = new Address();
51  			address.setLang(lang);
52  			entityList.add(address);
53  		}
54  		if (lang==null) return entityList.get(0);
55  		for (Address entity : entityList) {
56  			if (lang.equalsIgnoreCase(entity.getLang())) {
57  				return entity;
58  			}
59  		}
60  		return entityList.get(0);
61  	}
62  	
63  	public static Description getDescription(List<Description> entityList, String lang) {
64  		
65  		if (entityList.size()==0) {
66  			Description description = new Description();
67  			description.setValue("");
68  			description.setLang(lang);
69  			entityList.add(description);
70  		}
71  		if (lang==null) return entityList.get(0);
72  		for (Description entity : entityList) {
73  			if (lang.equalsIgnoreCase(entity.getLang())) {
74  				return entity;
75  			}
76  		}
77  		return entityList.get(0);
78  	}
79  	
80  	
81  }