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.codice.alliance.imaging.chip.actionprovider.ImagingChipActionProvider.java

private static Optional<URI> getOriginalDerivedResourceUri(final Metacard metacard) {
    final Attribute derivedResourceUriAttribute = metacard.getAttribute(Metacard.DERIVED_RESOURCE_URI);
    if (derivedResourceUriAttribute == null) {
        return Optional.empty();
    }/*www  .  ja v  a  2  s  .com*/
    List<String> derivedResourceUriStrings = derivedResourceUriAttribute.getValues().stream()
            .filter(String.class::isInstance).map(String.class::cast).collect(Collectors.toList());

    for (String resourceUri : derivedResourceUriStrings) {
        try {
            final URI derivedResourceUri = new URI(resourceUri);

            if (canBeChippedLocally(derivedResourceUri)
                    && StringUtils.equals(ORIGINAL_QUALIFIER, derivedResourceUri.getFragment())) {
                return Optional.of(derivedResourceUri);
            }
            for (NameValuePair parameter : URLEncodedUtils.parse(derivedResourceUri,
                    StandardCharsets.UTF_8.name())) {
                if (QUALIFIER_KEY.equals(parameter.getName())
                        && StringUtils.equals(ORIGINAL_QUALIFIER, parameter.getValue())) {
                    return Optional.of(derivedResourceUri);
                }
            }
        } catch (URISyntaxException e) {
            // This is not an unexpected exception, there is not enough info to construct a chipping URL
        }
    }
    return Optional.empty();
}

From source file:edu.stanford.junction.JunctionMaker.java

public static SwitchboardConfig getDefaultSwitchboardConfig(URI uri) {
    String fragment = uri.getFragment();
    if (fragment == null) {
        fragment = "xmpp";
    }//from   w  w  w.  jav a2s . co m
    fragment = fragment.toLowerCase();
    if (fragment.equals("jvm")) {
        return new edu.stanford.junction.provider.jvm.JVMSwitchboardConfig();
    } else if (fragment.equals("jx")) {
        return new edu.stanford.junction.provider.jx.JXSwitchboardConfig();
    } else if (fragment.equals("jx")) {
        return new edu.stanford.junction.provider.jx.JXSwitchboardConfig();
    } else if (fragment.equals("irc")) {
        return new edu.stanford.junction.provider.irc.IRCSwitchboardConfig();
    }

    // assume xmpp
    return new edu.stanford.junction.provider.xmpp.XMPPSwitchboardConfig(uri);
}

From source file:com.aaasec.sigserv.cscommon.xmldsig.OfflineResolver.java

private static URI getNewURI(String uri, String baseURI) throws URISyntaxException {
    URI newUri = null;
    if (baseURI == null || "".equals(baseURI)) {
        newUri = new URI(uri);
    } else {//  w ww . j  a v  a  2 s.c  om
        newUri = new URI(baseURI).resolve(uri);
    }

    // if the URI contains a fragment, ignore it
    if (newUri.getFragment() != null) {
        URI uriNewNoFrag = new URI(newUri.getScheme(), newUri.getSchemeSpecificPart(), null);
        return uriNewNoFrag;
    }
    return newUri;
}

From source file:com.bazaarvoice.seo.sdk.util.BVUtility.java

public static String getFragmentString(String uri) {

    if (StringUtils.isBlank(uri)) {
        return "";
    }//from  www  .  j av a  2s. c  o  m

    URI _uri = null;
    try {
        _uri = new URI(uri);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return (_uri.getFragment() == null) ? "" : _uri.getFragment();
}

From source file:com.github.wolf480pl.mias4j.util.AbstractTransformingClassLoader.java

public static URL guessCodeSourceURL(String resourcePath, URL resourceURL) {
    // FIXME: Find a better way to do this
    @SuppressWarnings("restriction")
    String escaped = sun.net.www.ParseUtil.encodePath(resourcePath, false);
    String path = resourceURL.getPath();
    if (!path.endsWith(escaped)) {
        // Umm... whadda we do now? Maybe let's fallback to full resource URL.
        LOG.warn("Resource URL path \"" + path + "\" doesn't end with escaped resource path \"" + escaped
                + "\" for resource \"" + resourcePath + "\"");
        return resourceURL;
    }/*ww w . ja  v  a 2  s.c o  m*/
    path = path.substring(0, path.length() - escaped.length());
    if (path.endsWith("!/")) { // JAR
        path = path.substring(0, path.length() - 2);
    }
    try {
        URI uri = resourceURL.toURI();
        return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(),
                uri.getFragment()).toURL();
    } catch (MalformedURLException | URISyntaxException e) {
        // Umm... whadda we do now? Maybe let's fallback to full resource URL.
        LOG.warn("Couldn't assemble CodeSource URL with modified path", e);
        return resourceURL;
    }
}

From source file:org.apache.hama.pipes.util.DistributedCacheUtil.java

