Example usage for java.net URL equals

List of usage examples for java.net URL equals

Introduction

In this page you can find the example usage for java.net URL equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Compares this URL for equality with another object.

If the given object is not a URL then this method immediately returns false .

Two URL objects are equal if they have the same protocol, reference equivalent hosts, have the same port number on the host, and the same file and fragment of the file.

Two hosts are considered equivalent if both host names can be resolved into the same IP addresses; else if either host name can't be resolved, the host names must be equal without regard to case; or both host names equal to null.

Since hosts comparison requires name resolution, this operation is a blocking operation.

Usage

From source file:org.jactr.eclipse.ui.editor.markers.PositionMarker.java

/**
 * return the smallest position containing offset
 *///  w  ww . j ava2s.co  m
static public ASTPosition getPosition(IDocument document, URL base, int offset) {
    ASTPosition bestPosition = null;
    int size = Integer.MAX_VALUE;
    try {
        Position[] positions = document.getPositions(POSITION_ID);
        for (Position position : positions)
            if (position instanceof ASTPosition) {
                ASTPosition ap = (ASTPosition) position;

                if (base != null && !base.equals(ap.getBase()))
                    continue;

                if (ap.contains(offset) && ap.getLength() < size) {
                    bestPosition = ap;
                    size = position.getLength();
                }
            }
    } catch (BadPositionCategoryException bpce) {
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Could not get position information", bpce);
    }
    return bestPosition;
}

From source file:org.zaproxy.zap.control.ExtensionFactory.java

private static void unloadHelpSet(Extension ext) {
    HelpBroker hb = ExtensionHelp.getHelpBroker();
    if (hb == null) {
        return;//from w w w. j  a v a  2  s  . c  o m
    }

    URL helpSetUrl = getExtensionHelpSetUrl(ext);
    if (helpSetUrl != null) {
        HelpSet baseHelpSet = hb.getHelpSet();
        Enumeration<?> helpSets = baseHelpSet.getHelpSets();
        while (helpSets.hasMoreElements()) {
            HelpSet extensionHelpSet = (HelpSet) helpSets.nextElement();
            if (helpSetUrl.equals(extensionHelpSet.getHelpSetURL())) {
                baseHelpSet.remove(extensionHelpSet);
                break;
            }
        }
    }
}

From source file:brooklyn.util.ResourceUtils.java

public static URL tidy(URL url) {
    // File class has helpful methods for URIs but not URLs. So we convert.
    URI in;/*from  www  .  j  a v  a 2  s .c o  m*/
    try {
        in = url.toURI();
    } catch (URISyntaxException e) {
        throw Exceptions.propagate(e);
    }
    URI out;

    Matcher matcher = pattern.matcher(in.toString());
    if (matcher.matches()) {
        // home-relative
        File home = new File(Os.home());
        File file = new File(home, matcher.group(1));
        out = file.toURI();
    } else if (in.getScheme().equals("file:")) {
        // some other file, so canonicalize
        File file = new File(in);
        out = file.toURI();
    } else {
        // some other scheme, so no-op
        out = in;
    }

    URL urlOut;
    try {
        urlOut = out.toURL();
    } catch (MalformedURLException e) {
        throw Exceptions.propagate(e);
    }
    if (!urlOut.equals(url) && log.isDebugEnabled()) {
        log.debug("quietly changing " + url + " to " + urlOut);
    }
    return urlOut;
}

From source file:io.github.lal872k.monotifier.MyBackPack.java

