예제 #1
0
  static void openURL(
      JopSession session, String name, boolean newFrame, String frameName, String bookmark) {
    System.out.println("openURL " + name);
    Object root = session.getRoot();

    // Replace any URL symbol
    name = replaceUrlSymbol(session, name);
    try {
      String url_str = null;
      if (name.substring(0, 5).equals("http:")) {
        url_str = name;
        if (url_str.lastIndexOf(".html") == -1
            && url_str.lastIndexOf(".shtml") == -1
            && url_str.lastIndexOf(".htm") == -1
            && url_str.lastIndexOf(".pdf") == -1) url_str = url_str + ".html";
      } else if (name.startsWith("$pwr_doc/")) {
        URL current = ((JApplet) root).getDocumentBase();
        String current_str = current.toString();
        int idx1 = current_str.indexOf('/');
        if (idx1 != -1 && current_str.length() > idx1 + 1) {
          idx1 = current_str.indexOf('/', idx1 + 1);
          if (idx1 != -1 && current_str.length() > idx1 + 1) {
            idx1 = current_str.indexOf('/', idx1 + 1);
            if (idx1 != -1 && current_str.length() > idx1 + 1) {
              url_str = current_str.substring(0, idx1 + 1) + "pwr_doc/" + name.substring(9);
              if (url_str.lastIndexOf(".html") == -1
                  && url_str.lastIndexOf(".shtml") == -1
                  && url_str.lastIndexOf(".htm") == -1
                  && url_str.lastIndexOf(".pdf") == -1) url_str = url_str + ".html";
            }
          }
        }
      } else {
        URL current = ((JApplet) root).getCodeBase();
        String current_str = current.toString();
        int idx1 = current_str.lastIndexOf('/');
        int idx2 = current_str.lastIndexOf(':');
        int idx = idx1;
        if (idx2 > idx) idx = idx2;
        String path = current_str.substring(0, idx + 1);
        if (name.lastIndexOf(".html") == -1
            && name.lastIndexOf(".shtml") == -1
            && name.lastIndexOf(".htm") == -1
            && name.lastIndexOf(".pdf") == -1) url_str = new String(path + name + ".html");
        else url_str = new String(path + name);
        if (bookmark != null) url_str += "#" + bookmark;
      }
      System.out.println("Opening URL: " + url_str);

      URL url = new URL(url_str);
      AppletContext appCtx = ((JApplet) root).getAppletContext();
      if (newFrame) appCtx.showDocument(url, "_blank");
      else if (frameName != null) appCtx.showDocument(url, frameName);
      else appCtx.showDocument(url, "_self");
    } catch (MalformedURLException e) {
      System.out.println("MalformedURL : " + name);
    }
  }
  JarFile get(URL url, boolean useCaches) throws IOException {

    JarFile result = null;
    JarFile local_result = null;

    if (useCaches) {
      synchronized (this) {
        result = getCachedJarFile(url);
      }
      if (result == null) {
        local_result = URLJarFile.getJarFile(url);
        synchronized (this) {
          result = getCachedJarFile(url);
          if (result == null) {
            fileCache.put(url, local_result);
            urlCache.put(local_result, url);
            result = local_result;
          } else {
            if (local_result != null) {
              local_result.close();
            }
          }
        }
      }
    } else {
      result = URLJarFile.getJarFile(url);
    }
    if (result == null) throw new FileNotFoundException(url.toString());

    return result;
  }
  public ArrayList<String> parseXML() throws Exception {
    ArrayList<String> ret = new ArrayList<String>();

    handshake();

    URL url =
        new URL(
            "http://mangaonweb.com/page.do?cdn="
                + cdn
                + "&cpn=book.xml&crcod="
                + crcod
                + "&rid="
                + (int) (Math.random() * 10000));
    String page = DownloaderUtils.getPage(url.toString(), "UTF-8", cookies);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource is = new InputSource(new StringReader(page));
    Document d = builder.parse(is);
    Element doc = d.getDocumentElement();

    NodeList pages = doc.getElementsByTagName("page");
    total = pages.getLength();
    for (int i = 0; i < pages.getLength(); i++) {
      Element e = (Element) pages.item(i);
      ret.add(e.getAttribute("path"));
    }

    return (ret);
  }
