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