Skip to content

Commit

Permalink
issue-9 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunbee Kim committed Oct 6, 2020
1 parent 97cbea3 commit f84d593
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 15 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="C:/Users/eunbee/Desktop/college/S5/OSD/Release/Release0.1/findBrokenGlass/lib/jna-5.6.0.jar"/>
<classpathentry exported="true" kind="lib" path="C:/Users/eunbee/Desktop/college/S5/OSD/Release/Release0.1/findBrokenGlass/lib/json-simple-1.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file modified bin/UrlCheck.class
Binary file not shown.
Binary file modified bin/mac/UrlCheck.jar
Binary file not shown.
Binary file modified bin/window/UrlCheck.exe
Binary file not shown.
Binary file modified bin/window/UrlCheck.jar
Binary file not shown.
Binary file added lib/json-simple-1.1.jar
Binary file not shown.
43 changes: 43 additions & 0 deletions src/ConvertJavaToJson.java
Original file line number Diff line number Diff line change
@@ -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;

}
}
54 changes: 39 additions & 15 deletions src/UrlCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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()
{
Expand All @@ -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("| |");
Expand All @@ -55,6 +57,11 @@ public static void helpMessage()
System.out.println("| UrlCheck --s <fileName> |");
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 <fileName> |");
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 |");
Expand All @@ -78,6 +85,11 @@ public static void helpMessage()
System.out.println("| UrlCheck /s <fileName> |");
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 <fileName> |");
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 |");
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"))
{
Expand All @@ -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"))
{
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit f84d593

Please sign in to comment.