public static boolean hasValidCredentials(User user, Engine engine) throws IOException {
    System.out.println("Checking validity of " + user.getName() + "'s credentials for MyBackPack...");

    final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_45);

    LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log",
            "org.apache.commons.logging.impl.NoOpLog");

    java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
    java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(Level.OFF);

    //webClient.setCssEnabled(false);
    // http://stackoverflow.com/questions/3600557/turning-htmlunit-warnings-off

    webClient.setIncorrectnessListener(new IncorrectnessListener() {

        @Override/*from ww w .j  a va  2  s .c o m*/
        public void notify(String arg0, Object arg1) {
            // TODO Auto-generated method stub

        }
    });
    webClient.setCssErrorHandler(new ErrorHandler() {

        @Override
        public void warning(CSSParseException exception) throws CSSException {
            // TODO Auto-generated method stub

        }

        @Override
        public void fatalError(CSSParseException exception) throws CSSException {
            // TODO Auto-generated method stub

        }

        @Override
        public void error(CSSParseException exception) throws CSSException {
            // TODO Auto-generated method stub

        }
    });
    webClient.setJavaScriptErrorListener(new JavaScriptErrorListener() {

        @Override
        public void scriptException(InteractivePage ip, ScriptException se) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void timeoutError(InteractivePage ip, long l, long l1) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void malformedScriptURL(InteractivePage ip, String string, MalformedURLException murle) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void loadScriptError(InteractivePage ip, URL url, Exception excptn) {
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    webClient.setHTMLParserListener(new HTMLParserListener() {

        @Override
        public void error(String string, URL url, String string1, int i, int i1, String string2) {
            //
        }

        @Override
        public void warning(String string, URL url, String string1, int i, int i1, String string2) {
            //
        }
    });

    //webClient.setThrowExceptionOnFailingStatusCode(false);
    //webClient.setThrowExceptionOnScriptError(false);

    //http://stackoverflow.com/questions/19551043/process-ajax-request-in-htmlunit/26268815#26268815
    webClient.getOptions().setJavaScriptEnabled(true);
    webClient.getOptions().setThrowExceptionOnScriptError(false);
    webClient.getOptions().setCssEnabled(false);
    webClient.setAjaxController(new NicelyResynchronizingAjaxController());

    // get the page
    HtmlPage page = webClient.getPage(
            "https://peddie.seniormbp.com/SeniorApps/studentParent/attendSummary.faces?selectedMenuId=true");

    // get login form
    final HtmlForm login_form = page.getFormByName("form");

    final HtmlTextInput username = login_form.getInputByName("form:userId");
    final HtmlPasswordInput password = login_form.getInputByName("form:userPassword");

    final HtmlButtonInput login_submit = login_form.getInputByName("form:signIn");

    username.setValueAttribute(user.getMyBackPackUsername());
    password.setValueAttribute(user.getDecryptedMyBackPackPassword());

    URL oldURL = page.getUrl();

    // Now submit the form by clicking the button and get back the new page.
    page = login_submit.click();

    engine.getHistory()
            .addAction(new Action("Accessed MyBackPack",
                    "Accessed the MyBackPack of " + user.getName() + " (" + user.getID() + ")("
                            + user.getEmail() + ") to check the validity of the account credentials."));

    if (oldURL.equals(page.getUrl())) {
        return false;
    }

    return true;
}

From source file:org.jactr.eclipse.core.ast.Support.java

static public Collection<CommonTree> getVisibleChildren(CommonTree node, URL source) {
    ArrayList<CommonTree> children = new ArrayList<CommonTree>();

    if (_dontDescend.contains(node.getType()))
        return children;

    for (int i = 0; i < node.getChildCount(); i++) {
        CommonTree child = (CommonTree) node.getChild(i);
        boolean ignore = false;

        if (child instanceof DetailedCommonTree && source != null && !mustDisplay(node)) {
            URL url = ((DetailedCommonTree) child).getSource();
            ignore = url == null || !source.equals(url);
            /*/*from   www  . j a va 2  s. c  om*/
             * now we might include the node still if it contains something that
             * should be included..
             */
            if (ignore)
                ignore = getVisibleChildren(child, source).size() == 0;
        }

        if (!ignore)
            if (shouldDisplay(child))
                children.add(child);
            else if (shouldFlattern(child))
                children.addAll(getVisibleChildren(child, source));
    }
    return children;
}

From source file:org.danann.cernunnos.spring.ApplicationContextTask.java

private synchronized ApplicationContext getApplicationContext(URL config, boolean useCache) {

    if (!useCache || !config.equals(prevUrl)) {
        prevBeans = new FileSystemXmlApplicationContext(config.toExternalForm());
        prevUrl = config;/*w  w  w.j  a  v a  2 s .c  om*/
    }

    return prevBeans;

}

From source file:com.shopgun.android.sdk.network.impl.DefaultRedirectProtocol.java

/**
 * Inefficient, and simple check, but usually we won't have too many redirects so it shouldn't matter.
 * @param previouslyVisited A {@link ArrayList} to check for recursion
 * @return {@code true} if two identical url's are detected, else {@code false}
 *//*from   ww w  .j a v a 2  s.  c  o  m*/
protected boolean isInfiniteLoop(ArrayList<URL> previouslyVisited, URL redirectUrl) {
    for (int i = 0; i < previouslyVisited.size(); i++) {
        URL outer = previouslyVisited.get(i);
        for (int j = i + 1; j < previouslyVisited.size(); j++) {
            URL inner = previouslyVisited.get(j);
            if (outer.equals(inner)) {
                return true;
            }
        }
        if (outer.equals(redirectUrl)) {
            return true;
        }
    }
    return false;
}

From source file:org.trianacode.taskgraph.tool.ToolClassLoader.java

private void addPath(String path) {
    File f = new File(path);
    if (f.exists()) {
        log.debug("parsing " + f.getAbsoluteFile());
        try {//w w w  .j  av a  2s.com
            String s = f.toURI().toURL().toString();
            if (f.isDirectory() && !s.endsWith("/")) {
                s += "/";
            }
            URL u = new URL(s);
            URL[] all = getURLs();
            boolean add = true;
            for (URL url : all) {
                if (url.equals(u)) {
                    add = false;
                    break;
                }
            }
            if (add) {
                String rootPath = UrlUtils.fromFile(root).toString();
                String relPath = UrlUtils.fromFile(f).toString();
                relPath = relPath.substring(relPath.indexOf(rootPath) + rootPath.length());
                if (f.getName().equals("help") || f.getName().equals("classes") || f.getName().equals("lib")
                        || f.getName().equals("nativ")) {
                    visibleRoots.add(s);
                }
                if (s.indexOf("/help/") == -1) { // TODO HACK ALERT
                    libPaths.add(relPath);
                }

                log.debug("adding URL:" + u);
                addURL(u);
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
}

From source file:de.bayern.gdi.services.Service.java

private boolean checkURLOptionsAndSetType() {
    try {// w w w .j  a  va2 s.  co  m
        URL newURL = guessURL(this.serviceURL);
        if (!newURL.equals(this.serviceURL)) {
            if (ServiceChecker.isReachable(newURL)) {
                ServiceType st;
                if (ServiceChecker.isRestricted(newURL)) {
                    st = ServiceChecker.checkService(newURL, this.username, this.password);
                } else {
                    st = ServiceChecker.checkService(newURL);
                }
                if (st != null) {
                    this.serviceURL = newURL;
                    this.serviceType = st;
                    return true;
                }
            }
        }
    } catch (Exception e) {
        return false;
    }
    return false;
}

From source file:org.trianacode.taskgraph.tool.ToolClassLoader.java

private void addToolBox(URL toolbox, boolean first, boolean descend) {
    if (UrlUtils.isFile(toolbox)) {

        try {/* w w w  .  j  a  v  a 2  s  .com*/
            File box = new File(toolbox.toURI());
            if (!box.exists() || box.getName().startsWith(".")) {
                return;
            }
            if (first) {
                root = box;
            }
            if (box.isDirectory()) {
                File[] files = box.listFiles();
                if (files == null) {
                    return;
                }
                for (File file : files) {
                    String name = file.getName();
                    if (name.startsWith(".")) {
                        continue;
                    }
                    if (file.isDirectory()) {
                        if (name.equals("classes")) {
                            addPath(file.getAbsolutePath());
                        } else if (name.equals("help")) {
                            addPath(file.getAbsolutePath());
                            addToolBox(file.toURI().toURL(), false, true);
                        } else if (name.equals("src")) {
                            continue;
                        } else if (name.equals("CVS")) {
                            continue;
                        } else if (name.equals("nativ")) {
                            addPath(file.getAbsolutePath());
                            addToolBox(file.toURI().toURL(), false, true);
                        } else {
                            if (descend) {
                                addPath(file.getAbsolutePath());
                            }
                            addToolBox(file.toURI().toURL(), false, descend);
                        }
                    } else {
                        if (name.endsWith(".jar")) {
                            addPath(file.getAbsolutePath());
                        }
                    }
                }
            } else {
                if (box.getName().endsWith(".jar")) {
                    addPath(box.getAbsolutePath());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        URL[] all = getURLs();
        boolean add = true;
        for (URL url : all) {
            if (url.equals(toolbox)) {
                add = false;
                break;
            }
        }
        if (add) {
            addURL(toolbox);
        }
    }

    log.debug("ToolClassLoader for TOOLBOX " + toolbox + " CLASSPATH:" + getClassPath());
}