Example #1
0
 public void copySub(String from, String to) {
   int start = 0;
   int end = unrolled.size(); // copy to the end if unspecified
   Integer t = (Integer) partMap.get(from);
   Debug.output(1, "Unroller.copySub: from " + from + " to " + to);
   if (t != null) {
     start = t.intValue();
   }
   t = (Integer) partMap.get(to);
   if (t != null) {
     end = t.intValue();
   }
   Debug.output(
       1, "Unroller.copySub: start " + start + " end " + end + " size " + unrolled.size());
   ArrayList temp = new ArrayList(unrolled.subList(start, end));
   unrolled.addAll(temp);
 }
Example #2
0
  /**
   * Load the named file from the named directory into the given <code>Properties</code> instance.
   * If the file is not found a warning is issued. If an IOException occurs, a fatal error is
   * printed.
   *
   * @param props the instance to receive the loaded properties
   * @param dir the directory where the properties file resides
   * @param file the name of the file
   * @return true if the properties file exists and was loaded.
   */
  public static boolean loadProperties(Properties props, String dir, String file) {
    File propsFile = new File(dir, file);

    try {
      InputStream propsStream = new FileInputStream(propsFile);
      props.load(propsStream);
      if (Debug.debugging("properties")) {
        Debug.output("PropUtils: Found " + propsFile);
      }
      return true;

    } catch (java.io.FileNotFoundException e) {
      if (Debug.debugging("properties")) {
        Debug.output("PropUtils: File not found -  \"" + propsFile + "\"");
      }
    } catch (java.io.IOException e) {
      Debug.error("PropUtils: Caught IO Exception reading \"" + propsFile + "\"");
      e.printStackTrace();
    } catch (java.security.AccessControlException ace) {
    }
    return false;
  }
Example #3
0
  /**
   * Parse a list of marker names from a space separated list within a String.
   *
   * <p>
   *
   * @param markerList a string containing a space delimited list of marker names.
   * @param delim the list of tokens to look for which separate the list elements.
   * @return Vector of marker names.
   */
  public static Vector parseMarkers(String markerList, String delim) {
    Vector vector = null;

    if (markerList == null) {
      Debug.message("propertiesdetail", "PropUtils: marker list null!");
      return new Vector(0);
    }

    if (Debug.debugging("propertiesdetail")) {
      Debug.output("PropertyHandler: parsing marker list |" + markerList + "|");
    }

    // First, get rid of the quotation marks;
    markerList = markerList.replace('\"', '\0');
    // Next, tokenize the space delimited string
    StringTokenizer tokens = new StringTokenizer(markerList, delim);
    vector = new Vector(tokens.countTokens());
    while (tokens.hasMoreTokens()) {
      String name = tokens.nextToken().trim();
      vector.addElement(name);
    }
    return vector;
  }
Example #4
0
 // forget previous ID
 public void forget(String id) {
   Debug.output(1, "Unroller.forget: " + id);
   partMap.remove(id);
 }
Example #5
0
 // remember where you are by ID
 public void remember(String id) {
   Debug.output(1, "Unroller.remember: " + id + " at " + unrolled.size());
   partMap.put(id, new Integer(unrolled.size()));
 }
Example #6
0
  /**
   * Returns a URL that names either a resource, a local file, or an internet URL.
   *
   * @param askingClass the class asking for the URL. Can be null.
   * @param name name of the resource, file or URL.
   * @throws java.net.MalformedURLException
   * @return URL
   */
  public static URL getResourceOrFileOrURL(Class askingClass, String name)
      throws java.net.MalformedURLException {

    boolean DEBUG = Debug.debugging("proputils");

    if (name == null) {
      if (DEBUG) Debug.output("PropUtils.getROFOU(): null file name");
      return null;
    }

    URL retval = null;
    if (DEBUG) Debug.output("PropUtils.getROFOU(): looking for " + name);

    if (askingClass != null) {
      // First see if we have a resource by that name
      if (DEBUG) Debug.output("PropUtils.getROFOU(): checking as resource");

      retval = askingClass.getResource(name);
    }
    if (retval == null) {
      // Check the general classpath...
      if (DEBUG) Debug.output("PropUtils.getROFOU(): checking in general classpath");
      retval = Thread.currentThread().getContextClassLoader().getResource(name);
    }
    if (retval == null && !Environment.isApplet()) {
      // Check the classpath plus the share directory, which may
      // be in the openmap.jar file or in the development
      // environment.
      if (DEBUG) Debug.output("PropUtils.getROFOU(): checking with ClassLoader");
      retval = ClassLoader.getSystemResource("share/" + name);
    }

    if (retval == null && Environment.isApplet()) {
      if (DEBUG) Debug.output("PropUtils.getROFOU(): checking with URLClassLoader");
      URL[] cba = new URL[1];
      cba[0] = Environment.getApplet().getCodeBase();
      URLClassLoader ucl = URLClassLoader.newInstance(cba);
      retval = ucl.getResource(name);
    }

    // If there was no resource by that name available
    if (retval == null) {
      if (DEBUG) Debug.output("PropUtils.getROFOU(): not found as resource");

      try {
        java.io.File file = new java.io.File(name);
        if (file.exists()) {
          retval = file.toURL();
          if (DEBUG) Debug.output("PropUtils.getROFOU(): found as file :)");
        } else {
          // Otherwise treat it as a raw URL.
          if (DEBUG) Debug.output("PropUtils.getROFOU(): Not a file, checking as URL");
          retval = new URL(name);
          java.io.InputStream is = retval.openStream();
          is.close();
          if (DEBUG) Debug.output("PropUtils.getROFOU(): OK as URL :)");
        }
      } catch (java.io.IOException ioe) {
        retval = null;
      } catch (java.security.AccessControlException ace) {
        Debug.error("PropUtils: AccessControlException trying to access " + name);
        retval = null;
      } catch (Exception e) {
        Debug.error("PropUtils: caught exception " + e.getMessage());
        retval = null;
      }
    }

    if (DEBUG) {
      if (retval != null) {
        Debug.output("Resource " + name + "=" + retval.toString());
      } else {
        Debug.output("Resource " + name + " can't be found...");
      }
    }

    return retval;
  }