예제 #4
0
  /** Create a FILE object to read from the specified filename. */
  public static FILE openFile(String filename) {
    try {
      FILE f = null;
      File file = new File(filename);

      if (file.isAbsolute()) {
        f = open(file);
      } else {
        if (documentBase != null) {
          String docBase = documentBase.toString();
          if (docBase.startsWith("file:/")) {
            docBase = docBase.substring(6);
            file = new File(docBase, filename);

            f = open(file);
          }
        }

        if (f == null && codeBase != null) {
          String cBase = codeBase.toString();
          if (cBase.startsWith("file:/")) {
            cBase = cBase.substring(6);
            file = new File(cBase, filename);

            f = open(file);
          }
        }

        if (f == null) {
          file = new File(filename);

          f = open(file);
        }
      }

      return f;
    } catch (Exception e) {
      setException(e);

      if (debug) {
        System.out.println("openFile: " + e);
      }
      return null;
    }
  }
예제 #5
0
  public static void parse(String fileNameOrURL, RDFParser parser, Model model)
      throws IOException, SAXException, MalformedURLException, ModelException {

    URL url = new URL(normalizeURI(fileNameOrURL));

    // maybe this model is loaded as schema...
    //    Model model = factory.registry().get(url.toString());
    //    if(model != null)
    //      return model;

    // Prepare input source
    model.setSourceURI(url.toString());
    InputStream in = url.openStream();
    InputSource source = new InputSource(in);
    source.setSystemId(url.toString());

    parser.parse(source, new ModelConsumer(model));
    in.close();
  }
  /**
   * Load grid configuration for specified node type.
   *
   * @param type Node type to load configuration for.
   * @return Grid configuration for specified node type.
   */
  static IgniteConfiguration getConfig(String type) {
    String path = NODE_CFG.get(type);

    if (path == null) throw new IllegalArgumentException("Unsupported node type: " + type);

    URL url = U.resolveIgniteUrl(path);

    BeanFactory ctx = new FileSystemXmlApplicationContext(url.toString());

    return (IgniteConfiguration) ctx.getBean("grid.cfg");
  }
  private T requestInfo(URI baseUrl, RenderingContext context)
      throws IOException, URISyntaxException, ParserConfigurationException, SAXException {
    URL url = loader.createURL(baseUrl, context);

    GetMethod method = null;
    try {
      final InputStream stream;

      if ((url.getProtocol().equals("http") || url.getProtocol().equals("https"))
          && context.getConfig().localHostForwardIsFrom(url.getHost())) {
        String scheme = url.getProtocol();
        final String host = url.getHost();
        if (url.getProtocol().equals("https")
            && context.getConfig().localHostForwardIsHttps2http()) {
          scheme = "http";
        }
        URL localUrl = new URL(scheme, "localhost", url.getPort(), url.getFile());
        HttpURLConnection connexion = (HttpURLConnection) localUrl.openConnection();
        connexion.setRequestProperty("Host", host);
        for (Map.Entry<String, String> entry : context.getHeaders().entrySet()) {
          connexion.setRequestProperty(entry.getKey(), entry.getValue());
        }
        stream = connexion.getInputStream();
      } else {
        method = new GetMethod(url.toString());
        for (Map.Entry<String, String> entry : context.getHeaders().entrySet()) {
          method.setRequestHeader(entry.getKey(), entry.getValue());
        }
        context.getConfig().getHttpClient(baseUrl).executeMethod(method);
        int code = method.getStatusCode();
        if (code < 200 || code >= 300) {
          throw new IOException(
              "Error "
                  + code
                  + " while reading the Capabilities from "
                  + url
                  + ": "
                  + method.getStatusText());
        }
        stream = method.getResponseBodyAsStream();
      }
      final T result;
      try {
        result = loader.parseInfo(stream);
      } finally {
        stream.close();
      }
      return result;
    } finally {
      if (method != null) {
        method.releaseConnection();
      }
    }
  }
