Пример #1
1
    public void run() {
      SearchTOCItem tocitem;
      Vector nodes = new Vector();

      // Add all the children of the topnode to the Vector of nodes.
      Enumeration children = topNode.children();
      while (children.hasMoreElements()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
        nodes.addElement(node);
      }

      debug("items found");
      HelpModel helpmodel = searchnav.getModel();
      HelpSet hs = helpmodel.getHelpSet();
      debug("hs:" + hs.toString());
      Map map = hs.getCombinedMap();
      Enumeration itemEnum = e.getSearchItems();
      while (itemEnum.hasMoreElements()) {
        SearchItem item = (SearchItem) itemEnum.nextElement();
        debug("  item: " + item);
        URL url;
        try {
          url = new URL(item.getBase(), item.getFilename());
        } catch (MalformedURLException me) {
          System.err.println(
              "Failed to create URL from " + item.getBase() + "|" + item.getFilename());
          continue;
        }
        boolean foundNode = false;
        DefaultMutableTreeNode node = null;
        Enumeration nodesEnum = nodes.elements();
        while (nodesEnum.hasMoreElements()) {
          node = (DefaultMutableTreeNode) nodesEnum.nextElement();
          tocitem = (SearchTOCItem) node.getUserObject();
          URL testURL = tocitem.getURL();
          if (testURL != null && url != null && url.sameFile(testURL)) {
            tocitem = (SearchTOCItem) node.getUserObject();
            tocitem.addSearchHit(
                new SearchHit(item.getConfidence(), item.getBegin(), item.getEnd()));
            foundNode = true;
            break;
          }
        }
        if (!foundNode) {
          tocitem = new SearchTOCItem(item);
          node = new DefaultMutableTreeNode(tocitem);
          nodes.addElement(node);
        }
      }
      reorder(nodes);
      ((DefaultTreeModel) tree.getModel()).reload();
    }
  /**
   * Test whether current Identity is identical to supplied Identity.
   *
   * @param id Identity to compare against.
   * @return true if Identities match, false otherwise.
   */
  public boolean isSameAs(Identity id) {
    boolean isSame = true;
    if (!areStringValuesSame(mPluginId, id.mPluginId)
        || !areStringValuesSame(mNetwork, id.mNetwork)
        || !areStringValuesSame(mIdentityId, id.mIdentityId)
        || !areStringValuesSame(mDisplayName, id.mDisplayName)) {
      isSame = false;
    }

    if (mNetworkUrl != null && id.mNetworkUrl != null) {
      if (!mNetworkUrl.sameFile(id.mNetworkUrl)) {
        isSame = false;
      }

    } else if (mNetworkUrl == null && id.mNetworkUrl == null) {
      // Do nothing.

    } else {
      isSame = false;
    }

    if (mIconUrl != null && id.mIconUrl != null) {
      if (!mIconUrl.sameFile(id.mIconUrl)) {
        isSame = false;
      }

    } else if (mIconUrl == null && id.mIconUrl == null) {
      // Do nothing.

    } else {
      isSame = false;
    }

    return isSame;
  }
