• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
38 *
39 *  14.12 Content-Language
40 *
41 *   The Content-Language entity-header field describes the natural
42 *   language(s) of the intended audience for the enclosed entity. Note
43 *   that this might not be equivalent to all the languages used within
44 *   the entity-body.
45 *
46 *       Content-Language  = "Content-Language" ":" 1#language-tag
47 *
48 *   Language tags are defined in section 3.10. The primary purpose of
49 *   Content-Language is to allow a user to identify and differentiate
50 *   entities according to the user's own preferred language. Thus, if the
51 *   body content is intended only for a Danish-literate audience, the
52 *   appropriate field is
53 *
54 *       Content-Language: da
55 *
56 *   If no Content-Language is specified, the default is that the content
57 *   is intended for all language audiences. This might mean that the
58 *   sender does not consider it to be specific to any natural language,
59 *   or that the sender does not know for which language it is intended.
60 *
61 *   Multiple languages MAY be listed for content that is intended for
62 *   multiple audiences. For example, a rendition of the "Treaty of
63 *   Waitangi," presented simultaneously in the original Maori and English
64 *   versions, would call for
65 *
66 *       Content-Language: mi, en
67 *
68 *   However, just because multiple languages are present within an entity
69 *   does not mean that it is intended for multiple linguistic audiences.
70 *   An example would be a beginner's language primer, such as "A First
71 *   Lesson in Latin," which is clearly intended to be used by an
72 *   English-literate audience. In this case, the Content-Language would
73 *   properly only include "en".
74 *
75 *   Content-Language MAY be applied to any media type -- it is not
76 *   limited to textual documents.
77 *</pre>
78 * @author M. Ranganathan
79 * @version 1.2 $Revision: 1.8 $ $Date: 2009/07/17 18:57:29 $
80 * @since 1.1
81 */
82 public class ContentLanguage
83     extends SIPHeader
84     implements javax.sip.header.ContentLanguageHeader {
85 
86     /**
87      * Comment for <code>serialVersionUID</code>
88      */
89     private static final long serialVersionUID = -5195728427134181070L;
90     /** languageTag field.
91      */
92     protected Locale locale;
93 
ContentLanguage()94     public ContentLanguage() {
95         super(CONTENT_LANGUAGE);
96     }
97 
98     /**
99      * Default constructor.
100      * @param languageTag String to set
101      */
ContentLanguage(String languageTag)102     public ContentLanguage(String languageTag) {
103         super(CONTENT_LANGUAGE);
104         this.setLanguageTag( languageTag );
105     }
106 
107     /**
108      * Canonical encoding of the  value of the header.
109      * @return encoded body of header.
110      */
encodeBody()111     public String encodeBody() {
112         return this.getLanguageTag();
113     }
114 
115     /** get the languageTag field.
116      * @return String
117      */
getLanguageTag()118     public String getLanguageTag() {
119         // JvB: Need to take sub-tags into account
120         if ( "".equals(locale.getCountry())) {
121             return locale.getLanguage();
122         } else {
123             return locale.getLanguage() + '-' + locale.getCountry();
124         }
125     }
126 
127     /** set the languageTag field
128      * @param languageTag -- language tag to set.
129      */
setLanguageTag(String languageTag)130     public void setLanguageTag(String languageTag) {
131 
132         final int slash = languageTag.indexOf('-');
133         if (slash>=0) {
134             this.locale = new Locale(languageTag.substring(0,slash), languageTag.substring(slash+1) );
135         } else {
136             this.locale = new Locale(languageTag);
137         }
138     }
139 
140     /**
141      * Gets the language value of the ContentLanguageHeader.
142      *
143      *
144      *
145      * @return the Locale value of this ContentLanguageHeader
146      *
147      */
getContentLanguage()148     public Locale getContentLanguage() {
149         return locale;
150     }
151 
152     /**
153      * Sets the language parameter of this ContentLanguageHeader.
154      *
155      * @param language - the new Locale value of the language of
156      *
157      * ContentLanguageHeader
158      *
159      */
setContentLanguage(Locale language)160     public void setContentLanguage(Locale language) {
161         this.locale = language;
162     }
163 
clone()164     public Object clone() {
165         ContentLanguage retval = (ContentLanguage) super.clone();
166         if (this.locale != null)
167             retval.locale = (Locale) this.locale.clone();
168         return retval;
169     }
170 }
171