Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Java in General
How to retrieve informations from the Java Control Panel ?
Oliver Rensen
Ranch Hand
Posts: 109
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
is it possible to retrieve informations from the
Java
Control Panel within a Java-program ?
In my source-code I want to know which option is selected in the network settings from the Java Control Panel.
How can I detect programmatically whether direct connection is selected or not?
Kind regards
Oliver
Oliver Rensen
Ranch Hand
Posts: 109
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have created my own proprietary solution. It's not nice, but it works.
public class ProxyFinder { public interface Search { public void visitFile(File current, int depth); public void visitDirectory(File current, int depth, File[] contents); } public interface Element { public void accept(Search v, int depth); } public class DirectoryElement implements Element { private File f; public DirectoryElement(File f) { this.f = f; } public void accept(Search v, int depth) { v.visitDirectory(f, depth, f.listFiles()); } } public class FileElement implements Element { private File f; public FileElement(File f) { this.f = f; } public void accept(Search v, int depth) { v.visitFile(f, depth); } } private File root; public ProxyFinder(String root) { this.root = new File(root); } public void traverse(Search searching) { topDown(root, searching, 0); } private void topDown(File root, Search searching, int depth) { Element e = root.isFile() ? (Element) (new FileElement(root)) : (Element) (new DirectoryElement(root)); e.accept(searching, depth); if (root.isDirectory()) { File[] children = root.listFiles(); if (children == null) { return; } for (int i = 0; i < children.length; ++i) { topDown(children[i], searching, depth + 1); } } } public static void main(String args[]) { final List<String> files = new ArrayList<String>(); String startDir = System.getProperty("user.home"); if (startDir == null || startDir.length() == 0) startDir = "C:\\"; ProxyFinder d = new ProxyFinder(startDir); d.traverse(new ProxyFinder.Search() { public void visitFile(File f, int depth) { if (f.getName().trim().toLowerCase().startsWith("deployment.properties")) { if (!f.getAbsolutePath().startsWith("C:\\Windows")) { files.add(f.getAbsolutePath()); } } } public void visitDirectory(File f, int depth, File[] children) { } }); for (String s : files) { try { FileInputStream file = new FileInputStream(s); DataInputStream in = new DataInputStream(file); byte[] b = new byte[in.available()]; in.readFully(b); in.close(); String fileAsString = new String (b, 0, b.length); String[] lines = fileAsString.split("\\n"); String type = "browser settings"; for (String l : lines) { if (l != null) { String line = l.trim(); if (line.equals("deployment.proxy.type=0")) { type = "direct connection"; } if (line.equals("deployment.proxy.type=1")) { type = "proxy server"; } if (line.equals("deployment.proxy.type=2")) { type = "proxy configuration script"; } } } System.out.println("Java Control Panel: " + type); } catch (Exception e) { System.out.println("Exception raised: " + e.getMessage()); } } } }
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
JSF drop down.
Repetitive acces to server using the same URLConnection
Read the Date Format String specified in control panel
servlet
Can I Programmatically choose Plugin (without touching the HTML)??
More...