Example usage for java.net URI getFragment

List of usage examples for java.net URI getFragment

Introduction

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

Prototype

public String getFragment() 

Source Link

Document

Returns the decoded fragment component of this URI.

Usage

From source file:com.thoughtworks.go.util.command.UrlArgument.java

@Override
public String forDisplay() {
    try {//from   w  ww .  jav a2s.com
        URI uri = new URI(sanitizeUrl());
        if (uri.getUserInfo() != null) {
            uri = new URI(uri.getScheme(), clean(uri.getScheme(), uri.getUserInfo()), uri.getHost(),
                    uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment());
        }
        return uri.toString();
    } catch (URISyntaxException e) {
        return url;
    }
}

From source file:org.eclipse.orion.internal.server.servlets.workspace.ProjectParentDecorator.java

private void addParents(URI resource, JSONObject representation, ProjectInfo project, IPath resourcePath)
        throws JSONException {
    //start at parent of current resource
    resourcePath = resourcePath.removeLastSegments(1).addTrailingSeparator();
    JSONArray parents = new JSONArray();
    //for all but the project we can just manipulate the path to get the name and location
    while (resourcePath.segmentCount() > 2) {
        try {/*  www . j  av a  2s.  c  o m*/
            URI uri = resource.resolve(new URI(null, null, resourcePath.toString(), null));
            addParent(parents, resourcePath.lastSegment(), new URI(resource.getScheme(),
                    resource.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment()));
        } catch (URISyntaxException e) {
            //ignore this parent
            LogHelper.log(e);
        }
        resourcePath = resourcePath.removeLastSegments(1);
    }
    //add the project
    if (resourcePath.segmentCount() == 2) {
        try {
            URI uri = resource.resolve(new URI(null, null, resourcePath.toString(), null));
            addParent(parents, project.getFullName(), new URI(resource.getScheme(), resource.getAuthority(),
                    uri.getPath(), uri.getQuery(), uri.getFragment()));
        } catch (URISyntaxException e) {
            //ignore this project
            LogHelper.log(e);
        }
    }
    representation.put(ProtocolConstants.KEY_PARENTS, parents);
}

From source file:nl.esciencecenter.octopus.webservice.job.OctopusManager.java

/**
 * Submit a job request.//from w w w . j a v a2 s .  c o  m
 *
 * @param request The job request
 * @param httpClient http client used to reporting status to job callback.
 * @return SandboxedJob job
 *
 * @throws OctopusIOException
 * @throws OctopusException
 * @throws URISyntaxException
 */
public SandboxedJob submitJob(JobSubmitRequest request, HttpClient httpClient)
        throws OctopusIOException, OctopusException, URISyntaxException {
    Credential credential = configuration.getCredential();
    // filesystems cant have path in them so strip eg. file:///tmp to file:///
    URI s = configuration.getSandboxRoot();
    URI sandboxURI = new URI(s.getScheme(), s.getUserInfo(), s.getHost(), s.getPort(), "/", s.getQuery(),
            s.getFragment());
    //create sandbox
    FileSystem sandboxFS = octopus.files().newFileSystem(sandboxURI, credential, null);
    String sandboxRoot = configuration.getSandboxRoot().getPath();
    AbsolutePath sandboxRootPath = octopus.files().newPath(sandboxFS, new RelativePath(sandboxRoot));
    Sandbox sandbox = request.toSandbox(octopus, sandboxRootPath, null);

    // create job description
    JobDescription description = request.toJobDescription();
    description.setQueueName(configuration.getQueue());
    description.setWorkingDirectory(sandbox.getPath().getPath());
    long cancelTimeout = configuration.getPollConfiguration().getCancelTimeout();
    // CancelTimeout is in milliseconds and MaxTime must be in minutes, so convert it
    int maxTime = (int) TimeUnit.MINUTES.convert(cancelTimeout, TimeUnit.MILLISECONDS);
    description.setMaxTime(maxTime);

    // stage input files
    sandbox.upload();

    // submit job
    Job job = octopus.jobs().submitJob(scheduler, description);

    // store job in jobs map
    SandboxedJob sjob = new SandboxedJob(sandbox, job, request, httpClient);
    jobs.put(sjob.getIdentifier(), sjob);

    // JobsPoller will poll job status and download sandbox when job is done.

    return sjob;
}

From source file:org.fcrepo.apix.loader.impl.LoaderService.java

private String toName(final URI uri) {
    if (uri.getPath() == null || uri.getPath().equals("")) {
        return null;
    }/*ww w  .  ja v a  2  s  .  c o m*/

    if (uri.getFragment() != null && !uri.getFragment().equals("")) {
        return uri.getPath() + "-" + uri.getFragment();
    } else {
        return uri.getPath();
    }
}

From source file:org.eel.kitchen.jsonschema.ref.JsonRef.java

/**
 * Main constructor, {@code protected} by design
 *
 * @param uri the URI to build that reference
 *///from  www.  j ava 2 s  .c o m
protected JsonRef(final URI uri) {
    final String scheme = uri.getScheme();
    final String ssp = uri.getSchemeSpecificPart();
    final String uriFragment = uri.getFragment();

    final String realFragment = uriFragment == null ? "" : uriFragment;

    try {
        this.uri = new URI(scheme, ssp, realFragment);
        locator = new URI(scheme, ssp, "");
        fragment = JsonFragment.fromFragment(realFragment);
        asString = this.uri.toString();
        hashCode = asString.hashCode();
    } catch (URISyntaxException e) {
        throw new RuntimeException("WTF??", e);
    }
}

From source file:org.deri.any23.http.DefaultHTTPClient.java

