Example usage for java.net URI relativize

List of usage examples for java.net URI relativize

Introduction

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

Prototype

public URI relativize(URI uri) 

Source Link

Document

Relativizes the given URI against this URI.

Usage

From source file:org.wso2.bps.samples.migration.deployment.ArchiveBasedHumanTaskDeploymentUnitBuilder.java

@Override
public void buildWSDLs() throws HumanTaskDeploymentException {
    URI baseUri = humantaskDir.toURI();
    for (File file : FileUtils.directoryEntriesInPath(humantaskDir, wsdlFilter)) {

        try {//from   ww  w  . j a v  a2s  .  c o  m
            URI uri = baseUri.relativize(file.toURI());
            if (!uri.isAbsolute()) {
                File f = new File(baseUri.getPath() + File.separator + uri.getPath());
                URI abUri = f.toURI();
                if (abUri.isAbsolute()) {
                    uri = abUri;
                }
            }

            WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
            reader.setFeature(HumanTaskConstants.JAVAX_WSDL_VERBOSE_MODE_KEY, false);
            reader.setFeature("javax.wsdl.importDocuments", true);
            Definition definition = reader.readWSDL(new HumanTaskWSDLLocator(uri));
            wsdlDefinitions.add(definition);

        } catch (WSDLException e) {
            System.out.println("Error processing wsdl " + file.getName());
            throw new HumanTaskDeploymentException(" Error processing wsdl ", e);
        } catch (URISyntaxException e) {
            System.out.println("Invalid uri in reading wsdl ");
            throw new HumanTaskDeploymentException(" Invalid uri in reading wsdl ", e);
        }
        //            wsdlsMap.put(file.getName(), is);
    }
}

From source file:org.apache.ode.store.DeploymentUnitDir.java

public DocumentRegistry getDocRegistry() {
    if (_docRegistry == null) {
        _docRegistry = new DocumentRegistry();

        WSDLFactory4BPEL wsdlFactory = (WSDLFactory4BPEL) WSDLFactoryBPEL20.newInstance();
        WSDLReader r = wsdlFactory.newWSDLReader();
        DefaultResourceFinder rf = new DefaultResourceFinder(_duDirectory, _duDirectory);
        URI basedir = _duDirectory.toURI();
        List<File> wsdls = FileUtils.directoryEntriesInPath(_duDirectory, DeploymentUnitDir._wsdlFilter);
        for (File file : wsdls) {
            URI uri = basedir.relativize(file.toURI());
            try {
                _docRegistry.addDefinition((Definition4BPEL) r.readWSDL(new WSDLLocatorImpl(rf, uri)));
            } catch (WSDLException e) {
                throw new ContextException("Couldn't read WSDL document at " + uri, e);
            }//from  w  w w  .j av  a2 s.  c  om
        }
    }
    return _docRegistry;
}

From source file:stargate.drivers.hazelcast.PersistentMapStore.java

@Override
public synchronized Iterable<String> loadAllKeys() {
    try {//  www .j  a va  2s  . c o  m
        URI bucketPath = this.getBucketPath();
        List<String> arr = new ArrayList<String>();
        if (this.temporalStorageManager.exists(bucketPath)) {
            Collection<URI> entries = this.temporalStorageManager.listDirectory(bucketPath);
            if (entries != null && !entries.isEmpty()) {
                for (URI entry : entries) {
                    URI relativePath = bucketPath.relativize(entry);
                    String path = relativePath.getPath();
                    arr.add(PathUtils.decodeHadoopFilename(path));
                }
            }
        }
        return arr;
    } catch (URISyntaxException ex) {
        LOG.error("Failed to load all entries", ex);
    } catch (IOException ex) {
        LOG.error("Failed to load all entries", ex);
    }

    return null;
}

From source file:org.apache.hadoop.mapred.lib.MobiusDelegatingInputFormat.java

