Example usage for java.net URI normalize

List of usage examples for java.net URI normalize

Introduction

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

Prototype

public URI normalize() 

Source Link

Document

Normalizes this URI's path.

Usage

From source file:ru.histone.resourceloaders.DefaultResourceLoader.java

public URI makeFullLocation(String location, String baseLocation) {
    if (location == null) {
        throw new ResourceLoadException("Resource location is undefined!");
    }//  w  w w . ja  v  a2s .com

    URI locationURI = URI.create(location);

    if (baseLocation == null && !locationURI.isAbsolute()) {
        throw new ResourceLoadException("Base HREF is empty and resource location is not absolute!");
    }

    if (baseLocation != null) {
        baseLocation = baseLocation.replace("\\", "/");
        baseLocation = baseLocation.replace("file://", "file:/");
    }
    URI baseLocationURI = (baseLocation != null) ? URI.create(baseLocation) : null;

    if (!locationURI.isAbsolute() && baseLocation != null) {
        locationURI = baseLocationURI.resolve(locationURI.normalize());
    }

    if (!locationURI.isAbsolute()) {
        throw new ResourceLoadException("Resource location is not absolute!");
    }

    return locationURI;
}

From source file:org.dita.dost.module.reader.AbstractReaderModule.java

/**
 * add FlagImangesSet to Properties, which needn't to change the dir level,
 * just ouput to the ouput dir.//from  ww  w .  j  av  a 2  s.  c o m
 *
 * @param prop job configuration
 * @param set absolute flag image files
 */
private void addFlagImagesSetToProperties(final Job prop, final Set<URI> set) {
    final Set<URI> newSet = new LinkedHashSet<>(128);
    for (final URI file : set) {
        //            assert file.isAbsolute();
        if (file.isAbsolute()) {
            // no need to append relative path before absolute paths
            newSet.add(file.normalize());
        } else {
            // In ant, all the file separator should be slash, so we need to
            // replace all the back slash with slash.
            newSet.add(file.normalize());
        }
    }

    // write list attribute to file
    final String fileKey = Constants.REL_FLAGIMAGE_LIST.substring(0,
            Constants.REL_FLAGIMAGE_LIST.lastIndexOf("list")) + "file";
    prop.setProperty(fileKey,
            Constants.REL_FLAGIMAGE_LIST.substring(0, Constants.REL_FLAGIMAGE_LIST.lastIndexOf("list"))
                    + ".list");
    final File list = new File(job.tempDir, prop.getProperty(fileKey));
    try (Writer bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(list)))) {
        for (URI aNewSet : newSet) {
            bufferedWriter.write(aNewSet.getPath());
            bufferedWriter.write('\n');
        }
        bufferedWriter.flush();
    } catch (final IOException e) {
        logger.error(e.getMessage(), e);
    }

    prop.setProperty(Constants.REL_FLAGIMAGE_LIST, StringUtils.join(newSet, COMMA));
}

From source file:org.wso2.carbon.ml.core.impl.BAMInputAdapter.java

/**
 * Set the size of the sample to be retrieved from BAM, and return the new URI.
 * //  www  . j av a  2s .  c o  m
 * @param uri           URI of the BAM Data Source
 * @param sampleSize    Size of the sample needed.
 * @return              New URI having the sample size set.
 * @throws              URISyntaxException
 * @throws              MLInputAdapterException
 */
private URI getUriWithSampleSize(URI uri, int sampleSize) throws URISyntaxException, MLInputAdapterException {
    if (uriResourceParameters.length == 1) {
        uri = new URI(uri.toString() + "/-1/-1/0/" + sampleSize);
    } else if (uriResourceParameters.length == 2) {
        uri = new URI(uri.toString() + "/-1/0/" + sampleSize);
    } else if (uriResourceParameters.length == 3) {
        uri = new URI(uri.toString() + "/0/" + sampleSize);
    } else if (uriResourceParameters.length == 4) {
        uri = new URI(uri.toString() + "/" + sampleSize);
    } else if (uriResourceParameters.length == 5) {
        uri = new URI(uri.getScheme() + "://" + uri.getAuthority() + "/analytics/tables/"
                + uriResourceParameters[0] + "/" + uriResourceParameters[1] + "/" + uriResourceParameters[2]
                + "/" + uriResourceParameters[3] + "/" + sampleSize);
    } else {
        throw new MLInputAdapterException("Invalid data source URI: " + uri);
    }
    return uri.normalize();
}

