From 0de1fbc62361950f1aef4f0ce79ada8b4d551831 Mon Sep 17 00:00:00 2001 From: srowen Date: Thu, 30 Apr 2009 20:19:20 +0000 Subject: [PATCH] Oops fixed invalid use of java.net classes git-svn-id: https://zxing.googlecode.com/svn/trunk@922 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../client/ContactInfoGenerator.java | 2 -- .../web/generator/client/Validators.java | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java b/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java index 2eeca40e4..d5caba2ba 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java +++ b/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/ContactInfoGenerator.java @@ -21,8 +21,6 @@ import com.google.gwt.user.client.ui.Grid; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.Widget; -import java.net.URI; - /** * A Generator for contact informations, output is in MeCard format. * diff --git a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/Validators.java b/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/Validators.java index 4f1432408..ef6c62944 100644 --- a/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/Validators.java +++ b/zxing.appspot.com/generator/src/com/google/zxing/web/generator/client/Validators.java @@ -16,9 +16,6 @@ package com.google.zxing.web.generator.client; -import java.net.URL; -import java.net.MalformedURLException; - /** * Helpers methods to check for phone numbers, email addresses, and URL. Other * general purpose check methods should go here as well. @@ -37,12 +34,22 @@ public final class Validators { } public static void validateUrl(String url) throws GeneratorException { - try { - new URL(url); - } catch (MalformedURLException mue) { + if (!isBasicallyValidURI(url)) { throw new GeneratorException("URL is not valid."); } } + + private static boolean isBasicallyValidURI(String uri) { + if (uri == null || uri.indexOf(' ') >= 0 || uri.indexOf('\n') >= 0) { + return false; + } + int period = uri.indexOf('.'); + // Look for period in a domain but followed by at least a two-char TLD + if (period >= uri.length() - 2) { + return false; + } + return period >= 0 || uri.indexOf(':') >= 0; + } public static void validateEmail(String email) throws GeneratorException { //FIXME: we can have a better check for email here.