1 /* 2 * Conditions Of Use 3 * 4 * This software was developed by employees of the National Institute of 5 * Standards and Technology (NIST), an agency of the Federal Government. 6 * Pursuant to title 15 Untied States Code Section 105, works of NIST 7 * employees are not subject to copyright protection in the United States 8 * and are considered to be in the public domain. As a result, a formal 9 * license is not needed to use the software. 10 * 11 * This software is provided by NIST as a service and is expressly 12 * provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED 13 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF 14 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT 15 * AND DATA ACCURACY. NIST does not warrant or make any representations 16 * regarding the use of the software or the results thereof, including but 17 * not limited to the correctness, accuracy, reliability or usefulness of 18 * the software. 19 * 20 * Permission to use this software is contingent upon your acceptance 21 * of the terms of this agreement 22 * 23 * . 24 * 25 */ 26 /******************************************************************************* 27 * Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * 28 *******************************************************************************/ 29 package gov.nist.javax.sip.header; 30 31 import java.util.Locale; 32 33 /** 34 * ContentLanguage header 35 * <pre> 36 *Fielding, et al. Standards Track [Page 118] 37 *RFC 2616 HTTP/1.1 June 1999 39 * 40 * 14.12 Content-Language 41 * 42 * The Content-Language entity-header field describes the natural 43 * language(s) of the intended audience for the enclosed entity. Note 44 * that this might not be equivalent to all the languages used within 45 * the entity-body. 46 * 47 * Content-Language = "Content-Language" ":" 1#language-tag 48 * 49 * Language tags are defined in section 3.10. The primary purpose of 50 * Content-Language is to allow a user to identify and differentiate 51 * entities according to the user's own preferred language. Thus, if the 52 * body content is intended only for a Danish-literate audience, the 53 * appropriate field is 54 * 55 * Content-Language: da 56 * 57 * If no Content-Language is specified, the default is that the content 58 * is intended for all language audiences. This might mean that the 59 * sender does not consider it to be specific to any natural language, 60 * or that the sender does not know for which language it is intended. 61 * 62 * Multiple languages MAY be listed for content that is intended for 63 * multiple audiences. For example, a rendition of the "Treaty of 64 * Waitangi," presented simultaneously in the original Maori and English 65 * versions, would call for 66 * 67 * Content-Language: mi, en 68 * 69 * However, just because multiple languages are present within an entity 70 * does not mean that it is intended for multiple linguistic audiences. 71 * An example would be a beginner's language primer, such as "A First 72 * Lesson in Latin," which is clearly intended to be used by an 73 * English-literate audience. In this case, the Content-Language would 74 * properly only include "en". 75 * 76 * Content-Language MAY be applied to any media type -- it is not 77 * limited to textual documents. 78 *</pre> 79 * @author M. Ranganathan 80 * @version 1.2 $Revision: 1.8 $ $Date: 2009/07/17 18:57:29 $ 81 * @since 1.1 82 */ 83 public class ContentLanguage 84 extends SIPHeader 85 implements javax.sip.header.ContentLanguageHeader { 86 87 /** 88 * Comment for <code>serialVersionUID</code> 89 */ 90 private static final long serialVersionUID = -5195728427134181070L; 91 /** languageTag field. 92 */ 93 protected Locale locale; 94 95 public ContentLanguage() { 96 super(CONTENT_LANGUAGE); 97 } 98 99 /** 100 * Default constructor. 101 * @param languageTag String to set 102 */ 103 public ContentLanguage(String languageTag) { 104 super(CONTENT_LANGUAGE); 105 this.setLanguageTag( languageTag ); 106 } 107 108 /** 109 * Canonical encoding of the value of the header. 110 * @return encoded body of header. 111 */ 112 public String encodeBody() { 113 return this.getLanguageTag(); 114 } 115 116 /** get the languageTag field. 117 * @return String 118 */ 119 public String getLanguageTag() { 120 // JvB: Need to take sub-tags into account 121 if ( "".equals(locale.getCountry())) { 122 return locale.getLanguage(); 123 } else { 124 return locale.getLanguage() + '-' + locale.getCountry(); 125 } 126 } 127 128 /** set the languageTag field 129 * @param languageTag -- language tag to set. 130 */ 131 public void setLanguageTag(String languageTag) { 132 133 final int slash = languageTag.indexOf('-'); 134 if (slash>=0) { 135 this.locale = new Locale(languageTag.substring(0,slash), languageTag.substring(slash+1) ); 136 } else { 137 this.locale = new Locale(languageTag); 138 } 139 } 140 141 /** 142 * Gets the language value of the ContentLanguageHeader. 143 * 144 * 145 * 146 * @return the Locale value of this ContentLanguageHeader 147 * 148 */ 149 public Locale getContentLanguage() { 150 return locale; 151 } 152 153 /** 154 * Sets the language parameter of this ContentLanguageHeader. 155 * 156 * @param language - the new Locale value of the language of 157 * 158 * ContentLanguageHeader 159 * 160 */ 161 public void setContentLanguage(Locale language) { 162 this.locale = language; 163 } 164 165 public Object clone() { 166 ContentLanguage retval = (ContentLanguage) super.clone(); 167 if (this.locale != null) 168 retval.locale = (Locale) this.locale.clone(); 169 return retval; 170 } 171 } 172