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.optional;
19 import com.google.zxing.BarcodeFormat;
20 import com.google.zxing.Result;
21 import com.google.zxing.client.result.ParsedReaderResultType;
24 * <p>Represents a "simple web" result encoded according to section 4.11 of the
25 * MobileTag Reader International Specification.</p>
27 * @author srowen@google.com (Sean Owen)
29 public final class MobileTagSimpleWebParsedResult extends AbstractMobileTagParsedResult {
31 public static final String SERVICE_TYPE = "04";
32 private static final String[] URI_PREFIXES = {
41 private final String title;
42 private final String uri;
44 private MobileTagSimpleWebParsedResult(String title, String uri) {
45 super(ParsedReaderResultType.MOBILETAG_SIMPLE_WEB);
50 public static MobileTagSimpleWebParsedResult parse(Result result) {
51 if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) {
54 String rawText = result.getText();
55 if (!rawText.startsWith(SERVICE_TYPE)) {
59 String[] matches = matchDelimitedFields(rawText.substring(2), 2);
60 if (matches == null) {
63 String uri = matches[0];
64 String title = matches[1];
66 char maybePrefixChar = uri.charAt(2);
67 if (maybePrefixChar >= '0' && maybePrefixChar <= '9') {
68 int prefixIndex = maybePrefixChar - '0';
69 // Note that '0' is reserved
70 if (prefixIndex >= 1 && prefixIndex < URI_PREFIXES.length) {
71 uri = URI_PREFIXES[prefixIndex] + uri.substring(1);
73 uri = uri.substring(1);
77 return new MobileTagSimpleWebParsedResult(title, uri);
80 public String getTitle() {
84 public String getURI() {
88 public String getDisplayResult() {
92 return title + '\n' + uri;