mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 11:47:26 -08:00
Add BIZCARD support and a little refactoring
git-svn-id: https://zxing.googlecode.com/svn/trunk@494 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
d392d57c67
commit
64369b3878
|
@ -28,9 +28,6 @@ package com.google.zxing.client.result;
|
|||
*/
|
||||
abstract class AbstractDoCoMoResultParser extends ResultParser {
|
||||
|
||||
// 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, ';');
|
||||
}
|
||||
|
@ -39,4 +36,8 @@ abstract class AbstractDoCoMoResultParser extends ResultParser {
|
|||
return matchSinglePrefixedField(prefix, rawText, ';');
|
||||
}
|
||||
|
||||
}
|
||||
static String[] maybeWrap(String value) {
|
||||
return value == null ? null : new String[] { value };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,9 +48,9 @@ public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultPar
|
|||
if (birthday != null && !isStringOfDigits(birthday, 8)) {
|
||||
return null;
|
||||
}
|
||||
return new AddressBookParsedResult(new String[] {name},
|
||||
return new AddressBookParsedResult(maybeWrap(name),
|
||||
phoneNumbers,
|
||||
new String[] {email},
|
||||
maybeWrap(email),
|
||||
note,
|
||||
address,
|
||||
null,
|
||||
|
@ -67,4 +67,4 @@ public final class AddressBookDoCoMoResultParser extends AbstractDoCoMoResultPar
|
|||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Implements the "BIZCARD" address book entry format, though this has been
|
||||
* largely reverse-engineered from examples observed in the wild -- still
|
||||
* looking for a definitive reference.
|
||||
*
|
||||
* @author srowen@google.com (Sean Owen)
|
||||
*/
|
||||
public final class BizcardResultParser extends AbstractDoCoMoResultParser {
|
||||
|
||||
// Yes, we extend AbstractDoCoMoResultParser since the format is very much
|
||||
// like the DoCoMo MECARD format, but this is not technically one of
|
||||
// DoCoMo's proposed formats
|
||||
|
||||
public static AddressBookParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (rawText == null || !rawText.startsWith("BIZCARD:")) {
|
||||
return null;
|
||||
}
|
||||
String firstName = matchSinglePrefixedField("N:", rawText);
|
||||
String lastName = matchSinglePrefixedField("X:", rawText);
|
||||
String fullName = buildName(firstName, lastName);
|
||||
String title = matchSinglePrefixedField("T:", rawText);
|
||||
String org = matchSinglePrefixedField("C:", rawText);
|
||||
String address = matchSinglePrefixedField("A:", rawText);
|
||||
String phoneNumber1 = matchSinglePrefixedField("B:", rawText);
|
||||
String phoneNumber2 = matchSinglePrefixedField("F:", rawText);
|
||||
String email = matchSinglePrefixedField("E:", rawText);
|
||||
|
||||
return new AddressBookParsedResult(maybeWrap(fullName),
|
||||
buildPhoneNumbers(phoneNumber1, phoneNumber2),
|
||||
maybeWrap(email),
|
||||
null,
|
||||
address,
|
||||
org,
|
||||
null,
|
||||
title);
|
||||
}
|
||||
|
||||
private static String[] buildPhoneNumbers(String number1, String number2) {
|
||||
if (number1 == null) {
|
||||
return maybeWrap(number2);
|
||||
} else {
|
||||
return number2 == null ? new String[] { number1 } : new String[] { number1, number2 };
|
||||
}
|
||||
}
|
||||
|
||||
private static String buildName(String firstName, String lastName) {
|
||||
if (firstName == null) {
|
||||
return lastName;
|
||||
} else {
|
||||
return lastName == null ? firstName : firstName + ' ' + lastName;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -51,6 +51,8 @@ public abstract class ResultParser {
|
|||
return result;
|
||||
} else if ((result = VCardResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = BizcardResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = TelResultParser.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = SMSMMSResultParser.parse(theResult)) != null) {
|
||||
|
@ -280,4 +282,4 @@ public abstract class ResultParser {
|
|||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue