Fixed naming convention. Everything should be a "ParsedResult"
[zxing.git] / core / src / com / google / zxing / client / result / BookmarkDoCoMoParsedResult.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 import com.google.zxing.Result;
20
21 /**
22  * @author srowen@google.com (Sean Owen)
23  */
24 public final class BookmarkDoCoMoParsedResult extends AbstractDoCoMoParsedResult {
25
26   private final String title;
27   private final String uri;
28
29   private BookmarkDoCoMoParsedResult(String title, String uri) {
30     super(ParsedReaderResultType.BOOKMARK);
31     this.title = title;
32     this.uri = uri;
33   }
34
35   public static BookmarkDoCoMoParsedResult parse(Result result) {
36     String rawText = result.getText();
37     if (!rawText.startsWith("MEBKM:")) {
38       return null;
39     }
40     String title = matchSinglePrefixedField("TITLE:", rawText);
41     String[] rawUri = matchPrefixedField("URL:", rawText);
42     if (rawUri == null) {
43       return null;
44     }
45     String uri = rawUri[0];
46     if (!URIParsedResult.isBasicallyValidURI(uri)) {
47       return null;
48     }
49     return new BookmarkDoCoMoParsedResult(title, uri);
50   }
51
52   public String getTitle() {
53     return title;
54   }
55
56   public String getURI() {
57     return uri;
58   }
59
60   public String getDisplayResult() {
61     if (title == null) {
62       return uri;
63     } else {
64       return title + '\n' + uri;
65     }
66   }
67
68 }