2 * Copyright 2007 Google Inc.
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;
20 * <p>Abstract class representing the result of decoding a barcode, as more than
21 * a String -- as some type of structured data. This might be a subclass which represents
22 * a URL, or an e-mail address. {@link #parseReaderResult(String)} will turn a raw
23 * decoded string into the most appropriate type of structured representation.</p>
25 * <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
26 * on exception-based mechanisms during parsing.</p>
28 * @author srowen@google.com (Sean Owen)
30 public abstract class ParsedReaderResult {
32 private final ParsedReaderResultType type;
34 public ParsedReaderResult(ParsedReaderResultType type) {
38 public ParsedReaderResultType getType() {
42 public abstract String getDisplayResult();
44 public static ParsedReaderResult parseReaderResult(String rawText) {
45 // This is a bit messy, but given limited options in MIDP / CLDC, this may well be the simplest
46 // way to go about this. For example, we have no reflection available, really.
47 // Order is important here.
48 ParsedReaderResult result;
49 if ((result = BookmarkDoCoMoResult.parse(rawText)) != null) {
51 } else if ((result = AddressBookDoCoMoResult.parse(rawText)) != null) {
53 } else if ((result = EmailDoCoMoResult.parse(rawText)) != null) {
55 } else if ((result = EmailAddressResult.parse(rawText)) != null) {
57 } else if ((result = AddressBookAUResult.parse(rawText)) != null) {
59 } else if ((result = URLTOResult.parse(rawText)) != null) {
61 } else if ((result = URIParsedResult.parse(rawText)) != null) {
63 } else if ((result = UPCParsedResult.parse(rawText)) != null) {
66 return TextParsedResult.parse(rawText);
69 public String toString() {
70 return getDisplayResult();