Example usage for java.net URI isAbsolute

List of usage examples for java.net URI isAbsolute

Introduction

In this page you can find the example usage for java.net URI isAbsolute.

Prototype

public boolean isAbsolute() 

Source Link

Document

Tells whether or not this URI is absolute.

Usage

From source file:org.restcomm.connect.http.client.rcmlserver.resolver.RcmlserverResolver.java

public URI resolveRelative(URI uri) {
    if (uri != null && rvdOrigin != null && filterPrefix != null) {
        if (uri.isAbsolute())
            return uri;
        try {//from w  w w .  j  a va 2 s. co  m
            String uriString = uri.toString();
            if (uriString.startsWith(filterPrefix))
                return new URI(rvdOrigin + uri.toString());
        } catch (URISyntaxException e) {
            logger.error("Cannot resolve uri: " + uri.toString() + ". Ignoring...", e);
        }
    }
    return uri;
}

From source file:org.nabucco.testautomation.engine.proxy.web.component.captcha.ReadCaptchaCommand.java

/**
 * {@inheritDoc}//  ww  w .j  a v  a 2s .  c  o  m
 */
@Override
public PropertyList executeCallback(Metadata metadata, PropertyList properties) throws WebComponentException {

    String captchaId = this.getComponentLocator(metadata);

    try {
        this.waitForElement(captchaId);
        captchaId += SRC_ATTRIBUTE;
        String imageLocation = this.getSelenium().getAttribute(captchaId);
        URI uri = new URI(imageLocation);

        if (!uri.isAbsolute()) {
            URI currentLocation = new URI(this.getSelenium().getLocation());
            uri = currentLocation.resolve(uri);
        }
        URL url = uri.toURL();

        this.start();
        this.getSelenium().openWindow(url.toString(), CAPTCHA_WINDOW);
        this.getSelenium().waitForPopUp(CAPTCHA_WINDOW, this.getTimeout());
        this.getSelenium().selectWindow(CAPTCHA_WINDOW);
        this.imageData = decode(this.getSelenium().captureEntirePageScreenshotToString("background=#FFFFFF"));
        this.getSelenium().close();
        this.getSelenium().selectWindow(null);
        this.stop();
        return null;
    } catch (IOException ex) {
        this.stop();
        this.setException(ex);
        throw new WebComponentException("Error during captcha identification: " + ex.getMessage());
    } catch (URISyntaxException ex) {
        this.stop();
        this.setException(ex);
        throw new WebComponentException("Error locating WebCaptcha: " + ex.getMessage());
    }
}

From source file:com.sworddance.util.UriFactoryImpl.java

public static URI createUriWithOptions(Object uriStr, boolean schemaRequired, boolean pathRequired) {
    URI uri = createUri(uriStr);
    if (uri != null && uriStr != null) {
        String newUriStr = uriStr.toString();
        String path = uri.getRawPath();
        if (pathRequired && isEmpty(path)) {
            String rawQuery = uri.getRawQuery();
            newUriStr += PATH_SEPARATOR + (rawQuery == null ? "" : rawQuery);
        }/*from  ww  w . j a v  a  2  s.c  o  m*/
        if (schemaRequired && !uri.isAbsolute() && !newUriStr.startsWith(PATH_SEPARATOR)) {
            // TODO: check for a relative uri! will produce something like http:/httpdocs/demo if newUriStr does not have host information.
            newUriStr = "//" + newUriStr;
        }
        //noinspection StringEquality
        if (uriStr != newUriStr) {
            uri = createUri(newUriStr);
        }
    }
    return uri;
}

From source file:com.github.caldav4j.CalDAVCalendarCollectionBase.java

/**
 * Sets base path. Also set the host, based on if the path was Absolute
 * @param path Calendar Collection Root//from w  w w  . ja  v  a2  s. c  o  m
 */
public void setCalendarCollectionRoot(String path) {
    URI temp = URI.create(path);
    if (temp.isAbsolute())
        setHttpHost(URIUtils.extractHost(temp));

    this.calendarCollectionRoot = UrlUtils.removeDoubleSlashes(UrlUtils.ensureTrailingSlash(temp.getPath()));
}

From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.WSDLActivityParser.java