예제 #8
0
 @Override
 public InputSource resolveEntity(String publicId, String systemId) {
   if (systemId != null && systemId.endsWith("dtd")) {
     URL url = FileFuncs.getResource(RuntimeProperties.PACKAGE_DTD, true);
     if (url != null) {
       return new InputSource(url.toString());
     }
     // if unable to find dtd in local fs, try getting it from web
     return new InputSource(RuntimeProperties.SCHEMA_LOC + RuntimeProperties.PACKAGE_DTD);
   }
   return null;
 }
예제 #9
0
  private void buildUrlSets(String url) {

    try {
      outputMessage("\nFetching " + url, TEST_SUMMARY_MESSAGE);
      URL srcUrl = new URL(url);
      //       URLConnection conn = srcUrl.openConnection();
      //       String type = conn.getContentType();
      //       type = conn.getHeaderField("content-type");
      //       InputStream istr = conn.getInputStream();

      LockssUrlConnection conn = UrlUtil.openConnection(url, connectionPool);
      if (proxyHost != null) {
        conn.setProxy(proxyHost, proxyPort);
      }
      if (userAgent != null) {
        conn.setRequestProperty("user-agent", userAgent);
      }
      try {
        conn.execute();
        int resp = conn.getResponseCode();
        if (resp != 200) {
          outputMessage("Resp: " + resp + ": " + conn.getResponseMessage(), TEST_SUMMARY_MESSAGE);
          return;
        }
        depth_fetched[m_curDepth - 1]++;
        String cookies = conn.getResponseHeaderValue("Set-Cookie");
        if (cookies != null) {
          outputMessage("Cookies: " + cookies, PLAIN_MESSAGE);
        }
        String type = conn.getResponseContentType();
        if (type == null || !type.toLowerCase().startsWith("text/html")) {
          outputMessage("Type: " + type + ", not parsing", URL_SUMMARY_MESSAGE);
          return;
        }
        outputMessage("Type: " + type + ", extracting Urls", URL_SUMMARY_MESSAGE);
        InputStream istr = conn.getResponseInputStream();
        InputStreamReader reader = new InputStreamReader(istr);
        //       MyMockCachedUrl mcu = new MyMockCachedUrl(srcUrl.toString(), reader);
        GoslingHtmlLinkExtractor extractor = new GoslingHtmlLinkExtractor();
        extractor.extractUrls(null, istr, null, srcUrl.toString(), new MyLinkExtractorCallback());
        istr.close();
        depth_parsed[m_curDepth - 1]++;
      } finally {
        conn.release();
      }
    } catch (MalformedURLException murle) {
      murle.printStackTrace();
      outputErrResults(url, "Malformed URL:" + murle.getMessage());
    } catch (IOException ex) {
      ex.printStackTrace();
      outputErrResults(url, "IOException: " + ex.getMessage());
    }
  }
예제 #10
0
  @Test(
      description = "Verify the downloads links return 200 rather than 404",
      groups = {"functional"})
  public void DownloadsTab_02() throws HarnessException {

    // Determine which links should be present
    List<String> locators = new ArrayList<String>();

    if (ZimbraSeleniumProperties.zimbraGetVersionString().contains("NETWORK")) {

      locators.addAll(Arrays.asList(NetworkOnlyLocators));
      locators.addAll(Arrays.asList(CommonLocators));

    } else if (ZimbraSeleniumProperties.zimbraGetVersionString().contains("FOSS")) {

      locators.addAll(Arrays.asList(FossOnlyLocators));
      locators.addAll(Arrays.asList(CommonLocators));

    } else {
      throw new HarnessException(
          "Unable to find NETWORK or FOSS in version string: "
              + ZimbraSeleniumProperties.zimbraGetVersionString());
    }

    for (String locator : locators) {
      String href = app.zPageDownloads.sGetAttribute("xpath=" + locator + "@href");
      String page = ZimbraSeleniumProperties.getBaseURL() + href;

      HttpURLConnection connection = null;
      try {

        URL url = new URL(page);
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("HEAD");
        int code = connection.getResponseCode();

        // TODO: why is 400 returned for the PDF links?
        // 200 and 400 are acceptable
        ZAssert.assertStringContains(
            "200 400", "" + code, "Verify the download URL is valid: " + url.toString());

      } catch (MalformedURLException e) {
        throw new HarnessException(e);
      } catch (IOException e) {
        throw new HarnessException(e);
      } finally {
        if (connection != null) {
          connection.disconnect();
          connection = null;
        }
      }
    }
  }
