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:edu.usc.goffish.gofs.namenode.DataNode.java

@Override
public IPartition loadLocalPartition(String graphId, int partitionId) throws IOException {
    URI partitionURI = _nameNode.getPartitionDirectory().getPartitionMapping(graphId, partitionId);
    URI relativization = _localhostURI.relativize(partitionURI);

    if (relativization == partitionURI) {
        // given partition is not in this data node
        throw new IllegalArgumentException();
    }//from   w w w .j ava2 s .  c o m

    Path slicePath = _dataNodeSliceDirPath.resolve(relativization.getPath());

    UUID partitionUUID;
    try {
        partitionUUID = UUID.fromString(relativization.getFragment());
    } catch (NullPointerException | IllegalArgumentException e) {
        // bad fragment returned by partition directory
        throw new IllegalStateException(e);
    }

    return SliceManager.create(partitionUUID, _sliceSerializer, new FileStorageManager(slicePath))
            .readPartition();
}

From source file:com.switchfly.inputvalidation.sanitizer.UrlStripHtmlSanitizer.java

@Override
public String execute(String content) {
    if (StringUtils.isBlank(content)) {
        return content;
    }/*w  w w.ja  v a 2s  . c  o m*/

    URI uri;
    try {
        uri = new URI(content);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }

    List<NameValuePair> cleanedPairs = parse(uri);

    String queryString = cleanedPairs.isEmpty() ? null : URLEncodedUtils.format(cleanedPairs, ENCODING);

    try {
        return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), queryString,
                uri.getFragment()).toString();
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.soyatec.windowsazure.authenticate.SharedKeyCredentialsWrapper.java

/**
 * Append the signedString to the uri./*from   www. java2s . co m*/
 * 
 * @param uri
 * @param signedString
 * @return The uri after be appended with signedString.
 */
private URI appendSignString(URI uri, String signedString) {
    try {
        return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(),
                HttpUtilities.getNormalizePath(uri),
                (uri.getQuery() == null ? Utilities.emptyString() : uri.getQuery()) + "&" + signedString,
                uri.getFragment());
    } catch (URISyntaxException e) {
        Logger.error("", e);
    }
    return uri;
}

From source file:org.eclipse.orion.server.git.objects.Status.java

private URI statusToFileLocation(URI u) throws URISyntaxException {
    String uriPath = u.getPath();
    String prefix = uriPath.substring(0, uriPath.indexOf(GitServlet.GIT_URI));
    uriPath = uriPath.substring(prefix.length() + (GitServlet.GIT_URI + '/' + Status.RESOURCE).length());
    return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), u.getPort(), uriPath, u.getQuery(),
            u.getFragment());
}

From source file:org.eclipse.orion.internal.server.hosting.HostedSiteServlet.java

private URI createUri(URI uri, String queryString) throws URISyntaxException {
    String queryPart = queryString == null ? "" : "?" + queryString; //$NON-NLS-1$ //$NON-NLS-2$
    String fragmentPart = uri.getFragment() == null ? "" : "#" + uri.getRawFragment();//$NON-NLS-1$ //$NON-NLS-2$
    URI pathonly = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(),
            null, null);//from www .  jav  a 2s .co m
    StringBuilder buf = new StringBuilder();
    buf.append(pathonly.toString()).append(queryPart).append(fragmentPart);
    return new URI(buf.toString());
}

From source file:org.dataconservancy.cos.packaging.OsfContentProvider.java

/**
 * Returns the IPM tree corresponding to the provided OSF package graph.
 * We manually build the IPM tree here. Fundamentally, we're doing three things:
 * 1) Creating "directory" nodes that correspond to a domain object.
 * 2) Creating "content" nodes that correspond to a domain object that describes associated content.
 * 3) Arranging these nodes into a tree structure of our liking.
 * @return The root Node for the IPM tree representing the content.
 *//*from   w  ww . ja v  a  2  s  . c o  m*/