From source file:org.dita.dost.module.GenMapAndTopicListModule.java

private FileInfo getOrCreateFileInfo(final Map<URI, FileInfo> fileInfos, final URI file) {
    assert file.getFragment() == null;
    final URI f = file.normalize();
    FileInfo.Builder b;// w  ww.  j  a  v a  2  s  .  co m
    if (fileInfos.containsKey(f)) {
        b = new FileInfo.Builder(fileInfos.get(f));
    } else {
        b = new FileInfo.Builder().src(file);
    }
    b = b.uri(tempFileNameScheme.generateTempFileName(file));
    final FileInfo i = b.build();
    fileInfos.put(i.src, i);
    return i;
}

From source file:org.dita.dost.module.GenMapAndTopicListModule.java

/**
 * add FlagImangesSet to Properties, which needn't to change the dir level,
 * just ouput to the ouput dir.//from  w  ww  .jav a2 s  . c o m
 *
 * @param prop job configuration
 * @param set absolute flag image files
 */
private void addFlagImagesSetToProperties(final Job prop, final Set<URI> set) {
    final Set<URI> newSet = new LinkedHashSet<>(128);
    for (final URI file : set) {
        //            assert file.isAbsolute();
        if (file.isAbsolute()) {
            // no need to append relative path before absolute paths
            newSet.add(file.normalize());
        } else {
            // In ant, all the file separator should be slash, so we need to
            // replace all the back slash with slash.
            newSet.add(file.normalize());
        }
    }

    // write list attribute to file
    final String fileKey = org.dita.dost.util.Constants.REL_FLAGIMAGE_LIST.substring(0,
            org.dita.dost.util.Constants.REL_FLAGIMAGE_LIST.lastIndexOf("list")) + "file";
    prop.setProperty(fileKey, org.dita.dost.util.Constants.REL_FLAGIMAGE_LIST.substring(0,
            org.dita.dost.util.Constants.REL_FLAGIMAGE_LIST.lastIndexOf("list")) + ".list");
    final File list = new File(job.tempDir, prop.getProperty(fileKey));
    try (Writer bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(list)))) {
        final Iterator<URI> it = newSet.iterator();
        while (it.hasNext()) {
            bufferedWriter.write(it.next().getPath());
            if (it.hasNext()) {
                bufferedWriter.write("\n");
            }
        }
        bufferedWriter.flush();
    } catch (final IOException e) {
        logger.error(e.getMessage(), e);
    }

    prop.setProperty(org.dita.dost.util.Constants.REL_FLAGIMAGE_LIST, StringUtils.join(newSet, COMMA));
}

From source file:org.dita.dost.module.reader.AbstractReaderModule.java

/**
 * Categorize current file type/* w w  w  .  j a  va  2 s. c  o m*/
 *
 * @param ref file path
 */