예제 #11
0
 private ExternalizableMap loadMap(String extMapName, ClassLoader loader)
     throws FileNotFoundException {
   String first = null;
   String next = extMapName;
   List<String> urls = new ArrayList<String>();
   ExternalizableMap res = null;
   while (next != null) {
     // convert the plugin class name to an xml file name
     String mapFile = next.replace('.', '/') + MAP_SUFFIX;
     URL url = loader.getResource(mapFile);
     if (url != null && urls.contains(url.toString())) {
       throw new PluginException.InvalidDefinition("Plugin inheritance loop: " + next);
     }
     // load into map
     ExternalizableMap oneMap = new ExternalizableMap();
     oneMap.loadMapFromResource(mapFile, loader);
     urls.add(url.toString());
     // apply overrides one plugin at a time in inheritance chain
     processOverrides(oneMap);
     if (res == null) {
       res = oneMap;
     } else {
       for (Map.Entry ent : oneMap.entrySet()) {
         String key = (String) ent.getKey();
         Object val = ent.getValue();
         if (!res.containsKey(key)) {
           res.setMapElement(key, val);
         }
       }
     }
     if (oneMap.containsKey(KEY_PLUGIN_PARENT)) {
       next = oneMap.getString(KEY_PLUGIN_PARENT);
     } else {
       next = null;
     }
   }
   loadedFromUrls = urls;
   return res;
 }
예제 #12
0
  public static String normalizeURI(String uri) {

    // normalise uri
    URL url = null;
    try {
      url = new URL(uri);
    } catch (Exception e) {
      try {
        if (uri.indexOf(':') == -1) url = new URL("file", null, uri);
      } catch (Exception e2) {
      }
    }
    return url != null ? url.toString() : uri;
  }
  private static String[] findStandardMBeans(URL codeBase) throws Exception {
    Set<String> names;
    if (codeBase.getProtocol().equalsIgnoreCase("file") && codeBase.toString().endsWith("/"))
      names = findStandardMBeansFromDir(codeBase);
    else names = findStandardMBeansFromJar(codeBase);

    Set<String> standardMBeanNames = new TreeSet<String>();
    for (String name : names) {
      if (name.endsWith("MBean")) {
        String prefix = name.substring(0, name.length() - 5);
        if (names.contains(prefix)) standardMBeanNames.add(prefix);
      }
    }
    return standardMBeanNames.toArray(new String[0]);
  }
  private void initDriverList() {
    try {
      Thread thread = Thread.currentThread();
      ClassLoader loader = thread.getContextClassLoader();

      Enumeration iter = loader.getResources("META-INF/services/java.sql.Driver");
      while (iter.hasMoreElements()) {
        URL url = (URL) iter.nextElement();

        ReadStream is = null;
        try {
          is = Vfs.lookup(url.toString()).openRead();

          String filename;

          while ((filename = is.readLine()) != null) {
            int p = filename.indexOf('#');

            if (p >= 0) filename = filename.substring(0, p);

            filename = filename.trim();
            if (filename.length() == 0) continue;

            try {
              Class cl = Class.forName(filename, false, loader);
              Driver driver = null;

              if (Driver.class.isAssignableFrom(cl)) driver = (Driver) cl.newInstance();

              if (driver != null) {
                log.fine(L.l("DatabaseManager adding driver '{0}'", driver.getClass().getName()));

                _driverList.add(driver);
              }
            } catch (Exception e) {
              log.log(Level.FINE, e.toString(), e);
            }
          }
        } catch (Exception e) {
          log.log(Level.FINE, e.toString(), e);
        } finally {
          if (is != null) is.close();
        }
      }
    } catch (Exception e) {
      log.log(Level.FINE, e.toString(), e);
    }
  }
