List of usage examples for java.net URI resolve
public URI resolve(String str)
From source file:com.reprezen.swagedit.editor.hyperlinks.JsonReferenceHyperlinkDetector.java
@Override protected IHyperlink[] doDetect(SwaggerDocument doc, ITextViewer viewer, HyperlinkInfo info, JsonPointer pointer) {/* ww w . java 2s. co m*/ URI baseURI = getBaseURI(); AbstractNode node = doc.getModel().find(pointer); JsonReference reference = getFactory().createSimpleReference(getBaseURI(), node); if (reference == null) { reference = getFactory().create(node); } if (reference.isInvalid() || reference.isMissing(doc, getBaseURI())) { return null; } if (reference.isLocal()) { IRegion target = doc.getRegion(reference.getPointer()); if (target == null) { return null; } return new IHyperlink[] { new SwaggerHyperlink(reference.getPointer().toString(), viewer, info.region, target) }; } else { URI resolved; try { resolved = baseURI.resolve(reference.getUri()); } catch (IllegalArgumentException e) { // the given string violates RFC 2396 return null; } IFile file = DocumentUtils.getWorkspaceFile(resolved); if (file != null && file.exists()) { return new IHyperlink[] { new SwaggerFileHyperlink(info.region, info.text, file, reference.getPointer()) }; } } return null; }
From source file:org.forgerock.cloudfoundry.Configuration.java
/** * Constructs a new Configuration.//w w w.j a va 2 s . com * @param baseUri the base URI of OpenAM * @param openAmUsername the username to use to authenticate against OpenAM * @param openAmPassword the password to use to authenticate against OpenAM * @param realm the OpenAM realm to use * @param brokerUsername the username that clients to this broker are required to use. * @param brokerPassword the password that clients to this broker are required to use. * @param scopes A space delimited list of scopes that OAuth 2.0 clients will be created with. */ public Configuration(String baseUri, String openAmUsername, String openAmPassword, String realm, String brokerUsername, String brokerPassword, String scopes) { URI openAmBaseUrl; try { openAmBaseUrl = new URI(validateProperty(baseUri, "OPENAM_BASE_URI") + "/"); } catch (URISyntaxException e) { throw new IllegalStateException("OPENAM_BASE_URI is not a valid URI", e); } this.openAmUsername = validateProperty(openAmUsername, "OPENAM_USERNAME"); this.openAmPassword = validateProperty(openAmPassword, "OPENAM_PASSWORD"); this.brokerUsername = validateProperty(brokerUsername, "SECURITY_USER_NAME"); this.brokerPassword = validateProperty(brokerPassword, "SECURITY_USER_PASSWORD"); this.scopes = Lists.newArrayList(validateProperty(scopes, "OAUTH2_SCOPES").split(" ")); realm = StringUtils.trimToEmpty(realm); openAmApiBaseUrl = openAmBaseUrl.resolve("json/"); openAmApiRealmUrl = openAmBaseUrl.resolve("json/" + realm + "/"); openAmOAuth2Url = openAmBaseUrl.resolve("oauth2/" + realm + "/"); }
From source file:org.kitodo.filemanagement.FileManagement.java
/** * Gets the image source directory./*from w ww .j av a 2 s. co m*/ * * @param processTitle * title of the process, to get the source directory for * @return the source directory as a string */ private URI getSourceDirectory(String processId, String processTitle) { final String suffix = "_" + KitodoConfig.getParameter(ParameterFileManagement.DIRECTORY_SUFFIX, "tif"); URI dir = URI.create(getProcessSubType(processId, processTitle, ProcessSubType.IMAGE, null)); FilenameFilter filterDirectory = new FileNameEndsWithFilter(suffix); URI sourceFolder = URI.create(""); try { List<URI> directories = getSubUris(filterDirectory, dir); if (directories.isEmpty()) { sourceFolder = dir.resolve(processTitle + suffix + "/"); if (KitodoConfig.getBooleanParameter(ParameterFileManagement.CREATE_SOURCE_FOLDER, false)) { if (!fileExist(dir)) { createDirectory(dir.resolve(".."), IMAGES_DIRECTORY_NAME); } createDirectory(dir, processTitle + suffix); } } else { sourceFolder = dir.resolve("/" + directories.get(0)); } } catch (IOException e) { logger.error(e.getMessage(), e); } return sourceFolder; }
From source file:org.paxle.desktop.impl.CrawlStartHelper.java
private void startCrawlImpl(final String location, final int depth) throws ServiceException, IOException { final URI uri = refNormalizer.normalizeReference(location); // check uri against robots.txt synchronized (this) { if (robots != null) try { final Method isDisallowed = robots.getClass().getMethod("isDisallowed", URI.class); final Object result = isDisallowed.invoke(robots, uri); if (((Boolean) result).booleanValue()) { logger.info("Domain does not allow crawling of '" + uri + "' due to robots.txt blockage"); Utilities.instance.showURLErrorMessage( "This URI is blocked by the domain's robots.txt, see", uri.resolve(URI.create("/robots.txt")).toString()); return; }/*ww w .j av a2 s.c o m*/ } catch (Exception e) { logger.warn( String.format("Error retrieving robots.txt from host '%s': [%s] %s - continuing crawl", uri.getHost(), e.getClass().getName(), e.getMessage())); } } // get or create the crawl profile to use for URI ICommandProfile cp = null; final Integer depthInt = Integer.valueOf(depth); final Integer id = profileDepthMap.get(depthInt); if (id != null) cp = profileDB.getProfileByID(id.intValue()); if (cp == null) { // create a new profile cp = this.profileFactory.createDocument(ICommandProfile.class); cp.setMaxDepth(depth); cp.setName(DEFAULT_NAME); profileDB.storeProfile(cp); } if (id == null || cp.getOID() != id.intValue()) profileDepthMap.put(depthInt, Integer.valueOf(cp.getOID())); try { final Method enqueueCommand = commandDB.getClass().getMethod("enqueue", URI.class, int.class, int.class); final Object result = enqueueCommand.invoke(commandDB, uri, Integer.valueOf(cp.getOID()), Integer.valueOf(0)); if (((Boolean) result).booleanValue()) { logger.info("Initiated crawl of URL '" + uri + "'"); } else { logger.info("Initiating crawl of URL '" + uri + "' failed, URL is already known"); } } catch (Exception e) { throw new ServiceException("Crawl start", e.getMessage(), e); } }
From source file:org.kitodo.production.services.file.FileServiceTest.java
@Test public void testMoveDirectory() throws IOException { URI directory = fileService.createDirectory(URI.create("fileServiceTest"), "movingDirectory"); fileService.createResource(directory, "test.xml"); URI target = URI.create("fileServiceTest/movingDirectoryTarget/"); assertTrue(fileService.fileExist(directory)); assertTrue(fileService.fileExist(directory.resolve("test.xml"))); assertFalse(fileService.fileExist(target)); fileService.moveDirectory(directory, target); assertFalse(fileService.fileExist(directory)); assertFalse(fileService.fileExist(directory.resolve("test.xml"))); assertTrue(fileService.fileExist(target)); assertTrue(fileService.fileExist(target.resolve("test.xml"))); }
From source file:org.kitodo.services.file.FileServiceTest.java
@Test public void testMoveDirectory() throws IOException { URI directory = fileService.createDirectory(URI.create("fileServiceTest"), "movingDirectory"); fileService.createResource(directory, "test.xml"); URI target = URI.create("fileServiceTest/movingDirectoryTarget/"); Assert.assertTrue(fileService.fileExist(directory)); Assert.assertTrue(fileService.fileExist(directory.resolve("test.xml"))); Assert.assertFalse(fileService.fileExist(target)); fileService.moveDirectory(directory, target); Assert.assertFalse(fileService.fileExist(directory)); Assert.assertFalse(fileService.fileExist(directory.resolve("test.xml"))); Assert.assertTrue(fileService.fileExist(target)); Assert.assertTrue(fileService.fileExist(target.resolve("test.xml"))); }
From source file:org.opencb.opencga.storage.app.cli.client.VariantCommandExecutor.java
private void annotation() throws StorageManagerException, IOException, URISyntaxException, VariantAnnotatorException { CliOptionsParser.AnnotateVariantsCommandOptions annotateVariantsCommandOptions = variantCommandOptions.annotateVariantsCommandOptions; VariantDBAdaptor dbAdaptor = variantStorageManager.getDBAdaptor(annotateVariantsCommandOptions.dbName); /*//from ww w . j a v a 2 s . c om * Create Annotator */ ObjectMap options = configuration.getStorageEngine(storageEngine).getVariant().getOptions(); if (annotateVariantsCommandOptions.annotator != null) { options.put(VariantAnnotationManager.ANNOTATION_SOURCE, annotateVariantsCommandOptions.annotator); } if (annotateVariantsCommandOptions.customAnnotationKey != null) { options.put(VariantAnnotationManager.CUSTOM_ANNOTATION_KEY, annotateVariantsCommandOptions.customAnnotationKey); } if (annotateVariantsCommandOptions.species != null) { options.put(VariantAnnotationManager.SPECIES, annotateVariantsCommandOptions.species); } if (annotateVariantsCommandOptions.assembly != null) { options.put(VariantAnnotationManager.ASSEMBLY, annotateVariantsCommandOptions.assembly); } options.putAll(annotateVariantsCommandOptions.commonOptions.params); VariantAnnotator annotator = VariantAnnotationManager.buildVariantAnnotator(configuration, storageEngine, options); // VariantAnnotator annotator = VariantAnnotationManager.buildVariantAnnotator(annotatorSource, annotatorProperties, // annotateVariantsCommandOptions.species, annotateVariantsCommandOptions.assembly); VariantAnnotationManager variantAnnotationManager = new VariantAnnotationManager(annotator, dbAdaptor); /* * Annotation options */ Query query = new Query(); if (annotateVariantsCommandOptions.filterRegion != null) { query.put(VariantDBAdaptor.VariantQueryParams.REGION.key(), annotateVariantsCommandOptions.filterRegion); } if (annotateVariantsCommandOptions.filterChromosome != null) { query.put(VariantDBAdaptor.VariantQueryParams.CHROMOSOME.key(), annotateVariantsCommandOptions.filterChromosome); } if (annotateVariantsCommandOptions.filterGene != null) { query.put(VariantDBAdaptor.VariantQueryParams.GENE.key(), annotateVariantsCommandOptions.filterGene); } if (annotateVariantsCommandOptions.filterAnnotConsequenceType != null) { query.put(VariantDBAdaptor.VariantQueryParams.ANNOT_CONSEQUENCE_TYPE.key(), annotateVariantsCommandOptions.filterAnnotConsequenceType); } if (!annotateVariantsCommandOptions.overwriteAnnotations) { query.put(VariantDBAdaptor.VariantQueryParams.ANNOTATION_EXISTS.key(), false); } URI outputUri = UriUtils.createUri( annotateVariantsCommandOptions.outdir == null ? "." : annotateVariantsCommandOptions.outdir); Path outDir = Paths.get(outputUri.resolve(".").getPath()); /* * Create and load annotations */ boolean doCreate = annotateVariantsCommandOptions.create, doLoad = annotateVariantsCommandOptions.load != null; if (!annotateVariantsCommandOptions.create && annotateVariantsCommandOptions.load == null) { doCreate = true; doLoad = true; } URI annotationFile = null; if (doCreate) { long start = System.currentTimeMillis(); logger.info("Starting annotation creation "); annotationFile = variantAnnotationManager.createAnnotation(outDir, annotateVariantsCommandOptions.fileName == null ? annotateVariantsCommandOptions.dbName : annotateVariantsCommandOptions.fileName, query, new QueryOptions(options)); logger.info("Finished annotation creation {}ms", System.currentTimeMillis() - start); } if (doLoad) { long start = System.currentTimeMillis(); logger.info("Starting annotation load"); if (annotationFile == null) { // annotationFile = new URI(null, c.load, null); annotationFile = Paths.get(annotateVariantsCommandOptions.load).toUri(); } variantAnnotationManager.loadAnnotation(annotationFile, new QueryOptions(options)); logger.info("Finished annotation load {}ms", System.currentTimeMillis() - start); } }
From source file:de.sub.goobi.export.dms.ExportDms.java
/** * Download full text./* w w w . j a va 2 s. c o m*/ * * @param process * object * @param userHome * File * @param atsPpnBand * String * @param ordnerEndung * String */ public void fulltextDownload(Process process, URI userHome, String atsPpnBand, final String ordnerEndung) throws IOException { // download sources URI sources = serviceManager.getFileService().getSourceDirectory(process); if (fileService.fileExist(sources) && fileService.getSubUris(sources).size() > 0) { URI destination = userHome.resolve(File.separator + atsPpnBand + "_src"); if (!fileService.fileExist(destination)) { fileService.createDirectory(userHome, atsPpnBand + "_src"); } ArrayList<URI> files = fileService.getSubUris(sources); for (URI file : files) { if (fileService.isFile(file)) { if (exportDmsTask != null) { exportDmsTask.setWorkDetail(fileService.getFileName(file)); } URI target = destination.resolve(File.separator + fileService.getFileName(file)); fileService.copyFile(file, target); } } } URI ocr = serviceManager.getFileService().getOcrDirectory(process); if (fileService.fileExist(ocr)) { ArrayList<URI> folder = fileService.getSubUris(ocr); for (URI dir : folder) { if (fileService.isDirectory(dir) && fileService.getSubUris(dir).size() > 0 && fileService.getFileName(dir).contains("_")) { String suffix = fileService.getFileName(dir) .substring(fileService.getFileName(dir).lastIndexOf("_")); URI destination = userHome.resolve(File.separator + atsPpnBand + suffix); if (!fileService.fileExist(destination)) { fileService.createDirectory(userHome, atsPpnBand + suffix); } ArrayList<URI> files = fileService.getSubUris(dir); for (URI file : files) { if (fileService.isFile(file)) { if (exportDmsTask != null) { exportDmsTask.setWorkDetail(fileService.getFileName(file)); } URI target = destination.resolve(File.separator + fileService.getFileName(file)); fileService.copyFile(file, target); } } } } } if (exportDmsTask != null) { exportDmsTask.setWorkDetail(null); } }
From source file:org.opencb.opencga.storage.app.cli.client.VariantCommandExecutor.java
private void stats() throws IOException, URISyntaxException, StorageManagerException, IllegalAccessException, InstantiationException, ClassNotFoundException { CliOptionsParser.StatsVariantsCommandOptions statsVariantsCommandOptions = variantCommandOptions.statsVariantsCommandOptions; ObjectMap options = storageConfiguration.getVariant().getOptions(); if (statsVariantsCommandOptions.dbName != null && !statsVariantsCommandOptions.dbName.isEmpty()) { options.put(VariantStorageManager.Options.DB_NAME.key(), statsVariantsCommandOptions.dbName); }/*from w w w. ja v a 2 s.c o m*/ options.put(VariantStorageManager.Options.OVERWRITE_STATS.key(), statsVariantsCommandOptions.overwriteStats); options.put(VariantStorageManager.Options.UPDATE_STATS.key(), statsVariantsCommandOptions.updateStats); if (statsVariantsCommandOptions.fileId != 0) { options.put(VariantStorageManager.Options.FILE_ID.key(), statsVariantsCommandOptions.fileId); } options.put(VariantStorageManager.Options.STUDY_ID.key(), statsVariantsCommandOptions.studyId); if (statsVariantsCommandOptions.studyConfigurationFile != null && !statsVariantsCommandOptions.studyConfigurationFile.isEmpty()) { options.put(FileStudyConfigurationManager.STUDY_CONFIGURATION_PATH, statsVariantsCommandOptions.studyConfigurationFile); } if (statsVariantsCommandOptions.commonOptions.params != null) { options.putAll(statsVariantsCommandOptions.commonOptions.params); } Map<String, Set<String>> cohorts = null; if (statsVariantsCommandOptions.cohort != null && !statsVariantsCommandOptions.cohort.isEmpty()) { cohorts = new LinkedHashMap<>(statsVariantsCommandOptions.cohort.size()); for (Map.Entry<String, String> entry : statsVariantsCommandOptions.cohort.entrySet()) { List<String> samples = Arrays.asList(entry.getValue().split(",")); if (samples.size() == 1 && samples.get(0).isEmpty()) { samples = new ArrayList<>(); } cohorts.put(entry.getKey(), new HashSet<>(samples)); } } options.put(VariantStorageManager.Options.AGGREGATED_TYPE.key(), statsVariantsCommandOptions.aggregated); if (statsVariantsCommandOptions.aggregationMappingFile != null) { Properties aggregationMappingProperties = new Properties(); try { aggregationMappingProperties .load(new FileInputStream(statsVariantsCommandOptions.aggregationMappingFile)); options.put(VariantStorageManager.Options.AGGREGATION_MAPPING_PROPERTIES.key(), aggregationMappingProperties); } catch (FileNotFoundException e) { logger.error("Aggregation mapping file {} not found. Population stats won't be parsed.", statsVariantsCommandOptions.aggregationMappingFile); } } /** * Create DBAdaptor */ VariantDBAdaptor dbAdaptor = variantStorageManager .getDBAdaptor(options.getString(VariantStorageManager.Options.DB_NAME.key())); // dbAdaptor.setConstantSamples(Integer.toString(statsVariantsCommandOptions.fileId)); // TODO jmmut: change to studyId when we // remove fileId StudyConfiguration studyConfiguration = dbAdaptor.getStudyConfigurationManager() .getStudyConfiguration(statsVariantsCommandOptions.studyId, new QueryOptions(options)).first(); if (studyConfiguration == null) { studyConfiguration = new StudyConfiguration(statsVariantsCommandOptions.studyId, statsVariantsCommandOptions.dbName); } /** * Create and load stats */ URI outputUri = UriUtils.createUri( statsVariantsCommandOptions.fileName == null ? "" : statsVariantsCommandOptions.fileName); URI directoryUri = outputUri.resolve("."); String filename = outputUri.equals(directoryUri) ? VariantStorageManager.buildFilename(studyConfiguration.getStudyName(), statsVariantsCommandOptions.fileId) : Paths.get(outputUri.getPath()).getFileName().toString(); // assertDirectoryExists(directoryUri); VariantStatisticsManager variantStatisticsManager = new VariantStatisticsManager(); boolean doCreate = true; boolean doLoad = true; // doCreate = statsVariantsCommandOptions.create; // doLoad = statsVariantsCommandOptions.load != null; // if (!statsVariantsCommandOptions.create && statsVariantsCommandOptions.load == null) { // doCreate = doLoad = true; // } else if (statsVariantsCommandOptions.load != null) { // filename = statsVariantsCommandOptions.load; // } try { Map<String, Integer> cohortIds = statsVariantsCommandOptions.cohortIds.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> Integer.parseInt(e.getValue()))); QueryOptions queryOptions = new QueryOptions(options); if (doCreate) { filename += "." + TimeUtils.getTime(); outputUri = outputUri.resolve(filename); outputUri = variantStatisticsManager.createStats(dbAdaptor, outputUri, cohorts, cohortIds, studyConfiguration, queryOptions); } if (doLoad) { outputUri = outputUri.resolve(filename); variantStatisticsManager.loadStats(dbAdaptor, outputUri, studyConfiguration, queryOptions); } } catch (Exception e) { // file not found? wrong file id or study id? bad parameters to ParallelTaskRunner? e.printStackTrace(); logger.error(e.getMessage()); } }
From source file:de.sub.goobi.export.dms.ExportDms.java
/** * Starts copying all directories configured in kitodo_config.properties * parameter "processDirs" to export folder. * * @param process//w ww . ja va 2 s.c om * object * @param zielVerzeichnis * the destination directory * */ private void directoryDownload(Process process, URI zielVerzeichnis) throws IOException { String[] processDirs = ConfigCore.getStringArrayParameter("processDirs"); for (String processDir : processDirs) { URI srcDir = serviceManager.getProcessService().getProcessDataDirectory(process) .resolve(processDir.replace("(processtitle)", process.getTitle())); URI dstDir = zielVerzeichnis.resolve(processDir.replace("(processtitle)", process.getTitle())); if (fileService.isDirectory(srcDir)) { fileService.copyDirectory(srcDir, dstDir); } } }