public static AddressBookParsedResult parse(Result result) { System.String rawText = result.Text; if (rawText == null || !rawText.StartsWith("MECARD:")) { return null; } System.String[] rawName = matchDoCoMoPrefixedField("N:", rawText, true); if (rawName == null) { return null; } System.String name = parseName(rawName[0]); System.String pronunciation = matchSingleDoCoMoPrefixedField("SOUND:", rawText, true); System.String[] phoneNumbers = matchDoCoMoPrefixedField("TEL:", rawText, true); System.String[] emails = matchDoCoMoPrefixedField("EMAIL:", rawText, true); System.String note = matchSingleDoCoMoPrefixedField("NOTE:", rawText, false); System.String[] addresses = matchDoCoMoPrefixedField("ADR:", rawText, true); System.String birthday = matchSingleDoCoMoPrefixedField("BDAY:", rawText, true); if (birthday != null && !isStringOfDigits(birthday, 8)) { // No reason to throw out the whole card because the birthday is formatted wrong. birthday = null; } System.String url = matchSingleDoCoMoPrefixedField("URL:", rawText, true); // Although ORG may not be strictly legal in MECARD, it does exist in VCARD and we might as well // honor it when found in the wild. System.String org = matchSingleDoCoMoPrefixedField("ORG:", rawText, true); return new AddressBookParsedResult(maybeWrap(name), pronunciation, phoneNumbers, emails, note, addresses, org, birthday, null, url); }
public static CalendarParsedResult parse(Result result) { System.String rawText = result.Text; if (rawText == null) { return null; } int vEventStart = rawText.IndexOf("BEGIN:VEVENT"); if (vEventStart < 0) { return null; } int vEventEnd = rawText.IndexOf("END:VEVENT"); if (vEventEnd < 0) { return null; } System.String summary = VCardResultParser.matchSingleVCardPrefixedField("SUMMARY", rawText, true); System.String start = VCardResultParser.matchSingleVCardPrefixedField("DTSTART", rawText, true); System.String end = VCardResultParser.matchSingleVCardPrefixedField("DTEND", rawText, true); try { return new CalendarParsedResult(summary, start, end, null, null, null); } catch (System.ArgumentException) { return null; } }
public static NDEFSmartPosterParsedResult parse(Result result) { sbyte[] bytes = result.RawBytes; if (bytes == null) { return null; } NDEFRecord headerRecord = NDEFRecord.readRecord(bytes, 0); // Yes, header record starts and ends a message if (headerRecord == null || !headerRecord.MessageBegin || !headerRecord.MessageEnd) { return null; } if (!headerRecord.Type.Equals(NDEFRecord.SMART_POSTER_WELL_KNOWN_TYPE)) { return null; } int offset = 0; int recordNumber = 0; NDEFRecord ndefRecord = null; sbyte[] payload = headerRecord.Payload; int action = NDEFSmartPosterParsedResult.ACTION_UNSPECIFIED; System.String title = null; System.String uri = null; while (offset < payload.Length && (ndefRecord = NDEFRecord.readRecord(payload, offset)) != null) { if (recordNumber == 0 && !ndefRecord.MessageBegin) { return null; } System.String type = ndefRecord.Type; if (NDEFRecord.TEXT_WELL_KNOWN_TYPE.Equals(type)) { System.String[] languageText = NDEFTextResultParser.decodeTextPayload(ndefRecord.Payload); title = languageText[1]; } else if (NDEFRecord.URI_WELL_KNOWN_TYPE.Equals(type)) { uri = NDEFURIResultParser.decodeURIPayload(ndefRecord.Payload); } else if (NDEFRecord.ACTION_WELL_KNOWN_TYPE.Equals(type)) { action = ndefRecord.Payload[0]; } recordNumber++; offset += ndefRecord.TotalRecordLength; } if (recordNumber == 0 || (ndefRecord != null && !ndefRecord.MessageEnd)) { return null; } return new NDEFSmartPosterParsedResult(action, uri, title); }
public static URIParsedResult parse(Result result) { System.String rawText = result.Text; // We specifically handle the odd "URL" scheme here for simplicity if (rawText != null && rawText.StartsWith("URL:")) { rawText = rawText.Substring(4); } if (!isBasicallyValidURI(rawText)) { return null; } return new URIParsedResult(rawText, null); }
public static TelParsedResult parse(Result result) { System.String rawText = result.Text; if (rawText == null || (!rawText.StartsWith("tel:") && !rawText.StartsWith("TEL:"))) { return null; } // Normalize "TEL:" to "tel:" System.String telURI = rawText.StartsWith("TEL:")?"tel:" + rawText.Substring(4):rawText; // Drop tel, query portion //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'" int queryStart = rawText.IndexOf('?', 4); System.String number = queryStart < 0?rawText.Substring(4):rawText.Substring(4, (queryStart) - (4)); return new TelParsedResult(number, telURI, null); }
public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints) { System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); doDecodeMultiple(image, hints, results, 0, 0); if ((results.Count == 0)) { throw ReaderException.Instance; } int numResults = results.Count; Result[] resultArray = new Result[numResults]; for (int i = 0; i < numResults; i++) { resultArray[i] = (Result) results[i]; } return resultArray; }
public static URIParsedResult parse(Result result) { System.String rawText = result.Text; if (rawText == null || (!rawText.StartsWith("urlto:") && !rawText.StartsWith("URLTO:"))) { return null; } //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'" int titleEnd = rawText.IndexOf(':', 6); if (titleEnd < 0) { return null; } System.String title = titleEnd <= 6?null:rawText.Substring(6, (titleEnd) - (6)); System.String uri = rawText.Substring(titleEnd + 1); return new URIParsedResult(uri, title); }
public static TextParsedResult parse(Result result) { sbyte[] bytes = result.RawBytes; if (bytes == null) { return null; } NDEFRecord ndefRecord = NDEFRecord.readRecord(bytes, 0); if (ndefRecord == null || !ndefRecord.MessageBegin || !ndefRecord.MessageEnd) { return null; } if (!ndefRecord.Type.Equals(NDEFRecord.TEXT_WELL_KNOWN_TYPE)) { return null; } System.String[] languageText = decodeTextPayload(ndefRecord.Payload); return new TextParsedResult(languageText[0], languageText[1]); }
public static URIParsedResult parse(Result result) { sbyte[] bytes = result.RawBytes; if (bytes == null) { return null; } NDEFRecord ndefRecord = NDEFRecord.readRecord(bytes, 0); if (ndefRecord == null || !ndefRecord.MessageBegin || !ndefRecord.MessageEnd) { return null; } if (!ndefRecord.Type.Equals(NDEFRecord.URI_WELL_KNOWN_TYPE)) { return null; } System.String fullURI = decodeURIPayload(ndefRecord.Payload); return new URIParsedResult(fullURI, null); }
public static URIParsedResult parse(Result result) { System.String rawText = result.Text; if (rawText == null || !rawText.StartsWith("MEBKM:")) { return null; } System.String title = matchSingleDoCoMoPrefixedField("TITLE:", rawText, true); System.String[] rawUri = matchDoCoMoPrefixedField("URL:", rawText, true); if (rawUri == null) { return null; } System.String uri = rawUri[0]; if (!URIResultParser.isBasicallyValidURI(uri)) { return null; } return new URIParsedResult(uri, title); }
// 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) { System.String rawText = result.Text; if (rawText == null || !rawText.StartsWith("BIZCARD:")) { return null; } System.String firstName = matchSingleDoCoMoPrefixedField("N:", rawText, true); System.String lastName = matchSingleDoCoMoPrefixedField("X:", rawText, true); System.String fullName = buildName(firstName, lastName); System.String title = matchSingleDoCoMoPrefixedField("T:", rawText, true); System.String org = matchSingleDoCoMoPrefixedField("C:", rawText, true); System.String[] addresses = matchDoCoMoPrefixedField("A:", rawText, true); System.String phoneNumber1 = matchSingleDoCoMoPrefixedField("B:", rawText, true); System.String phoneNumber2 = matchSingleDoCoMoPrefixedField("M:", rawText, true); System.String phoneNumber3 = matchSingleDoCoMoPrefixedField("F:", rawText, true); System.String email = matchSingleDoCoMoPrefixedField("E:", rawText, true); return new AddressBookParsedResult(maybeWrap(fullName), null, buildPhoneNumbers(phoneNumber1, phoneNumber2, phoneNumber3), maybeWrap(email), null, addresses, org, null, title, null); }
public static EmailAddressParsedResult parse(Result result) { System.String rawText = result.Text; if (rawText == null || !rawText.StartsWith("MATMSG:")) { return null; } System.String[] rawTo = matchDoCoMoPrefixedField("TO:", rawText, true); if (rawTo == null) { return null; } System.String to = rawTo[0]; if (!isBasicallyValidEmailAddress(to)) { return null; } System.String subject = matchSingleDoCoMoPrefixedField("SUB:", rawText, false); System.String body = matchSingleDoCoMoPrefixedField("BODY:", rawText, false); return new EmailAddressParsedResult(to, subject, body, "mailto:" + to); }
public static AddressBookParsedResult parse(Result result) { System.String rawText = result.Text; // MEMORY is mandatory; seems like a decent indicator, as does end-of-record separator CR/LF if (rawText == null || rawText.IndexOf("MEMORY") < 0 || rawText.IndexOf("\r\n") < 0) { return null; } // NAME1 and NAME2 have specific uses, namely written name and pronunciation, respectively. // Therefore we treat them specially instead of as an array of names. System.String name = matchSinglePrefixedField("NAME1:", rawText, '\r', true); System.String pronunciation = matchSinglePrefixedField("NAME2:", rawText, '\r', true); System.String[] phoneNumbers = matchMultipleValuePrefix("TEL", 3, rawText, true); System.String[] emails = matchMultipleValuePrefix("MAIL", 3, rawText, true); System.String note = matchSinglePrefixedField("MEMORY:", rawText, '\r', false); System.String address = matchSinglePrefixedField("ADD:", rawText, '\r', true); System.String[] addresses = address == null?null:new System.String[]{address}; return new AddressBookParsedResult(maybeWrap(name), pronunciation, phoneNumbers, emails, note, addresses, null, null, null, null); }
public Result[] decodeMultiple(BinaryBitmap image, System.Collections.Hashtable hints) { System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10)); DetectorResult[] detectorResult = new MultiDetector(image.BlackMatrix).detectMulti(hints); for (int i = 0; i < detectorResult.Length; i++) { try { DecoderResult decoderResult = Decoder.decode(detectorResult[i].Bits); ResultPoint[] points = detectorResult[i].Points; Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE); if (decoderResult.ByteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments); } if (decoderResult.ECLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString()); } results.Add(result); } catch (ReaderException) { // ignore and continue } } if ((results.Count == 0)) { return EMPTY_RESULT_ARRAY; } else { Result[] resultArray = new Result[results.Count]; for (int i = 0; i < results.Count; i++) { resultArray[i] = (Result) results[i]; } return resultArray; } }
public static GeoParsedResult parse(Result result) { System.String rawText = result.Text; if (rawText == null || (!rawText.StartsWith("geo:") && !rawText.StartsWith("GEO:"))) { return null; } // Drop geo, query portion //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'" int queryStart = rawText.IndexOf('?', 4); System.String geoURIWithoutQuery = queryStart < 0?rawText.Substring(4):rawText.Substring(4, (queryStart) - (4)); int latitudeEnd = geoURIWithoutQuery.IndexOf(','); if (latitudeEnd < 0) { return null; } //UPGRADE_WARNING: Method 'java.lang.String.indexOf' was converted to 'System.String.IndexOf' which may throw an exception. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1101'" int longitudeEnd = geoURIWithoutQuery.IndexOf(',', latitudeEnd + 1); double latitude, longitude, altitude; try { latitude = System.Double.Parse(geoURIWithoutQuery.Substring(0, (latitudeEnd) - (0))); if (longitudeEnd < 0) { longitude = System.Double.Parse(geoURIWithoutQuery.Substring(latitudeEnd + 1)); altitude = 0.0; } else { longitude = System.Double.Parse(geoURIWithoutQuery.Substring(latitudeEnd + 1, (longitudeEnd) - (latitudeEnd + 1))); altitude = System.Double.Parse(geoURIWithoutQuery.Substring(longitudeEnd + 1)); } } catch (System.FormatException) { return null; } return new GeoParsedResult(rawText.StartsWith("GEO:")?"geo:" + rawText.Substring(4):rawText, latitude, longitude, altitude); }
public static AddressBookParsedResult parse(Result result) { // Although we should insist on the raw text ending with "END:VCARD", there's no reason // to throw out everything else we parsed just because this was omitted. In fact, Eclair // is doing just that, and we can't parse its contacts without this leniency. System.String rawText = result.Text; if (rawText == null || !rawText.StartsWith("BEGIN:VCARD")) { return null; } System.String[] names = matchVCardPrefixedField("FN", rawText, true); if (names == null) { // If no display names found, look for regular name fields and format them names = matchVCardPrefixedField("N", rawText, true); formatNames(names); } System.String[] phoneNumbers = matchVCardPrefixedField("TEL", rawText, true); System.String[] emails = matchVCardPrefixedField("EMAIL", rawText, true); System.String note = matchSingleVCardPrefixedField("NOTE", rawText, false); System.String[] addresses = matchVCardPrefixedField("ADR", rawText, true); if (addresses != null) { for (int i = 0; i < addresses.Length; i++) { addresses[i] = formatAddress(addresses[i]); } } System.String org = matchSingleVCardPrefixedField("ORG", rawText, true); System.String birthday = matchSingleVCardPrefixedField("BDAY", rawText, true); if (!isLikeVCardDate(birthday)) { birthday = null; } System.String title = matchSingleVCardPrefixedField("TITLE", rawText, true); System.String url = matchSingleVCardPrefixedField("URL", rawText, true); return new AddressBookParsedResult(names, null, phoneNumbers, emails, note, addresses, org, birthday, title, url); }
// Treat all UPC and EAN variants as UPCs, in the sense that they are all product barcodes. public static ProductParsedResult parse(Result result) { BarcodeFormat format = result.BarcodeFormat; if (!(BarcodeFormat.UPC_A.Equals(format) || BarcodeFormat.UPC_E.Equals(format) || BarcodeFormat.EAN_8.Equals(format) || BarcodeFormat.EAN_13.Equals(format))) { return null; } // Really neither of these should happen: System.String rawText = result.Text; if (rawText == null) { return null; } int length = rawText.Length; for (int x = 0; x < length; x++) { char c = rawText[x]; if (c < '0' || c > '9') { return null; } } // Not actually checking the checksum again here System.String normalizedProductID; // Expand UPC-E for purposes of searching if (BarcodeFormat.UPC_E.Equals(format)) { normalizedProductID = UPCEReader.convertUPCEtoUPCA(rawText); } else { normalizedProductID = rawText; } return new ProductParsedResult(rawText, normalizedProductID); }
// ISBN-13 For Dummies // http://www.bisg.org/isbn-13/for.dummies.html public static ISBNParsedResult parse(Result result) { BarcodeFormat format = result.BarcodeFormat; if (!BarcodeFormat.EAN_13.Equals(format)) { return null; } System.String rawText = result.Text; if (rawText == null) { return null; } int length = rawText.Length; if (length != 13) { return null; } if (!rawText.StartsWith("978") && !rawText.StartsWith("979")) { return null; } return new ISBNParsedResult(rawText); }
public Result decode(BinaryBitmap image, System.Collections.Hashtable hints) { DecoderResult decoderResult; ResultPoint[] points; if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE)) { BitMatrix bits = extractPureBits(image.BlackMatrix); decoderResult = decoder.decode(bits); points = NO_POINTS; } else { DetectorResult detectorResult = new Detector(image.BlackMatrix).detect(); decoderResult = decoder.decode(detectorResult.Bits); points = detectorResult.Points; } Result result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.DATAMATRIX); if (decoderResult.ByteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, decoderResult.ByteSegments); } if (decoderResult.ECLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, decoderResult.ECLevel.ToString()); } return result; }
public static ParsedResult parseResult(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. ParsedResult result; if ((result = BookmarkDoCoMoResultParser.parse(theResult)) != null) { return result; } else if ((result = AddressBookDoCoMoResultParser.parse(theResult)) != null) { return result; } else if ((result = EmailDoCoMoResultParser.parse(theResult)) != null) { return result; } else if ((result = AddressBookAUResultParser.parse(theResult)) != null) { return result; } else if ((result = VCardResultParser.parse(theResult)) != null) { return result; } else if ((result = BizcardResultParser.parse(theResult)) != null) { return result; } else if ((result = VEventResultParser.parse(theResult)) != null) { return result; } else if ((result = EmailAddressResultParser.parse(theResult)) != null) { return result; } else if ((result = TelResultParser.parse(theResult)) != null) { return result; } else if ((result = SMSMMSResultParser.parse(theResult)) != null) { return result; } else if ((result = GeoResultParser.parse(theResult)) != null) { return result; } else if ((result = URLTOResultParser.parse(theResult)) != null) { return result; } else if ((result = URIResultParser.parse(theResult)) != null) { return result; } else if ((result = ISBNResultParser.parse(theResult)) != null) { // We depend on ISBN parsing coming before UPC, as it is a subset. return result; } else if ((result = ProductResultParser.parse(theResult)) != null) { return result; } return new TextParsedResult(theResult.Text, null); }
private static Result translateResultPoints(Result result, int xOffset, int yOffset) { ResultPoint[] oldResultPoints = result.ResultPoints; ResultPoint[] newResultPoints = new ResultPoint[oldResultPoints.Length]; for (int i = 0; i < oldResultPoints.Length; i++) { ResultPoint oldPoint = oldResultPoints[i]; newResultPoints[i] = new ResultPoint(oldPoint.X + xOffset, oldPoint.Y + yOffset); } return new Result(result.Text, result.RawBytes, newResultPoints, result.BarcodeFormat); }