예제 #15
0
 /** Remove data component data JAR from cache */
 public static void removeInstallerComponent() {
   DownloadService downloadService = Config.getDownloadService();
   if (downloadService != null) {
     String component = Config.getInstallerLocation();
     String version = Config.getInstallerVersion();
     try {
       URL codebase = Config.getBasicService().getCodeBase();
       URL url = new URL(codebase, component);
       component = url.toString();
       Config.trace("Removing: " + component + "/" + version);
       downloadService.removeResource(url, version);
     } catch (IOException ioe) {
       Config.trace("Unable to remove " + component + "/" + version);
     }
   } else {
     Config.trace("No download service found");
   }
 }
예제 #16
0
 /** ** Sets the 'port' */
 public boolean setPort(int _port) {
   String uri = this.getURI();
   if ((_port > 0) && URIArg.isAbsoluteURL(uri)) {
     try {
       URL oldURI = new URL(uri);
       String proto = oldURI.getProtocol();
       String host = oldURI.getHost();
       int port = _port;
       String file = oldURI.getFile();
       URL newURI = new URL(proto, host, port, file);
       this._setURI(newURI.toString());
       return true;
     } catch (MalformedURLException mue) {
       // error
     }
   }
   return false;
 }
예제 #17
0
  /** Download data component JAR */
  public static boolean downloadInstallerComponent() {
    DownloadService downloadService = Config.getDownloadService();
    DownloadServiceListener listener = downloadService.getDefaultProgressWindow();
    String compName = Config.getInstallerLocation();
    String compVer = Config.getInstallerVersion();
    try {
      URL codebase = Config.getBasicService().getCodeBase();
      URL url = new URL(codebase, compName);
      String urlstr = url.toString();

      if (!downloadService.isResourceCached(url, compVer)) {
        // The installFailed string is only for debugging. No localization needed
        Config.trace("Downloading: " + urlstr);
        // Do download
        downloadService.loadResource(url, compVer, listener);
      }
    } catch (IOException ioe) {
      Config.trace("Unable to download: " + compName + "/" + compVer);
      return false;
    }
    return true;
  }
예제 #18
0
  @Test(groups = {"pulse"}) // test method
  public void testUserTx() throws Exception {

    try {

      String testurl =
          "http://" + host + ":" + port + "/" + strContextRoot + "/MyServlet?testcase=usertx";
      URL url = new URL(testurl);
      echo("Connecting to: " + url.toString());
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.connect();
      int responseCode = conn.getResponseCode();

      InputStream is = conn.getInputStream();
      BufferedReader input = new BufferedReader(new InputStreamReader(is));

      String line = null;
      boolean result = false;
      String testLine = null;
      String EXPECTED_RESPONSE = "user-tx-commit:true";
      String EXPECTED_RESPONSE2 = "user-tx-rollback:true";
      while ((line = input.readLine()) != null) {
        // echo(line);
        if (line.indexOf(EXPECTED_RESPONSE) != -1 && line.indexOf(EXPECTED_RESPONSE2) != -1) {
          testLine = line;
          echo(testLine);
          result = true;
          break;
        }
      }

      Assert.assertEquals(result, true, "Unexpected Results");

    } catch (Exception e) {
      e.printStackTrace();
      throw new Exception(e);
    }
  }
