Initial commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/* Author: Maple
|
||||
* Jan. 18 2026
|
||||
* */
|
||||
|
||||
package org.openautonomousconnection.infonamelib;
|
||||
|
||||
import org.openautonomousconnection.infonamelib.protocols.ftp.FTPInfoNameURLStreamHandler;
|
||||
import org.openautonomousconnection.infonamelib.protocols.web.WebInfoNameURLStreamHandler;
|
||||
|
||||
import java.net.URLStreamHandler;
|
||||
import java.net.URLStreamHandlerFactory;
|
||||
|
||||
public class InfoNameURLStreamHandlerFactory implements URLStreamHandlerFactory {
|
||||
@Override
|
||||
public URLStreamHandler createURLStreamHandler(String protocol) {
|
||||
return switch (protocol) {
|
||||
case "web" -> new WebInfoNameURLStreamHandler();
|
||||
case "ftp" -> new FTPInfoNameURLStreamHandler();
|
||||
default -> null;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/* Author: Maple
|
||||
* Jan. 18 2026
|
||||
* */
|
||||
|
||||
package org.openautonomousconnection.infonamelib;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
public class InfoNames {
|
||||
/**
|
||||
* Switches accepted Schemes in URLs to InfoName ones
|
||||
*/
|
||||
public static void registerOACInfoNameProtocols() {
|
||||
URL.setURLStreamHandlerFactory(new InfoNameURLStreamHandlerFactory());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/* Author: Maple
|
||||
* Jan. 18 2026
|
||||
* */
|
||||
|
||||
package org.openautonomousconnection.infonamelib.protocols.ftp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class FTPInfoNameURLConnection extends URLConnection {
|
||||
/**
|
||||
* Constructs a URL connection to the specified URL. A connection to
|
||||
* the object referenced by the URL is not created.
|
||||
*
|
||||
* @param url the specified URL.
|
||||
*/
|
||||
protected FTPInfoNameURLConnection(URL url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect() throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/* Author: Maple
|
||||
* Jan. 18 2026
|
||||
* */
|
||||
|
||||
package org.openautonomousconnection.infonamelib.protocols.ftp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
|
||||
public class FTPInfoNameURLStreamHandler extends URLStreamHandler {
|
||||
@Override
|
||||
protected URLConnection openConnection(URL url) throws IOException {
|
||||
return new FTPInfoNameURLConnection(url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/* Author: Maple
|
||||
* Jan. 18 2026
|
||||
* */
|
||||
|
||||
package org.openautonomousconnection.infonamelib.protocols.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class WebInfoNameURLConnection extends URLConnection {
|
||||
/**
|
||||
* Constructs a URL connection to the specified URL. A connection to
|
||||
* the object referenced by the URL is not created.
|
||||
*
|
||||
* @param url the specified URL.
|
||||
*/
|
||||
protected WebInfoNameURLConnection(URL url) {
|
||||
super(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect() throws IOException {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/* Author: Maple
|
||||
* Jan. 18 2026
|
||||
* */
|
||||
|
||||
package org.openautonomousconnection.infonamelib.protocols.web;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
|
||||
public class WebInfoNameURLStreamHandler extends URLStreamHandler {
|
||||
@Override
|
||||
protected URLConnection openConnection(URL url) throws IOException {
|
||||
return new WebInfoNameURLConnection(url);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.openautonomousconnection.infonamelib.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.openautonomousconnection.infonamelib.InfoNames;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
||||
public class URLTests {
|
||||
@Test
|
||||
public void createWebUrl() {
|
||||
System.out.println("Registering OAC protocols");
|
||||
|
||||
InfoNames.registerOACInfoNameProtocols();
|
||||
|
||||
System.out.println("Creating url to: web://localhost:8080");
|
||||
|
||||
URI uri = URI.create("web://localhost:8080");
|
||||
|
||||
try {
|
||||
URL url = uri.toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user