private String getDatasetIDBySplit(InputSplit split, JobConf conf) throws IOException {
    // The <code>split</code> is an instance of {@link TaggedInputSplit}
    // but the TaggedInputSplit is not a public class, so we need to place
    // this class under the package of org.apache.hadoop.mapred.lib.

    TaggedInputSplit taggedSplit = (TaggedInputSplit) split;
    InputSplit inputSplit = taggedSplit.getInputSplit();
    URI currentFileURI = MultiInputsHelpersRepository.getInstance(conf).getURIBySplit(inputSplit, conf);
    String currentFile = currentFileURI.toString();

    LOGGER.debug("Using [" + currentFile + "] to locate current Dataset");

    String datasetID = null;/*from  w  ww  .j a v  a2 s  .  c  o m*/
    for (URI anInput : _INPUT_URIS) {
        if (anInput.equals(currentFileURI)) {
            datasetID = _URI_TO_DATASETID_MAPPING.get(anInput);
            if (datasetID == null || datasetID.trim().length() == 0)
                throw new IllegalArgumentException(
                        "Dataet ID for the input path:[" + anInput + "] did not set.");
        } else {
            // not equal, compute the relative URI
            URI relative = anInput.relativize(currentFileURI);
            if (!relative.equals(currentFileURI)) {
                // found the key
                datasetID = _URI_TO_DATASETID_MAPPING.get(anInput);
                if (datasetID == null || datasetID.trim().length() == 0)
                    throw new IllegalArgumentException(
                            "Dataet ID for the input path:[" + anInput + "] did not set.");
            }
        }
    }

    if (datasetID == null) {
        throw new IllegalArgumentException("Cannot find dataset id using the given uri:[" + currentFile + "], "
                + ConfigureConstants.INPUT_TO_DATASET_MAPPING + ":"
                + conf.get(ConfigureConstants.INPUT_TO_DATASET_MAPPING));
    }

    return datasetID;
}

From source file:org.wso2.carbon.appfactory.repository.mgt.git.JGitAgent.java

/**
 * Get relative path of {@code file} against {@code baseFile}
 *
 * @param file     The file to be relativized against {@code baseFile}
 * @param baseFile base file// ww w  . j a  va 2s .  c om
 * @return null if {@code file} isn't relative to {@code baseFile}, else the relative path.
 */
private String getRelativePath(File file, File baseFile) {
    String relativePath = null;
    URI baseUri = baseFile.toURI();
    URI fileUri = file.toURI();
    if (fileUri.getPath().startsWith(baseUri.getPath())) {
        relativePath = baseUri.relativize(fileUri).getPath();
    }
    return relativePath;
}

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

private Map<String, String> relativize(Map<URI, URI> changeTable, File tempDir) {
    final URI t = tempDir.toURI();
    return changeTable.entrySet().stream().collect(Collectors.toMap(e -> t.relativize(e.getKey()).toString(),
            e -> t.relativize(e.getValue()).toString()));
}

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

@Override
public AbstractPipelineOutput execute(final AbstractPipelineInput input) throws DITAOTException {
    final URI base = job.getInputDir();

    final Collection<FileInfo> fis = job.getFileInfo().stream().collect(Collectors.toList());

    final LinkFilter filter = new LinkFilter();
    filter.setJob(job);// w  w w  .  j a va2  s.  c om
    filter.setLogger(logger);
    final Collection<FileInfo> res = new ArrayList<>(fis.size());
    for (final FileInfo fi : fis) {
        try {
            final FileInfo.Builder builder = new FileInfo.Builder(fi);
            final File srcFile = new File(job.tempDirURI.resolve(fi.uri));
            if (srcFile.exists()) {
                final URI rel = base.relativize(fi.result);
                final File destFile = new File(job.tempDirURI.resolve(rel));
                if (fi.format == null || fi.format.equals(ATTR_FORMAT_VALUE_DITA)
                        || fi.format.equals(ATTR_FORMAT_VALUE_DITAMAP)) {
                    logger.info("Processing " + srcFile.toURI() + " to " + destFile.toURI());
                    filter.setCurrentFile(srcFile.toURI());
                    filter.setDestFile(destFile.toURI());
                    transform(srcFile.toURI(), destFile.toURI(), Collections.singletonList(filter));
                    if (!srcFile.equals(destFile)) {
                        logger.debug("Deleting " + srcFile.toURI());
                        FileUtils.deleteQuietly(srcFile);
                    }
                } else if (fi.format.equals("coderef")) {
                    // SKIP
                } else if (!srcFile.equals(destFile)) {
                    logger.info("Copying " + srcFile.toURI() + " to " + destFile.toURI());
                    FileUtils.moveFile(srcFile, destFile);
                }
                builder.uri(rel);

                // start map
                if (fi.src.equals(job.getInputFile())) {
                    job.setProperty(INPUT_DITAMAP_URI, rel.toString());
                    job.setProperty(INPUT_DITAMAP, toFile(rel).getPath());
                }
            }
            res.add(builder.build());
        } catch (final IOException e) {
            logger.error("Failed to clean " + job.tempDirURI.resolve(fi.uri) + ": " + e.getMessage(), e);
        }
    }

    fis.stream().forEach(fi -> job.remove(fi));
    res.stream().forEach(fi -> job.add(fi));

    try {
        job.write();
    } catch (IOException e) {
        throw new DITAOTException();
    }

    return null;
}

