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:org.apache.hadoop.fs.Path.java

/**
 * Returns a qualified path object.// ww w  .  ja va2 s .  c  o m
 *
 * @param defaultUri if this path is missing the scheme or authority
 * components, borrow them from this URI
 * @param workingDir if this path isn't absolute, treat it as relative to this
 * working directory
 * @return this path if it contains a scheme and authority and is absolute, or
 * a new path that includes a path and authority and is fully qualified
 */
@InterfaceAudience.LimitedPrivate({ "HDFS", "MapReduce" })
public Path makeQualified(URI defaultUri, Path workingDir) {
    Path path = this;
    if (!isAbsolute()) {
        path = new Path(workingDir, this);
    }

    URI pathUri = path.toUri();

    String scheme = pathUri.getScheme();
    String authority = pathUri.getAuthority();
    String fragment = pathUri.getFragment();

    if (scheme != null && (authority != null || defaultUri.getAuthority() == null))
        return path;

    if (scheme == null) {
        scheme = defaultUri.getScheme();
    }

    if (authority == null) {
        authority = defaultUri.getAuthority();
        if (authority == null) {
            authority = "";
        }
    }

    URI newUri = null;
    try {
        newUri = new URI(scheme, authority, normalizePath(scheme, pathUri.getPath()), null, fragment);
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
    return new Path(newUri);
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitRemoteTest.java

@Test
public void testGetUnknownRemote() throws Exception {
    // clone a  repo
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = getClonePath(workspaceId, project);
    clone(clonePath);//from  ww w  .  jav a 2  s  .  c  o m

    // get project metadata
    WebRequest request = getGetRequest(project.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
    WebResponse response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    project = new JSONObject(response.getText());
    JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT);
    assertNotNull(gitSection);
    String gitRemoteUri = gitSection.getString(GitConstants.KEY_REMOTE);

    request = getGetGitRemoteRequest(gitRemoteUri);
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    JSONObject remotes = new JSONObject(response.getText());
    JSONArray remotesArray = remotes.getJSONArray(ProtocolConstants.KEY_CHILDREN);
    assertEquals(1, remotesArray.length());
    JSONObject remote = remotesArray.getJSONObject(0);
    assertNotNull(remote);
    String remoteLocation = remote.getString(ProtocolConstants.KEY_LOCATION);
    assertNotNull(remoteLocation);

    URI u = URI.create(toRelativeURI(remoteLocation));
    IPath p = new Path(u.getPath());
    p = p.uptoSegment(2).append("xxx").append(p.removeFirstSegments(3));
    URI nu = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), p.toString(), u.getQuery(),
            u.getFragment());

    request = getGetGitRemoteRequest(nu.toString());
    response = webConversation.getResponse(request);
    ServerStatus status = waitForTask(response);
    assertEquals(status.toString(), status.getHttpCode(), HttpURLConnection.HTTP_NOT_FOUND);

    p = new Path(u.getPath());
    p = p.uptoSegment(3).append("xxx").append(p.removeFirstSegments(3));
    nu = new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), p.toString(), u.getQuery(),
            u.getFragment());

    request = getGetGitRemoteRequest(nu.toString());
    response = webConversation.getResponse(request);
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());
}

From source file:org.apache.ws.scout.transport.RMITransport.java

/** 
 * Sends an element and returns an element.
 *//*from  www  .j  a  va 2 s .c  o m*/
public Element send(Element request, URI endpointURI) throws TransportException {
    Element response = null;

    if (log.isDebugEnabled()) {
        log.debug("\nRequest message:\n" + XMLUtils.convertNodeToXMLString(request));
        log.debug("Calling " + endpointURI + " using rmi");
    }

    try {
        String host = endpointURI.getHost();
        int port = endpointURI.getPort();
        String scheme = endpointURI.getScheme();
        String service = endpointURI.getPath();
        String className = endpointURI.getQuery();
        String methodName = endpointURI.getFragment();
        Properties env = new Properties();
        //It be a lot nicer if this is configured through properties, but for now
        //I'd like to keep the changes localized, so this seems pretty reasonable.
        String factoryInitial = SecurityActions.getProperty("java.naming.factory.initial");
        if (factoryInitial == null)
            factoryInitial = "org.jnp.interfaces.NamingContextFactory";
        String factoryURLPkgs = SecurityActions.getProperty("java.naming.factory.url.pkgs");
        if (factoryURLPkgs == null)
            factoryURLPkgs = "org.jboss.naming";
        env.setProperty("java.naming.factory.initial", factoryInitial);
        env.setProperty("java.naming.factory.url.pkgs", factoryURLPkgs);
        env.setProperty("java.naming.provider.url", scheme + "://" + host + ":" + port);
        log.debug("Initial Context using env=" + env.toString());
        InitialContext context = new InitialContext(env);
        log.debug("Calling service=" + service + ", Class = " + className + ", Method=" + methodName);
        //Looking up the object (i.e. Publish)
        Object requestHandler = context.lookup(service);
        //Loading up the stub
        Class<?> c = Class.forName(className);
        //Getting a handle to method we want to call (i.e. publish.publish(Element element))
        Method method = c.getMethod(methodName, Element.class);
        //Calling that method
        Node node = (Node) method.invoke(requestHandler, request);
        //The result is in the first element
        if (node.getFirstChild() != null) {
            response = (Element) node.getFirstChild();
        }
    } catch (Exception ex) {
        throw new TransportException(ex);
    }
    if (log.isDebugEnabled()) {
        log.debug("\nResponse message:\n" + XMLUtils.convertNodeToXMLString(response));
    }
    return response;
}

