/** * Parse a uri from a string and return a URI structure for it. * * @param url * a String containing the URI structure to be parsed. * @return A parsed URI structure * @exception ParseException * if there was an error parsing the message. */ public GenericURI parseUrl(String url) throws ParseException { return new URLParser(url).parse(); }
dbg_enter("uriReference"); GenericURI retval = null; Token[] tokens = lexer.peekNextToken(2); t1.getTokenType() == TokenTypes.SIPS) { if (t2.getTokenType() == ':') retval = sipURL( inBrackets ); else throw createParseException("Expecting \':\'"); } else if (t1.getTokenType() == TokenTypes.TEL) { if (t2.getTokenType() == ':') { retval = telURL( inBrackets ); } else throw createParseException("Expecting \':\'"); } else { String urlString = uricString(); try { retval = new GenericURI(urlString); } catch (ParseException ex) { throw createParseException(ex.getMessage()); dbg_leave("uriReference");
dbg_enter("telephone_subscriber"); lexer.selectLexer("charLexer"); try { char c = lexer.lookAhead(0); if (c == '+') tn = global_phone_number( inBrackets ); else if ( || c == '(' || c == ')' ) { tn = local_phone_number( inBrackets ); } else throw createParseException("unexpected char " + c); return tn; } finally { if (debug) dbg_leave("telephone_subscriber");
/** * Parse a telephone number return a parsed structure. * * @param telephone_number * is a String containing the telephone # to be parsed * @return a parsed address structure. * @since v1.0 * @exception ParseException * a ParseException when the address is badly formatted. */ public TelephoneNumber parseTelephoneNumber(String telephone_number) throws ParseException { // Bug fix contributed by Will Scullin return new URLParser(telephone_number).parseTelephoneNumber(true); }
/** * Parse a SIP url from a string and return a URI structure for it. * * @param url * a String containing the URI structure to be parsed. * @return A parsed URI structure * @exception ParseException * if there was an error parsing the message. */ public SipUri parseSIPUrl(String url) throws ParseException { try { return new URLParser(url).sipURL(true); } catch (ClassCastException ex) { throw new ParseException(url + " Not a SIP URL ", 0); } }
dbg_enter("sipURL"); SipUri retval = new SipUri(); retval.setScheme(scheme); int startOfUser = lexer.markInputPosition(); String userOrHost = user();// Note: user may contain ';', host may not... String passOrPort = null; passOrPort = password(); HostNameParser hnp = new HostNameParser(this.getLexer()); HostPort hp = hnp.hostPort( false ); retval.setHostPort(hp); break; lexer.consume(1); NameValue parms = uriParam(); if (parms != null) retval.setUriParameter(parms); lexer.consume(1); while (lexer.hasMoreChars()) { NameValue parms = qheader(); retval.setQHeader(parms); if (lexer.hasMoreChars() && lexer.lookAhead(0) != '&') } finally { if (debug) dbg_leave("sipURL");
protected String user() throws ParseException { if (debug) dbg_enter("user"); try { int startIdx = lexer.getPtr(); while (lexer.hasMoreChars()) { char la = lexer.lookAhead(0); if (isUnreserved(la) || isUserUnreserved(la)) { lexer.consume(1); } else if (isEscaped()) { lexer.consume(3); } else break; } return lexer.getBuffer().substring(startIdx, lexer.getPtr()); } finally { if (debug) dbg_leave("user"); } }
protected String uric() { if (debug) dbg_enter("uric"); try { try { char la = lexer.lookAhead(0); if (isUnreserved(la)) { lexer.consume(1); return Lexer.charAsString(la); } else if (isReserved(la)) { lexer.consume(1); return Lexer.charAsString(la); } else if (isEscaped()) { String retval = lexer.charAsString(3); lexer.consume(3); return retval; } else return null; } catch (Exception ex) { return null; } } finally { if (debug) dbg_leave("uric"); } }
protected String uricNoSlash() { if (debug) dbg_enter("uricNoSlash"); try { try { char la = lexer.lookAhead(0); if (isEscaped()) { String retval = lexer.charAsString(3); lexer.consume(3); return retval; } else if (isUnreserved(la)) { lexer.consume(1); return Lexer.charAsString(la); } else if (isReservedNoSlash(la)) { lexer.consume(1); return Lexer.charAsString(la); } else return null; } catch (ParseException ex) { return null; } } finally { if (debug) dbg_leave("uricNoSlash"); } }
/** * Parser for the base phone number. */ private String base_phone_number() throws ParseException { StringBuilder s = new StringBuilder(); if (debug) dbg_enter("base_phone_number"); try { int lc = 0; while (lexer.hasMoreChars()) { char w = lexer.lookAhead(0); if (Lexer.isDigit(w) || w == '-' || w == '.' || w == '(' || w == ')') { lexer.consume(1); s.append(w); lc++; } else if (lc > 0) break; else throw createParseException("unexpected " + w); } return s.toString(); } finally { if (debug) dbg_leave("base_phone_number"); } }
protected String mark() throws ParseException { if (debug) dbg_enter("mark"); try { char next = lexer.lookAhead(0); if (isMark(next)) { lexer.consume(1); return new String( new char[]{next} ); } else throw createParseException("mark"); } finally { if (debug) dbg_leave("mark"); } }
} else if (la == ':' || la == '/') { retval = new AddressImpl(); URLParser uriParser = new URLParser((Lexer) lexer); GenericURI uri = uriParser.uriReference( inclParams ); retval.setAddressType(AddressImpl.ADDRESS_SPEC); retval.setURI(uri);
private final TelephoneNumber global_phone_number( boolean inBrackets ) throws ParseException { if (debug) dbg_enter("global_phone_number"); try { TelephoneNumber tn = new TelephoneNumber(); tn.setGlobal(true); NameValueList nv = null; this.lexer.match(PLUS); String b = base_phone_number(); tn.setPhoneNumber(b); if (lexer.hasMoreChars()) { char tok = lexer.lookAhead(0); if (tok == ';' && inBrackets) { this.lexer.consume(1); nv = tel_parameters(); tn.setParameters(nv); } } return tn; } finally { if (debug) dbg_leave("global_phone_number"); } }
private TelephoneNumber local_phone_number( boolean inBrackets ) throws ParseException { if (debug) dbg_enter("local_phone_number"); TelephoneNumber tn = new TelephoneNumber(); tn.setGlobal(false); String b = null; try { b = local_number(); tn.setPhoneNumber(b); if (lexer.hasMoreChars()) { nv = tel_parameters(); tn.setParameters(nv); dbg_leave("local_phone_number");
private NameValue uriParam() throws ParseException { if (debug) dbg_enter("uriParam"); try { String pvalue = ""; String pname = paramNameOrValue(); char next = lexer.lookAhead(0); boolean isFlagParam = true; if (next == '=') { lexer.consume(1); pvalue = paramNameOrValue(); isFlagParam = false; } if (pname.length() == 0 && ( pvalue == null || pvalue.length() == 0)) return null; else return new NameValue(pname, pvalue, isFlagParam); } finally { if (debug) dbg_leave("uriParam"); } }
protected String password() throws ParseException { int startIdx = lexer.getPtr(); while (true) { char la = lexer.lookAhead(0); boolean isValidChar = false; switch (la) { case '&': case '=': case '+': case '$': case ',': isValidChar = true; } if (isValidChar || isUnreserved(la)) { lexer.consume(1); } else if (isEscaped()) { lexer.consume(3); // bug reported by // Jeff Haynie } else break; } return lexer.getBuffer().substring(startIdx, lexer.getPtr()); }
protected String unreserved() throws ParseException { char next = lexer.lookAhead(0); if (isUnreserved(next)) { lexer.consume(1); return String.valueOf(next); } else throw createParseException("unreserved"); }
protected String reserved() throws ParseException { char next = lexer.lookAhead(0); if (isReserved(next)) { lexer.consume(1); return new StringBuilder().append(next).toString(); } else throw createParseException("reserved"); }
/** * 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") || 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(!SCHEME_PATTERN.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); }
protected String uricString() throws ParseException { StringBuilder retval = new StringBuilder(); while (true) { String next = uric(); if (next == null) { char la = lexer.lookAhead(0); // JvB: allow IPv6 addresses in generic URI strings // e.g. http://[::1] if ( la == '[' ) { HostNameParser hnp = new HostNameParser(this.getLexer()); HostPort hp = hnp.hostPort( false ); retval.append(hp.toString()); continue; } break; } retval.append(next); } return retval.toString(); }