@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
        ParserState parserState) throws ReaderException {
    WSDLConfig wsdlConfig = unmarshallConfig(t2FlowParser, configBean, "xstream", WSDLConfig.class);

    Configuration configuration = new Configuration();
    configuration.setType(WSDL.resolve("#Config"));

    URI wsdl;
    try {//w  w w. j  a  v a  2 s .  c  om
        wsdl = URI.create(wsdlConfig.getWsdl());
        if (!wsdl.isAbsolute())
            throw new ReaderException("WSDL URI is not absolute: " + wsdlConfig.getWsdl());
    } catch (IllegalArgumentException ex) {
        throw new ReaderException("WSDL not a valid URI: " + wsdlConfig.getWsdl());
    } catch (NullPointerException ex) {
        throw new ReaderException("WSDL config has no wsdl set");
    }
    String operation = wsdlConfig.getOperation();
    if (operation == null || operation.equals(""))
        throw new ReaderException("WSDL config has no operation set");

    ObjectNode json = (ObjectNode) configuration.getJson();

    ObjectNode wsdlOperation = json.objectNode();
    json.put("operation", wsdlOperation);

    wsdlOperation.put("wsdl", wsdl.toString());
    wsdlOperation.put("name", operation);

    if (wsdlConfig.getSecurityProfile() != null && !wsdlConfig.getSecurityProfile().isEmpty()) {
        URI securityProfileURI = SECURITY.resolve("#" + wsdlConfig.getSecurityProfile());
        json.put("securityProfile", securityProfileURI.toString());
    }
    return configuration;
}

From source file:com.github.fge.jsonschema.load.URIManager.java

/**
 * Get the content at a given URI as a {@link JsonNode}
 *
 * @param uri the URI//w w  w .  j av  a 2 s.c  o m
 * @return the content
 * @throws ProcessingException scheme is not registered, failed to get
 * content, or content is not JSON
 */
public JsonNode getContent(final URI uri) throws ProcessingException {
    Preconditions.checkNotNull(uri, "null URI");

    final URI target = schemaRedirects.containsKey(uri) ? schemaRedirects.get(uri) : uri;

    if (!target.isAbsolute())
        throw new ProcessingException(BUNDLE.message("uriNotAbsolute").put("uri", uri));

    final String scheme = target.getScheme();

    final URIDownloader downloader = downloaders.get(scheme);

    if (downloader == null)
        throw new ProcessingException(BUNDLE.message("unhandledScheme").put("uri", uri).put("scheme", scheme));

    final InputStream in;

    try {
        in = downloader.fetch(target);
        return READER.readTree(in);
    } catch (JsonProcessingException e) {
        throw new ProcessingException(
                BUNDLE.message("uriNotJson").put("uri", uri).put("parsingMessage", e.getOriginalMessage()));
    } catch (IOException e) {
        throw new ProcessingException(
                BUNDLE.message("uriIOError").put("uri", uri).put("exceptionMessage", e.getMessage()));
    }
}

From source file:org.alfresco.module.vti.web.fp.GetDocsMetaInfoMethod.java

private boolean urlIsAbsolute(String url) {
    String pathEncodedURL;//from  w  w  w .  j a  v  a 2s  .co m
    try {
        // Encode the path part of since this may have spaces in it, for example. 
        pathEncodedURL = URIUtil.encodePath(url, "UTF-8");
    } catch (URIException error) {
        throw new IllegalArgumentException("Invalid URL: " + url, error);
    }
    URI uriObj = URI.create(pathEncodedURL);
    return uriObj.isAbsolute();
}

From source file:com.igormaznitsa.nbmindmap.nb.refactoring.elements.MoveFileActionPlugin.java

@Override
protected Problem processFile(final Project project, final int level, final File projectFolder,
        final FileObject fileObject) {
    final MMapURI fileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null);

    final Lookup targetLookup = this.refactoring.getTarget();
    if (targetLookup == null) {
        return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantFindLookup"));
    }//  w ww  .j ava2  s.c o  m

    final URL targetURL = targetLookup.lookup(URL.class);

    if (targetURL != null) {
        try {
            URI baseURI = targetURL.toURI();
            if (baseURI.isAbsolute()) {
                final URI projectURI = Utilities.toURI(projectFolder);
                baseURI = projectURI.relativize(baseURI);
            }

            final MMapURI newFileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null)
                    .replaceBaseInPath(true, baseURI, level);

            for (final FileObject mmap : allMapsInProject(project)) {
                try {
                    if (doesMindMapContainFileLink(project, mmap, fileAsURI)) {
                        final MoveElement element = new MoveElement(new MindMapLink(mmap), projectFolder,
                                MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null));
                        element.setTarget(newFileAsURI);
                        addElement(element);
                    }
                } catch (Exception ex) {
                    ErrorManager.getDefault().notify(ex);
                    return new Problem(true, BUNDLE.getString("Refactoring.CantProcessMindMap"));
                }
            }
        } catch (URISyntaxException ex) {
            LOGGER.error("Can't make new file uri for " + fileObject.getPath(), ex); //NOI18N
            return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantMakeURIForFile")); //NOI18N
        }
        return null;
    } else {
        return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantFindURL"));
    }
}

