View Javadoc

1   /***
2    * Java DAB EPG API - Serialize/Deserialize To/From POJOs to XML/Binary as per
3    * ETSI specifications TS 102 818 (XML Specification for DAB EPG) and TS 102 
4    * 371 (Transportation and Binary Encoding Specification for EPG).
5    * 
6    * Copyright (C) 2007 GCap Media PLC
7    *
8    * This library is free software; you can redistribute it and/or
9    * modify it under the terms of the GNU Lesser General Public
10   * License as published by the Free Software Foundation; either
11   * version 2.1 of the License, or (at your option) any later version.
12   *
13   * This library is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   * Lesser General Public License for more details.
17   *
18   * You should have received a copy of the GNU Lesser General Public
19   * License along with this library; if not, write to the Free Software
20   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21   */
22  package com.gcapmedia.dab.epg;
23  
24  import java.util.Locale;
25  
26  /***
27   * @author ben.poor
28   *
29   */
30  public abstract class DescriptiveText {
31  
32  	/***
33  	 * Descriptive text
34  	 */
35  	private String text;
36  	
37  	/***
38  	 * Maximum length of the description
39  	 */
40  	private int maxLength;
41  	
42  	/***
43  	 * Description locale, defining the language of the description
44  	 */
45  	private Locale locale;
46  	
47  	/***
48  	 * Create a new descriptive text
49  	 * @param text Descriptive text
50  	 * @param maxLength Maximum length
51  	 * @param locale Text locale, defining the language of the description
52  	 */
53  	public DescriptiveText(String text, int maxLength, Locale locale) {
54  		this.text = text;
55  		this.maxLength = maxLength;
56  		this.locale = locale;
57  		
58  		// trim the text if necessary
59  		if(text.length() > maxLength) {
60  			this.text = this.text.substring(0, maxLength -1);
61  		}
62  	}
63  	
64  	/***
65  	 * @return Returns the descriptive text
66  	 */
67  	public String getText() {
68  		return text;
69  	}
70  	
71  	/***
72  	 * @return Returns the maximum length of the descriptive text
73  	 */
74  	public int getMaximumLength() {
75  		return maxLength;
76  	}
77  	
78  	/***
79  	 * @return Returns the language of the text as ISO 639
80  	 */
81  	public String getLanguage() {
82  		return locale.getLanguage();
83  	}
84  	
85  	/***
86  	 * @return Returns the text length
87  	 */
88  	public int getLength() {
89  		return text.length();
90  	}
91  	
92  	/***
93  	 * @see java.lang.Object#toString()
94  	 */
95  	public String toString() {
96  		return "[" + getLanguage() + "]" + getText();
97  	}
98  	
99  }