Moved com.google.zxing.client.result from core-ext to core, rewrote it for J2ME,...
[zxing.git] / core / src / com / google / zxing / client / result / EmailAddressResult.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  * Represents a result that encodes an e-mail address, either as a plain address
21  * like "joe@example.org" or a mailto: URL like "mailto:joe@example.org".
22  *
23  * @author srowen@google.com (Sean Owen)
24  */
25 public final class EmailAddressResult extends AbstractDoCoMoResult {
26
27   private final String emailAddress;
28
29   public EmailAddressResult(String rawText) {
30     super(ParsedReaderResultType.EMAIL_ADDRESS);
31     if (rawText.startsWith("mailto:")) {
32       // If it starts with mailto:, assume it is definitely trying to be an email address
33       emailAddress = rawText.substring(7);
34     } else {
35       if (!EmailDoCoMoResult.isBasicallyValidEmailAddress(rawText)) {
36         throw new IllegalArgumentException("Invalid email address: " + rawText);
37       }
38       emailAddress = rawText;
39     }
40   }
41
42   public String getEmailAddress() {
43     return emailAddress;
44   }
45
46   public String getDisplayResult() {
47     return emailAddress;
48   }
49
50 }