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
 *
 * .
 *
 */
 package gov.nist.javax.sip.address;
 
 
 
Implementation of the JAIN-SIP address factory.

Author(s):
M. Ranganathan
IPv6 Support added by Emil Ivov (emil_ivov@yahoo.com)
Network Research Team (http://www-r2.u-strasbg.fr))
Louis Pasteur University - Strasbourg - France
Version:
1.2 $Revision: 1.11 $ $Date: 2010-07-27 10:55:29 $
 
 public class AddressFactoryImpl implements AddressFactoryEx {
     public static final Pattern SCHEME_PATTERN = Pattern.compile("\\p{Alpha}[[{\\p{Alpha}][\\p{Digit}][\\+][-][\\.]]*");
    
    
Creates a new instance of AddressFactoryImpl
 
     public AddressFactoryImpl() {
     }


    
Create an empty address object. SPEC_REVISION
 
 
     public javax.sip.address.Address createAddress() {
         return new AddressImpl();
     }
    
Creates an Address with the new display name and URI attribute values.

Parameters:
displayName - the new string value of the display name of the address. A null value does not set the display name.
uri - the new URI value of the address.
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the displayName value.
 
         String displayName,
         javax.sip.address.URI uri) {
         if (uri == null)
             throw new NullPointerException("null  URI");
         AddressImpl addressImpl = new AddressImpl();
         if (displayName != null)
             addressImpl.setDisplayName(displayName);
         addressImpl.setURI(uri);
         return addressImpl;
 
     }
 
 
         if (uri == null)
             throw new NullPointerException("null address");
         AddressImpl addressImpl = new AddressImpl();
         addressImpl.setURI(uri);
         return addressImpl;
     }

    
Creates an Address with the new address string value. The address string is parsed in order to create the new Address instance. Create with a String value of "*" creates a wildcard address. The wildcard can be determined if ((SipURI)Address.getURI).getUser() == *;.

Parameters:
address - the new string value of the address.
Throws:
java.text.ParseException which signals that an error has been reached unexpectedly while parsing the address value.
    public javax.sip.address.Address createAddress(String address)
        throws java.text.ParseException {
        if (address == null)
            throw new NullPointerException("null address");
        if (address.equals("*")) {
            AddressImpl addressImpl = new AddressImpl();
            addressImpl.setAddressType(.);
            SipURI uri = new SipUri();
            uri.setUser("*");
            addressImpl.setURIuri );
            return addressImpl;
        } else {
            StringMsgParser smp = new StringMsgParser();
            return smp.parseAddress(address);
        }
    }


    
create a sip uri.

Parameters:
uri -- the uri to parse.
    public javax.sip.address.SipURI createSipURI(String urithrows ParseException {
        if (uri == null)
            throw new NullPointerException("null URI");
        try {
            StringMsgParser smp = new StringMsgParser();
            SipUri sipUri = smp.parseSIPUrl(uri);
            return (SipURIsipUri;
        } catch (ParseException ex) {
            throw new ParseException(ex.getMessage(), 0);
        }
    }

    
Create a SipURI

Parameters:
user -- the user
host -- the host.
    public javax.sip.address.SipURI createSipURI(String userString hostthrows ParseException {
        if (host == null)
            throw new NullPointerException("null host");
        StringBuilder uriString = new StringBuilder("sip:");
        if (user != null) {
            uriString.append(user);
            uriString.append("@");
        }
        //if host is an IPv6 string we should enclose it in sq brackets
        if (host.indexOf(':') != host.lastIndexOf(':')
            && host.trim().charAt(0) != '[')
            host = '[' + host + ']';
        uriString.append(host);
       
        try {
           return this.createSipURI(uriString.toString());
        } catch (ParseException ex) {
            throw new ParseException(ex.getMessage(), 0);
        }
    }

    
Creates a TelURL based on given URI string. The '+' should not be included in the phoneNumber string argument. If scheme is not present, it will be added.

Parameters:
uri - the new string value of the phoneNumber.
Throws:
URISyntaxException if the URI string is malformed.
    public javax.sip.address.TelURL createTelURL(String uri)
        throws ParseException {
        if (uri == null)
            throw new NullPointerException("null url");
        String telUrl = null;
        if(uri.startsWith("tel:"))
        {
        	telUrl = uri;
        }else
        {
        	telUrl = "tel:" + uri;
        }
        try {
            StringMsgParser smp = new StringMsgParser();
            TelURLImpl timp = (TelURLImplsmp.parseUrl(telUrl);
            return (TelURLtimp;
        } catch (ParseException ex) {
            throw new ParseException(ex.getMessage(), 0);
        }
    }
    
    
    
Creates a URI based on given URI string. The URI string is parsed in order to create the new URI instance. Depending on the scheme the returned may or may not be a SipURI or TelURL cast as a URI.

Parameters:
uri - the new string value of the URI.
Throws:
URISyntaxException if the URI string is malformed.
    public javax.sip.address.URI createURI(String urithrows ParseException {
        if (uri == null)
            throw new NullPointerException("null arg");
        try {
            URLParser urlParser = new URLParser(uri);
            String scheme = urlParser.peekScheme();
            if (scheme == null)
                throw new ParseException("bad scheme", 0);
            if (scheme.equalsIgnoreCase("sip") || scheme.equalsIgnoreCase("sips")) {
               return this.createSipURI(uri);
            } else if (scheme.equalsIgnoreCase("tel")) {
                return this.createTelURL(uri);
            }
            // Issue 316 : the scheme should match ALPHA *(ALPHA / DIGIT / "+" / "-" / "." )
            if(!.matcher(scheme).matches()) {
                throw new ParseException("the scheme " + scheme + " from the following uri " + uri + " doesn't match ALPHA *(ALPHA / DIGIT / \"+\" / \"-\" / \".\" ) from RFC3261",0);
            }
        } catch (ParseException ex) {
            throw new ParseException(ex.getMessage(), 0);
        }        
        return new gov.nist.javax.sip.address.GenericURI(uri);
    }
New to GrepCode? Check out our FAQ X