From source file:pcgen.gui2.dialog.ExportDialog.java

private void refreshFiles() {
    if (allTemplates != null) {
        String outputSheetsDir;//  w  w  w . j av  a2s  .com
        SheetFilter sheetFilter = (SheetFilter) exportBox.getSelectedItem();
        IOFileFilter ioFilter = FileFilterUtils.asFileFilter(sheetFilter);
        IOFileFilter prefixFilter;
        String defaultSheet = null;
        String outputSheetDirectory = SettingsHandler.getGame().getOutputSheetDirectory();
        if (outputSheetDirectory == null) {
            outputSheetsDir = ConfigurationSettings.getOutputSheetsDir() + "/" + sheetFilter.getPath();
        } else {
            outputSheetsDir = ConfigurationSettings.getOutputSheetsDir() + "/" + outputSheetDirectory + "/"
                    + sheetFilter.getPath();
        }

        if (partyBox.isSelected()) {
            prefixFilter = FileFilterUtils.prefixFileFilter(Constants.PARTY_TEMPLATE_PREFIX);
        } else {
            CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem();
            prefixFilter = FileFilterUtils.prefixFileFilter(Constants.CHARACTER_TEMPLATE_PREFIX);
            defaultSheet = character.getDefaultOutputSheet(sheetFilter == SheetFilter.PDF);
            if (StringUtils.isEmpty(defaultSheet)) {
                defaultSheet = outputSheetsDir + "/"
                        + SettingsHandler.getGame().getOutputSheetDefault(sheetFilter.getTag());
            }
        }
        IOFileFilter filter = FileFilterUtils.and(prefixFilter, ioFilter);
        List<File> files = FileFilterUtils.filterList(filter, allTemplates);
        Collections.sort(files);

        URI osPath = new File(outputSheetsDir).toURI();
        URI[] uriList = new URI[files.size()];
        for (int i = 0; i < uriList.length; i++) {
            uriList[i] = osPath.relativize(files.get(i).toURI());
        }
        fileList.setListData(uriList);
        if (StringUtils.isNotEmpty(defaultSheet)) {
            URI defaultPath = new File(defaultSheet).toURI();
            fileList.setSelectedValue(osPath.relativize(defaultPath), true);
        }
    }
}

From source file:org.apache.sling.testing.clients.AbstractSlingClient.java

/**
 * <p>Transforms an external {@code url} into a sling path, by subtracting the {@code server url} (incl. contextPath).
 * The returned path will not contain the context path, so it can be used with {@link #getUrl(String)}</p>
 *
 * <p>The url can be absolute (incl. hostname) or relative to root (starts with "/").</p>
 *
 * <p>If the server url is not a prefix of the given url, it returns the given url</p>
 *
 * <p>If the url is just a path, it returns the path (with leading slash if not already present)</p>
 *
 * @param url full url/*from www .  java  2 s  .  c om*/
 * @return sling path
 */
public URI getPath(URI url) {
    // special case for urls that are server urls, but without trailing slash
    if (url.relativize(getUrl()).equals(URI.create(""))) {
        return slash;
    }

    URI contextPath = URI.create(getUrl().getPath());
    URI relativeUrl = contextPath.relativize(slash.resolve(url));

    if (relativeUrl.relativize(contextPath).equals(URI.create(""))) {
        return slash;
    }

    return slash.resolve(getUrl().relativize(relativeUrl));
}

From source file:org.apache.openmeetings.backup.BackupExport.java

private void writeZipDir(URI base, File dir, ZipOutputStream zos, File zipFile) throws IOException {
    for (File file : dir.listFiles()) {
        if (zipFile.equals(file)) {
            continue;
        }//from   ww w.  j a va 2s  .c om
        if (file.isDirectory()) {
            writeZipDir(base, file, zos, zipFile);
        } else {
            String path = base.relativize(file.toURI()).toString();
            log.debug("Writing '" + path + "' to zip file");
            ZipEntry zipEntry = new ZipEntry(path);
            zos.putNextEntry(zipEntry);

            OmFileHelper.copyFile(file, zos);
            zos.closeEntry();
        }
    }
}