Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * Conditions Of Use
  *
  * This software was developed by employees of the National Institute of
  * Standards and Technology (NIST), an agency of the Federal Government.
  * Pursuant to title 15 Untied States Code Section 105, works of NIST
  * employees are not subject to copyright protection in the United States
  * and are considered to be in the public domain.  As a result, a formal
  * license is not needed to use the software.
 *
 * This software is provided by NIST as a service and is expressly
 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
 * AND DATA ACCURACY.  NIST does not warrant or make any representations
 * regarding the use of the software or the results thereof, including but
 * not limited to the correctness, accuracy, reliability or usefulness of
 * the software.
 *
 * Permission to use this software is contingent upon your acceptance
 * of the terms of this agreement
 *
 * .
 *
 */
 
Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * /
 
 package gov.nist.javax.sip.header;
Accept Language body.

Author(s):
M. Ranganathan
Version:
1.2 $Revision: 1.8 $ $Date: 2009/10/18 13:46:32 $
Since:
1.1
 HTTP RFC 2616 Section 14.4
 Accept-Language = "Accept-Language" ":"
                         1.( language-range [ ";" "q" "=" qvalue ] )
       language-range  = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )

 
See also:
AcceptLanguageList
 
 public final class AcceptLanguage
     extends ParametersHeader
     implements AcceptLanguageHeader {

    
Comment for serialVersionUID
 
     private static final long serialVersionUID = -4473982069737324919L;
    
languageRange field
 
     protected String languageRange;

    
default constructor
 
     public AcceptLanguage() {
         super();
     }

    
Encode the value of this header to a string.

Returns:
encoded header as a string.
 
     protected String encodeBody() {
         StringBuffer encoding = new StringBuffer();
         if ( != null) {
             encoding.append();
         }
         if (!.isEmpty()) {
             encoding.append().append(.encode());
         }
         return encoding.toString();
     }

    
get the LanguageRange field

Returns:
String
 
     public String getLanguageRange() {
         return ;
     }

    
get the QValue field. Return -1 if the parameter has not been set.

Returns:
float
 
 
     public float getQValue() {
         if (!hasParameter("q"))
             return -1;
        return ((Float.getValue("q")).floatValue();
    }

    
Return true if the q value has been set.

Returns:
boolean
Since:
1.0
    public boolean hasQValue() {
        return hasParameter("q");
    }

    
Remove the q value.

Since:
1.0
    public void removeQValue() {
        removeParameter("q");
    }

    
Set the languageRange.

Parameters:
languageRange is the language range to set.
    public void setLanguageRange(String languageRange) {
        this. = languageRange.trim();
    }

    
Sets q-value for media-range in AcceptLanguageHeader. Q-values allow the user to indicate the relative degree of preference for that media-range, using the qvalue scale from 0 to 1. If no q-value is present, the media-range should be treated as having a q-value of 1.

Parameters:
q The new float value of the q-value, a value of -1 resets the qValue.
Throws:
javax.sip.InvalidArgumentException if the q parameter value is not -1 or between 0 and 1.
    public void setQValue(float qthrows InvalidArgumentException {
        if (q < 0.0 || q > 1.0)
            throw new InvalidArgumentException("qvalue out of range!");
        if (q == -1)
            this.removeParameter("q");
        else
            this.setParameter(new NameValue("q", Float.valueOf(q)));
    }

    
Gets the language value of the AcceptLanguageHeader.

Returns:
the language Locale value of this AcceptLanguageHeader
    public Locale getAcceptLanguage() {
        if (this. == null)
            return null;
        else {
            int dash = .indexOf('-');
            if (dash>=0) {
                return new Locale.substring(0,dash), .substring(dash+1) );
            } else return new Localethis. );
        }
    }

    
Sets the language parameter of this AcceptLanguageHeader.

Parameters:
language - the new Locale value of the language of AcceptLanguageHeader
    public void setAcceptLanguage(Locale language) {
        // JvB: need to take sub-tag into account
        if ( "".equals(language.getCountry())) {
            this. = language.getLanguage();
        } else {
            this. = language.getLanguage() + '-' + language.getCountry();
        }
    }
New to GrepCode? Check out our FAQ X