77import java .net .MalformedURLException ;
88import java .net .URI ;
99import java .net .URISyntaxException ;
10+ import java .net .URL ;
1011import java .util .ArrayList ;
1112import java .util .LinkedHashMap ;
1213import java .util .List ;
@@ -137,7 +138,21 @@ public void parseJNLP() {
137138
138139 Jnlp data = null ;
139140 try {
140- data = (Jnlp ) um .unmarshal (jnlpUri .toURL ());
141+ URL url = jnlpUri .toURL ();
142+
143+ if (url .getProtocol ().equalsIgnoreCase ("file" )) {
144+ try {
145+ File file = new File (url .getPath ());
146+ data = (Jnlp ) um .unmarshal (file );
147+ } catch (Exception e ) {
148+ // TODO Auto-generated catch block
149+ e .printStackTrace ();
150+ }
151+
152+ } else {
153+ data = (Jnlp ) um .unmarshal (url );
154+ }
155+
141156 } catch (JAXBException | MalformedURLException e ) {
142157 if (logger .isInfoEnabled ())
143158 logger .info ("Exception Unmarshalling" , e );
@@ -198,25 +213,40 @@ public void parseJNLP(URI jnlpUri) {
198213 JAXBContext jc = null ;
199214 try {
200215 jc = JAXBContext .newInstance (Jnlp .class );
201- } catch (JAXBException e ) {
216+ } catch (Exception e ) {
202217 if (logger .isInfoEnabled ())
203- logger .info ("JAXBException " , e );
218+ logger .info ("Exception " , e );
204219 }
205220
206221 Unmarshaller um = null ;
207222 try {
208223 um = jc .createUnmarshaller ();
209- } catch (JAXBException e ) {
224+ } catch (Exception e ) {
210225 if (logger .isInfoEnabled ())
211- logger .info ("JAXBException " , e );
226+ logger .info ("Exception " , e );
212227 }
213228
214229 Jnlp data = null ;
230+
215231 try {
216- data = (Jnlp ) um .unmarshal (jnlpUri .toURL ());
217- } catch (JAXBException | MalformedURLException e ) {
232+
233+ if (jnlpUri .toString ().toLowerCase ().startsWith ("file" )) {
234+ try {
235+ File file = new File (jnlpUri .getRawPath ());
236+ data = (Jnlp ) um .unmarshal (file );
237+ } catch (Exception e ) {
238+ // TODO Auto-generated catch block
239+ e .printStackTrace ();
240+ }
241+
242+ } else {
243+ URL url = jnlpUri .toURL ();
244+ data = (Jnlp ) um .unmarshal (url );
245+ }
246+
247+ } catch (Exception e ) {
218248 if (logger .isInfoEnabled ())
219- logger .info ("JAXBException | MalformedURLException " , e );
249+ logger .info ("Exception " , e );
220250 }
221251
222252 if (logger .isInfoEnabled ()) {
@@ -237,7 +267,7 @@ public void parseJNLP(URI jnlpUri) {
237267 }
238268
239269 for (Resources resource : resources ) {
240- logger .info (resource .getArch () + " " + resource .getOs ());
270+ logger .info ("resources: " + resource .getArch () + " " + resource .getOs ());
241271 for (Object libRef : resource .getJavaOrJ2SeOrJarOrNativelibOrExtensionOrPropertyOrPackage ()) {
242272
243273 if (libRef instanceof Jar ) {
@@ -471,22 +501,25 @@ private String getJavaLocation(String javaHome) {
471501 */
472502 public static URI getURIReference (String codeBase , String parentRef , String fileName ) {
473503 String fullUri = codeBase + "/" + fileName ;
474-
475504 if (codeBase .toUpperCase ().startsWith ("HTTP" )) {
476505 // no-op
477506 } else if (fileName .toUpperCase ().startsWith ("HTTP" )) {
478507 fullUri = fileName ;
479508 } else if (parentRef .toUpperCase ().startsWith ("HTTP" )) {
480509 fullUri = parentRef + "/" + fileName ;
510+ } else if (parentRef .toUpperCase ().startsWith ("FILE" )) {
511+ return new File (parentRef .replaceAll ("file://" , "" ) + File .separator + fileName ).toURI ();
512+ } else if (new File (parentRef ).isDirectory ()) {
513+ return new File (parentRef + File .separator + fileName ).toURI ();
481514 }
482515
483516 URI theUri = null ;
484517
485518 try {
486519 theUri = new URI (fullUri );
487- } catch (URISyntaxException e ) {
520+ } catch (Exception e ) {
488521 if (logger .isInfoEnabled ())
489- logger .info ("URISyntaxException " , e );
522+ logger .info ("Exception " , e );
490523 }
491524
492525 return theUri .normalize ();
@@ -513,9 +546,25 @@ public static String getFileNameFromUri(URI uri) {
513546 * @return the parent uri
514547 */
515548 private String getParentUri (URI uri ) {
516- String uriString = uri .toString ();
517549
518- return uriString .substring (0 , uriString .lastIndexOf ('/' ) + 1 ).split ("\\ ?" )[0 ].split ("#" )[0 ];
550+ try {
551+ File f = new File (uri );
552+
553+ if (f .isFile ()) {
554+ return f .getParent ();
555+
556+ } else {
557+ String uriString = uri .toString ();
558+
559+ return uriString .substring (0 , uriString .lastIndexOf ('/' ) + 1 ).split ("\\ ?" )[0 ].split ("#" )[0 ];
560+
561+ }
562+ } catch (Exception e ) {
563+ String uriString = uri .toString ();
564+
565+ return uriString .substring (0 , uriString .lastIndexOf ('/' ) + 1 ).split ("\\ ?" )[0 ].split ("#" )[0 ];
566+ }
567+
519568 }
520569
521570}
0 commit comments