1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 package org.scilab.modules.commons.jarsci;
17 
18 import java.io.File;
19 import java.io.IOException;
20 import java.net.URL;
21 import java.net.URLConnection;
22 import java.net.URLStreamHandler;
23 
24 import org.scilab.modules.commons.ScilabConstants;
25 
26 /**
27  * A {@link URLStreamHandler} that handles images resource.
28  */
29 public class Handler extends URLStreamHandler {
30 
31     private static String JARPATH = new File(ScilabConstants.SCI, "/modules/helptools/jar/scilab_images.jar").getAbsoluteFile().toURI().toString();
32 
Handler()33     public Handler() {
34 
35     }
36 
37     @Override
openConnection(URL u)38     protected URLConnection openConnection(URL u) throws IOException {
39         String path = u.getPath();
40         if (path.startsWith("./")) {
41             path = path.substring(1);
42         } else {
43             path = "/" + path;
44         }
45 
46         URL jar = new URL("jar:" + JARPATH + "!" + path);
47         return jar.openConnection();
48     }
49 }
50