예제 #19
0
 public void run(String arg) {
   if (arg.equals("menus")) {
     updateMenus();
     return;
   }
   if (IJ.getApplet() != null) return;
   URL url = getClass().getResource("/ij/IJ.class");
   String ij_jar = url == null ? null : url.toString().replaceAll("%20", " ");
   if (ij_jar == null || !ij_jar.startsWith("jar:file:")) {
     error("Could not determine location of ij.jar");
     return;
   }
   int exclamation = ij_jar.indexOf('!');
   ij_jar = ij_jar.substring(9, exclamation);
   if (IJ.debugMode) IJ.log("Updater (jar loc): " + ij_jar);
   File file = new File(ij_jar);
   if (!file.exists()) {
     error("File not found: " + file.getPath());
     return;
   }
   if (!file.canWrite()) {
     String msg = "No write access: " + file.getPath();
     error(msg);
     return;
   }
   String[] list = openUrlAsList(IJ.URL + "/download/jars/list.txt");
   int count = list.length + 3;
   String[] versions = new String[count];
   String[] urls = new String[count];
   String uv = getUpgradeVersion();
   if (uv == null) return;
   versions[0] = "v" + uv;
   urls[0] = IJ.URL + "/upgrade/ij.jar";
   if (versions[0] == null) return;
   for (int i = 1; i < count - 2; i++) {
     String version = list[i - 1];
     versions[i] = version.substring(0, version.length() - 1); // remove letter
     urls[i] =
         IJ.URL + "/download/jars/ij" + version.substring(1, 2) + version.substring(3, 6) + ".jar";
   }
   versions[count - 2] = "daily build";
   urls[count - 2] = IJ.URL + "/ij.jar";
   versions[count - 1] = "previous";
   urls[count - 1] = IJ.URL + "/upgrade/ij2.jar";
   int choice = showDialog(versions);
   if (choice == -1 || !Commands.closeAll()) return;
   // System.out.println("choice: "+choice);
   // for (int i=0; i<urls.length; i++) System.out.println("  "+i+" "+urls[i]);
   byte[] jar = null;
   if ("daily build".equals(versions[choice]) && notes != null && notes.contains(" </title>"))
     jar = getJar("http://wsr.imagej.net/download/daily-build/ij.jar");
   if (jar == null) jar = getJar(urls[choice]);
   if (jar == null) {
     error("Unable to download ij.jar from " + urls[choice]);
     return;
   }
   Prefs.savePreferences();
   // System.out.println("saveJar: "+file);
   saveJar(file, jar);
   if (choice < count - 2) // force macro Function Finder to download fresh list
   new File(IJ.getDirectory("macros") + "functions.html").delete();
   System.exit(0);
 }
예제 #20
0
 public void run(String arg) {
   if (arg.equals("menus")) {
     updateMenus();
     return;
   }
   if (IJ.getApplet() != null) return;
   // File file = new File(Prefs.getHomeDir() + File.separator + "ij.jar");
   // if (isMac() && !file.exists())
   //	file = new File(Prefs.getHomeDir() + File.separator +
   // "ImageJ.app/Contents/Resources/Java/ij.jar");
   URL url = getClass().getResource("/ij/IJ.class");
   String ij_jar = url == null ? null : url.toString().replaceAll("%20", " ");
   if (ij_jar == null || !ij_jar.startsWith("jar:file:")) {
     error("Could not determine location of ij.jar");
     return;
   }
   int exclamation = ij_jar.indexOf('!');
   ij_jar = ij_jar.substring(9, exclamation);
   if (IJ.debugMode) IJ.log("Updater: " + ij_jar);
   File file = new File(ij_jar);
   if (!file.exists()) {
     error("File not found: " + file.getPath());
     return;
   }
   if (!file.canWrite()) {
     String msg = "No write access: " + file.getPath();
     if (IJ.isVista()) msg += Prefs.vistaHint;
     error(msg);
     return;
   }
   String[] list = openUrlAsList(IJ.URL + "/download/jars/list.txt");
   int count = list.length + 2;
   String[] versions = new String[count];
   String[] urls = new String[count];
   String uv = getUpgradeVersion();
   if (uv == null) return;
   versions[0] = "v" + uv;
   urls[0] = IJ.URL + "/upgrade/ij.jar";
   if (versions[0] == null) return;
   for (int i = 1; i < count - 1; i++) {
     String version = list[i - 1];
     versions[i] = version.substring(0, version.length() - 1); // remove letter
     urls[i] =
         IJ.URL + "/download/jars/ij" + version.substring(1, 2) + version.substring(3, 6) + ".jar";
   }
   versions[count - 1] = "daily build";
   urls[count - 1] = IJ.URL + "/ij.jar";
   int choice = showDialog(versions);
   if (choice == -1) return;
   if (!versions[choice].startsWith("daily")
       && versions[choice].compareTo("v1.39") < 0
       && Menus.getCommands().get("ImageJ Updater") == null) {
     String msg =
         "This command is not available in versions of ImageJ prior\n"
             + "to 1.39 so you will need to install the plugin version at\n"
             + "<"
             + IJ.URL
             + "/plugins/imagej-updater.html>.";
     if (!IJ.showMessageWithCancel("Update ImageJ", msg)) return;
   }
   byte[] jar = getJar(urls[choice]);
   // file.renameTo(new File(file.getParent()+File.separator+"ij.bak"));
   if (version().compareTo("1.37v") >= 0) Prefs.savePreferences();
   // if (!renameJar(file)) return; // doesn't work on Vista
   saveJar(file, jar);
   if (choice < count - 1) // force macro Function Finder to download fresh list
   new File(IJ.getDirectory("macros") + "functions.html").delete();
   System.exit(0);
 }
 public static void main(String[] args) throws InterruptedException {
   for (URL url : discoverWsDevicesAsUrls()) {
     System.out.println("Device discovered: " + url.toString());
   }
 }
