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);
		}
示例#2
0
        // 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));
        }
示例#3
0
        public virtual 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(hints);
                decoderResult = decoder.decode(detectorResult.Bits);
                points        = detectorResult.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());
            }
            return(result);
        }
示例#4
0
        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));
        }
示例#5
0
		public virtual 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(hints);
				decoderResult = decoder.decode(detectorResult.Bits);
				points = detectorResult.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());
			}
			return result;
		}
		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);
		}
示例#7
0
 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 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);
		}
示例#10
0
        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 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);
		}
示例#12
0
        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 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 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]);
		}
示例#15
0
        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 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);
		}
示例#18
0
        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]));
        }
示例#19
0
        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));
        }
示例#20
0
        // 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));
        }
示例#21
0
 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));
 }
		public static EmailAddressParsedResult parse(Result result)
		{
			System.String rawText = result.Text;
			if (rawText == null)
			{
				return null;
			}
			System.String emailAddress;
			if (rawText.StartsWith("mailto:") || rawText.StartsWith("MAILTO:"))
			{
				// If it starts with mailto:, assume it is definitely trying to be an email address
				emailAddress = rawText.Substring(7);
				int queryStart = emailAddress.IndexOf('?');
				if (queryStart >= 0)
				{
					emailAddress = emailAddress.Substring(0, (queryStart) - (0));
				}
				System.Collections.Hashtable nameValues = parseNameValuePairs(rawText);
				System.String subject = null;
				System.String body = null;
				if (nameValues != null)
				{
					if (emailAddress.Length == 0)
					{
						emailAddress = ((System.String) nameValues["to"]);
					}
					subject = ((System.String) nameValues["subject"]);
					body = ((System.String) nameValues["body"]);
				}
				return new EmailAddressParsedResult(emailAddress, subject, body, rawText);
			}
			else
			{
				if (!EmailDoCoMoResultParser.isBasicallyValidEmailAddress(rawText))
				{
					return null;
				}
				emailAddress = rawText;
				return new EmailAddressParsedResult(emailAddress, null, null, "mailto:" + emailAddress);
			}
		}
 public static EmailAddressParsedResult parse(Result result)
 {
     System.String rawText = result.Text;
     if (rawText == null)
     {
         return(null);
     }
     System.String emailAddress;
     if (rawText.StartsWith("mailto:") || rawText.StartsWith("MAILTO:"))
     {
         // If it starts with mailto:, assume it is definitely trying to be an email address
         emailAddress = rawText.Substring(7);
         int queryStart = emailAddress.IndexOf('?');
         if (queryStart >= 0)
         {
             emailAddress = emailAddress.Substring(0, (queryStart) - (0));
         }
         System.Collections.Hashtable nameValues = parseNameValuePairs(rawText);
         System.String subject = null;
         System.String body    = null;
         if (nameValues != null)
         {
             if (emailAddress.Length == 0)
             {
                 emailAddress = ((System.String)nameValues["to"]);
             }
             subject = ((System.String)nameValues["subject"]);
             body    = ((System.String)nameValues["body"]);
         }
         return(new EmailAddressParsedResult(emailAddress, subject, body, rawText));
     }
     else
     {
         if (!EmailDoCoMoResultParser.isBasicallyValidEmailAddress(rawText))
         {
             return(null);
         }
         emailAddress = rawText;
         return(new EmailAddressParsedResult(emailAddress, null, null, "mailto:" + emailAddress));
     }
 }
		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);
		}
示例#25
0
 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));
 }
示例#26
0
        // 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));
        }
示例#27
0
 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 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;
			}
		}
示例#29
0
		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);
		}
		// 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);
		}
		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);
		}
