Home | History | Annotate | Download | only in ims
      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 PT INOVACAO - EST DEPARTMENT and Telecommunications Institute (Aveiro, Portugal)  *
     28  ************************************************************************************************/
     29 
     30 
     31 package gov.nist.javax.sip.parser.ims;
     32 
     33 /**
     34  * Privacy header parser.
     35  *
     36  * @author Miguel Freitas (IT) PT-Inovacao
     37  */
     38 
     39 /*
     40  * Privacy-hdr  =  "Privacy" HCOLON priv-value *(";" priv-value)
     41  * priv-value   =   "header" / "session" / "user" / "none" / "critical" / token
     42  */
     43 
     44 import gov.nist.core.*;
     45 import gov.nist.javax.sip.header.SIPHeader;
     46 import gov.nist.javax.sip.parser.Lexer;
     47 import gov.nist.javax.sip.parser.TokenTypes;
     48 import gov.nist.javax.sip.parser.HeaderParser;
     49 
     50 import java.text.ParseException;
     51 
     52 import gov.nist.javax.sip.header.ims.Privacy;
     53 import gov.nist.javax.sip.header.ims.PrivacyList;
     54 import gov.nist.javax.sip.header.ims.SIPHeaderNamesIms;
     55 
     56 
     57 
     58 public class PrivacyParser
     59     extends HeaderParser
     60     implements TokenTypes
     61 {
     62 
     63 
     64     public PrivacyParser(String privacyType) {
     65 
     66         super(privacyType);
     67     }
     68 
     69     protected PrivacyParser(Lexer lexer) {
     70 
     71         super(lexer);
     72     }
     73 
     74 
     75     public SIPHeader parse() throws ParseException
     76     {
     77         if (debug)
     78             dbg_enter("PrivacyParser.parse");
     79 
     80         PrivacyList privacyList = new PrivacyList();
     81 
     82         try
     83         {
     84             this.headerName(TokenTypes.PRIVACY);
     85 
     86             while (lexer.lookAhead(0) != '\n') {
     87                 this.lexer.SPorHT();
     88 
     89                 Privacy privacy = new Privacy();
     90                 privacy.setHeaderName(SIPHeaderNamesIms.PRIVACY);
     91 
     92                 this.lexer.match(TokenTypes.ID);
     93                 Token token = lexer.getNextToken();
     94                 privacy.setPrivacy(token.getTokenValue());
     95                 this.lexer.SPorHT();
     96                 privacyList.add(privacy);
     97 
     98                 // Parsing others option-tags
     99                 while (lexer.lookAhead(0) == ';')
    100                 {
    101                     this.lexer.match(';');
    102                     this.lexer.SPorHT();
    103                     privacy = new Privacy();
    104                     this.lexer.match(TokenTypes.ID);
    105                     token = lexer.getNextToken();
    106                     privacy.setPrivacy(token.getTokenValue());
    107                     this.lexer.SPorHT();
    108 
    109                     privacyList.add(privacy);
    110                 }
    111             }
    112 
    113             return privacyList;
    114 
    115         }
    116         finally {
    117             if (debug)
    118                 dbg_leave("PrivacyParser.parse");
    119         }
    120 
    121     }
    122 
    123 
    124     /** Test program */
    125     public static void main(String args[]) throws ParseException
    126     {
    127         String rou[] = {
    128 
    129                 "Privacy: none\n",
    130                 "Privacy: none;id;user\n"
    131             };
    132 
    133         for (int i = 0; i < rou.length; i++ ) {
    134             PrivacyParser rp =
    135               new PrivacyParser(rou[i]);
    136             PrivacyList list = (PrivacyList) rp.parse();
    137             System.out.println("encoded = " +list.encode());
    138         }
    139     }
    140 
    141 
    142 
    143 }
    144 
    145