Example #1
0
 /**
  * Gets the DTD for the specified doctype file name.
  *
  * @param doctype the doctype file name (e.g., "osp10.dtd")
  * @return the DTD as a string
  */
 public static String getDTD(String doctype) {
   if (dtdName != doctype) {
     // set to defaults in case doctype is not found
     dtdName = defaultName;
     try {
       String dtdPath = "/org/opensourcephysics/resources/controls/doctypes/"; // $NON-NLS-1$
       java.net.URL url = XML.class.getResource(dtdPath + doctype);
       if (url == null) {
         return dtd;
       }
       Object content = url.getContent();
       if (content instanceof InputStream) {
         BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream) content));
         StringBuffer buffer = new StringBuffer(0);
         String line;
         while ((line = reader.readLine()) != null) {
           buffer.append(line + NEW_LINE);
         }
         dtd = buffer.toString();
         dtdName = doctype;
       }
     } catch (IOException ex) {
       ex.printStackTrace();
     }
   }
   return dtd;
 }
 public void InitFunctionConfigXML(String Name) {
   String URI = null;
   if (Name == null) System.out.print("Name=null");
   if (FunctionConfigXML != null) return;
   //    RB = this.getClass().getName().replace('.','/');;
   //    RB = "Codebase/"+RB;
   java.net.URL url = JXMLResource.LoadXML(this, Name, "");
   if (url == null) {
     System.out.println("url=null");
     return;
   }
   URI = url.toString();
   //    URI = JActiveDComDM.CodeBase+RB+"/function.xml";
   FunctionConfigXML = new JXMLBaseObject();
   FunctionConfigXML.InitXMLURI(URI);
 }
  // ===================================================
  // ObjHtmlPanel.Listener
  public void linkSelected(java.net.URL href, String target) {
    String url = href.toExternalForm();
    int slash = url.lastIndexOf('/');
    if (slash > 0) url = url.substring(slash + 1);

    Job t = actionMap.get(url);
    fapp.guiRun().run(this, new Job(t.getPermissions(), t.getCBRunnable()));
  }
  // ===================================================
  // ObjHtmlPanel.Listener
  public void linkSelected(java.net.URL href, String target) {
    String url = href.toExternalForm();
    int slash = url.lastIndexOf('/');
    if (slash > 0) url = url.substring(slash + 1);

    Job job = actionMap.get(url);
    if (job != null) app.guiRun().run(this, job);
  }
  protected void downloadTile(final Tile tile, DownloadPostProcessor postProcessor) {
    if (!this.isNetworkRetrievalEnabled()) return;

    if (!WorldWind.getRetrievalService().isAvailable()) return;

    java.net.URL url;
    try {
      url = tile.getRequestURL();
      if (WorldWind.getNetworkStatus().isHostUnavailable(url)) return;
    } catch (java.net.MalformedURLException e) {
      Logging.logger()
          .log(
              java.util.logging.Level.SEVERE,
              Logging.getMessage("layers.PlaceNameLayer.ExceptionCreatingUrl", tile),
              e);
      return;
    }

    Retriever retriever;

    if ("http".equalsIgnoreCase(url.getProtocol()) || "https".equalsIgnoreCase(url.getProtocol())) {
      if (postProcessor == null) postProcessor = new DownloadPostProcessor(this, tile);
      retriever = new HTTPRetriever(url, postProcessor);
    } else {
      Logging.logger()
          .severe(
              Logging.getMessage("layers.PlaceNameLayer.UnknownRetrievalProtocol", url.toString()));
      return;
    }

    // Apply any overridden timeouts.
    Integer cto = AVListImpl.getIntegerValue(this, AVKey.URL_CONNECT_TIMEOUT);
    if (cto != null && cto > 0) retriever.setConnectTimeout(cto);
    Integer cro = AVListImpl.getIntegerValue(this, AVKey.URL_READ_TIMEOUT);
    if (cro != null && cro > 0) retriever.setReadTimeout(cro);
    Integer srl = AVListImpl.getIntegerValue(this, AVKey.RETRIEVAL_QUEUE_STALE_REQUEST_LIMIT);
    if (srl != null && srl > 0) retriever.setStaleRequestLimit(srl);

    WorldWind.getRetrievalService().runRetriever(retriever, tile.getPriority());
  }
  public static void main(String[] args) {
    // Create a Scanner
    Scanner input = new Scanner(System.in);

    // Prompt the user to enter one of file names
    System.out.print("Enter a file name for baby name ranking: ");
    String fileName = input.next();

    // Create to sets
    Set<String> set1 = new HashSet<>();
    Set<String> set2 = new HashSet<>();

    try {
      java.net.URL url = new java.net.URL("http://www.cs.armstrong.edu/liang/data/" + fileName);

      // Create input file from url and add names to sets
      Scanner inputStream = new Scanner(url.openStream());
      while (inputStream.hasNext()) {
        inputStream.next();
        set1.add(inputStream.next());
        inputStream.next();
        set2.add(inputStream.next());
        inputStream.next();
      }
    } catch (java.net.MalformedURLException ex) {
      System.out.println("Invalid URL");
    } catch (java.io.IOException ex) {
      System.out.println("I/O Errors; no such file");
    }

    // Display the names that are used for both genders
    set1.retainAll(set2);
    System.out.println(set1.size() + " names used for both genders");
    System.out.print("They are ");
    for (String name : set1) {
      System.out.print(name + " ");
    }
    System.out.println();
  }
  protected static PlaceNameChunk readTileData(Tile tile, java.net.URL url) {
    java.io.InputStream is = null;

    try {
      String path = url.getFile();
      path =
          path.replaceAll(
              "%20", " "); // TODO: find a better way to get a path usable by FileInputStream

      java.io.FileInputStream fis = new java.io.FileInputStream(path);
      java.io.BufferedInputStream buf = new java.io.BufferedInputStream(fis);
      is = new java.util.zip.GZIPInputStream(buf);

      GMLPlaceNameSAXHandler handler = new GMLPlaceNameSAXHandler();
      javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser().parse(is, handler);
      return handler.createPlaceNameChunk(tile.getPlaceNameService());
    } catch (Exception e) {
      // todo log actual error
      Logging.logger()
          .log(
              Level.FINE,
              Logging.getMessage(
                  "layers.PlaceNameLayer.ExceptionAttemptingToReadFile", url.toString()),
              e);
    } finally {
      try {
        if (is != null) is.close();
      } catch (java.io.IOException e) {
        Logging.logger()
            .log(
                Level.FINE,
                Logging.getMessage(
                    "layers.PlaceNameLayer.ExceptionAttemptingToReadFile", url.toString()),
                e);
      }
    }

    return null;
  }
Example #8
0
 private static long getLastModified(Class cls) {
   try {
     String shortName = cls.getName().substring(1 + cls.getName().lastIndexOf('.'));
     java.net.URL url = cls.getResource(shortName + ".class");
     String file = url.getFile();
     // System.out.println("url="+url);
     if ("file".equals(url.getProtocol())) {
       // example:
       // file='/home/cliffwd/cvs/dublin/nb_all/schema2beans/rt/src/org/netbeans/modules/schema2beans/GenBeans.class'
       String result = file.substring(0, file.length() - cls.getName().length() - 6);
       return new File(file).lastModified();
     } else if ("jar".equals(url.getProtocol())) {
       // example: file = 'jar:/usr/local/j2sdkee1.3.1/lib/j2ee.jar!/org/w3c/dom/Node.class'
       String jarFile = file.substring(file.indexOf(':') + 1);
       jarFile = jarFile.substring(0, jarFile.indexOf('!'));
       // System.out.println("jarFile="+jarFile);
       return new File(jarFile).lastModified();
     }
     return url.openConnection().getDate();
   } catch (java.io.IOException e) {
     return 0;
   }
 }