public Node getIpmModel() {

    // Synthesize a root node to anchor the objects in the domain object graph
    final Node root = new Node(URI.create(UUID.randomUUID().toString()));
    root.setFileInfo(directory("root"));
    root.setIgnored(true);

    // For each subject resource that is not anonymous, create a node
    //   - If the type of the node is a osf:File, then it will be a content node
    //   - Otherwise, make a directory node
    domainObjects.listSubjects().forEachRemaining(subject -> {

        if (subject.isAnon()) {
            log.debug("Skipping IPM node creation for anonymous resource '{}'", subject.getId().toString());
            return;
        }

        final URI u = URI.create(subject.getURI());

        // Hash URIs do not get their own node; they will be considered to be a single node.
        if (u.getFragment() != null) {
            log.debug("Skipping IPM node creation for hash URI resource '{}'", subject.getURI());
            return;
        }

        final String msgFmt = "Creating %s IPM node named %s for domain object %s";

        final Node n = new Node(u);
        n.setDomainObject(u);

        if (isFile(subject)) {
            final String binaryUri = getBinaryUri(subject);
            final String filename = getFileName(subject);
            log.info(String.format(msgFmt, "binary file", filename, subject.getURI()));

            n.setFileInfo(contentFromUrl(filename, binaryUri));

        } else {
            final String filename;
            if (u.getPath() != null) {
                final String[] pathElements = u.getPath().split("\\/");
                filename = escape(pathElements[pathElements.length - 1]);
            } else {
                filename = escape(subject.getURI());
            }
            log.info(String.format(msgFmt, "directory", filename, subject.getURI()));
            n.setFileInfo(directory(filename));
        }

        root.addChild(n);

    });

    return root;
}

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

private URI updateURI(URI uri, PHP php) throws URISyntaxException {
    return new URI(php.protocol != null ? php.protocol : uri.getScheme(), uri.getUserInfo(),
            php.host != null ? php.host : uri.getHost(),
            php.host != null ? php.port != null ? php.port : -1 : uri.getPort(), uri.getPath(), uri.getQuery(),
            uri.getFragment());/*from  w w w  .jav a2 s.  c o m*/
}

From source file:uk.co.flax.biosolr.elasticsearch.mapper.ontology.owl.OntologyHelper.java

private Optional<String> getShortForm(IRI entityIRI) {
    LOGGER.trace("Attempting to extract fragment name of URI '" + entityIRI + "'");
    String termURI = entityIRI.toString();
    URI entUri = entityIRI.toURI();

    // we want the "final part" of the URI...
    if (!StringUtils.isEmpty(entUri.getFragment())) {
        // a uri with a non-null fragment, so use this...
        LOGGER.trace("Extracting fragment name using URI fragment (" + entUri.getFragment() + ")");
        return Optional.of(entUri.getFragment());
    } else if (entityIRI.toURI().getPath() != null) {
        // no fragment, but there is a path so try and extract the final
        // part...
        if (entityIRI.toURI().getPath().contains("/")) {
            LOGGER.trace("Extracting fragment name using final part of the path of the URI");
            return Optional.of(
                    entityIRI.toURI().getPath().substring(entityIRI.toURI().getPath().lastIndexOf('/') + 1));
        } else {/*from   w w w. j  a va 2s .  com*/
            // no final path part, so just return whole path
            LOGGER.trace("Extracting fragment name using the path of the URI");
            return Optional.of(entityIRI.toURI().getPath());
        }
    } else {
        // no fragment, path is null, we've run out of rules so don't
        // shorten
        LOGGER.trace("No rules to shorten this URI could be found (" + termURI + ")");
        return Optional.empty();
    }
}

From source file:de.betterform.connector.xmlrpc.XMLRPCURIResolver.java

/**
 * Decodes the <code>xmlrpc</code> URI, runs the indicated function
 * and returns the result as a DOM document.
 *
 * @return a DOM node parsed from the <code>xmlrpc</code> URI.
 * @throws XFormsException if any error occurred.
 *//*  w ww  .  j  ava2s .co  m*/
public Object resolve() throws XFormsException {
    try {

        URI uri = new URI(getURI());
        log.info("Getting URI: '" + uri + "'");

        Vector v = parseURI(uri);
        String rpcURL = (String) v.get(0);
        String function = (String) v.get(1);
        Hashtable params = (Hashtable) v.get(2);

        de.betterform.connector.xmlrpc.RPCClient rpc = new de.betterform.connector.xmlrpc.RPCClient(rpcURL);

        Document document = rpc.getDocument(function, params);

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

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