From source file:eu.supersede.fe.rest.NotificationRest.java

@RequestMapping("")
public List<Notification> getByUserId(Authentication authentication, HttpServletRequest request,
        @RequestParam(defaultValue = "true") Boolean toRead) {
    String scheme;/*  w ww  . j  a  va 2  s.  c  om*/
    String host;
    String port;

    if (request.getHeader("x-forwarded-proto") != null || request.getHeader("x-forwarded-host") != null
            || request.getHeader("x-forwarded-port") != null) {
        scheme = request.getHeader("x-forwarded-proto") != null ? request.getHeader("x-forwarded-proto")
                : "http";
        host = request.getHeader("x-forwarded-host") != null ? request.getHeader("x-forwarded-host")
                : request.getServerName();
        port = request.getHeader("x-forwarded-port") != null ? request.getHeader("x-forwarded-port") : null;
    } else {
        scheme = request.getScheme();
        host = request.getServerName();
        port = new Integer(request.getServerPort()).toString();
    }

    String baseUrl = port != null ? scheme + "://" + host + ":" + port + "/#/" : scheme + "://" + host + "/#/";

    DatabaseUser currentUser = (DatabaseUser) authentication.getPrincipal();
    User u = users.getOne(currentUser.getUserId());
    List<Notification> ns;

    if (toRead) {
        ns = notifications.findByUserAndReadOrderByCreationTimeDesc(u, !toRead);
    } else {
        ns = notifications.findByUserOrderByCreationTimeDesc(u);
    }

    for (Notification n : ns) {
        if (n.getLink() != null && !n.getLink().equals("")) {
            try {
                URI uri = new URI(n.getLink());

                if (!uri.isAbsolute()) {
                    n.setLink(baseUrl + n.getLink());
                }
            } catch (URISyntaxException e) {
                log.debug("Error inside link: " + e.getMessage());
            }
        }
    }

    return ns;
}

From source file:org.mcxiaoke.commons.http.util.URIUtilsEx.java

/**
 * Extracts target host from the given {@link URI}.
 * //w  ww . j a v  a2 s  . c o m
 * @param uri
 * @return the target host if the URI is absolute or
 *         <code>null</null> if the URI is
 * relative or does not contain a valid host name.
 * 
 * @since 4.1
 */
public static HttpHost extractHost(final URI uri) {
    if (uri == null) {
        return null;
    }
    HttpHost target = null;
    if (uri.isAbsolute()) {
        int port = uri.getPort(); // may be overridden later
        String host = uri.getHost();
        if (host == null) { // normal parse failed; let's do it ourselves
            // authority does not seem to care about the valid character-set
            // for host names
            host = uri.getAuthority();
            if (host != null) {
                // Strip off any leading user credentials
                int at = host.indexOf('@');
                if (at >= 0) {
                    if (host.length() > at + 1) {
                        host = host.substring(at + 1);
                    } else {
                        host = null; // @ on its own
                    }
                }
                // Extract the port suffix, if present
                if (host != null) {
                    int colon = host.indexOf(':');
                    if (colon >= 0) {
                        int pos = colon + 1;
                        int len = 0;
                        for (int i = pos; i < host.length(); i++) {
                            if (Character.isDigit(host.charAt(i))) {
                                len++;
                            } else {
                                break;
                            }
                        }
                        if (len > 0) {
                            try {
                                port = Integer.parseInt(host.substring(pos, pos + len));
                            } catch (NumberFormatException ex) {
                            }
                        }
                        host = host.substring(0, colon);
                    }
                }
            }
        }
        String scheme = uri.getScheme();
        if (host != null) {
            target = new HttpHost(host, port, scheme);
        }
    }
    return target;
}