예제 #22
0
 /** Retourne le Stream associé à une URL */
 public InputStream get(URL url) throws Exception {
   return get(url.toString());
 }
예제 #23
0
  public static Image getImage(JopSession session, String image) {
    String fullName;
    if (session.getRoot() instanceof JopApplet) {
      String name;
      try {
        URL current = ((JApplet) session.getRoot()).getCodeBase();
        String current_str = current.toString();
        int idx1 = current_str.lastIndexOf('/');
        int idx2 = current_str.lastIndexOf(':');
        int idx = idx1;
        if (idx2 > idx) idx = idx2;
        String path = current_str.substring(0, idx + 1);
        String url_str;

        //        String url_str = new String( path + name);
        if (image.substring(0, 5).compareTo("jpwr/") == 0) {
          idx = image.lastIndexOf('/');
          name = image.substring(5, idx);

          url_str = new String("jar:" + path + "pwr_" + name + ".jar!/" + image);
        } else {
          idx = image.lastIndexOf('/');
          if (idx == -1) name = new String(image);
          else name = image.substring(idx + 1);

          url_str = new String("jar:" + path + "pwrp_" + systemName + "_web.jar!/" + name);
        }
        System.out.println("Opening URL: " + url_str);
        URL url = new URL(url_str);
        return Toolkit.getDefaultToolkit().getImage(url);
      } catch (MalformedURLException e) {
      }
      return null;
    } else {
      // Add default directory /pwrp/img
      System.out.println("Image: " + image);

      //      int idx = image.lastIndexOf('/');
      //      if ( idx == -1)
      //  fullName = new String("/pwrp/img/" + image);
      // else
      fullName = new String(image);
      //      return Toolkit.getDefaultToolkit().getImage( fullName);

      try {
        String name;
        String url_str;
        int idx;
        String path = new String("file://");
        if (image.substring(0, 5).compareTo("jpwr/") == 0) {
          idx = image.lastIndexOf('/');
          name = image.substring(5, idx);

          url_str = new String("$pwr_lib/pwr_" + name + ".jar");
          url_str = Gdh.translateFilename(url_str);
          url_str = new String("jar:" + path + url_str + "!/" + image);
        } else {
          idx = image.lastIndexOf('/');
          if (idx == -1) name = new String(image);
          else name = image.substring(idx + 1);

          url_str = new String("$pwrp_lib/pwrp_" + systemName + ".jar");
          System.out.println("java: " + url_str);
          url_str = Gdh.translateFilename(url_str);
          url_str = new String("jar:" + path + url_str + "!/" + name);
        }
        System.out.println("Opening URL: " + url_str);
        URL url = new URL(url_str);
        return Toolkit.getDefaultToolkit().getImage(url);
      } catch (MalformedURLException e) {
      }
    }
    return null;
  }
 private static Set<String> findStandardMBeansFromDir(URL codeBase) throws Exception {
   File dir = new File(new URI(codeBase.toString()));
   Set<String> names = new TreeSet<String>();
   scanDir(dir, "", names);
   return names;
 }