示例#32
0
 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));
 }
		// 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 static SMSParsedResult parse(Result result)
		{
			System.String rawText = result.Text;
			if (rawText == null)
			{
				return null;
			}
			int prefixLength;
			if (rawText.StartsWith("sms:") || rawText.StartsWith("SMS:") || rawText.StartsWith("mms:") || rawText.StartsWith("MMS:"))
			{
				prefixLength = 4;
			}
			else if (rawText.StartsWith("smsto:") || rawText.StartsWith("SMSTO:") || rawText.StartsWith("mmsto:") || rawText.StartsWith("MMSTO:"))
			{
				prefixLength = 6;
			}
			else
			{
				return null;
			}
			
			// Check up front if this is a URI syntax string with query arguments
			System.Collections.Hashtable nameValuePairs = parseNameValuePairs(rawText);
			System.String subject = null;
			System.String body = null;
			bool querySyntax = false;
			if (nameValuePairs != null && !(nameValuePairs.Count == 0))
			{
				subject = ((System.String) nameValuePairs["subject"]);
				body = ((System.String) nameValuePairs["body"]);
				querySyntax = true;
			}
			
			// Drop sms, 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('?', prefixLength);
			System.String smsURIWithoutQuery;
			// If it's not query syntax, the question mark is part of the subject or message
			if (queryStart < 0 || !querySyntax)
			{
				smsURIWithoutQuery = rawText.Substring(prefixLength);
			}
			else
			{
				smsURIWithoutQuery = rawText.Substring(prefixLength, (queryStart) - (prefixLength));
			}
			int numberEnd = smsURIWithoutQuery.IndexOf(';');
			System.String number;
			System.String via;
			if (numberEnd < 0)
			{
				number = smsURIWithoutQuery;
				via = null;
			}
			else
			{
				number = smsURIWithoutQuery.Substring(0, (numberEnd) - (0));
				System.String maybeVia = smsURIWithoutQuery.Substring(numberEnd + 1);
				if (maybeVia.StartsWith("via="))
				{
					via = maybeVia.Substring(4);
				}
				else
				{
					via = null;
				}
			}
			
			// Thanks to dominik.wild for suggesting this enhancement to support
			// smsto:number:body URIs
			if (body == null)
			{
				int bodyStart = number.IndexOf(':');
				if (bodyStart >= 0)
				{
					body = number.Substring(bodyStart + 1);
					number = number.Substring(0, (bodyStart) - (0));
				}
			}
			return new SMSParsedResult("sms:" + number, number, via, subject, body, 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));
        }
示例#36
0
        public static SMSParsedResult parse(Result result)
        {
            System.String rawText = result.Text;
            if (rawText == null)
            {
                return(null);
            }
            int prefixLength;

            if (rawText.StartsWith("sms:") || rawText.StartsWith("SMS:") || rawText.StartsWith("mms:") || rawText.StartsWith("MMS:"))
            {
                prefixLength = 4;
            }
            else if (rawText.StartsWith("smsto:") || rawText.StartsWith("SMSTO:") || rawText.StartsWith("mmsto:") || rawText.StartsWith("MMSTO:"))
            {
                prefixLength = 6;
            }
            else
            {
                return(null);
            }

            // Check up front if this is a URI syntax string with query arguments
            System.Collections.Hashtable nameValuePairs = parseNameValuePairs(rawText);
            System.String subject     = null;
            System.String body        = null;
            bool          querySyntax = false;

            if (nameValuePairs != null && !(nameValuePairs.Count == 0))
            {
                subject     = ((System.String)nameValuePairs["subject"]);
                body        = ((System.String)nameValuePairs["body"]);
                querySyntax = true;
            }

            // Drop sms, 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('?', prefixLength);

            System.String smsURIWithoutQuery;
            // If it's not query syntax, the question mark is part of the subject or message
            if (queryStart < 0 || !querySyntax)
            {
                smsURIWithoutQuery = rawText.Substring(prefixLength);
            }
            else
            {
                smsURIWithoutQuery = rawText.Substring(prefixLength, (queryStart) - (prefixLength));
            }
            int numberEnd = smsURIWithoutQuery.IndexOf(';');

            System.String number;
            System.String via;
            if (numberEnd < 0)
            {
                number = smsURIWithoutQuery;
                via    = null;
            }
            else
            {
                number = smsURIWithoutQuery.Substring(0, (numberEnd) - (0));
                System.String maybeVia = smsURIWithoutQuery.Substring(numberEnd + 1);
                if (maybeVia.StartsWith("via="))
                {
                    via = maybeVia.Substring(4);
                }
                else
                {
                    via = null;
                }
            }

            // Thanks to dominik.wild for suggesting this enhancement to support
            // smsto:number:body URIs
            if (body == null)
            {
                int bodyStart = number.IndexOf(':');
                if (bodyStart >= 0)
                {
                    body   = number.Substring(bodyStart + 1);
                    number = number.Substring(0, (bodyStart) - (0));
                }
            }
            return(new SMSParsedResult("sms:" + number, number, via, subject, body, null));
        }