/**
 * Transfers DistributedCache files into the local cache files. Also creates
 * symbolic links for URIs specified with a fragment if
 * DistributedCache.getSymlinks() is true.
 * /* w ww .j  a  v  a 2s .  co  m*/
 * @param conf The job's configuration
 * @throws IOException If a DistributedCache file cannot be found.
 */
public static final void moveLocalFiles(Configuration conf) throws IOException {
    StringBuilder files = new StringBuilder();
    boolean first = true;
    if (DistributedCache.getCacheFiles(conf) != null) {
        for (URI uri : DistributedCache.getCacheFiles(conf)) {
            if (uri != null) {
                if (!first) {
                    files.append(",");
                }
                if (null != uri.getFragment() && DistributedCache.getSymlink(conf)) {

                    FileUtil.symLink(uri.getPath(), uri.getFragment());
                    files.append(uri.getFragment()).append(",");
                }
                FileSystem hdfs = FileSystem.get(conf);
                Path pathSrc = new Path(uri.getPath());
                // LOG.info("pathSrc: " + pathSrc);
                if (hdfs.exists(pathSrc)) {
                    LocalFileSystem local = LocalFileSystem.getLocal(conf);
                    Path pathDst = new Path(local.getWorkingDirectory(), pathSrc.getName());
                    // LOG.info("user.dir: "+System.getProperty("user.dir"));
                    // LOG.info("WorkingDirectory: "+local.getWorkingDirectory());
                    // LOG.info("pathDst: " + pathDst);
                    LOG.debug("copyToLocalFile: " + pathDst);
                    hdfs.copyToLocalFile(pathSrc, pathDst);
                    local.deleteOnExit(pathDst);
                    files.append(pathDst.toUri().getPath());
                }
                first = false;
            }
        }
    }
    if (files.length() > 0) {
        // I've replaced the use of the missing setLocalFiles and
        // addLocalFiles methods (hadoop 0.23.x) with our own DistCacheUtils
        // methods which set the cache configurations directly.
        DistCacheUtils.addLocalFiles(conf, files.toString());
    }
}

From source file:org.apache.xmlgraphics.image.loader.util.ImageUtil.java

/**
 * Extracts page index information from a URI. The expected pattern is "page=x" where x is
 * a non-negative integer number. The page index must be specified as part of the URI fragment
 * and is 1-based, i.e. the first page is 1 but the the method returns a zero-based page
 * index./*from  www. j a va 2s  .c o m*/
 * An example: <code>http://www.foo.bar/images/scan1.tif#page=4</code> (The method will return
 * 3.)
 * <p>
 * If no page index information is found in the URI or if the URI cannot be parsed, the
 * method returns null.
 * @param uri the URI that should be inspected
 * @return the page index (0 is the first page) or null if there's no page index information
 *         in the URI
 */
public static Integer getPageIndexFromURI(String uri) {
    if (uri.indexOf('#') < 0) {
        return null;
    }
    try {
        URI u = new URI(uri);
        String fragment = u.getFragment();
        if (fragment != null) {
            int pos = fragment.indexOf(PAGE_INDICATOR);
            if (pos >= 0) {
                pos += PAGE_INDICATOR.length();
                StringBuffer sb = new StringBuffer();
                while (pos < fragment.length()) {
                    char c = fragment.charAt(pos);
                    if (c >= '0' && c <= '9') {
                        sb.append(c);
                    } else {
                        break;
                    }
                    pos++;
                }
                if (sb.length() > 0) {
                    int pageIndex = Integer.parseInt(sb.toString()) - 1;
                    pageIndex = Math.max(0, pageIndex);
                    return new Integer(pageIndex);
                }
            }
        }
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException("URI is invalid: " + e.getLocalizedMessage());
    }
    return null;
}

From source file:uk.co.flax.biosolr.ontology.core.owl.OWLOntologyHelper.java

private static 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 av a2  s .  c o  m
            // 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:org.esigate.util.UriUtils.java

/**
 * Removes the server information frome a {@link URI}.
 * //  w ww . ja  v  a  2  s.c  o  m
 * @param uri
 *            the {@link URI}
 * @return a new {@link URI} with no scheme, host and port
 */
public static URI removeServer(URI uri) {
    try {
        return new URI(null, null, null, -1, uri.getPath(), uri.getQuery(), uri.getFragment());
    } catch (URISyntaxException e) {
        throw new InvalidUriException(e);
    }

}

From source file:edu.stanford.junction.android.AndroidJunctionMaker.java

public static SwitchboardConfig getDefaultSwitchboardConfig(URI uri) {
    String fragment = uri.getFragment();
    if (fragment != null) {
        if (fragment.equalsIgnoreCase("bt")) {
            return new BluetoothSwitchboardConfig();
        }//  w w w  . j ava 2 s. c  om
    }
    return JunctionMaker.getDefaultSwitchboardConfig(uri);
}