/**
 *
 * Opens an {@link java.io.InputStream} from a given URI.
 * It follows redirects.//from   w  w  w  . j  av a  2s . c  o  m
 *
 * @param uri to be opened
 * @return {@link java.io.InputStream}
 * @throws IOException
 */
public InputStream openInputStream(String uri) throws IOException {
    GetMethod method = null;
    try {
        ensureClientInitialized();
        String uriStr = null;
        try {
            URI uriObj = new URI(uri);
            // [scheme:][//authority][path][?query][#fragment]
            final String path = uriObj.getPath();
            final String query = uriObj.getQuery();
            final String fragment = uriObj.getFragment();
            uriStr = String
                    .format("%s://%s%s%s%s%s%s", uriObj.getScheme(), uriObj.getAuthority(),
                            path != null ? URLEncoder.encode(path, "UTF-8").replaceAll("%2F", "/") : "",
                            query == null ? "" : "?",
                            query != null ? URLEncoder.encode(query, "UTF-8").replaceAll("%3D", "=")
                                    .replaceAll("%26", "&") : "",
                            fragment == null ? "" : "#",
                            fragment != null ? URLEncoder.encode(fragment, "UTF-8") : "");
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("Invalid URI string.", e);
        }
        method = new GetMethod(uriStr);
        method.setFollowRedirects(true);
        client.executeMethod(method);
        _contentLength = method.getResponseContentLength();
        final Header contentTypeHeader = method.getResponseHeader("Content-Type");
        contentType = contentTypeHeader == null ? null : contentTypeHeader.getValue();
        if (method.getStatusCode() != 200) {
            throw new IOException(
                    "Failed to fetch " + uri + ": " + method.getStatusCode() + " " + method.getStatusText());
        }
        actualDocumentURI = method.getURI().toString();
        byte[] response = method.getResponseBody();

        return new ByteArrayInputStream(response);
    } finally {
        if (method != null) {
            method.releaseConnection();
        }
    }
}

From source file:com.esri.geoportal.commons.http.BotsHttpClient.java

private String getRelativePath(URI u) throws MalformedURLException {
    return String.format("%s%s%s", u.getPath() != null ? u.getPath() : "/",
            u.getQuery() != null ? "?" + u.getQuery() : "",
            u.getFragment() != null ? "#" + u.getFragment() : "");
}

From source file:info.magnolia.ui.admincentral.shellapp.favorites.FavoritesPresenter.java

public JcrNewNodeAdapter determinePreviousLocation() {
    JcrNewNodeAdapter favoriteLocation;//from   w  w  w . j av  a2 s  .  c o  m

    // at this point the current location in the browser hasn't yet changed to favorite shellapp,
    // so it is what we need to pre-populate the form for creating a new favorite
    final URI previousLocation = Page.getCurrent().getLocation();
    final String previousLocationFragment = previousLocation.getFragment();

    // skip bookmark resolution if for some reason fragment is empty
    if (previousLocationFragment == null) {
        return createNewFavoriteSuggestion("", "", "");
    }

    final String appName = DefaultLocation.extractAppName(previousLocationFragment);
    final String appType = DefaultLocation.extractAppType(previousLocationFragment);
    // TODO MGNLUI-1190 should this be added to DefaultLocation as a convenience static method?
    final String path = StringUtils.substringBetween(previousLocationFragment, ";", ":");

    // skip bookmark resolution shell apps
    if (Location.LOCATION_TYPE_SHELL_APP.equals(appType)) {
        favoriteLocation = createNewFavoriteSuggestion("", "", "");
    } else {
        final AppDescriptor appDescriptor;

        try {
            DefinitionProvider<AppDescriptor> definitionProvider = appDescriptorRegistry.getProvider(appName);
            appDescriptor = i18nizer.decorate(definitionProvider.get());
        } catch (Registry.NoSuchDefinitionException | IllegalStateException e) {
            throw new RuntimeException(e);
        }

        final String appIcon = StringUtils.defaultIfEmpty(appDescriptor.getIcon(), "icon-app");
        final String title = appDescriptor.getLabel() + " " + (path == null ? "/" : path);
        final String urlFragment = getUrlFragmentFromURI(previousLocation);
        favoriteLocation = createNewFavoriteSuggestion(urlFragment, title, appIcon);
    }
    return favoriteLocation;
}

From source file:org.surfnet.oaaas.resource.TokenResourceTest.java

@Test
public void testPrincipalDisplayName() {
    AuthorizationRequest authRequest = createAuthRequest(OAuth2Validator.IMPLICIT_GRANT_RESPONSE_TYPE);
    authRequest.getClient().setIncludePrincipal(true);

    AccessToken accessToken = createAccessToken();

    when(authorizationRequestRepository.findByAuthState("auth_state")).thenReturn(authRequest);
    when(request.getAttribute(AbstractAuthenticator.AUTH_STATE)).thenReturn("auth_state");
    when(request.getAttribute(AbstractUserConsentHandler.GRANTED_SCOPES))
            .thenReturn(accessToken.getScopes().toArray(new String[] {}));
    when(accessTokenRepository.save((AccessToken) any())).thenReturn(accessToken);

    URI uri = (URI) tokenResource.authorizeCallback(request).getMetadata().get("Location").get(0);

    assertEquals(/*from   w w  w .  j a va 2  s  .  c o m*/
            "http://localhost:8080#access_token=ABCDEF&token_type=bearer&expires_in=123456&scope=read,write&state=important&principal=sammy%20sammy",
            uri.toString());
    assertTrue(uri.getFragment().endsWith("principal=" + authRequest.getPrincipal().getDisplayName()));
}