From source file:org.lockss.util.UrlUtil.java

/** Resolve child relative to base */
// This version is a wrapper for java.net.URI.resolve().  Java class has
// two undesireable behaviors: it resolves ("http://foo.bar", "a.html")
// to "http://foo.bara.html" (fails to supply missing "/" to base with no
// path), and it resolves ("http://foo.bar/xxx.php", "?foo=bar") to
// "http://foo.bar/?foo=bar" (in accordance with RFC 2396), while all the
// browsers resolve it to "http://foo.bar/xxx.php?foo=bar" (in accordance
// with RFC 1808).  This mimics enough of the logic of
// java.net.URI.resolve(URI, URI) to detect those two cases, and defers
// to the URI code for other cases.

private static java.net.URI resolveUri0(java.net.URI base, java.net.URI child) throws MalformedURLException {

    // check if child is opaque first so that NPE is thrown 
    // if child is null.
    if (child.isOpaque() || base.isOpaque()) {
        return child;
    }//from   www. j  a  va  2s.c  o  m

    try {
        String scheme = base.getScheme();
        String authority = base.getAuthority();
        String path = base.getPath();
        String query = base.getQuery();
        String fragment = child.getFragment();

        // If base has null path, ensure authority is separated from path in
        // result.  (java.net.URI resolves ("http://foo.bar", "x.y") to
        // http://foo.barx.y)
        if (StringUtil.isNullString(base.getPath())) {
            path = "/";
            base = new java.net.URI(scheme, authority, path, query, fragment);
        }

        // Absolute child
        if (child.getScheme() != null)
            return child;

        if (child.getAuthority() != null) {
            // not relative, defer to URI
            return base.resolve(child);
        }

        // Fragment only, return base with this fragment
        if (child.getPath().equals("") && (child.getFragment() != null) && (child.getQuery() == null)) {
            if ((base.getFragment() != null) && child.getFragment().equals(base.getFragment())) {
                return base;
            }
            java.net.URI ru = new java.net.URI(scheme, authority, path, query, fragment);
            return ru;
        }

        query = child.getQuery();

        authority = base.getAuthority();

        if (StringUtil.isNullString(child.getPath())) {
            // don't truncate base path if child has no path
            path = base.getPath();
        } else if (child.getPath().charAt(0) == '/') {
            // Absolute child path
            path = child.getPath();
        } else {
            // normal relative path, defer to URI
            return base.resolve(child);
        }
        // create URI from relativized components
        java.net.URI ru = new java.net.URI(scheme, authority, path, query, fragment);
        return ru;
    } catch (URISyntaxException e) {
        throw newMalformedURLException(e);
    }
}

From source file:com.microsoftopentechnologies.azchat.web.mediaservice.AzureChatMediaService.java

/**
 * This method retrieve the MP4 streaming URL from assetInfoFile.
 * /*from  w  ww . j a va2  s  .  c om*/
 * @param streaming
 * @param streamingAssetFile
 * @param streamingAsset
 * @return
 * @throws Exception
 */
private String getMP4StreamngURL(AccessPolicyInfo streaming, AssetFileInfo streamingAssetFile,
        AssetInfo streamingAsset) throws Exception {
    String streamingURL = null;
    LocatorInfo locator = mediaService
            .create(Locator.create(streaming.getId(), streamingAsset.getId(), LocatorType.SAS));
    URI mp4Uri = new URI(locator.getPath());
    mp4Uri = new URI(mp4Uri.getScheme(), mp4Uri.getUserInfo(), mp4Uri.getHost(), mp4Uri.getPort(),
            mp4Uri.getPath() + AzureChatConstants.CONSTANT_BACK_SLASH + streamingAssetFile.getName(),
            mp4Uri.getQuery(), mp4Uri.getFragment());
    streamingURL = mp4Uri.toString();
    return streamingURL;

}

From source file:com.buaa.cfs.fs.Path.java

