1 19 20 package org.netbeans.upgrade.systemoptions; 21 22 import java.net.MalformedURLException ; 23 import java.net.URL ; 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 30 class URLProcessor extends PropertyProcessor { 31 URLProcessor() { 32 super("java.net.URL"); } 34 35 void processPropertyImpl(String propertyName, Object value) { 36 StringBuffer sb = new StringBuffer (); 37 if ("mainProjectURL".equals(propertyName)) { List l = ((SerParser.ObjectWrapper)value).data; 39 try { 40 URL url = createURL(l); 41 addProperty(propertyName, url.toExternalForm()); 42 } catch (MalformedURLException ex) { 43 ex.printStackTrace(); 44 } 45 } else { 46 throw new IllegalStateException (); 47 } 48 } 49 50 public static URL createURL(List l) throws MalformedURLException { 51 String protocol = null; 52 String host = null; 53 int port = -1; 54 String file = null; 55 String authority = null; 56 String ref = null; 57 for (Iterator it = l.iterator(); it.hasNext();) { 58 Object elem = (Object ) it.next(); 59 if (elem instanceof SerParser.NameValue) { 60 SerParser.NameValue nv = (SerParser.NameValue)elem; 61 if (nv.value != null && nv.name != null) { 62 if (nv.name.name.equals("port")) { port = ((Integer )nv.value).intValue(); } 65 else if (nv.name.name.equals("file")) { file = nv.value.toString(); } 68 else if (nv.name.name.equals("authority")) { authority = nv.value.toString(); } 71 else if (nv.name.name.equals("host")) { host = nv.value.toString(); } 74 else if (nv.name.name.equals("protocol")) { protocol = nv.value.toString(); } 77 else if (nv.name.name.equals("ref")) { ref = nv.value.toString(); } 80 } 81 } 82 } 83 return new URL (protocol, host, port, file); 84 85 } 86 } 87 | Popular Tags |