فهرست منبع

Initial commit: utils

Mathias Landhäußer 11 سال پیش
والد
کامیت
d9600614a4

+ 20 - 0
jplag.utils/pom.xml

@@ -0,0 +1,20 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<artifactId>utils</artifactId>
+	<version>0.0.3-SNAPSHOT</version>
+
+	<parent>
+		<groupId>edu.kit.ipd.jplag</groupId>
+		<artifactId>parent</artifactId>
+		<version>0.3-SNAPSHOT</version>
+	</parent>
+
+	<repositories>
+		<repository>
+			<id>ipdNexus</id>
+			<name>Recaa Repository</name>
+			<url>http://bob.ipd.kit.edu/nexus/content/repositories/public/</url>
+		</repository>
+	</repositories>
+</project>

+ 51 - 0
jplag.utils/src/main/java/jplagUtils/DesktopUtils.java

@@ -0,0 +1,51 @@
+package jplagUtils;
+
+import java.awt.Desktop;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+public class DesktopUtils {
+	public static boolean isBrowseSupported() {
+		Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
+		if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+
+	public static void openWebpage(URI uri) {
+		if (isBrowseSupported()) {
+			Desktop desktop = Desktop.getDesktop();
+			try {
+				desktop.browse(uri);
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+		} else {
+			System.out.println("Desktop does not support opening of a browser :/ open " + uri + " yourself");
+		}
+	}
+
+	public static void openWebpage(URL url) {
+		if (isBrowseSupported()) {
+			try {
+				openWebpage(url.toURI());
+			} catch (URISyntaxException e) {
+				e.printStackTrace();
+			}
+		} else {
+			System.out.println("Desktop does not support opening of a browser :/ open " + url + " yourself");
+		}
+	}
+
+	public static void openWebpage(String url) throws MalformedURLException {
+		if (isBrowseSupported()) {
+			openWebpage(new URL((!url.startsWith("https://") && !url.startsWith("http://") ? "http://" : "") + url));
+		} else {
+			System.out.println("Desktop does not support opening of a browser :/ open " + url + " yourself");
+		}
+	}
+}

+ 21 - 0
jplag.utils/src/main/java/jplagUtils/PropertiesLoader.java

@@ -0,0 +1,21 @@
+package jplagUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+public class PropertiesLoader {
+	public static Properties loadProps(String resourceName) {
+		InputStream in = PropertiesLoader.class.getClassLoader().getResourceAsStream(resourceName);
+		Properties props = new Properties();
+		if (in != null) {
+			try {
+				props.load(in);
+				in.close();
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		return props;
+	}
+}