Now supports KDDI/AU / Softbank address book format
[zxing.git] / core / src / com / google / zxing / client / result / ParsedReaderResult.java
1 /*
2  * Copyright 2007 Google Inc.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.client.result;
18
19 /**
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>
24  *
25  * <p>Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
26  * on exception-based mechanisms during parsing.</p>
27  *
28  * @author srowen@google.com (Sean Owen)
29  */
30 public abstract class ParsedReaderResult {
31
32   private final ParsedReaderResultType type;
33
34   ParsedReaderResult(ParsedReaderResultType type) {
35     this.type = type;
36   }
37
38   public ParsedReaderResultType getType() {
39     return type;
40   }
41
42   public abstract String getDisplayResult();
43
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) {
50       return result;
51     } else if ((result = AddressBookDoCoMoResult.parse(rawText)) != null) {
52       return result;
53     } else if ((result = EmailDoCoMoResult.parse(rawText)) != null) {
54       return result;
55     } else if ((result = EmailAddressResult.parse(rawText)) != null) {
56       return result;
57     } else if ((result = AddressBookAUResult.parse(rawText)) != null) {
58       return result;
59     } else if ((result = URLTOResult.parse(rawText)) != null) {
60       return result;
61     } else if ((result = URIParsedResult.parse(rawText)) != null) {
62       return result;
63     } else if ((result = UPCParsedResult.parse(rawText)) != null) {
64       return result;
65     }
66     return TextParsedResult.parse(rawText);
67   }
68
69   public String toString() {
70     return getDisplayResult();
71   }
72
73 }