diff --git a/.classpath b/.classpath
index 2327353..cb6a5ac 100644
--- a/.classpath
+++ b/.classpath
@@ -3,5 +3,6 @@
+
diff --git a/bin/UrlCheck.class b/bin/UrlCheck.class
index 87651aa..f50d0f2 100644
Binary files a/bin/UrlCheck.class and b/bin/UrlCheck.class differ
diff --git a/bin/mac/UrlCheck.jar b/bin/mac/UrlCheck.jar
index 29eb71e..2ce4fcc 100644
Binary files a/bin/mac/UrlCheck.jar and b/bin/mac/UrlCheck.jar differ
diff --git a/bin/window/UrlCheck.exe b/bin/window/UrlCheck.exe
index e5e4492..a9b7a40 100644
Binary files a/bin/window/UrlCheck.exe and b/bin/window/UrlCheck.exe differ
diff --git a/bin/window/UrlCheck.jar b/bin/window/UrlCheck.jar
index 5297e5b..154a640 100644
Binary files a/bin/window/UrlCheck.jar and b/bin/window/UrlCheck.jar differ
diff --git a/lib/json-simple-1.1.jar b/lib/json-simple-1.1.jar
new file mode 100644
index 0000000..f395f41
Binary files /dev/null and b/lib/json-simple-1.1.jar differ
diff --git a/src/ConvertJavaToJson.java b/src/ConvertJavaToJson.java
new file mode 100644
index 0000000..b556763
--- /dev/null
+++ b/src/ConvertJavaToJson.java
@@ -0,0 +1,43 @@
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.json.simple.JSONObject;
+
+public class ConvertJavaToJson {
+
+ public static JSONObject availableURL(String host)
+ {
+
+ try {
+ // request url
+ URL url = new URL(host);
+ URLConnection con;
+ con = url.openConnection();
+
+ // response
+ HttpURLConnection exitCode = (HttpURLConnection) con;
+ exitCode.setInstanceFollowRedirects(true);
+ HttpURLConnection.setFollowRedirects(true);
+ exitCode.setConnectTimeout(1000);
+
+ return ConvertJavaObjectToJson(host, exitCode.getResponseCode());
+
+ }catch (Exception e) {
+
+ return ConvertJavaObjectToJson(host, 599);
+ }
+
+
+ }
+
+ public static JSONObject ConvertJavaObjectToJson(String url, int code)
+ {
+ JSONObject obj = new JSONObject();
+ obj.put("url",url);
+ obj.put("status",code);
+
+ return obj;
+
+ }
+}
diff --git a/src/UrlCheck.java b/src/UrlCheck.java
index 86cec8b..faa1f12 100644
--- a/src/UrlCheck.java
+++ b/src/UrlCheck.java
@@ -9,7 +9,6 @@
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -19,6 +18,8 @@
import java.nio.file.SimpleFileVisitor;
import java.nio.file.FileVisitResult;
import java.nio.file.attribute.BasicFileAttributes;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
public class UrlCheck {
// url set regex
@@ -27,6 +28,7 @@ public class UrlCheck {
// delimiter to get url from input file
final static String delimiter = "[\\[\\]\"<>'\n\b\r]";
+ static JSONArray list = new JSONArray();
public static void helpMessage()
{
@@ -41,7 +43,7 @@ public static void helpMessage()
System.out.println("| |");
System.out.println("| 2) UrlCheck help |");
System.out.println("| |");
- System.out.println("| 3) Option a, s, v, m, d |");
+ System.out.println("| 3) Option a, s, v, m, d, j/json |");
System.out.println("| |");
System.out.println("| For Window : |");
System.out.println("| |");
@@ -55,6 +57,11 @@ public static void helpMessage()
System.out.println("| UrlCheck --s |");
System.out.println("| ex) UrlCheck --s index2.html |");
System.out.println("| |");
+ System.out.println("| Option j/json : To return JSON format |");
+ System.out.println("| |");
+ System.out.println("| UrlCheck --j |");
+ System.out.println("| ex) UrlCheck --json index2.html |");
+ System.out.println("| |");
System.out.println("| Option v : To check the version |");
System.out.println("| |");
System.out.println("| UrlCheck --v |");
@@ -78,6 +85,11 @@ public static void helpMessage()
System.out.println("| UrlCheck /s |");
System.out.println("| ex) UrlCheck /s index2.html |");
System.out.println("| |");
+ System.out.println("| Option j/json : To return JSON format |");
+ System.out.println("| |");
+ System.out.println("| UrlCheck /j |");
+ System.out.println("| ex) UrlCheck /json index2.html |");
+ System.out.println("| |");
System.out.println("| Option v : To check the version |");
System.out.println("| |");
System.out.println("| UrlCheck /v |");
@@ -102,7 +114,7 @@ public static void endMessage()
// list up url in input file
- public static void fileUrlListUp(String fName, boolean archived, boolean secured, boolean runMac)
+ public static void fileUrlListUp(String fName, boolean archived, boolean secured, boolean runMac, boolean jsonOut)
{
String regSecure = "^(http)://";
Pattern pat = Pattern.compile(regex, Pattern.MULTILINE);
@@ -134,23 +146,32 @@ public static void fileUrlListUp(String fName, boolean archived, boolean secured
Matcher matcher = pat.matcher(str);
if(matcher.find())
{
- // change http to https
- if(secured) str = str.replaceFirst(regSecure, "https://");
-
- if(runMac)
+ if(jsonOut)
{
- UrlCheckForMac.availableURL(str);
+ JSONObject temp = new JSONObject();
+ temp = ConvertJavaToJson.availableURL(str);
+ list.add(temp);
}
else
- {
- UrlCheckForWindow.availableURL(str);
+ {
+ // change http to https
+ if(secured) str = str.replaceFirst(regSecure, "https://");
+
+ if(runMac)
+ {
+ UrlCheckForMac.availableURL(str);
+ }
+ else
+ {
+ UrlCheckForWindow.availableURL(str);
+ }
}
-
// request archived
if(archived) archiveUrl(str);
}
}
}
+ if(jsonOut) System.out.println(list);
br.close();
}
} catch (FileNotFoundException e) {
@@ -199,6 +220,7 @@ public static void main(String[] args) {
boolean archived = false;
boolean secured = false;
boolean runMac = false;
+ boolean jsonOut = false;
if(args.length == 0 || args[0].toLowerCase().equals("help"))
{
@@ -209,7 +231,7 @@ public static void main(String[] args) {
startMessage();
// command line flag a, s, d
- if(args[0].startsWith("--") || args[0].startsWith("/"))
+ if(args[0].startsWith("-") || args[0].startsWith("/") || args[0].startsWith("\\"))
{
if(args[0].contains("v") || args[0].contains("version"))
{
@@ -226,12 +248,14 @@ public static void main(String[] args) {
// secure request flag handle
if(args[0].contains("m")) runMac = true;
- if(archived || secured || runMac)
+ if(args[0].contains("j") || args[0].contains("json")) jsonOut = true;
+
+ if(archived || secured || runMac || jsonOut)
{
for(int i = 1; i < args.length; i++)
{
System.out.println("File/Directory : " + args[i]);
- fileUrlListUp(args[i],archived,secured,runMac);
+ fileUrlListUp(args[i],archived,secured,runMac,jsonOut);
}
}
@@ -241,7 +265,7 @@ public static void main(String[] args) {
for(int i = 0; i < args.length; i++)
{
System.out.println("File : " + args[i]);
- fileUrlListUp(args[i],archived,secured,runMac);
+ fileUrlListUp(args[i],archived,secured,runMac,jsonOut);
}
}
}