2 * Copyright 2008 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.result;
19 import com.google.zxing.Result;
22 * Represents a "sms:" URI result, which specifies a number to SMS and optional
23 * "via" number. See <a href="http://gbiv.com/protocols/uri/drafts/draft-antti-gsm-sms-url-04.txt">
24 * the IETF draft</a> on this.
26 * @author srowen@google.com (Sean Owen)
28 public final class SMSParsedResult extends ParsedReaderResult {
30 private final String smsURI;
31 private final String number;
32 private final String via;
34 private SMSParsedResult(String smsURI, String number, String via) {
35 super(ParsedReaderResultType.SMS);
41 public static SMSParsedResult parse(Result result) {
42 String rawText = result.getText();
43 if (rawText == null || !rawText.startsWith("sms:")) {
46 // Drop sms, query portion
47 int queryStart = rawText.indexOf('?', 4);
48 String smsURIWithoutQuery;
50 smsURIWithoutQuery = rawText.substring(4);
52 smsURIWithoutQuery = rawText.substring(4, queryStart);
54 int numberEnd = smsURIWithoutQuery.indexOf(';');
58 number = smsURIWithoutQuery;
61 number = smsURIWithoutQuery.substring(0, numberEnd);
62 String maybeVia = smsURIWithoutQuery.substring(numberEnd + 1);
63 if (maybeVia.startsWith("via=")) {
64 via = maybeVia.substring(4);
69 return new SMSParsedResult(rawText, number, via);
72 public String getSMSURI() {
76 public String getNumber() {
80 public String getVia() {
84 public String getDisplayResult() {