use of java.text.ParseException in project XobotOS by xamarin.
the class AddressFactoryImpl method createURI.
/**
* 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.
*
* @param uri - the new string value of the URI.
* @throws URISyntaxException if the URI string is malformed.
*/
public javax.sip.address.URI createURI(String uri) throws 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")) {
return (javax.sip.address.URI) urlParser.sipURL(true);
} else if (scheme.equalsIgnoreCase("sips")) {
return (javax.sip.address.URI) urlParser.sipURL(true);
} else if (scheme.equalsIgnoreCase("tel")) {
return (javax.sip.address.URI) urlParser.telURL(true);
}
} catch (ParseException ex) {
throw new ParseException(ex.getMessage(), 0);
}
return new gov.nist.javax.sip.address.GenericURI(uri);
}
use of java.text.ParseException in project XobotOS by xamarin.
the class LexerCore method comment.
/** Parse a comment string cursor is at a "(". Leave cursor at )
*@return the substring containing the comment excluding the
* closing brace.
*/
public String comment() throws ParseException {
StringBuffer retval = new StringBuffer();
if (lookAhead(0) != '(')
return null;
consume(1);
while (true) {
char next = getNextChar();
if (next == ')') {
break;
} else if (next == '\0') {
throw new ParseException(this.buffer + " :unexpected EOL", this.ptr);
} else if (next == '\\') {
retval.append(next);
next = getNextChar();
if (next == '\0')
throw new ParseException(this.buffer + " : unexpected EOL", this.ptr);
retval.append(next);
} else {
retval.append(next);
}
}
return retval.toString();
}
use of java.text.ParseException in project XobotOS by xamarin.
the class LexerCore method match.
/** Match the given token or throw an exception if no such token
* can be matched.
*/
public Token match(int tok) throws ParseException {
if (Debug.parserDebug) {
Debug.println("match " + tok);
}
if (tok > START && tok < END) {
if (tok == ID) {
// Generic ID sought.
if (!startsId())
throw new ParseException(buffer + "\nID expected", ptr);
String id = getNextId();
this.currentMatch = new Token();
this.currentMatch.tokenValue = id;
this.currentMatch.tokenType = ID;
} else if (tok == SAFE) {
if (!startsSafeToken())
throw new ParseException(buffer + "\nID expected", ptr);
String id = ttokenSafe();
this.currentMatch = new Token();
this.currentMatch.tokenValue = id;
this.currentMatch.tokenType = SAFE;
} else {
String nexttok = getNextId();
Integer cur = (Integer) currentLexer.get(nexttok.toUpperCase());
if (cur == null || cur.intValue() != tok)
throw new ParseException(buffer + "\nUnexpected Token : " + nexttok, ptr);
this.currentMatch = new Token();
this.currentMatch.tokenValue = nexttok;
this.currentMatch.tokenType = tok;
}
} else if (tok > END) {
// Character classes.
char next = lookAhead(0);
if (tok == DIGIT) {
if (!isDigit(next))
throw new ParseException(buffer + "\nExpecting DIGIT", ptr);
this.currentMatch = new Token();
this.currentMatch.tokenValue = String.valueOf(next);
this.currentMatch.tokenType = tok;
consume(1);
} else if (tok == ALPHA) {
if (!isAlpha(next))
throw new ParseException(buffer + "\nExpecting ALPHA", ptr);
this.currentMatch = new Token();
this.currentMatch.tokenValue = String.valueOf(next);
this.currentMatch.tokenType = tok;
consume(1);
}
} else {
// This is a direct character spec.
char ch = (char) tok;
char next = lookAhead(0);
if (next == ch) {
/*this.currentMatch = new Token();
this.currentMatch.tokenValue =
String.valueOf(ch);
this.currentMatch.tokenType = tok;*/
consume(1);
} else
throw new ParseException(buffer + "\nExpecting >>>" + ch + "<<< got >>>" + next + "<<<", ptr);
}
return this.currentMatch;
}
use of java.text.ParseException in project XobotOS by xamarin.
the class SipUri method equals.
/**
* Compare two URIs and return true if they are equal.
* @param that the object to compare to.
* @return true if the object is equal to this object.
*
* JvB: Updated to define equality in terms of API methods, according to the rules
* in RFC3261 section 19.1.4
*
* Jean Deruelle: Updated to define equality of API methods, according to the rules
* in RFC3261 section 19.1.4 convert potential ie :
* %HEX HEX encoding parts of the URI before comparing them
* transport param added in comparison
* header equality enforced in comparison
*
*/
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object that) {
// Shortcut for same object
if (that == this)
return true;
if (that instanceof SipURI) {
final SipURI a = this;
final SipURI b = (SipURI) that;
// A SIP and SIPS URI are never equivalent
if (a.isSecure() ^ b.isSecure())
return false;
// components must match; comparison of userinfo is case-sensitive
if (a.getUser() == null ^ b.getUser() == null)
return false;
if (a.getUserPassword() == null ^ b.getUserPassword() == null)
return false;
if (a.getUser() != null && !RFC2396UrlDecoder.decode(a.getUser()).equals(RFC2396UrlDecoder.decode(b.getUser())))
return false;
if (a.getUserPassword() != null && !RFC2396UrlDecoder.decode(a.getUserPassword()).equals(RFC2396UrlDecoder.decode(b.getUserPassword())))
return false;
if (a.getHost() == null ^ b.getHost() == null)
return false;
if (a.getHost() != null && !a.getHost().equalsIgnoreCase(b.getHost()))
return false;
if (a.getPort() != b.getPort())
return false;
// URI parameters
for (Iterator i = a.getParameterNames(); i.hasNext(); ) {
String pname = (String) i.next();
String p1 = a.getParameter(pname);
String p2 = b.getParameter(pname);
// those present in both must match (case-insensitive)
if (p1 != null && p2 != null && !RFC2396UrlDecoder.decode(p1).equalsIgnoreCase(RFC2396UrlDecoder.decode(p2)))
return false;
}
// transport, user, ttl or method must match when present in either
if (a.getTransportParam() == null ^ b.getTransportParam() == null)
return false;
if (a.getUserParam() == null ^ b.getUserParam() == null)
return false;
if (a.getTTLParam() == -1 ^ b.getTTLParam() == -1)
return false;
if (a.getMethodParam() == null ^ b.getMethodParam() == null)
return false;
if (a.getMAddrParam() == null ^ b.getMAddrParam() == null)
return false;
// Headers: must match according to their definition.
if (a.getHeaderNames().hasNext() && !b.getHeaderNames().hasNext())
return false;
if (!a.getHeaderNames().hasNext() && b.getHeaderNames().hasNext())
return false;
if (a.getHeaderNames().hasNext() && b.getHeaderNames().hasNext()) {
HeaderFactory headerFactory = null;
try {
headerFactory = SipFactory.getInstance().createHeaderFactory();
} catch (PeerUnavailableException e) {
Debug.logError("Cannot get the header factory to parse the header of the sip uris to compare", e);
return false;
}
for (Iterator i = a.getHeaderNames(); i.hasNext(); ) {
String hname = (String) i.next();
String h1 = a.getHeader(hname);
String h2 = b.getHeader(hname);
if (h1 == null && h2 != null)
return false;
if (h2 == null && h1 != null)
return false;
// The following check should not be needed but we add it for findbugs.
if (h1 == null && h2 == null)
continue;
try {
Header header1 = headerFactory.createHeader(hname, RFC2396UrlDecoder.decode(h1));
Header header2 = headerFactory.createHeader(hname, RFC2396UrlDecoder.decode(h2));
// those present in both must match according to the equals method of the corresponding header
if (!header1.equals(header2))
return false;
} catch (ParseException e) {
Debug.logError("Cannot parse one of the header of the sip uris to compare " + a + " " + b, e);
return false;
}
}
}
// Finally, we can conclude that they are indeed equal
return true;
}
return false;
}
use of java.text.ParseException in project XobotOS by xamarin.
the class AuthenticationHeader method setParameter.
/**
* set the specified parameter. Bug reported by Dominic Sparks.
*
* @param name --
* name of the parameter
* @param value --
* value of the parameter.
*/
public void setParameter(String name, String value) throws ParseException {
NameValue nv = super.parameters.getNameValue(name.toLowerCase());
if (nv == null) {
nv = new NameValue(name, value);
if (name.equalsIgnoreCase(ParameterNames.QOP) || name.equalsIgnoreCase(ParameterNames.REALM) || name.equalsIgnoreCase(ParameterNames.CNONCE) || name.equalsIgnoreCase(ParameterNames.NONCE) || name.equalsIgnoreCase(ParameterNames.USERNAME) || name.equalsIgnoreCase(ParameterNames.DOMAIN) || name.equalsIgnoreCase(ParameterNames.OPAQUE) || name.equalsIgnoreCase(ParameterNames.NEXT_NONCE) || name.equalsIgnoreCase(ParameterNames.URI) || name.equalsIgnoreCase(ParameterNames.RESPONSE) || name.equalsIgnoreCase(ParameterNamesIms.IK) || name.equalsIgnoreCase(ParameterNamesIms.CK) || name.equalsIgnoreCase(ParameterNamesIms.INTEGRITY_PROTECTED)) {
if (((this instanceof Authorization) || (this instanceof ProxyAuthorization)) && name.equalsIgnoreCase(ParameterNames.QOP)) {
// NOP, QOP not quoted in authorization headers
} else {
nv.setQuotedValue();
}
if (value == null)
throw new NullPointerException("null value");
if (value.startsWith(Separators.DOUBLE_QUOTE))
throw new ParseException(value + " : Unexpected DOUBLE_QUOTE", 0);
}
super.setParameter(nv);
} else
nv.setValueAsObject(value);
}
Aggregations