diff --git a/android/src/com/google/zxing/client/android/AndroidIntentParsedResult.java b/android/src/com/google/zxing/client/android/AndroidIntentParsedResult.java index b5e99a47a..1683fd1f2 100644 --- a/android/src/com/google/zxing/client/android/AndroidIntentParsedResult.java +++ b/android/src/com/google/zxing/client/android/AndroidIntentParsedResult.java @@ -17,23 +17,23 @@ package com.google.zxing.client.android; import android.content.Intent; -import com.google.zxing.client.result.ParsedReaderResult; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.ParsedResult; +import com.google.zxing.client.result.ParsedResultType; import java.net.URISyntaxException; /** - * A {@link ParsedReaderResult} derived from a URI that encodes an Android + * A {@link com.google.zxing.client.result.ParsedResult} derived from a URI that encodes an Android * {@link Intent}, and which should presumably trigger that intent on Android. * * @author srowen@google.com (Sean Owen) */ -public final class AndroidIntentParsedResult extends ParsedReaderResult { +public final class AndroidIntentParsedResult extends ParsedResult { private final Intent intent; private AndroidIntentParsedResult(Intent intent) { - super(ParsedReaderResultType.ANDROID_INTENT); + super(ParsedResultType.ANDROID_INTENT); this.intent = intent; } diff --git a/android/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java b/android/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java index fc2a403bb..a8d677832 100644 --- a/android/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java +++ b/android/src/com/google/zxing/client/android/BarcodeReaderCaptureActivity.java @@ -31,8 +31,9 @@ import android.view.Window; import android.widget.TextView; import com.google.zxing.Result; import com.google.zxing.ResultPoint; -import com.google.zxing.client.result.ParsedReaderResult; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.ParsedResult; +import com.google.zxing.client.result.ParsedResultType; +import com.google.zxing.client.result.ResultParser; /** * The barcode reader activity itself. This is loosely based on the CameraPreview @@ -182,15 +183,15 @@ public final class BarcodeReaderCaptureActivity extends Activity { } TextView textView = (TextView) findViewById(R.id.status_text_view); - ParsedReaderResult readerResult = parseReaderResult(rawResult); - textView.setText(readerResult.getDisplayResult() + " (" + duration + " ms)"); + ParsedResult result = parseReaderResult(rawResult); + textView.setText(result.getDisplayResult() + " (" + duration + " ms)"); TextView actionButton = (TextView) findViewById(R.id.status_action_button); - int buttonText = getActionButtonText(readerResult.getType()); + int buttonText = getActionButtonText(result.getType()); if (buttonText != 0) { actionButton.setVisibility(View.VISIBLE); actionButton.setText(buttonText); - View.OnClickListener handler = new ResultHandler(this, readerResult); + View.OnClickListener handler = new ResultHandler(this, result); actionButton.setOnClickListener(handler); actionButton.requestFocus(); } else { @@ -227,9 +228,9 @@ public final class BarcodeReaderCaptureActivity extends Activity { statusView.setBackgroundColor(0x50000000); } - private static ParsedReaderResult parseReaderResult(Result rawResult) { - ParsedReaderResult readerResult = ParsedReaderResult.parseReaderResult(rawResult); - if (readerResult.getType().equals(ParsedReaderResultType.TEXT)) { + private static ParsedResult parseReaderResult(Result rawResult) { + ParsedResult result = ResultParser.parseReaderResult(rawResult); + if (result.getType().equals(ParsedResultType.TEXT)) { String rawText = rawResult.getText(); AndroidIntentParsedResult androidResult = AndroidIntentParsedResult.parse(rawText); if (androidResult != null) { @@ -237,29 +238,26 @@ public final class BarcodeReaderCaptureActivity extends Activity { if (!Intent.VIEW_ACTION.equals(intent.getAction())) { // For now, don't take anything that just parses as a View action. A lot // of things are accepted as a View action by default. - readerResult = androidResult; + result = androidResult; } } } - return readerResult; + return result; } - private static int getActionButtonText(ParsedReaderResultType type) { + private static int getActionButtonText(ParsedResultType type) { int buttonText; - if (type.equals(ParsedReaderResultType.ADDRESSBOOK)) { + if (type.equals(ParsedResultType.ADDRESSBOOK)) { buttonText = R.string.button_add_contact; - } else if (type.equals(ParsedReaderResultType.URI) || - type.equals(ParsedReaderResultType.BOOKMARK) || - type.equals(ParsedReaderResultType.URLTO)) { + } else if (type.equals(ParsedResultType.URI)) { buttonText = R.string.button_open_browser; - } else if (type.equals(ParsedReaderResultType.EMAIL) || - type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) { + } else if (type.equals(ParsedResultType.EMAIL_ADDRESS)) { buttonText = R.string.button_email; - } else if (type.equals(ParsedReaderResultType.UPC)) { + } else if (type.equals(ParsedResultType.UPC)) { buttonText = R.string.button_lookup_product; - } else if (type.equals(ParsedReaderResultType.TEL)) { + } else if (type.equals(ParsedResultType.TEL)) { buttonText = R.string.button_dial; - } else if (type.equals(ParsedReaderResultType.GEO)) { + } else if (type.equals(ParsedResultType.GEO)) { buttonText = R.string.button_show_map; } else { buttonText = 0; diff --git a/android/src/com/google/zxing/client/android/ResultHandler.java b/android/src/com/google/zxing/client/android/ResultHandler.java index 9627b9eb2..8f4189a21 100755 --- a/android/src/com/google/zxing/client/android/ResultHandler.java +++ b/android/src/com/google/zxing/client/android/ResultHandler.java @@ -21,20 +21,15 @@ import android.net.Uri; import android.provider.Contacts; import android.view.View; import android.widget.Button; -import com.google.zxing.client.result.AddressBookAUParsedResult; -import com.google.zxing.client.result.AddressBookDoCoMoParsedResult; -import com.google.zxing.client.result.BookmarkDoCoMoParsedResult; +import com.google.zxing.client.result.AddressBookParsedResult; import com.google.zxing.client.result.EmailAddressParsedResult; -import com.google.zxing.client.result.EmailDoCoMoParsedResult; import com.google.zxing.client.result.GeoParsedResult; -import com.google.zxing.client.result.ParsedReaderResult; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.ParsedResult; +import com.google.zxing.client.result.ParsedResultType; import com.google.zxing.client.result.SMSParsedResult; -import com.google.zxing.client.result.SMSTOParsedResult; import com.google.zxing.client.result.TelParsedResult; import com.google.zxing.client.result.UPCParsedResult; import com.google.zxing.client.result.URIParsedResult; -import com.google.zxing.client.result.URLTOParsedResult; /** * Handles the result of barcode decoding in the context of the Android platform, @@ -48,65 +43,44 @@ final class ResultHandler implements Button.OnClickListener { private final Intent intent; private final BarcodeReaderCaptureActivity captureActivity; - ResultHandler(BarcodeReaderCaptureActivity captureActivity, ParsedReaderResult result) { + ResultHandler(BarcodeReaderCaptureActivity captureActivity, ParsedResult result) { this.captureActivity = captureActivity; this.intent = resultToIntent(result); } - private static Intent resultToIntent(ParsedReaderResult result) { + private static Intent resultToIntent(ParsedResult result) { Intent intent = null; - ParsedReaderResultType type = result.getType(); - if (type.equals(ParsedReaderResultType.ADDRESSBOOK)) { - AddressBookDoCoMoParsedResult addressResult = (AddressBookDoCoMoParsedResult) result; - intent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI); - putExtra(intent, Contacts.Intents.Insert.NAME, addressResult.getName()); - putExtra(intent, Contacts.Intents.Insert.PHONE, addressResult.getPhoneNumbers()); - putExtra(intent, Contacts.Intents.Insert.EMAIL, addressResult.getEmail()); - putExtra(intent, Contacts.Intents.Insert.NOTES, addressResult.getNote()); - putExtra(intent, Contacts.Intents.Insert.POSTAL, addressResult.getAddress()); - } else if (type.equals(ParsedReaderResultType.ADDRESSBOOK_AU)) { - AddressBookAUParsedResult addressResult = (AddressBookAUParsedResult) result; + ParsedResultType type = result.getType(); + if (type.equals(ParsedResultType.ADDRESSBOOK)) { + AddressBookParsedResult addressResult = (AddressBookParsedResult) result; intent = new Intent(Contacts.Intents.Insert.ACTION, Contacts.People.CONTENT_URI); putExtra(intent, Contacts.Intents.Insert.NAME, addressResult.getNames()); putExtra(intent, Contacts.Intents.Insert.PHONE, addressResult.getPhoneNumbers()); putExtra(intent, Contacts.Intents.Insert.EMAIL, addressResult.getEmails()); putExtra(intent, Contacts.Intents.Insert.NOTES, addressResult.getNote()); putExtra(intent, Contacts.Intents.Insert.POSTAL, addressResult.getAddress()); - } else if (type.equals(ParsedReaderResultType.BOOKMARK)) { - // For now, we can only open the browser, and not actually add a bookmark - intent = new Intent(Intent.VIEW_ACTION, Uri.parse(((BookmarkDoCoMoParsedResult) result).getURI())); - } else if (type.equals(ParsedReaderResultType.URLTO)) { - intent = new Intent(Intent.VIEW_ACTION, Uri.parse(((URLTOParsedResult) result).getURI())); - } else if (type.equals(ParsedReaderResultType.EMAIL)) { - EmailDoCoMoParsedResult emailResult = (EmailDoCoMoParsedResult) result; - intent = new Intent(Intent.SENDTO_ACTION, Uri.parse(emailResult.getMailtoURI())); - putExtra(intent, "subject", emailResult.getSubject()); - putExtra(intent, "body", emailResult.getBody()); - } else if (type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) { + } else if (type.equals(ParsedResultType.EMAIL_ADDRESS)) { EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result; intent = new Intent(Intent.SENDTO_ACTION, Uri.parse(emailResult.getMailtoURI())); putExtra(intent, "subject", emailResult.getSubject()); putExtra(intent, "body", emailResult.getBody()); - } else if (type.equals(ParsedReaderResultType.SMS)) { + } else if (type.equals(ParsedResultType.SMS)) { SMSParsedResult smsResult = (SMSParsedResult) result; intent = new Intent(Intent.SENDTO_ACTION, Uri.parse(smsResult.getSMSURI())); - } else if (type.equals(ParsedReaderResultType.SMSTO)) { - SMSTOParsedResult smsToResult = (SMSTOParsedResult) result; - intent = new Intent(Intent.SENDTO_ACTION, Uri.parse(smsToResult.getSMSURI())); - } else if (type.equals(ParsedReaderResultType.TEL)) { + } else if (type.equals(ParsedResultType.TEL)) { TelParsedResult telResult = (TelParsedResult) result; intent = new Intent(Intent.DIAL_ACTION, Uri.parse(telResult.getTelURI())); - } else if (type.equals(ParsedReaderResultType.GEO)) { + } else if (type.equals(ParsedResultType.GEO)) { GeoParsedResult geoResult = (GeoParsedResult) result; intent = new Intent(Intent.VIEW_ACTION, Uri.parse(geoResult.getGeoURI())); - } else if (type.equals(ParsedReaderResultType.UPC)) { + } else if (type.equals(ParsedResultType.UPC)) { UPCParsedResult upcResult = (UPCParsedResult) result; Uri uri = Uri.parse("http://www.upcdatabase.com/item.asp?upc=" + upcResult.getUPC()); intent = new Intent(Intent.VIEW_ACTION, uri); - } else if (type.equals(ParsedReaderResultType.URI)) { + } else if (type.equals(ParsedResultType.URI)) { URIParsedResult uriResult = (URIParsedResult) result; intent = new Intent(Intent.VIEW_ACTION, Uri.parse(uriResult.getURI())); - } else if (type.equals(ParsedReaderResultType.ANDROID_INTENT)) { + } else if (type.equals(ParsedResultType.ANDROID_INTENT)) { intent = ((AndroidIntentParsedResult) result).getIntent(); } return intent; diff --git a/core/src/com/google/zxing/client/result/AbstractDoCoMoParsedResult.java b/core/src/com/google/zxing/client/result/AbstractDoCoMoParsedResult.java index b32de6208..8c8026040 100644 --- a/core/src/com/google/zxing/client/result/AbstractDoCoMoParsedResult.java +++ b/core/src/com/google/zxing/client/result/AbstractDoCoMoParsedResult.java @@ -16,8 +16,6 @@ package com.google.zxing.client.result; -import java.util.Vector; - /** *
See
*
@@ -28,78 +26,10 @@ import java.util.Vector;
*
* @author srowen@google.com (Sean Owen)
*/
-abstract class AbstractDoCoMoParsedResult extends ParsedReaderResult {
+abstract class AbstractDoCoMoParsedResult extends ParsedResult {
- AbstractDoCoMoParsedResult(ParsedReaderResultType type) {
+ AbstractDoCoMoParsedResult(ParsedResultType type) {
super(type);
}
- // This could as well be implemented with java.util.regex. It was already implemented partially
- // to run in a J2ME enviroment, where this unavailable.
-
- static String[] matchPrefixedField(String prefix, String rawText) {
- return matchPrefixedField(prefix, rawText, ';');
- }
-
- private static String[] matchPrefixedField(String prefix, String rawText, char endChar) {
- Vector matches = null;
- int i = 0;
- int max = rawText.length();
- while (i < max) {
- i = rawText.indexOf(prefix, i);
- if (i < 0) {
- break;
- }
- i += prefix.length(); // Skip past this prefix we found to start
- int start = i; // Found the start of a match here
- boolean done = false;
- while (!done) {
- i = rawText.indexOf((int) endChar, i);
- if (i < 0) {
- // No terminating end character? uh, done. Set i such that loop terminates and break
- i = rawText.length();
- done = true;
- } else if (rawText.charAt(i - 1) == '\\') {
- // semicolon was escaped so continue
- i++;
- } else {
- // found a match
- if (matches == null) {
- matches = new Vector(3); // lazy init
- }
- matches.addElement(unescapeBackslash(rawText.substring(start, i)));
- i++;
- done = true;
- }
- }
- }
- if (matches == null || matches.isEmpty()) {
- return null;
- }
- int size = matches.size();
- String[] result = new String[size];
- for (int j = 0; j < size; j++) {
- result[j] = (String) matches.elementAt(j);
- }
- return result;
- }
-
- static String matchSinglePrefixedField(String prefix, String rawText) {
- return matchSinglePrefixedField(prefix, rawText, ';');
- }
-
- static String matchSinglePrefixedField(String prefix, String rawText, char endChar) {
- String[] matches = matchPrefixedField(prefix, rawText, endChar);
- return matches == null ? null : matches[0];
- }
-
- static void maybeAppend(String[] value, StringBuffer result) {
- if (value != null) {
- for (int i = 0; i < value.length; i++) {
- result.append('\n');
- result.append(value[i]);
- }
- }
- }
-
}
\ No newline at end of file
diff --git a/core/src/com/google/zxing/client/result/AbstractDoCoMoResultParser.java b/core/src/com/google/zxing/client/result/AbstractDoCoMoResultParser.java
new file mode 100644
index 000000000..3b320e2f3
--- /dev/null
+++ b/core/src/com/google/zxing/client/result/AbstractDoCoMoResultParser.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.google.zxing.client.result;
+
+import java.util.Vector;
+
+/**
+ * See
+ *
+ * DoCoMo's documentation about the result types represented by subclasses of this class. Thanks to Jeff Griffin for proposing rewrite of these classes that relies less
+ * on exception-based mechanisms during parsing. We would return the start and end date as a {@link java.util.Date} except that this code
+ * needs to work under JavaME / MIDP and there is no date parsing library available there, such
+ * as Instead this is a String formatted as YYYYMMdd'T'HHmmss'Z'.java.text.SimpleDateFormat
.
Abstract class representing the result of decoding a barcode, as more than + * a String -- as some type of structured data. This might be a subclass which represents + * a URL, or an e-mail address. {@link #parseReaderResult(Result)} will turn a raw + * decoded string into the most appropriate type of structured representation.
+ * + *Thanks to Jeff Griffin for proposing rewrite of these classes that relies less + * on exception-based mechanisms during parsing.
+ * + * @author srowen@google.com (Sean Owen) + */ +public abstract class ParsedResult { + + private final ParsedResultType type; + + protected ParsedResult(ParsedResultType type) { + this.type = type; + } + + public ParsedResultType getType() { + return type; + } + + public abstract String getDisplayResult(); + + + public String toString() { + return getDisplayResult(); + } + + protected static void maybeAppend(String value, StringBuffer result) { + if (value != null) { + result.append('\n'); + result.append(value); + } + } + + protected static void maybeAppend(String[] value, StringBuffer result) { + if (value != null) { + for (int i = 0; i < value.length; i++) { + result.append('\n'); + result.append(value[i]); + } + } + } + +} diff --git a/core/src/com/google/zxing/client/result/ParsedResultType.java b/core/src/com/google/zxing/client/result/ParsedResultType.java new file mode 100644 index 000000000..9449b03e7 --- /dev/null +++ b/core/src/com/google/zxing/client/result/ParsedResultType.java @@ -0,0 +1,51 @@ +/* + * Copyright 2007 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.result; + +/** + * Represents the type of data encoded by a barcode -- from plain text, to a + * URI, to an e-mail address, etc. + * + * @author srowen@google.com (Sean Owen) + */ +public final class ParsedResultType { + + public static final ParsedResultType ADDRESSBOOK = new ParsedResultType("ADDRESSBOOK"); + public static final ParsedResultType EMAIL_ADDRESS = new ParsedResultType("EMAIL_ADDRESS"); + public static final ParsedResultType UPC = new ParsedResultType("UPC"); + public static final ParsedResultType URI = new ParsedResultType("URI"); + public static final ParsedResultType TEXT = new ParsedResultType("TEXT"); + public static final ParsedResultType ANDROID_INTENT = new ParsedResultType("ANDROID_INTENT"); + public static final ParsedResultType GEO = new ParsedResultType("GEO"); + public static final ParsedResultType TEL = new ParsedResultType("TEL"); + public static final ParsedResultType SMS = new ParsedResultType("SMS"); + public static final ParsedResultType CALENDAR = new ParsedResultType("CALENDAR"); + // "optional" types + public static final ParsedResultType NDEF_SMART_POSTER = new ParsedResultType("NDEF_SMART_POSTER"); + public static final ParsedResultType MOBILETAG_RICH_WEB = new ParsedResultType("MOBILETAG_RICH_WEB"); + + private final String name; + + private ParsedResultType(String name) { + this.name = name; + } + + public String toString() { + return name; + } + +} diff --git a/core/src/com/google/zxing/client/result/ParsedReaderResult.java b/core/src/com/google/zxing/client/result/ResultParser.java similarity index 80% rename from core/src/com/google/zxing/client/result/ParsedReaderResult.java rename to core/src/com/google/zxing/client/result/ResultParser.java index fc20db85d..440c6e5b6 100644 --- a/core/src/com/google/zxing/client/result/ParsedReaderResult.java +++ b/core/src/com/google/zxing/client/result/ResultParser.java @@ -23,7 +23,7 @@ import java.util.Hashtable; /** *Abstract class representing the result of decoding a barcode, as more than * a String -- as some type of structured data. This might be a subclass which represents - * a URL, or an e-mail address. {@link #parseReaderResult(Result)} will turn a raw + * a URL, or an e-mail address. {@link #parseReaderResult(com.google.zxing.Result)} will turn a raw * decoded string into the most appropriate type of structured representation.
* *Thanks to Jeff Griffin for proposing rewrite of these classes that relies less @@ -31,55 +31,39 @@ import java.util.Hashtable; * * @author srowen@google.com (Sean Owen) */ -public abstract class ParsedReaderResult { +public abstract class ResultParser { - private final ParsedReaderResultType type; - - protected ParsedReaderResult(ParsedReaderResultType type) { - this.type = type; - } - - public ParsedReaderResultType getType() { - return type; - } - - public abstract String getDisplayResult(); - - public static ParsedReaderResult parseReaderResult(Result theResult) { + public static ParsedResult parseReaderResult(Result theResult) { // This is a bit messy, but given limited options in MIDP / CLDC, this may well be the simplest // way to go about this. For example, we have no reflection available, really. // Order is important here. - ParsedReaderResult result; - if ((result = BookmarkDoCoMoParsedResult.parse(theResult)) != null) { + ParsedResult result; + if ((result = BookmarkDoCoMoResultParser.parse(theResult)) != null) { return result; - } else if ((result = AddressBookDoCoMoParsedResult.parse(theResult)) != null) { + } else if ((result = AddressBookDoCoMoResultParser.parse(theResult)) != null) { return result; - } else if ((result = EmailDoCoMoParsedResult.parse(theResult)) != null) { + } else if ((result = EmailDoCoMoResultParser.parse(theResult)) != null) { return result; - } else if ((result = EmailAddressParsedResult.parse(theResult)) != null) { + } else if ((result = EmailAddressResultParser.parse(theResult)) != null) { return result; - } else if ((result = AddressBookAUParsedResult.parse(theResult)) != null) { + } else if ((result = AddressBookAUResultParser.parse(theResult)) != null) { return result; - } else if ((result = TelParsedResult.parse(theResult)) != null) { + } else if ((result = TelResultParser.parse(theResult)) != null) { return result; - } else if ((result = SMSParsedResult.parse(theResult)) != null) { + } else if ((result = SMSResultParser.parse(theResult)) != null) { return result; - } else if ((result = SMSTOParsedResult.parse(theResult)) != null) { + } else if ((result = SMSTOResultParser.parse(theResult)) != null) { return result; - } else if ((result = GeoParsedResult.parse(theResult)) != null) { + } else if ((result = GeoResultParser.parse(theResult)) != null) { return result; - } else if ((result = URLTOParsedResult.parse(theResult)) != null) { + } else if ((result = URLTOResultParser.parse(theResult)) != null) { return result; - } else if ((result = URIParsedResult.parse(theResult)) != null) { + } else if ((result = URIResultParser.parse(theResult)) != null) { return result; - } else if ((result = UPCParsedResult.parse(theResult)) != null) { + } else if ((result = UPCResultParser.parse(theResult)) != null) { return result; } - return TextParsedResult.parse(theResult); - } - - public String toString() { - return getDisplayResult(); + return new TextParsedResult(theResult.getText(), null); } protected static void maybeAppend(String value, StringBuffer result) { @@ -89,6 +73,15 @@ public abstract class ParsedReaderResult { } } + protected static void maybeAppend(String[] value, StringBuffer result) { + if (value != null) { + for (int i = 0; i < value.length; i++) { + result.append('\n'); + result.append(value[i]); + } + } + } + protected static String unescapeBackslash(String escaped) { if (escaped != null) { int backslash = escaped.indexOf((int) '\\'); @@ -217,4 +210,4 @@ public abstract class ParsedReaderResult { } } -} +} \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/SMSParsedResult.java b/core/src/com/google/zxing/client/result/SMSParsedResult.java index 4b3337518..23b8d7e16 100644 --- a/core/src/com/google/zxing/client/result/SMSParsedResult.java +++ b/core/src/com/google/zxing/client/result/SMSParsedResult.java @@ -16,57 +16,26 @@ package com.google.zxing.client.result; -import com.google.zxing.Result; - /** - * Represents a "sms:" URI result, which specifies a number to SMS and optional - * "via" number. See - * the IETF draft on this. - * * @author srowen@google.com (Sean Owen) */ -public final class SMSParsedResult extends ParsedReaderResult { +public final class SMSParsedResult extends ParsedResult { private final String smsURI; private final String number; private final String via; + private final String subject; + private final String body; + private final String title; - private SMSParsedResult(String smsURI, String number, String via) { - super(ParsedReaderResultType.SMS); + public SMSParsedResult(String smsURI, String number, String via, String subject, String body, String title) { + super(ParsedResultType.SMS); this.smsURI = smsURI; this.number = number; this.via = via; - } - - public static SMSParsedResult parse(Result result) { - String rawText = result.getText(); - if (rawText == null || !rawText.startsWith("sms:")) { - return null; - } - // Drop sms, query portion - int queryStart = rawText.indexOf('?', 4); - String smsURIWithoutQuery; - if (queryStart < 0) { - smsURIWithoutQuery = rawText.substring(4); - } else { - smsURIWithoutQuery = rawText.substring(4, queryStart); - } - int numberEnd = smsURIWithoutQuery.indexOf(';'); - String number; - String via; - if (numberEnd < 0) { - number = smsURIWithoutQuery; - via = null; - } else { - number = smsURIWithoutQuery.substring(0, numberEnd); - String maybeVia = smsURIWithoutQuery.substring(numberEnd + 1); - if (maybeVia.startsWith("via=")) { - via = maybeVia.substring(4); - } else { - via = null; - } - } - return new SMSParsedResult(rawText, number, via); + this.subject = subject; + this.body = body; + this.title = title; } public String getSMSURI() { @@ -81,6 +50,18 @@ public final class SMSParsedResult extends ParsedReaderResult { return via; } + public String getSubject() { + return subject; + } + + public String getBody() { + return body; + } + + public String getTitle() { + return title; + } + public String getDisplayResult() { return number; } diff --git a/core/src/com/google/zxing/client/result/SMSResultParser.java b/core/src/com/google/zxing/client/result/SMSResultParser.java new file mode 100644 index 000000000..8b8e2d36a --- /dev/null +++ b/core/src/com/google/zxing/client/result/SMSResultParser.java @@ -0,0 +1,64 @@ +/* + * Copyright 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.result; + +import com.google.zxing.Result; + +/** + * Parses an "sms:" URI result, which specifies a number to SMS and optional + * "via" number. See + * the IETF draft on this. + * + * @author srowen@google.com (Sean Owen) + */ +public final class SMSResultParser extends ResultParser { + + private SMSResultParser() { + } + + public static SMSParsedResult parse(Result result) { + String rawText = result.getText(); + if (rawText == null || !rawText.startsWith("sms:")) { + return null; + } + // Drop sms, query portion + int queryStart = rawText.indexOf('?', 4); + String smsURIWithoutQuery; + if (queryStart < 0) { + smsURIWithoutQuery = rawText.substring(4); + } else { + smsURIWithoutQuery = rawText.substring(4, queryStart); + } + int numberEnd = smsURIWithoutQuery.indexOf(';'); + String number; + String via; + if (numberEnd < 0) { + number = smsURIWithoutQuery; + via = null; + } else { + number = smsURIWithoutQuery.substring(0, numberEnd); + String maybeVia = smsURIWithoutQuery.substring(numberEnd + 1); + if (maybeVia.startsWith("via=")) { + via = maybeVia.substring(4); + } else { + via = null; + } + } + return new SMSParsedResult(rawText, number, via, null, null, null); + } + +} \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/SMSTOParsedResult.java b/core/src/com/google/zxing/client/result/SMSTOResultParser.java similarity index 62% rename from core/src/com/google/zxing/client/result/SMSTOParsedResult.java rename to core/src/com/google/zxing/client/result/SMSTOResultParser.java index e22198c42..5730a8a74 100644 --- a/core/src/com/google/zxing/client/result/SMSTOParsedResult.java +++ b/core/src/com/google/zxing/client/result/SMSTOResultParser.java @@ -19,38 +19,22 @@ package com.google.zxing.client.result; import com.google.zxing.Result; /** - * Represents a "SMSTO:" result, which specifies a number to SMS. + * Parses an "SMSTO:" result, which specifies a number to SMS. * * @author srowen@google.com (Sean Owen) */ -public final class SMSTOParsedResult extends ParsedReaderResult { +public final class SMSTOResultParser extends ResultParser { - private final String number; - - private SMSTOParsedResult(String number) { - super(ParsedReaderResultType.SMSTO); - this.number = number; + private SMSTOResultParser() { } - public static SMSTOParsedResult parse(Result result) { + public static SMSParsedResult parse(Result result) { String rawText = result.getText(); if (rawText == null || !rawText.startsWith("SMSTO:")) { return null; } String number = rawText.substring(6); - return new SMSTOParsedResult(number); - } - - public String getNumber() { - return number; - } - - public String getDisplayResult() { - return number; - } - - public String getSMSURI() { - return "sms:" + number; + return new SMSParsedResult("sms:" + number, number, null, null, null, null); } } \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/TelParsedResult.java b/core/src/com/google/zxing/client/result/TelParsedResult.java index 9ab524c99..bddb85a2a 100644 --- a/core/src/com/google/zxing/client/result/TelParsedResult.java +++ b/core/src/com/google/zxing/client/result/TelParsedResult.java @@ -16,38 +16,20 @@ package com.google.zxing.client.result; -import com.google.zxing.Result; - /** - * Represents a "tel:" URI result, which specifies a phone number. - * * @author srowen@google.com (Sean Owen) */ -public final class TelParsedResult extends ParsedReaderResult { +public final class TelParsedResult extends ParsedResult { private final String number; private final String telURI; + private final String title; - private TelParsedResult(String number, String telURI) { - super(ParsedReaderResultType.TEL); + public TelParsedResult(String number, String telURI, String title) { + super(ParsedResultType.TEL); this.number = number; this.telURI = telURI; - } - - public static TelParsedResult parse(Result result) { - String rawText = result.getText(); - if (rawText == null || !rawText.startsWith("tel:")) { - return null; - } - String telURI = rawText; - // Drop tel, query portion - int queryStart = rawText.indexOf('?', 4); - if (queryStart < 0) { - rawText = rawText.substring(4); - } else { - rawText = rawText.substring(4, queryStart); - } - return new TelParsedResult(rawText, telURI); + this.title = title; } public String getNumber() { @@ -58,6 +40,10 @@ public final class TelParsedResult extends ParsedReaderResult { return telURI; } + public String getTitle() { + return title; + } + public String getDisplayResult() { return number; } diff --git a/core/src/com/google/zxing/client/result/TelResultParser.java b/core/src/com/google/zxing/client/result/TelResultParser.java new file mode 100644 index 000000000..2eb3b87f2 --- /dev/null +++ b/core/src/com/google/zxing/client/result/TelResultParser.java @@ -0,0 +1,47 @@ +/* + * Copyright 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.result; + +import com.google.zxing.Result; + +/** + * Parses a "tel:" URI result, which specifies a phone number. + * + * @author srowen@google.com (Sean Owen) + */ +public final class TelResultParser extends ResultParser { + + private TelResultParser() { + } + + public static TelParsedResult parse(Result result) { + String rawText = result.getText(); + if (rawText == null || !rawText.startsWith("tel:")) { + return null; + } + String telURI = rawText; + // Drop tel, query portion + int queryStart = rawText.indexOf('?', 4); + if (queryStart < 0) { + rawText = rawText.substring(4); + } else { + rawText = rawText.substring(4, queryStart); + } + return new TelParsedResult(rawText, telURI, null); + } + +} \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/TextParsedResult.java b/core/src/com/google/zxing/client/result/TextParsedResult.java index 9d58d20bf..39e8f1532 100644 --- a/core/src/com/google/zxing/client/result/TextParsedResult.java +++ b/core/src/com/google/zxing/client/result/TextParsedResult.java @@ -16,28 +16,31 @@ package com.google.zxing.client.result; -import com.google.zxing.Result; - /** + * A simple result type encapsulating a string that has no further + * interpretation. + * * @author srowen@google.com (Sean Owen) */ -public final class TextParsedResult extends ParsedReaderResult { +public final class TextParsedResult extends ParsedResult { private final String text; + private final String language; - private TextParsedResult(String text) { - super(ParsedReaderResultType.TEXT); + public TextParsedResult(String text, String language) { + super(ParsedResultType.TEXT); this.text = text; - } - - public static TextParsedResult parse(Result result) { - return new TextParsedResult(result.getText()); + this.language = language; } public String getText() { return text; } + public String getLanguage() { + return language; + } + public String getDisplayResult() { return text; } diff --git a/core/src/com/google/zxing/client/result/UPCParsedResult.java b/core/src/com/google/zxing/client/result/UPCParsedResult.java index 14feec6ca..fd74b4dbb 100644 --- a/core/src/com/google/zxing/client/result/UPCParsedResult.java +++ b/core/src/com/google/zxing/client/result/UPCParsedResult.java @@ -16,46 +16,18 @@ package com.google.zxing.client.result; -import com.google.zxing.BarcodeFormat; -import com.google.zxing.Result; - /** * @author dswitkin@google.com (Daniel Switkin) */ -public final class UPCParsedResult extends ParsedReaderResult { +public final class UPCParsedResult extends ParsedResult { private final String upc; - private UPCParsedResult(String upc) { - super(ParsedReaderResultType.UPC); + UPCParsedResult(String upc) { + super(ParsedResultType.UPC); this.upc = upc; } - // Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes. - public static UPCParsedResult parse(Result result) { - BarcodeFormat format = result.getBarcodeFormat(); - if (!BarcodeFormat.UPC_A.equals(format) && !BarcodeFormat.UPC_E.equals(format) && - !BarcodeFormat.EAN_8.equals(format) && !BarcodeFormat.EAN_13.equals(format)) { - return null; - } - String rawText = result.getText(); - if (rawText == null) { - return null; - } - int length = rawText.length(); - if (length != 12 && length != 13) { - return null; - } - for (int x = 0; x < length; x++) { - char c = rawText.charAt(x); - if (c < '0' || c > '9') { - return null; - } - } - // Not actually checking the checkusm again here - return new UPCParsedResult(rawText); - } - public String getUPC() { return upc; } diff --git a/core/src/com/google/zxing/client/result/UPCResultParser.java b/core/src/com/google/zxing/client/result/UPCResultParser.java new file mode 100644 index 000000000..7236b3382 --- /dev/null +++ b/core/src/com/google/zxing/client/result/UPCResultParser.java @@ -0,0 +1,57 @@ +/* + * Copyright 2007 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.result; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; + +/** + * Parses strings of digits that repesent a UPC code. + * + * @author dswitkin@google.com (Daniel Switkin) + */ +public final class UPCResultParser extends ResultParser { + + private UPCResultParser() { + } + + // Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes. + public static UPCParsedResult parse(Result result) { + BarcodeFormat format = result.getBarcodeFormat(); + if (!BarcodeFormat.UPC_A.equals(format) && !BarcodeFormat.UPC_E.equals(format) && + !BarcodeFormat.EAN_8.equals(format) && !BarcodeFormat.EAN_13.equals(format)) { + return null; + } + String rawText = result.getText(); + if (rawText == null) { + return null; + } + int length = rawText.length(); + if (length != 12 && length != 13) { + return null; + } + for (int x = 0; x < length; x++) { + char c = rawText.charAt(x); + if (c < '0' || c > '9') { + return null; + } + } + // Not actually checking the checkusm again here + return new UPCParsedResult(rawText); + } + +} \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/URIParsedResult.java b/core/src/com/google/zxing/client/result/URIParsedResult.java index 614e0cd02..93bd6372a 100644 --- a/core/src/com/google/zxing/client/result/URIParsedResult.java +++ b/core/src/com/google/zxing/client/result/URIParsedResult.java @@ -16,65 +16,35 @@ package com.google.zxing.client.result; -import com.google.zxing.Result; - /** * @author srowen@google.com (Sean Owen) */ -public final class URIParsedResult extends ParsedReaderResult { +public final class URIParsedResult extends ParsedResult { private final String uri; + private final String title; - private URIParsedResult(String uri) { - super(ParsedReaderResultType.URI); + public URIParsedResult(String uri, String title) { + super(ParsedResultType.URI); this.uri = uri; - } - - public static URIParsedResult parse(Result result) { - String rawText = result.getText(); - if (!isBasicallyValidURI(rawText)) { - return null; - } - String uri = massagePossibleURI(rawText); - return new URIParsedResult(uri); + this.title = title; } public String getURI() { return uri; } + public String getTitle() { + return title; + } + public String getDisplayResult() { - return uri; - } - - /** - * Transforms a string that possibly represents a URI into something more proper, by adding or canonicalizing - * the protocol. - */ - private static String massagePossibleURI(String uri) { - // Take off leading "URL:" if present - if (uri.startsWith("URL:")) { - uri = uri.substring(4); - } - int protocolEnd = uri.indexOf(':'); - if (protocolEnd < 0) { - // No protocol, assume http - uri = "http://" + uri; + if (title == null) { + return uri; } else { - // Lowercase protocol to avoid problems - uri = uri.substring(0, protocolEnd).toLowerCase() + uri.substring(protocolEnd); - // TODO this logic isn't quite right for URIs like "example.org:443/foo" + return title + '\n' + uri; } - return uri; } - /** - * Determines whether a string is not obviously not a URI. This implements crude checks; this class does not - * intend to strictly check URIs as its only function is to represent what is in a barcode, but, it does - * need to know when a string is obviously not a URI. - */ - static boolean isBasicallyValidURI(String uri) { - return uri != null && uri.indexOf(' ') < 0 && (uri.indexOf(':') >= 0 || uri.indexOf('.') >= 0); - } } \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/URIResultParser.java b/core/src/com/google/zxing/client/result/URIResultParser.java new file mode 100644 index 000000000..7be06359e --- /dev/null +++ b/core/src/com/google/zxing/client/result/URIResultParser.java @@ -0,0 +1,70 @@ +/* + * Copyright 2007 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.result; + +import com.google.zxing.Result; + +/** + * Tries to parse results that are a URI of some kind. + * + * @author srowen@google.com (Sean Owen) + */ +public final class URIResultParser extends ResultParser { + + private URIResultParser() { + } + + public static URIParsedResult parse(Result result) { + String rawText = result.getText(); + if (!isBasicallyValidURI(rawText)) { + return null; + } + String uri = massagePossibleURI(rawText); + return new URIParsedResult(uri, null); + } + + /** + * Transforms a string that possibly represents a URI into something more proper, by adding or canonicalizing + * the protocol. + */ + private static String massagePossibleURI(String uri) { + // Take off leading "URL:" if present + if (uri.startsWith("URL:")) { + uri = uri.substring(4); + } + int protocolEnd = uri.indexOf(':'); + if (protocolEnd < 0) { + // No protocol, assume http + uri = "http://" + uri; + } else { + // Lowercase protocol to avoid problems + uri = uri.substring(0, protocolEnd).toLowerCase() + uri.substring(protocolEnd); + // TODO this logic isn't quite right for URIs like "example.org:443/foo" + } + return uri; + } + + /** + * Determines whether a string is not obviously not a URI. This implements crude checks; this class does not + * intend to strictly check URIs as its only function is to represent what is in a barcode, but, it does + * need to know when a string is obviously not a URI. + */ + static boolean isBasicallyValidURI(String uri) { + return uri != null && uri.indexOf(' ') < 0 && (uri.indexOf(':') >= 0 || uri.indexOf('.') >= 0); + } + +} \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/URLTOParsedResult.java b/core/src/com/google/zxing/client/result/URLTOResultParser.java similarity index 63% rename from core/src/com/google/zxing/client/result/URLTOParsedResult.java rename to core/src/com/google/zxing/client/result/URLTOResultParser.java index 95ebcd275..719cdaa46 100644 --- a/core/src/com/google/zxing/client/result/URLTOParsedResult.java +++ b/core/src/com/google/zxing/client/result/URLTOResultParser.java @@ -19,24 +19,18 @@ package com.google.zxing.client.result; import com.google.zxing.Result; /** - * "URLTO" result format, which is of the form "URLTO:[title]:[url]". + * Parses the "URLTO" result format, which is of the form "URLTO:[title]:[url]". * This seems to be used sometimes, but I am not able to find documentation * on its origin or official format? * * @author srowen@google.com (Sean Owen) */ -public final class URLTOParsedResult extends ParsedReaderResult { +public final class URLTOResultParser { - private final String title; - private final String uri; - - private URLTOParsedResult(String title, String uri) { - super(ParsedReaderResultType.URLTO); - this.title = title; - this.uri = uri; + private URLTOResultParser() { } - public static URLTOParsedResult parse(Result result) { + public static URIParsedResult parse(Result result) { String rawText = result.getText(); if (rawText == null || !rawText.startsWith("URLTO:")) { return null; @@ -47,23 +41,7 @@ public final class URLTOParsedResult extends ParsedReaderResult { } String title = rawText.substring(6, titleEnd); String uri = rawText.substring(titleEnd + 1); - return new URLTOParsedResult(title, uri); - } - - public String getTitle() { - return title; - } - - public String getURI() { - return uri; - } - - public String getDisplayResult() { - if (title == null) { - return uri; - } else { - return title + '\n' + uri; - } + return new URIParsedResult(uri, title); } } \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/AbstractMobileTagParsedResult.java b/core/src/com/google/zxing/client/result/optional/AbstractMobileTagResultParser.java similarity index 88% rename from core/src/com/google/zxing/client/result/optional/AbstractMobileTagParsedResult.java rename to core/src/com/google/zxing/client/result/optional/AbstractMobileTagResultParser.java index f2de27aa2..b845a5ebf 100644 --- a/core/src/com/google/zxing/client/result/optional/AbstractMobileTagParsedResult.java +++ b/core/src/com/google/zxing/client/result/optional/AbstractMobileTagResultParser.java @@ -16,8 +16,7 @@ package com.google.zxing.client.result.optional; -import com.google.zxing.client.result.ParsedReaderResult; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.ResultParser; /** *
Superclass for classes encapsulating reader results encoded according @@ -25,16 +24,12 @@ import com.google.zxing.client.result.ParsedReaderResultType; * * @author srowen@google.com (Sean Owen) */ -abstract class AbstractMobileTagParsedResult extends ParsedReaderResult { +abstract class AbstractMobileTagResultParser extends ResultParser { public static final int ACTION_DO = 1; public static final int ACTION_EDIT = 2; public static final int ACTION_SAVE = 4; - AbstractMobileTagParsedResult(ParsedReaderResultType type) { - super(type); - } - static String[] matchDelimitedFields(String rawText, int maxItems) { String[] result = new String[maxItems]; int item = 0; diff --git a/core/src/com/google/zxing/client/result/optional/AbstractNDEFParsedResult.java b/core/src/com/google/zxing/client/result/optional/AbstractNDEFResultParser.java similarity index 85% rename from core/src/com/google/zxing/client/result/optional/AbstractNDEFParsedResult.java rename to core/src/com/google/zxing/client/result/optional/AbstractNDEFResultParser.java index 05250adf0..47472e58a 100644 --- a/core/src/com/google/zxing/client/result/optional/AbstractNDEFParsedResult.java +++ b/core/src/com/google/zxing/client/result/optional/AbstractNDEFResultParser.java @@ -16,8 +16,7 @@ package com.google.zxing.client.result.optional; -import com.google.zxing.client.result.ParsedReaderResult; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.ResultParser; import java.io.UnsupportedEncodingException; @@ -31,11 +30,7 @@ import java.io.UnsupportedEncodingException; * * @author srowen@google.com (Sean Owen) */ -abstract class AbstractNDEFParsedResult extends ParsedReaderResult { - - AbstractNDEFParsedResult(ParsedReaderResultType type) { - super(type); - } +abstract class AbstractNDEFResultParser extends ResultParser { static String bytesToString(byte[] bytes, int offset, int length, String encoding) { try { diff --git a/core/src/com/google/zxing/client/result/optional/MobileTagMMSParsedResult.java b/core/src/com/google/zxing/client/result/optional/MobileTagMMSResultParser.java similarity index 57% rename from core/src/com/google/zxing/client/result/optional/MobileTagMMSParsedResult.java rename to core/src/com/google/zxing/client/result/optional/MobileTagMMSResultParser.java index a28514b68..17d97d98b 100644 --- a/core/src/com/google/zxing/client/result/optional/MobileTagMMSParsedResult.java +++ b/core/src/com/google/zxing/client/result/optional/MobileTagMMSResultParser.java @@ -18,7 +18,7 @@ package com.google.zxing.client.result.optional; import com.google.zxing.BarcodeFormat; import com.google.zxing.Result; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.SMSParsedResult; /** *
Represents a "MMS" result encoded according to section 4.7 of the @@ -26,24 +26,11 @@ import com.google.zxing.client.result.ParsedReaderResultType; * * @author srowen@google.com (Sean Owen) */ -public final class MobileTagMMSParsedResult extends AbstractMobileTagParsedResult { +public final class MobileTagMMSResultParser extends AbstractMobileTagResultParser { public static final String SERVICE_TYPE = "05"; - private final String to; - private final String subject; - private final String body; - private final String title; - - private MobileTagMMSParsedResult(String to, String subject, String body, String title) { - super(ParsedReaderResultType.MOBILETAG_MMS); - this.to = to; - this.subject = subject; - this.body = body; - this.title = title; - } - - public static MobileTagMMSParsedResult parse(Result result) { + public static SMSParsedResult parse(Result result) { if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) { return null; } @@ -61,31 +48,7 @@ public final class MobileTagMMSParsedResult extends AbstractMobileTagParsedResul String body = matches[2]; String title = matches[3]; - return new MobileTagMMSParsedResult(to, subject, body, title); - } - - public String getTo() { - return to; - } - - public String getSubject() { - return subject; - } - - public String getBody() { - return body; - } - - public String getTitle() { - return title; - } - - public String getDisplayResult() { - StringBuffer result = new StringBuffer(to); - maybeAppend(subject, result); - maybeAppend(title, result); - maybeAppend(body, result); - return result.toString(); + return new SMSParsedResult("sms:" + to, to, null, subject, body, title); } } \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/MobileTagRichWebParsedResult.java b/core/src/com/google/zxing/client/result/optional/MobileTagRichWebParsedResult.java index 7e55e1596..f5efcd6d9 100644 --- a/core/src/com/google/zxing/client/result/optional/MobileTagRichWebParsedResult.java +++ b/core/src/com/google/zxing/client/result/optional/MobileTagRichWebParsedResult.java @@ -16,64 +16,26 @@ package com.google.zxing.client.result.optional; -import com.google.zxing.BarcodeFormat; -import com.google.zxing.Result; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.ParsedResult; +import com.google.zxing.client.result.ParsedResultType; /** - *
Represents a "rich web" result encoded according to section 5 of the - * MobileTag Reader International Specification.
- * * @author srowen@google.com (Sean Owen) */ -public final class MobileTagRichWebParsedResult extends AbstractMobileTagParsedResult { +public final class MobileTagRichWebParsedResult extends ParsedResult { - public static final String SERVICE_TYPE = "54"; - - private static final int DEFAULT_ACTION = ACTION_DO; // Example: "http://www.tagserver.com/script.asp?id=" - private static final String TAGSERVER_URI_PREFIX = System.getProperty("zxing.mobiletag.tagserver"); + static final String TAGSERVER_URI_PREFIX = System.getProperty("zxing.mobiletag.tagserver"); private final String id; private final int action; - private MobileTagRichWebParsedResult(String id, int action) { - super(ParsedReaderResultType.MOBILETAG_RICH_WEB); + MobileTagRichWebParsedResult(String id, int action) { + super(ParsedResultType.MOBILETAG_RICH_WEB); this.id = id; this.action = action; } - public static MobileTagRichWebParsedResult parse(Result result) { - if (TAGSERVER_URI_PREFIX == null) { - return null; - } - if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) { - return null; - } - String rawText = result.getText(); - if (!rawText.startsWith(SERVICE_TYPE)) { - return null; - } - - int length = rawText.length(); - if (!isDigits(rawText, length)) { - return null; - } - int action; - String id; - if (length == 15) { - action = DEFAULT_ACTION; - id = rawText.substring(0, 2) + action + rawText.substring(2); - } else if (length == 16) { - action = rawText.charAt(2) - '0'; - id = rawText; - } else { - return null; - } - - return new MobileTagRichWebParsedResult(id, action); - } - public static String getTagserverURIPrefix() { return TAGSERVER_URI_PREFIX; } diff --git a/core/src/com/google/zxing/client/result/optional/MobileTagRichWebResultParser.java b/core/src/com/google/zxing/client/result/optional/MobileTagRichWebResultParser.java new file mode 100644 index 000000000..99d3361d9 --- /dev/null +++ b/core/src/com/google/zxing/client/result/optional/MobileTagRichWebResultParser.java @@ -0,0 +1,65 @@ +/* + * Copyright 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.result.optional; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; + +/** + *Represents a "rich web" result encoded according to section 5 of the + * MobileTag Reader International Specification.
+ * + * @author srowen@google.com (Sean Owen) + */ +public final class MobileTagRichWebResultParser extends AbstractMobileTagResultParser { + + public static final String SERVICE_TYPE = "54"; + + private static final int DEFAULT_ACTION = ACTION_DO; + + public static MobileTagRichWebParsedResult parse(Result result) { + if (MobileTagRichWebParsedResult.TAGSERVER_URI_PREFIX == null) { + return null; + } + if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) { + return null; + } + String rawText = result.getText(); + if (!rawText.startsWith(SERVICE_TYPE)) { + return null; + } + + int length = rawText.length(); + if (!isDigits(rawText, length)) { + return null; + } + int action; + String id; + if (length == 15) { + action = DEFAULT_ACTION; + id = rawText.substring(0, 2) + action + rawText.substring(2); + } else if (length == 16) { + action = rawText.charAt(2) - '0'; + id = rawText; + } else { + return null; + } + + return new MobileTagRichWebParsedResult(id, action); + } + +} \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/MobileTagSMSParsedResult.java b/core/src/com/google/zxing/client/result/optional/MobileTagSMSResultParser.java similarity index 60% rename from core/src/com/google/zxing/client/result/optional/MobileTagSMSParsedResult.java rename to core/src/com/google/zxing/client/result/optional/MobileTagSMSResultParser.java index b1c95c51d..e5ee3bf8c 100644 --- a/core/src/com/google/zxing/client/result/optional/MobileTagSMSParsedResult.java +++ b/core/src/com/google/zxing/client/result/optional/MobileTagSMSResultParser.java @@ -18,7 +18,7 @@ package com.google.zxing.client.result.optional; import com.google.zxing.BarcodeFormat; import com.google.zxing.Result; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.SMSParsedResult; /** *Represents a "SMS" result encoded according to section 4.6 of the @@ -26,22 +26,11 @@ import com.google.zxing.client.result.ParsedReaderResultType; * * @author srowen@google.com (Sean Owen) */ -public final class MobileTagSMSParsedResult extends AbstractMobileTagParsedResult { +public final class MobileTagSMSResultParser extends AbstractMobileTagResultParser { public static final String SERVICE_TYPE = "03"; - private final String to; - private final String body; - private final String title; - - private MobileTagSMSParsedResult(String to, String body, String title) { - super(ParsedReaderResultType.MOBILETAG_SMS); - this.to = to; - this.body = body; - this.title = title; - } - - public static MobileTagSMSParsedResult parse(Result result) { + public static SMSParsedResult parse(Result result) { if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) { return null; } @@ -58,26 +47,7 @@ public final class MobileTagSMSParsedResult extends AbstractMobileTagParsedResul String body = matches[1]; String title = matches[2]; - return new MobileTagSMSParsedResult(to, body, title); - } - - public String getTo() { - return to; - } - - public String getBody() { - return body; - } - - public String getTitle() { - return title; - } - - public String getDisplayResult() { - StringBuffer result = new StringBuffer(to); - maybeAppend(title, result); - maybeAppend(body, result); - return result.toString(); + return new SMSParsedResult("sms:" + to, to, null, null, body, title); } } \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/MobileTagSimpleCalendarParsedResult.java b/core/src/com/google/zxing/client/result/optional/MobileTagSimpleCalendarParsedResult.java deleted file mode 100644 index c0e35f72f..000000000 --- a/core/src/com/google/zxing/client/result/optional/MobileTagSimpleCalendarParsedResult.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2008 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.zxing.client.result.optional; - -import com.google.zxing.BarcodeFormat; -import com.google.zxing.Result; -import com.google.zxing.client.result.ParsedReaderResultType; - -/** - *
Represents a "simple calendar" result encoded according to section 4.9 of the - * MobileTag Reader International Specification.
- * - * @author srowen@google.com (Sean Owen) - */ -public final class MobileTagSimpleCalendarParsedResult extends AbstractMobileTagParsedResult { - - public static final String SERVICE_TYPE = "07"; - - private final String summary; - private final String start; - private final String end; - private final String location; - private final String attendee; - private final String title; - - private MobileTagSimpleCalendarParsedResult(String summary, - String start, - String end, - String location, - String attendee, - String title) { - super(ParsedReaderResultType.MOBILETAG_SIMPLE_CALENDAR); - this.summary = summary; - this.start = start; - this.end = end; - this.location = location; - this.attendee = attendee; - this.title = title; - } - - public static MobileTagSimpleCalendarParsedResult parse(Result result) { - if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) { - return null; - } - String rawText = result.getText(); - if (!rawText.startsWith(SERVICE_TYPE)) { - return null; - } - - String[] matches = matchDelimitedFields(rawText.substring(2), 6); - if (matches == null || !isDigits(matches[1], 10) || !isDigits(matches[2], 10)) { - return null; - } - String summary = matches[0]; - String start = expandDateString(matches[1]); - String end = expandDateString(matches[2]); - String location = matches[3]; - String attendee = matches[4]; - String title = matches[5]; - - return new MobileTagSimpleCalendarParsedResult(summary, start, end, location, attendee, title); - } - - public String getSummary() { - return summary; - } - - /** - *We would return the start and end date as a {@link java.util.Date} except that this code
- * needs to work under JavaME / MIDP and there is no date parsing library available there, such
- * as java.text.SimpleDateFormat
.
However we do translate the date from its encoded format of, say, "0602212156" to its full - * text representation of "20060221T215600Z", per the specification.
- */ - public String getStart() { - return start; - } - - /** - * @see #getStart() - */ - public String getEnd() { - return end; - } - - public String getLocation() { - return location; - } - - public String getAttendee() { - return attendee; - } - - public String getTitle() { - return title; - } - - public String getDisplayResult() { - StringBuffer result = new StringBuffer(summary); - maybeAppend(start, result); - maybeAppend(end, result); - maybeAppend(location, result); - maybeAppend(attendee, result); - maybeAppend(title, result); - return result.toString(); - } - - private static String expandDateString(String date) { - if (date == null) { - return null; - } - // Input is of form YYMMddHHmmss, and needs to be YYYYMMdd'T'HHmmss'Z' - return "20" + date.substring(0, 6) + 'T' + date.substring(6) + "00Z"; - } - -} \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/MobileTagSimpleCalendarResultParser.java b/core/src/com/google/zxing/client/result/optional/MobileTagSimpleCalendarResultParser.java new file mode 100644 index 000000000..34f709355 --- /dev/null +++ b/core/src/com/google/zxing/client/result/optional/MobileTagSimpleCalendarResultParser.java @@ -0,0 +1,64 @@ +/* + * Copyright 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.result.optional; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import com.google.zxing.client.result.CalendarParsedResult; + +/** + *Represents a "simple calendar" result encoded according to section 4.9 of the + * MobileTag Reader International Specification.
+ * + * @author srowen@google.com (Sean Owen) + */ +public final class MobileTagSimpleCalendarResultParser extends AbstractMobileTagResultParser { + + public static final String SERVICE_TYPE = "07"; + + public static CalendarParsedResult parse(Result result) { + if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) { + return null; + } + String rawText = result.getText(); + if (!rawText.startsWith(SERVICE_TYPE)) { + return null; + } + + String[] matches = matchDelimitedFields(rawText.substring(2), 6); + if (matches == null || !isDigits(matches[1], 10) || !isDigits(matches[2], 10)) { + return null; + } + String summary = matches[0]; + String start = expandDateString(matches[1]); + String end = expandDateString(matches[2]); + String location = matches[3]; + String attendee = matches[4]; + String title = matches[5]; + + return new CalendarParsedResult(summary, start, end, location, attendee, title); + } + + private static String expandDateString(String date) { + if (date == null) { + return null; + } + // Input is of form YYMMddHHmmss, and needs to be YYYYMMdd'T'HHmmss'Z' + return "20" + date.substring(0, 6) + 'T' + date.substring(6) + "00Z"; + } + +} \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/MobileTagSimpleContactParsedResult.java b/core/src/com/google/zxing/client/result/optional/MobileTagSimpleContactParsedResult.java deleted file mode 100644 index 6f0eb20f9..000000000 --- a/core/src/com/google/zxing/client/result/optional/MobileTagSimpleContactParsedResult.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2008 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.zxing.client.result.optional; - -import com.google.zxing.BarcodeFormat; -import com.google.zxing.Result; -import com.google.zxing.client.result.ParsedReaderResultType; - -/** - *Represents a "simple contact" result encoded according to section 4.8 of the - * MobileTag Reader International Specification.
- * - * @author srowen@google.com (Sean Owen) - */ -public final class MobileTagSimpleContactParsedResult extends AbstractMobileTagParsedResult { - - public static final String SERVICE_TYPE = "02"; - - private final String fullName; - private final String telephoneCell; - private final String telephone; - private final String email1; - private final String email2; - private final String address; - private final String org; - private final String birthday; - private final String title; - - private MobileTagSimpleContactParsedResult(String fullName, - String telephoneCell, - String telephone, - String email1, - String email2, - String address, - String org, - String birthday, - String title) { - super(ParsedReaderResultType.MOBILETAG_SIMPLE_CONTACT); - this.fullName = fullName; - this.telephoneCell = telephoneCell; - this.telephone = telephone; - this.email1 = email1; - this.email2 = email2; - this.address = address; - this.org = org; - this.birthday = birthday; - this.title = title; - } - - public static MobileTagSimpleContactParsedResult parse(Result result) { - if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) { - return null; - } - String rawText = result.getText(); - if (!rawText.startsWith(SERVICE_TYPE)) { - return null; - } - - String[] matches = matchDelimitedFields(rawText.substring(2), 9); - if (matches == null || !isDigits(matches[7], 8)) { - return null; - } - String fullName = matches[0]; - String telephoneCell = matches[1]; - String telephone = matches[2]; - String email1 = matches[3]; - String email2 = matches[4]; - String address = matches[5]; - String org = matches[6]; - String birthday = matches[7]; - String title = matches[8]; - - return new MobileTagSimpleContactParsedResult(fullName, - telephoneCell, - telephone, - email1, - email2, - address, - org, - birthday, - title); - } - - - public String getFullName() { - return fullName; - } - - public String getTelephoneCell() { - return telephoneCell; - } - - public String getTelephone() { - return telephone; - } - - public String getEmail1() { - return email1; - } - - public String getEmail2() { - return email2; - } - - public String getAddress() { - return address; - } - - public String getOrg() { - return org; - } - - public String getBirthday() { - return birthday; - } - - public String getTitle() { - return title; - } - - public String getDisplayResult() { - StringBuffer result = new StringBuffer(fullName); - maybeAppend(telephoneCell, result); - maybeAppend(telephone, result); - maybeAppend(email1, result); - maybeAppend(email2, result); - maybeAppend(address, result); - maybeAppend(org, result); - maybeAppend(birthday, result); - maybeAppend(title, result); - return result.toString(); - } - -} \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/MobileTagSimpleContactResultParser.java b/core/src/com/google/zxing/client/result/optional/MobileTagSimpleContactResultParser.java new file mode 100644 index 000000000..412f878ea --- /dev/null +++ b/core/src/com/google/zxing/client/result/optional/MobileTagSimpleContactResultParser.java @@ -0,0 +1,66 @@ +/* + * Copyright 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.result.optional; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.Result; +import com.google.zxing.client.result.AddressBookParsedResult; + +/** + *Represents a "simple contact" result encoded according to section 4.8 of the + * MobileTag Reader International Specification.
+ * + * @author srowen@google.com (Sean Owen) + */ +public final class MobileTagSimpleContactResultParser extends AbstractMobileTagResultParser { + + public static final String SERVICE_TYPE = "02"; + + public static AddressBookParsedResult parse(Result result) { + if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) { + return null; + } + String rawText = result.getText(); + if (!rawText.startsWith(SERVICE_TYPE)) { + return null; + } + + String[] matches = matchDelimitedFields(rawText.substring(2), 9); + if (matches == null || !isDigits(matches[7], 8)) { + return null; + } + String fullName = matches[0]; + String telephoneCell = matches[1]; + String telephone = matches[2]; + String email1 = matches[3]; + String email2 = matches[4]; + String address = matches[5]; + String org = matches[6]; + String birthday = matches[7]; + String title = matches[8]; + + return new AddressBookParsedResult(new String[] {fullName}, + new String[] {telephoneCell, telephone}, + new String[] {email1, email2}, + null, + address, + org, + birthday, + title); + } + +} \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/MobileTagSimpleWebParsedResult.java b/core/src/com/google/zxing/client/result/optional/MobileTagSimpleWebResultParser.java similarity index 71% rename from core/src/com/google/zxing/client/result/optional/MobileTagSimpleWebParsedResult.java rename to core/src/com/google/zxing/client/result/optional/MobileTagSimpleWebResultParser.java index 702a963b1..6abc72362 100644 --- a/core/src/com/google/zxing/client/result/optional/MobileTagSimpleWebParsedResult.java +++ b/core/src/com/google/zxing/client/result/optional/MobileTagSimpleWebResultParser.java @@ -18,7 +18,7 @@ package com.google.zxing.client.result.optional; import com.google.zxing.BarcodeFormat; import com.google.zxing.Result; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.URIParsedResult; /** *Represents a "simple web" result encoded according to section 4.11 of the @@ -26,7 +26,7 @@ import com.google.zxing.client.result.ParsedReaderResultType; * * @author srowen@google.com (Sean Owen) */ -public final class MobileTagSimpleWebParsedResult extends AbstractMobileTagParsedResult { +public final class MobileTagSimpleWebResultParser extends AbstractMobileTagResultParser { public static final String SERVICE_TYPE = "04"; private static final String[] URI_PREFIXES = { @@ -38,16 +38,7 @@ public final class MobileTagSimpleWebParsedResult extends AbstractMobileTagParse "rtsp://", }; - private final String title; - private final String uri; - - private MobileTagSimpleWebParsedResult(String title, String uri) { - super(ParsedReaderResultType.MOBILETAG_SIMPLE_WEB); - this.title = title; - this.uri = uri; - } - - public static MobileTagSimpleWebParsedResult parse(Result result) { + public static URIParsedResult parse(Result result) { if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) { return null; } @@ -74,23 +65,7 @@ public final class MobileTagSimpleWebParsedResult extends AbstractMobileTagParse } } - return new MobileTagSimpleWebParsedResult(title, uri); - } - - public String getTitle() { - return title; - } - - public String getURI() { - return uri; - } - - public String getDisplayResult() { - if (title == null) { - return uri; - } else { - return title + '\n' + uri; - } + return new URIParsedResult(uri, title); } } \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/MobileTagTelParsedResult.java b/core/src/com/google/zxing/client/result/optional/MobileTagTelResultParser.java similarity index 64% rename from core/src/com/google/zxing/client/result/optional/MobileTagTelParsedResult.java rename to core/src/com/google/zxing/client/result/optional/MobileTagTelResultParser.java index 477ff13db..0c8a674f1 100644 --- a/core/src/com/google/zxing/client/result/optional/MobileTagTelParsedResult.java +++ b/core/src/com/google/zxing/client/result/optional/MobileTagTelResultParser.java @@ -18,28 +18,19 @@ package com.google.zxing.client.result.optional; import com.google.zxing.BarcodeFormat; import com.google.zxing.Result; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.TelParsedResult; /** *
Represents a "TEL" result encoded according to section 4.4 of the * MobileTag Reader International Specification.
- * + * * @author srowen@google.com (Sean Owen) */ -public final class MobileTagTelParsedResult extends AbstractMobileTagParsedResult { +public final class MobileTagTelResultParser extends AbstractMobileTagResultParser { public static final String SERVICE_TYPE = "01"; - private final String number; - private final String title; - - private MobileTagTelParsedResult(String number, String title) { - super(ParsedReaderResultType.MOBILETAG_TEL); - this.number = number; - this.title = title; - } - - public static MobileTagTelParsedResult parse(Result result) { + public static TelParsedResult parse(Result result) { if (!result.getBarcodeFormat().equals(BarcodeFormat.DATAMATRIX)) { return null; } @@ -55,23 +46,7 @@ public final class MobileTagTelParsedResult extends AbstractMobileTagParsedResul String number = matches[0]; String title = matches[1]; - return new MobileTagTelParsedResult(number, title); - } - - public String getNumber() { - return number; - } - - public String getTitle() { - return title; - } - - public String getDisplayResult() { - if (title == null) { - return number; - } else { - return title + '\n' + number; - } + return new TelParsedResult(number, "tel:" + number, title); } } \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/NDEFRecord.java b/core/src/com/google/zxing/client/result/optional/NDEFRecord.java index 00a565e72..e92161d14 100644 --- a/core/src/com/google/zxing/client/result/optional/NDEFRecord.java +++ b/core/src/com/google/zxing/client/result/optional/NDEFRecord.java @@ -56,7 +56,7 @@ final class NDEFRecord { int payloadLength = bytes[offset + 2] & 0xFF; - String type = AbstractNDEFParsedResult.bytesToString(bytes, offset + 3, typeLength, "US-ASCII"); + String type = AbstractNDEFResultParser.bytesToString(bytes, offset + 3, typeLength, "US-ASCII"); byte[] payload = new byte[payloadLength]; System.arraycopy(bytes, offset + 3 + typeLength, payload, 0, payloadLength); diff --git a/core/src/com/google/zxing/client/result/optional/NDEFSmartPosterParsedResult.java b/core/src/com/google/zxing/client/result/optional/NDEFSmartPosterParsedResult.java index 3ef632670..2ea126c02 100644 --- a/core/src/com/google/zxing/client/result/optional/NDEFSmartPosterParsedResult.java +++ b/core/src/com/google/zxing/client/result/optional/NDEFSmartPosterParsedResult.java @@ -16,21 +16,13 @@ package com.google.zxing.client.result.optional; -import com.google.zxing.Result; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.ParsedResult; +import com.google.zxing.client.result.ParsedResultType; /** - *Recognizes an NDEF message that encodes information according to the - * "Smart Poster Record Type Definition" specification.
- * - *This actually only supports some parts of the Smart Poster format: title, - * URI, and action records. Icon records are not supported because the size - * of these records are infeasibly large for barcodes. Size and type records - * are not supported. Multiple titles are not supported.
- * * @author srowen@google.com (Sean Owen) */ -public final class NDEFSmartPosterParsedResult extends AbstractNDEFParsedResult { +public final class NDEFSmartPosterParsedResult extends ParsedResult { public static final int ACTION_UNSPECIFIED = -1; public static final int ACTION_DO = 0; @@ -41,53 +33,11 @@ public final class NDEFSmartPosterParsedResult extends AbstractNDEFParsedResult private String uri; private int action; - private NDEFSmartPosterParsedResult() { - super(ParsedReaderResultType.NDEF_SMART_POSTER); - action = ACTION_UNSPECIFIED; - } - - public static NDEFSmartPosterParsedResult parse(Result result) { - byte[] bytes = result.getRawBytes(); - if (bytes == null) { - return null; - } - NDEFRecord headerRecord = NDEFRecord.readRecord(bytes, 0); - // Yes, header record starts and ends a message - if (headerRecord == null || !headerRecord.isMessageBegin() || !headerRecord.isMessageEnd()) { - return null; - } - if (!headerRecord.getType().equals(NDEFRecord.SMART_POSTER_WELL_KNOWN_TYPE)) { - return null; - } - - int offset = 0; - int recordNumber = 0; - NDEFRecord ndefRecord = null; - byte[] payload = headerRecord.getPayload(); - NDEFSmartPosterParsedResult smartPosterParsedResult = new NDEFSmartPosterParsedResult(); - - while (offset < payload.length && (ndefRecord = NDEFRecord.readRecord(payload, offset)) != null) { - if (recordNumber == 0 && !ndefRecord.isMessageBegin()) { - return null; - } - String type = ndefRecord.getType(); - if (NDEFRecord.TEXT_WELL_KNOWN_TYPE.equals(type)) { - String[] languageText = NDEFTextParsedResult.decodeTextPayload(ndefRecord.getPayload()); - smartPosterParsedResult.title = languageText[1]; - } else if (NDEFRecord.URI_WELL_KNOWN_TYPE.equals(type)) { - smartPosterParsedResult.uri = NDEFURIParsedResult.decodeURIPayload(ndefRecord.getPayload()); - } else if (NDEFRecord.ACTION_WELL_KNOWN_TYPE.equals(type)) { - smartPosterParsedResult.action = ndefRecord.getPayload()[0]; - } - recordNumber++; - offset += ndefRecord.getTotalRecordLength(); - } - - if (recordNumber == 0 || (ndefRecord != null && !ndefRecord.isMessageEnd())) { - return null; - } - - return smartPosterParsedResult; + NDEFSmartPosterParsedResult(int action, String uri, String title) { + super(ParsedResultType.NDEF_SMART_POSTER); + this.action = action; + this.uri = uri; + this.title = title; } public String getTitle() { diff --git a/core/src/com/google/zxing/client/result/optional/NDEFSmartPosterResultParser.java b/core/src/com/google/zxing/client/result/optional/NDEFSmartPosterResultParser.java new file mode 100644 index 000000000..ee9a9bab5 --- /dev/null +++ b/core/src/com/google/zxing/client/result/optional/NDEFSmartPosterResultParser.java @@ -0,0 +1,81 @@ +/* + * Copyright 2008 ZXing authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.zxing.client.result.optional; + +import com.google.zxing.Result; + +/** + *Recognizes an NDEF message that encodes information according to the + * "Smart Poster Record Type Definition" specification.
+ * + *This actually only supports some parts of the Smart Poster format: title, + * URI, and action records. Icon records are not supported because the size + * of these records are infeasibly large for barcodes. Size and type records + * are not supported. Multiple titles are not supported.
+ * + * @author srowen@google.com (Sean Owen) + */ +public final class NDEFSmartPosterResultParser extends AbstractNDEFResultParser { + + public static NDEFSmartPosterParsedResult parse(Result result) { + byte[] bytes = result.getRawBytes(); + if (bytes == null) { + return null; + } + NDEFRecord headerRecord = NDEFRecord.readRecord(bytes, 0); + // Yes, header record starts and ends a message + if (headerRecord == null || !headerRecord.isMessageBegin() || !headerRecord.isMessageEnd()) { + return null; + } + if (!headerRecord.getType().equals(NDEFRecord.SMART_POSTER_WELL_KNOWN_TYPE)) { + return null; + } + + int offset = 0; + int recordNumber = 0; + NDEFRecord ndefRecord = null; + byte[] payload = headerRecord.getPayload(); + int action = NDEFSmartPosterParsedResult.ACTION_UNSPECIFIED; + String title = null; + String uri = null; + + while (offset < payload.length && (ndefRecord = NDEFRecord.readRecord(payload, offset)) != null) { + if (recordNumber == 0 && !ndefRecord.isMessageBegin()) { + return null; + } + + String type = ndefRecord.getType(); + if (NDEFRecord.TEXT_WELL_KNOWN_TYPE.equals(type)) { + String[] languageText = NDEFTextResultParser.decodeTextPayload(ndefRecord.getPayload()); + title = languageText[1]; + } else if (NDEFRecord.URI_WELL_KNOWN_TYPE.equals(type)) { + uri = NDEFURIResultParser.decodeURIPayload(ndefRecord.getPayload()); + } else if (NDEFRecord.ACTION_WELL_KNOWN_TYPE.equals(type)) { + action = ndefRecord.getPayload()[0]; + } + recordNumber++; + offset += ndefRecord.getTotalRecordLength(); + } + + if (recordNumber == 0 || (ndefRecord != null && !ndefRecord.isMessageEnd())) { + return null; + } + + return new NDEFSmartPosterParsedResult(action, uri, title); + } + +} \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/NDEFTextParsedResult.java b/core/src/com/google/zxing/client/result/optional/NDEFTextResultParser.java similarity index 73% rename from core/src/com/google/zxing/client/result/optional/NDEFTextParsedResult.java rename to core/src/com/google/zxing/client/result/optional/NDEFTextResultParser.java index 02083c905..02dd65d49 100644 --- a/core/src/com/google/zxing/client/result/optional/NDEFTextParsedResult.java +++ b/core/src/com/google/zxing/client/result/optional/NDEFTextResultParser.java @@ -17,7 +17,7 @@ package com.google.zxing.client.result.optional; import com.google.zxing.Result; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.TextParsedResult; /** * Recognizes an NDEF message that encodes text according to the @@ -25,18 +25,9 @@ import com.google.zxing.client.result.ParsedReaderResultType; * * @author srowen@google.com (Sean Owen) */ -public final class NDEFTextParsedResult extends AbstractNDEFParsedResult { +public final class NDEFTextResultParser extends AbstractNDEFResultParser { - private final String language; - private final String text; - - private NDEFTextParsedResult(String language, String text) { - super(ParsedReaderResultType.NDEF_TEXT); - this.language = language; - this.text = text; - } - - public static NDEFTextParsedResult parse(Result result) { + public static TextParsedResult parse(Result result) { byte[] bytes = result.getRawBytes(); if (bytes == null) { return null; @@ -49,7 +40,7 @@ public final class NDEFTextParsedResult extends AbstractNDEFParsedResult { return null; } String[] languageText = decodeTextPayload(ndefRecord.getPayload()); - return new NDEFTextParsedResult(languageText[0], languageText[1]); + return new TextParsedResult(languageText[0], languageText[1]); } static String[] decodeTextPayload(byte[] payload) { @@ -63,16 +54,4 @@ public final class NDEFTextParsedResult extends AbstractNDEFParsedResult { return new String[] { language, text }; } - public String getLanguage() { - return language; - } - - public String getText() { - return text; - } - - public String getDisplayResult() { - return text; - } - } \ No newline at end of file diff --git a/core/src/com/google/zxing/client/result/optional/NDEFURIParsedResult.java b/core/src/com/google/zxing/client/result/optional/NDEFURIResultParser.java similarity index 82% rename from core/src/com/google/zxing/client/result/optional/NDEFURIParsedResult.java rename to core/src/com/google/zxing/client/result/optional/NDEFURIResultParser.java index 12d5e16e5..3337fee39 100644 --- a/core/src/com/google/zxing/client/result/optional/NDEFURIParsedResult.java +++ b/core/src/com/google/zxing/client/result/optional/NDEFURIResultParser.java @@ -17,15 +17,15 @@ package com.google.zxing.client.result.optional; import com.google.zxing.Result; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.URIParsedResult; /** * Recognizes an NDEF message that encodes a URI according to the * "URI Record Type Definition" specification. - * + * * @author srowen@google.com (Sean Owen) */ -public final class NDEFURIParsedResult extends AbstractNDEFParsedResult { +public final class NDEFURIResultParser extends AbstractNDEFResultParser { private static final String[] URI_PREFIXES = { null, @@ -66,14 +66,7 @@ public final class NDEFURIParsedResult extends AbstractNDEFParsedResult { "urn:nfc:", }; - private final String uri; - - private NDEFURIParsedResult(String uri) { - super(ParsedReaderResultType.NDEF_URI); - this.uri = uri; - } - - public static NDEFURIParsedResult parse(Result result) { + public static URIParsedResult parse(Result result) { byte[] bytes = result.getRawBytes(); if (bytes == null) { return null; @@ -86,7 +79,7 @@ public final class NDEFURIParsedResult extends AbstractNDEFParsedResult { return null; } String fullURI = decodeURIPayload(ndefRecord.getPayload()); - return new NDEFURIParsedResult(fullURI); + return new URIParsedResult(fullURI, null); } static String decodeURIPayload(byte[] payload) { @@ -99,12 +92,4 @@ public final class NDEFURIParsedResult extends AbstractNDEFParsedResult { return prefix == null ? restOfURI : prefix + restOfURI; } - public String getURI() { - return uri; - } - - public String getDisplayResult() { - return uri; - } - } \ No newline at end of file diff --git a/core/test/src/com/google/zxing/client/result/ParsedReaderResultTestCase.java b/core/test/src/com/google/zxing/client/result/ParsedReaderResultTestCase.java index 11b074875..af10e0efe 100644 --- a/core/test/src/com/google/zxing/client/result/ParsedReaderResultTestCase.java +++ b/core/test/src/com/google/zxing/client/result/ParsedReaderResultTestCase.java @@ -21,89 +21,89 @@ import com.google.zxing.Result; import junit.framework.TestCase; /** - * Tests {@link ParsedReaderResult}. + * Tests {@link ParsedResult}. * * @author srowen@google.com (Sean Owen) */ public final class ParsedReaderResultTestCase extends TestCase { public void testTextType() { - doTestResult("foo", ParsedReaderResultType.TEXT); - doTestResult("", ParsedReaderResultType.TEXT); - doTestResult("This is a test", ParsedReaderResultType.TEXT); + doTestResult("foo", ParsedResultType.TEXT); + doTestResult("", ParsedResultType.TEXT); + doTestResult("This is a test", ParsedResultType.TEXT); } public void testBookmarkType() { - doTestResult("MEBKM:URL:google.com;;", ParsedReaderResultType.BOOKMARK); - doTestResult("MEBKM:URL:google.com;TITLE:Google;;", ParsedReaderResultType.BOOKMARK); - doTestResult("MEBKM:TITLE:Google;URL:google.com;;", ParsedReaderResultType.BOOKMARK); - doTestResult("MEBKM:URL:http://google.com;;", ParsedReaderResultType.BOOKMARK); - doTestResult("MEBKM:URL:HTTPS://google.com;;", ParsedReaderResultType.BOOKMARK); + doTestResult("MEBKM:URL:google.com;;", ParsedResultType.URI); + doTestResult("MEBKM:URL:google.com;TITLE:Google;;", ParsedResultType.URI); + doTestResult("MEBKM:TITLE:Google;URL:google.com;;", ParsedResultType.URI); + doTestResult("MEBKM:URL:http://google.com;;", ParsedResultType.URI); + doTestResult("MEBKM:URL:HTTPS://google.com;;", ParsedResultType.URI); } public void testURLTOType() { - doTestResult("URLTO:foo:bar.com", ParsedReaderResultType.URLTO); - doTestResult("URLTO::bar.com", ParsedReaderResultType.URLTO); - doTestResult("URLTO::http://bar.com", ParsedReaderResultType.URLTO); + doTestResult("URLTO:foo:bar.com", ParsedResultType.URI); + doTestResult("URLTO::bar.com", ParsedResultType.URI); + doTestResult("URLTO::http://bar.com", ParsedResultType.URI); } public void testEmailType() { - doTestResult("MATMSG:TO:srowen@example.org;;", ParsedReaderResultType.EMAIL); - doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;;", ParsedReaderResultType.EMAIL); - doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedReaderResultType.EMAIL); - doTestResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;", ParsedReaderResultType.EMAIL); - doTestResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedReaderResultType.TEXT); + doTestResult("MATMSG:TO:srowen@example.org;;", ParsedResultType.EMAIL_ADDRESS); + doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;;", ParsedResultType.EMAIL_ADDRESS); + doTestResult("MATMSG:TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.EMAIL_ADDRESS); + doTestResult("MATMSG:SUB:Stuff;BODY:This is some text;TO:srowen@example.org;;", ParsedResultType.EMAIL_ADDRESS); + doTestResult("TO:srowen@example.org;SUB:Stuff;BODY:This is some text;;", ParsedResultType.TEXT); } public void testEmailAddressType() { - doTestResult("srowen@example.org", ParsedReaderResultType.EMAIL_ADDRESS); - doTestResult("mailto:srowen@example.org", ParsedReaderResultType.EMAIL_ADDRESS); - doTestResult("srowen@example", ParsedReaderResultType.TEXT); - doTestResult("srowen", ParsedReaderResultType.TEXT); - doTestResult("Let's meet @ 2", ParsedReaderResultType.TEXT); + doTestResult("srowen@example.org", ParsedResultType.EMAIL_ADDRESS); + doTestResult("mailto:srowen@example.org", ParsedResultType.EMAIL_ADDRESS); + doTestResult("srowen@example", ParsedResultType.TEXT); + doTestResult("srowen", ParsedResultType.TEXT); + doTestResult("Let's meet @ 2", ParsedResultType.TEXT); } public void testAddressBookType() { - doTestResult("MECARD:N:Sean Owen;;", ParsedReaderResultType.ADDRESSBOOK); - doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;;", ParsedReaderResultType.ADDRESSBOOK); - doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;;", ParsedReaderResultType.ADDRESSBOOK); - doTestResult("TEL:+12125551212;N:Sean Owen;;", ParsedReaderResultType.TEXT); + doTestResult("MECARD:N:Sean Owen;;", ParsedResultType.ADDRESSBOOK); + doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;;", ParsedResultType.ADDRESSBOOK); + doTestResult("MECARD:TEL:+12125551212;N:Sean Owen;URL:google.com;;", ParsedResultType.ADDRESSBOOK); + doTestResult("TEL:+12125551212;N:Sean Owen;;", ParsedResultType.TEXT); } public void testAddressBookAUType() { - doTestResult("MEMORY:\r\n", ParsedReaderResultType.ADDRESSBOOK_AU); - doTestResult("MEMORY:foo\r\nNAME1:Sean\r\n", ParsedReaderResultType.ADDRESSBOOK_AU); - doTestResult("TEL1:+12125551212\r\nMEMORY:\r\n", ParsedReaderResultType.ADDRESSBOOK_AU); + doTestResult("MEMORY:\r\n", ParsedResultType.ADDRESSBOOK); + doTestResult("MEMORY:foo\r\nNAME1:Sean\r\n", ParsedResultType.ADDRESSBOOK); + doTestResult("TEL1:+12125551212\r\nMEMORY:\r\n", ParsedResultType.ADDRESSBOOK); } public void testUPC() { - doTestResult("123456789012", ParsedReaderResultType.UPC, BarcodeFormat.UPC_A); - doTestResult("1234567890123", ParsedReaderResultType.UPC, BarcodeFormat.UPC_A); - doTestResult("12345678901", ParsedReaderResultType.TEXT); + doTestResult("123456789012", ParsedResultType.UPC, BarcodeFormat.UPC_A); + doTestResult("1234567890123", ParsedResultType.UPC, BarcodeFormat.UPC_A); + doTestResult("12345678901", ParsedResultType.TEXT); } public void testURI() { - doTestResult("http://google.com", ParsedReaderResultType.URI); - doTestResult("google.com", ParsedReaderResultType.URI); - doTestResult("https://google.com", ParsedReaderResultType.URI); - doTestResult("HTTP://google.com", ParsedReaderResultType.URI); - doTestResult("http://google.com/foobar", ParsedReaderResultType.URI); - doTestResult("https://google.com:443/foobar", ParsedReaderResultType.URI); - doTestResult("google.com:443/foobar", ParsedReaderResultType.URI); + doTestResult("http://google.com", ParsedResultType.URI); + doTestResult("google.com", ParsedResultType.URI); + doTestResult("https://google.com", ParsedResultType.URI); + doTestResult("HTTP://google.com", ParsedResultType.URI); + doTestResult("http://google.com/foobar", ParsedResultType.URI); + doTestResult("https://google.com:443/foobar", ParsedResultType.URI); + doTestResult("google.com:443/foobar", ParsedResultType.URI); } public void testGeo() { - doTestResult("geo:1,2", ParsedReaderResultType.GEO); - doTestResult("geo:1,2,3", ParsedReaderResultType.GEO); - doTestResult("geo:100.33,-32.3344,3.35", ParsedReaderResultType.GEO); - doTestResult("geography", ParsedReaderResultType.TEXT); + doTestResult("geo:1,2", ParsedResultType.GEO); + doTestResult("geo:1,2,3", ParsedResultType.GEO); + doTestResult("geo:100.33,-32.3344,3.35", ParsedResultType.GEO); + doTestResult("geography", ParsedResultType.TEXT); } public void testTel() { - doTestResult("tel:+15551212", ParsedReaderResultType.TEL); - doTestResult("tel:212 555 1212", ParsedReaderResultType.TEL); - doTestResult("tel:2125551212", ParsedReaderResultType.TEL); - doTestResult("telephone", ParsedReaderResultType.TEXT); + doTestResult("tel:+15551212", ParsedResultType.TEL); + doTestResult("tel:212 555 1212", ParsedResultType.TEL); + doTestResult("tel:2125551212", ParsedResultType.TEL); + doTestResult("telephone", ParsedResultType.TEXT); } /* @@ -111,14 +111,14 @@ public final class ParsedReaderResultTestCase extends TestCase { doTestResult(new byte[] {(byte)0xD1,(byte)0x01,(byte)0x05,(byte)0x54, (byte)0x02,(byte)0x65,(byte)0x6E,(byte)0x68, (byte)0x69}, - ParsedReaderResultType.NDEF_TEXT); + ParsedResultType.NDEF_TEXT); } public void testNDEFURI() { doTestResult(new byte[] {(byte)0xD1,(byte)0x01,(byte)0x08,(byte)0x55, (byte)0x01,(byte)0x6E,(byte)0x66,(byte)0x63, (byte)0x2E,(byte)0x63,(byte)0x6F,(byte)0x6D}, - ParsedReaderResultType.NDEF_URI); + ParsedResultType.NDEF_URI); } public void testNDEFSmartPoster() { @@ -135,24 +135,24 @@ public final class ParsedReaderResultTestCase extends TestCase { (byte)0x48,(byte)0x65,(byte)0x6C,(byte)0x6C, (byte)0x6F,(byte)0x2C,(byte)0x20,(byte)0x77, (byte)0x6F,(byte)0x72,(byte)0x6C,(byte)0x64}, - ParsedReaderResultType.NDEF_SMART_POSTER); + ParsedResultType.NDEF_SMART_POSTER); } */ - private static void doTestResult(String text, ParsedReaderResultType type) { + private static void doTestResult(String text, ParsedResultType type) { doTestResult(text, type, null); } - private static void doTestResult(String text, ParsedReaderResultType type, BarcodeFormat format) { + private static void doTestResult(String text, ParsedResultType type, BarcodeFormat format) { Result fakeResult = new Result(text, null, null, format); - ParsedReaderResult result = ParsedReaderResult.parseReaderResult(fakeResult); + ParsedResult result = ResultParser.parseReaderResult(fakeResult); assertNotNull(result); assertEquals(type, result.getType()); } - private static void doTestResult(byte[] rawBytes, ParsedReaderResultType type) { + private static void doTestResult(byte[] rawBytes, ParsedResultType type) { Result fakeResult = new Result(null, rawBytes, null, null); - ParsedReaderResult result = ParsedReaderResult.parseReaderResult(fakeResult); + ParsedResult result = ResultParser.parseReaderResult(fakeResult); assertNotNull(result); assertEquals(type, result.getType()); } diff --git a/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java b/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java index 994181405..b1aa9be41 100644 --- a/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java +++ b/javame/src/com/google/zxing/client/j2me/ZXingMIDlet.java @@ -17,17 +17,14 @@ package com.google.zxing.client.j2me; import com.google.zxing.Result; -import com.google.zxing.client.result.BookmarkDoCoMoParsedResult; import com.google.zxing.client.result.EmailAddressParsedResult; -import com.google.zxing.client.result.EmailDoCoMoParsedResult; -import com.google.zxing.client.result.ParsedReaderResult; -import com.google.zxing.client.result.ParsedReaderResultType; +import com.google.zxing.client.result.ParsedResult; +import com.google.zxing.client.result.ParsedResultType; +import com.google.zxing.client.result.ResultParser; import com.google.zxing.client.result.SMSParsedResult; -import com.google.zxing.client.result.SMSTOParsedResult; import com.google.zxing.client.result.TelParsedResult; import com.google.zxing.client.result.UPCParsedResult; import com.google.zxing.client.result.URIParsedResult; -import com.google.zxing.client.result.URLTOParsedResult; import javax.microedition.io.ConnectionNotFoundException; import javax.microedition.lcdui.Alert; @@ -195,34 +192,22 @@ public final class ZXingMIDlet extends MIDlet { } void handleDecodedText(Result theResult) { - ParsedReaderResult result = ParsedReaderResult.parseReaderResult(theResult); - ParsedReaderResultType type = result.getType(); - if (type.equals(ParsedReaderResultType.URI)) { + ParsedResult result = ResultParser.parseReaderResult(theResult); + ParsedResultType type = result.getType(); + if (type.equals(ParsedResultType.URI)) { String uri = ((URIParsedResult) result).getURI(); showOpenURL("Open Web Page?", uri, uri); - } else if (type.equals(ParsedReaderResultType.BOOKMARK)) { - String uri = ((BookmarkDoCoMoParsedResult) result).getURI(); - showOpenURL("Open Web Page?", uri, uri); - } else if (type.equals(ParsedReaderResultType.URLTO)) { - String uri = ((URLTOParsedResult) result).getURI(); - showOpenURL("Open Web Page?", uri, uri); - } else if (type.equals(ParsedReaderResultType.EMAIL)) { - EmailDoCoMoParsedResult emailResult = (EmailDoCoMoParsedResult) result; - showOpenURL("Compose E-mail?", emailResult.getTo(), emailResult.getMailtoURI()); - } else if (type.equals(ParsedReaderResultType.EMAIL_ADDRESS)) { + } else if (type.equals(ParsedResultType.EMAIL_ADDRESS)) { EmailAddressParsedResult emailResult = (EmailAddressParsedResult) result; showOpenURL("Compose E-mail?", emailResult.getEmailAddress(), emailResult.getMailtoURI()); - } else if (type.equals(ParsedReaderResultType.SMS)) { + } else if (type.equals(ParsedResultType.SMS)) { SMSParsedResult smsResult = (SMSParsedResult) result; showOpenURL("Compose SMS?", smsResult.getNumber(), smsResult.getSMSURI()); - } else if (type.equals(ParsedReaderResultType.SMSTO)) { - SMSTOParsedResult smsToResult = (SMSTOParsedResult) result; - showOpenURL("Compose SMS?", smsToResult.getNumber(), smsToResult.getSMSURI()); - } else if (type.equals(ParsedReaderResultType.UPC)) { + } else if (type.equals(ParsedResultType.UPC)) { String upc = ((UPCParsedResult) result).getUPC(); String uri = "http://www.upcdatabase.com/item.asp?upc=" + upc; showOpenURL("Look Up Barcode Online?", upc, uri); - } else if (type.equals(ParsedReaderResultType.TEL)) { + } else if (type.equals(ParsedResultType.TEL)) { TelParsedResult telResult = (TelParsedResult) result; showOpenURL("Dial Number?", telResult.getNumber(), telResult.getTelURI()); } else { diff --git a/zxingorg/src/com/google/zxing/web/DecodeServlet.java b/zxingorg/src/com/google/zxing/web/DecodeServlet.java index 5a2effc91..6a67be7e8 100644 --- a/zxingorg/src/com/google/zxing/web/DecodeServlet.java +++ b/zxingorg/src/com/google/zxing/web/DecodeServlet.java @@ -22,7 +22,8 @@ import com.google.zxing.Reader; import com.google.zxing.ReaderException; import com.google.zxing.Result; import com.google.zxing.client.j2se.BufferedImageMonochromeBitmapSource; -import com.google.zxing.client.result.ParsedReaderResult; +import com.google.zxing.client.result.ParsedResult; +import com.google.zxing.client.result.ResultParser; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.disk.DiskFileItemFactory; @@ -243,8 +244,8 @@ public final class DecodeServlet extends HttpServlet { } else { request.setAttribute("rawBytesString", "(Not applicable)"); } - ParsedReaderResult parsedReaderResult = ParsedReaderResult.parseReaderResult(result); - request.setAttribute("parsedReaderResult", parsedReaderResult); + ParsedResult parsedResult = ResultParser.parseReaderResult(result); + request.setAttribute("parsedResult", parsedResult); request.getRequestDispatcher("decoderesult.jspx").forward(request, response); } } diff --git a/zxingorg/web/decoderesult.jspx b/zxingorg/web/decoderesult.jspx index ae4371bc5..df90640ef 100644 --- a/zxingorg/web/decoderesult.jspx +++ b/zxingorg/web/decoderesult.jspx @@ -23,7 +23,7 @@