/** Resolve a child path against a parent path. */
public Path(Path parent, Path child) {
    // Add a slash to parent's path so resolution is compatible with URI's
    URI parentUri = parent.uri;
    String parentPath = parentUri.getPath();
    if (!(parentPath.equals("/") || parentPath.isEmpty())) {
        try {//w w w.j  a va  2 s  .c  o m
            parentUri = new URI(parentUri.getScheme(), parentUri.getAuthority(), parentUri.getPath() + "/",
                    null, parentUri.getFragment());
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException(e);
        }
    }
    URI resolved = parentUri.resolve(child.uri);
    initialize(resolved.getScheme(), resolved.getAuthority(), resolved.getPath(), resolved.getFragment());
}

From source file:org.codice.ddf.catalog.content.impl.FileSystemStorageProvider.java

private Path getTempContentItemDir(String requestId, URI contentUri) {
    List<String> pathParts = new ArrayList<>();
    pathParts.add(requestId);/* ww  w. ja  v a  2s .c om*/
    pathParts.addAll(getContentFilePathParts(contentUri.getSchemeSpecificPart(), contentUri.getFragment()));

    return Paths.get(baseContentTmpDirectory.toAbsolutePath().toString(),
            pathParts.toArray(new String[pathParts.size()]));
}

From source file:org.chiba.xml.xforms.connector.http.HTTPURIResolver.java

/**
 * Performs link traversal of the <code>http</code> URI and returns the result
 * as a DOM document.//from www.ja  v  a  2s  .  com
 *
 * @return a DOM node parsed from the <code>http</code> URI.
 * @throws XFormsException if any error occurred during link traversal.
 */
public Object resolve() throws XFormsException {
    try {
        URI uri = new URI(getURI());

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("getting '" + uri + "'");
        }

        get(getURIWithoutFragment());

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("converting response stream to XML");
        }

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(false);

        Document document = factory.newDocumentBuilder().parse(getResponseBody());

        if (uri.getFragment() != null) {
            return document.getElementById(uri.getFragment());
        }

        return document;
    } catch (Exception e) {
        throw new XFormsException(e);
    }
}

From source file:org.obiba.opal.rest.client.magma.OpalJavaClient.java

public UriBuilder newUri(URI root) {
    String rootPath = root.getPath();
    if (!rootPath.endsWith("/")) {
        try {//  w ww .  ja v a  2  s. co m
            return new UriBuilder(new URI(root.getScheme(), root.getHost() + ":" + root.getPort(),
                    rootPath + "/", root.getQuery(), root.getFragment()));
        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
    return new UriBuilder(root);
}

From source file:com.microsoft.tfs.core.clients.reporting.ReportingClient.java

/**
 * <p>/*w  ww . j a  v a  2  s . c om*/
 * TEE will automatically correct the endpoints registered URL when creating
 * the web service, however we must provide a mechansim to correct fully
 * qualified URI's provided as additional URI from the same webservice.
 * </p>
 * <p>
 * We compare the passed uri with the registered web service endpoint, if
 * they share the same root (i.e. http://TFSERVER) then we correct the
 * passed uri to be the same as the corrected web service enpoint (i.e.
 * http://tfsserver.mycompany.com)
 * </p>
 *
 * @see WSSClient#getFixedURI(String)
 */
public String getFixedURI(final String uri) {
    Check.notNull(uri, "uri"); //$NON-NLS-1$

    try {
        // Get what the server thinks the url is.
        String url = connection.getRegistrationClient().getServiceInterfaceURL(ToolNames.WAREHOUSE,
                ServiceInterfaceNames.REPORTING);

        if (url == null || url.length() == 0) {
            // Might be a Rosario server
            url = connection.getRegistrationClient().getServiceInterfaceURL(ToolNames.WAREHOUSE,
                    ServiceInterfaceNames.REPORTING_WEB_SERVICE_URL);
            if (url == null || url.length() == 0) {
                // Couldn't figure this out - just give up and return what
                // we
                // were passed.
                return uri;
            }
            is2010Server = true;
        }

        final URI registeredEndpointUri = new URI(url);

        final URI passedUri = new URI(uri);

        if (passedUri.getScheme().equals(registeredEndpointUri.getScheme())
                && passedUri.getHost().equals(registeredEndpointUri.getHost())
                && passedUri.getPort() == registeredEndpointUri.getPort()) {
            final URI endpointUri = ((SOAPService) getProxy()).getEndpoint();
            final URI fixedUri = new URI(endpointUri.getScheme(), endpointUri.getHost(), passedUri.getPath(),
                    passedUri.getQuery(), passedUri.getFragment());
            return fixedUri.toASCIIString();
        }
    } catch (final URISyntaxException e) {
        // ignore;
    }
    return uri;
}