Пример #3
0
  public static void main(String args[]) throws URISyntaxException, MalformedURLException {

    URL url = null;
    URL url1 = null;

    try {
      url = new URL(unencoded);
      url1 = new URL(encoded);
    } catch (Exception e) {
      System.out.println("Unexpected exception :" + e);
      System.exit(-1);
    }

    if (url.sameFile(url1)) {
      throw new RuntimeException("URL does not understand escaping");
    }

    /* check decoding of a URL */

    URI uri = url1.toURI();
    if (!uri.getPath().equals(path)) {
      throw new RuntimeException("Got: " + uri.getPath() + " expected: " + path);
    }

    /* check encoding of a URL */

    URI uri1 = new URI(scheme, auth, path);
    url = uri.toURL();
    if (!url.toString().equals(encoded)) {
      throw new RuntimeException("Got: " + url.toString() + " expected: " + encoded);
    }
  }
  /**
   * Copy sourceURL to destinationFile without doing any byte conversion.
   *
   * @param sourceURL The source URL
   * @param destinationFile The destination File.
   * @return true if the file was copied, false if the file was not copied because the sourceURL and
   *     the destinationFile refer to the same file.
   * @exception IOException If the source file does not exist.
   */
  public static boolean binaryCopyURLToFile(URL sourceURL, File destinationFile)
      throws IOException {
    URL destinationURL = destinationFile.getCanonicalFile().toURI().toURL();

    if (sourceURL.sameFile(destinationURL)) {
      return false;
    }

    // If sourceURL is of the form file:./foo, then we need to try again.
    File sourceFile = new File(sourceURL.getFile());

    // If the sourceURL is not a jar URL, then check to see if we
    // have the same file.
    // FIXME: should we check for !/ and !\ everywhere?
    if ((sourceFile.getPath().indexOf("!/") == -1) && (sourceFile.getPath().indexOf("!\\") == -1)) {
      try {
        if (sourceFile.getCanonicalFile().toURI().toURL().sameFile(destinationURL)) {
          return false;
        }
      } catch (IOException ex) {
        // JNLP Jar urls sometimes throw an exception here.
        // IOException constructor does not take a cause
        IOException ioException =
            new IOException("Cannot find canonical file name of '" + sourceFile + "'");
        ioException.initCause(ex);
        throw ioException;
      }
    }

    _binaryCopyStream(sourceURL.openStream(), destinationFile);

    return true;
  }
Пример #5
0
 /**
  * Check if this jar:file: resource is contained in the named resource. Eg <code>
  * jar:file:///a/b/c/foo.jar!/x.html</code> isContainedIn <code>file:///a/b/c/foo.jar</code>
  *
  * @param resource
  * @return true if resource is contained in the named resource
  * @throws MalformedURLException
  */
 @Override
 public boolean isContainedIn(Resource resource) throws MalformedURLException {
   String string = _urlString;
   int index = string.indexOf("!/");
   if (index > 0) string = string.substring(0, index);
   if (string.startsWith("jar:")) string = string.substring(4);
   URL url = new URL(string);
   return url.sameFile(resource.getURL());
 }
Пример #6
0
 /*
  * Validate a URL can be read
  */
 @Test(enabled = true)
 public void test10() throws Exception {
   URL u = new URL("http://www.oracle.com/");
   ;
   Object[] values = {u};
   SQLInputImpl sqli = new SQLInputImpl(values, map);
   URL u2 = sqli.readURL();
   assertTrue(u2.equals(u));
   assertTrue(u2.sameFile(u));
 }
  public static void main(String[] args) throws Exception {
    URL u =
        new URL(
            "jar:file:/C:/bea/user_projects/domains/mydomain/myserver/.wlnotdelete/gallery/gallery-rar.jar!/");

    // differ from a "/./"
    URL u2 =
        new URL(
            "jar:file:/C:/bea/user_projects/domains/mydomain/./myserver/.wlnotdelete/gallery/gallery-rar.jar!/");
    if (u.sameFile(u2)) {
      System.out.println("same");
    } else {
      System.out.println("differ");
    }
  }
Пример #8
0
 private DefaultMutableTreeNode findIDorURL(DefaultMutableTreeNode node, ID id, URL url) {
   SearchTOCItem item = (SearchTOCItem) node.getUserObject();
   if (item != null) {
     ID testID = item.getID();
     if (testID != null && id != null && testID.equals(id)) {
       return node;
     } else {
       URL testURL = item.getURL();
       if (testURL != null && url != null && url.sameFile(testURL)) {
         return node;
       }
     }
   }
   int size = node.getChildCount();
   for (int i = 0; i < size; i++) {
     DefaultMutableTreeNode tmp = (DefaultMutableTreeNode) node.getChildAt(i);
     DefaultMutableTreeNode test = findIDorURL(tmp, id, url);
     if (test != null) {
       return test;
     }
   }
   return null;
 }