Added "URLTO" format support
[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  * @author srowen@google.com (Sean Owen)
21  */
22 public abstract class ParsedReaderResult {
23
24   private final ParsedReaderResultType type;
25
26   ParsedReaderResult(ParsedReaderResultType type) {
27     this.type = type;
28   }
29
30   public ParsedReaderResultType getType() {
31     return type;
32   }
33
34   public abstract String getDisplayResult();
35
36   public static ParsedReaderResult parseReaderResult(String rawText) {
37     // This is a bit messy, but given limited options in MIDP / CLDC, this may well be the simplest
38     // way to go about this. For example, we have no reflection available, really.
39     // Order is important here.
40     try {
41       return new BookmarkDoCoMoResult(rawText);
42     } catch (IllegalArgumentException iae) {
43       // continue
44     }
45     try {
46       return new AddressBookDoCoMoResult(rawText);
47     } catch (IllegalArgumentException iae) {
48       // continue
49     }
50     try {
51       return new EmailDoCoMoResult(rawText);
52     } catch (IllegalArgumentException iae) {
53       // continue
54     }
55     try {
56       return new EmailAddressResult(rawText);
57     } catch (IllegalArgumentException iae) {
58       // continue
59     }
60     try {
61       return new URLTOResult(rawText);
62     } catch (IllegalArgumentException iae) {
63       // continue
64     }
65     try {
66       return new URIParsedResult(rawText);
67     } catch (IllegalArgumentException iae) {
68       // continue
69     }
70     try {
71       return new UPCParsedResult(rawText);
72     } catch (IllegalArgumentException iae) {
73       // continue
74     }
75     return new TextParsedResult(rawText);
76   }
77
78   public String toString() {
79     return getDisplayResult();
80   }
81
82 }