void categorizeCurrentFile(final Reference ref) {
    final URI currentFile = ref.filename;
    if (listFilter.hasConaction()) {
        conrefpushSet.add(currentFile);
    }

    if (listFilter.hasConRef()) {
        conrefSet.add(currentFile);
    }

    if (listFilter.hasKeyRef()) {
        keyrefSet.add(currentFile);
    }

    if (listFilter.hasCodeRef()) {
        coderefSet.add(currentFile);
    }

    if (listFilter.isDitaTopic()) {
        if (ref.format != null && !ref.format.equals(ATTR_FORMAT_VALUE_DITA)) {
            assert currentFile.getFragment() == null;
            final URI f = currentFile.normalize();
            if (!fileinfos.containsKey(f)) {
                final FileInfo i = new FileInfo.Builder()
                        .uri(tempFileNameScheme.generateTempFileName(currentFile)).src(currentFile)
                        .format(ref.format).build();
                fileinfos.put(i.src, i);
            }
        }
        fullTopicSet.add(currentFile);
        hrefTargetSet.add(currentFile);
        if (listFilter.hasHref()) {
            hrefTopicSet.add(currentFile);
        }
    } else if (listFilter.isDitaMap()) {
        fullMapSet.add(currentFile);
    }
}

From source file:org.neo4j.server.rest.web.RestfulGraphDatabase.java

@POST
@Path(PATH_TO_CREATE_PAGED_TRAVERSERS)
public Response createPagedTraverser(@PathParam("nodeId") long startNode,
        @PathParam("returnType") TraverserReturnType returnType,
        @QueryParam("pageSize") @DefaultValue(FIFTY_ENTRIES) int pageSize,
        @QueryParam("leaseTime") @DefaultValue(SIXTY_SECONDS) int leaseTimeInSeconds, String body) {
    try {/*from   www  .  ja  v  a  2  s  .c o m*/
        validatePageSize(pageSize);
        validateLeaseTime(leaseTimeInSeconds);

        String traverserId = actions.createPagedTraverser(startNode, input.readMap(body), pageSize,
                leaseTimeInSeconds);

        URI uri = new URI("node/" + startNode + "/paged/traverse/" + returnType + "/" + traverserId);

        return output.created(
                new ListEntityRepresentation(actions.pagedTraverse(traverserId, returnType), uri.normalize()));
    } catch (EvaluationException e) {
        return output.badRequest(e);
    } catch (BadInputException e) {
        return output.badRequest(e);
    } catch (NotFoundException e) {
        return output.notFound(e);
    } catch (URISyntaxException e) {
        return output.serverError(e);
    }
}

From source file:eu.planets_project.tb.gui.backing.ExperimentBean.java

private static String normaliseDataReference(String inUri) {
    URI uri;
    try {/*from   w  ww .  j  av a2s .c  o  m*/
        uri = new URI(inUri);
        return uri.normalize().toASCIIString();
    } catch (Exception e) {
        log.error("Could not normalise: " + inUri);
    }
    return inUri;
}

From source file:org.dita.dost.module.GenMapAndTopicListModule.java

/**
 * Categorize current file type/*from www  .  j  a  v a  2 s  .c  om*/
 * 
 * @param ref file path
 */
private void categorizeCurrentFile(final Reference ref) {
    final URI currentFile = ref.filename;
    if (listFilter.hasConaction()) {
        conrefpushSet.add(currentFile);
    }

    if (listFilter.hasConRef()) {
        conrefSet.add(currentFile);
    }

    if (listFilter.hasKeyRef()) {
        keyrefSet.add(currentFile);
    }

    if (listFilter.hasCodeRef()) {
        coderefSet.add(currentFile);
    }

    if (listFilter.isDitaTopic()) {
        if (ref.format != null && !ref.format.equals(ATTR_FORMAT_VALUE_DITA)) {
            assert currentFile.getFragment() == null;
            final URI f = currentFile.normalize();
            if (!fileinfos.containsKey(f)) {
                final FileInfo i = new FileInfo.Builder()
                        //.uri(tempFileNameScheme.generateTempFileName(currentFile))
                        .src(currentFile).format(ref.format).build();
                fileinfos.put(i.src, i);
            }
        }
        fullTopicSet.add(currentFile);
        hrefTargetSet.add(currentFile);
        if (listFilter.hasHref()) {
            hrefTopicSet.add(currentFile);
        }
    } else if (listFilter.isDitaMap()) {
        fullMapSet.add(currentFile);
    }
}