List of usage examples for java.net URI getSchemeSpecificPart
public String getSchemeSpecificPart()
From source file:com.collaborne.jsonschema.generator.pojo.PojoGenerator.java
/** * Get the {@link SchemaTree} for the given {@code uri}. * /*from w w w. j a v a2 s . c o m*/ * This is similar to {@link SchemaLoader#get(URI)}, but allows {@code uri} to contain a fragment. * * @param uri * @return * @throws ProcessingException */ // XXX: Should this be the default behavior of SchemaLoader#get()? @VisibleForTesting protected SchemaTree getSchema(SchemaLoader schemaLoader, URI uri) throws ProcessingException { String fragment = uri.getFragment(); if (fragment == null) { return schemaLoader.get(uri); } else { try { URI schemaTreeUri = new URI(uri.getScheme(), uri.getSchemeSpecificPart(), null); JsonPointer pointer = new JsonPointer(fragment); SchemaTree schema = schemaLoader.get(schemaTreeUri); return schema.setPointer(pointer); } catch (URISyntaxException | JsonPointerException e) { assert false : "Was a valid before, we split things up!"; throw new RuntimeException(e); } } }
From source file:org.apache.openmeetings.service.calendar.caldav.IcalUtils.java
/** * Add properties from the Given VEvent Component to the Appointment * * @param a Appointment to which the properties are to be added * @param event VEvent to parse properties from. * @return Updated Appointment/*w ww . j a v a 2 s . c o m*/ */ private Appointment addVEventPropertiestoAppointment(Appointment a, CalendarComponent event) { DateProperty dtstart = (DateProperty) event.getProperty(Property.DTSTART), dtend = (DateProperty) event.getProperty(Property.DTEND), dtstamp = (DateProperty) event.getProperty(Property.DTSTAMP), lastmod = (DateProperty) event.getProperty(Property.LAST_MODIFIED); Property uid = event.getProperty(Property.UID), description = event.getProperty(Property.DESCRIPTION), summary = event.getProperty(Property.SUMMARY), location = event.getProperty(Property.LOCATION), organizer = event.getProperty(Property.ORGANIZER), recur = event.getProperty(Property.RRULE); PropertyList<Attendee> attendees = event.getProperties(Property.ATTENDEE); if (uid != null) { a.setIcalId(uid.getValue()); } Date d = dtstart.getDate(); a.setStart(d); if (dtend == null) { a.setEnd(addTimetoDate(d, java.util.Calendar.HOUR_OF_DAY, 1)); } else { a.setEnd(dtend.getDate()); } a.setInserted(dtstamp.getDate()); if (lastmod != null) { a.setUpdated(lastmod.getDate()); } if (description != null) { a.setDescription(description.getValue()); } if (summary != null) { a.setTitle(summary.getValue()); } if (location != null) { a.setLocation(location.getValue()); } if (recur != null) { Parameter freq = recur.getParameter("FREQ"); if (freq != null) { if (freq.getValue().equals(Frequency.DAILY.name())) { a.setIsDaily(true); } else if (freq.getValue().equals(Frequency.WEEKLY.name())) { a.setIsWeekly(true); } else if (freq.getValue().equals(Frequency.MONTHLY.name())) { a.setIsMonthly(true); } else if (freq.getValue().equals(Frequency.YEARLY.name())) { a.setIsYearly(true); } } } Set<MeetingMember> attList = a.getMeetingMembers() == null ? new HashSet<>() : new HashSet<>(a.getMeetingMembers()); String organizerEmail = null; //Note this value can be repeated in attendees as well. if (organizer != null) { URI uri = URI.create(organizer.getValue()); //If the value of the organizer is an email if ("mailto".equals(uri.getScheme())) { String email = uri.getSchemeSpecificPart(); organizerEmail = email; if (!email.equals(a.getOwner().getAddress().getEmail())) { //Contact or exist and owner User org = userDao.getByEmail(email); if (org == null) { org = userDao.getContact(email, a.getOwner()); attList.add(createMeetingMember(a, org)); } else if (!org.getId().equals(a.getOwner().getId())) { attList.add(createMeetingMember(a, org)); } } } } if (attendees != null && !attendees.isEmpty()) { for (Property attendee : attendees) { URI uri = URI.create(attendee.getValue()); if ("mailto".equals(uri.getScheme())) { String email = uri.getSchemeSpecificPart(); Role role = attendee.getParameter(Role.CHAIR.getName()); if (role != null && role.getValue().equals(Role.CHAIR.getValue()) && email.equals(organizerEmail)) { continue; } User u = userDao.getByEmail(email); if (u == null) { u = userDao.getContact(email, a.getOwner()); } attList.add(createMeetingMember(a, u)); } } } a.setMeetingMembers(attList.isEmpty() ? null : new ArrayList<>(attList)); return a; }
From source file:org.codice.ddf.catalog.content.impl.FileSystemStorageProvider.java
private ContentItem readContent(URI uri) throws StorageException { Path file = getContentFilePath(uri); if (file == null) { throw new StorageException("Unable to find file for content ID: " + uri.getSchemeSpecificPart()); }/*from w w w . j a v a 2 s .c o m*/ String extension = FilenameUtils.getExtension(file.getFileName().toString()); String mimeType; try (InputStream fileInputStream = Files.newInputStream(file)) { mimeType = mimeTypeMapper.guessMimeType(fileInputStream, extension); } catch (Exception e) { LOGGER.warn("Could not determine mime type for file extension = {}; defaulting to {}", extension, DEFAULT_MIME_TYPE); mimeType = DEFAULT_MIME_TYPE; } if (mimeType == null || DEFAULT_MIME_TYPE.equals(mimeType)) { try { mimeType = Files.probeContentType(file); } catch (IOException e) { LOGGER.warn("Unable to determine mime type using Java Files service.", e); mimeType = DEFAULT_MIME_TYPE; } } LOGGER.debug("mimeType = {}", mimeType); long size = 0; try { size = Files.size(file); } catch (IOException e) { LOGGER.warn("Unable to retrieve size of file: {}", file.toAbsolutePath().toString(), e); } return new ContentItemImpl(uri.getSchemeSpecificPart(), uri.getFragment(), com.google.common.io.Files.asByteSource(file.toFile()), mimeType, file.getFileName().toString(), size, null); }
From source file:org.codice.ddf.catalog.content.resource.reader.ContentResourceReader.java
@Override public ResourceResponse retrieveResource(URI resourceUri, Map<String, Serializable> arguments) throws IOException, ResourceNotFoundException, ResourceNotSupportedException { LOGGER.trace("ENTERING: retrieveResource"); ResourceResponse response = null;/* ww w . ja v a 2s . c om*/ if (resourceUri == null) { LOGGER.warn("Resource URI was null"); throw new ResourceNotFoundException("Unable to find resource - resource URI was null"); } if (resourceUri.getScheme().equals(ContentItem.CONTENT_SCHEME)) { LOGGER.debug("Resource URI is content scheme"); String contentId = resourceUri.getSchemeSpecificPart(); if (contentId != null && !contentId.isEmpty()) { if (arguments != null && arguments.get(ContentItem.QUALIFIER) instanceof String && StringUtils.isNotBlank((String) arguments.get(ContentItem.QUALIFIER))) { try { resourceUri = new URI(resourceUri.getScheme(), resourceUri.getSchemeSpecificPart(), (String) arguments.get(ContentItem.QUALIFIER)); } catch (URISyntaxException e) { throw new ResourceNotFoundException("Unable to create with qualifier", e); } } ReadStorageRequest readRequest = new ReadStorageRequestImpl(resourceUri, arguments); try { ReadStorageResponse readResponse = storage.read(readRequest); ContentItem contentItem = readResponse.getContentItem(); String fileName = contentItem.getFilename(); LOGGER.debug("resource name: " + fileName); InputStream is = contentItem.getInputStream(); response = new ResourceResponseImpl( new ResourceImpl(new BufferedInputStream(is), contentItem.getMimeType(), fileName)); } catch (StorageException e) { throw new ResourceNotFoundException(e); } } } LOGGER.trace("EXITING: retrieveResource"); return response; }
From source file:org.codice.ddf.catalog.content.impl.FileSystemStorageProviderTest.java
private void assertReadRequest(URI uri, String mimeType) throws StorageException, IOException { ReadStorageRequest readRequest = new ReadStorageRequestImpl(uri, null); ReadStorageResponse readResponse = provider.read(readRequest); ContentItem item = readResponse.getContentItem(); LOGGER.debug("Item retrieved: {}", item); assertThat(item.getId(), is(uri.getSchemeSpecificPart())); if (uri.getFragment() != null) { assertThat(item.getQualifier(), is(uri.getFragment())); }/*from ww w. j av a2 s.com*/ assertThat(item.getMimeTypeRawData(), is(mimeType)); List<String> parts = provider.getContentFilePathParts(uri.getSchemeSpecificPart(), uri.getFragment()); String expectedFilePath = baseDir + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_REPOSITORY + File.separator + FileSystemStorageProvider.DEFAULT_CONTENT_STORE + File.separator + parts.get(0) + File.separator + parts.get(1) + File.separator + parts.get(2) + (StringUtils.isNotBlank(item.getQualifier()) ? File.separator + item.getQualifier() : "") + File.separator + item.getFilename(); assertThat(Files.exists(Paths.get(expectedFilePath)), is(true)); assertTrue(item.getSize() > 0); }
From source file:biz.dfch.j.graylog2.plugin.filter.dfchBizExecScript.java
public dfchBizExecScript() throws IOException, URISyntaxException { try {/*w w w .j a va2 s .c o m*/ LOG.debug(String.format("*** [%d] %s: Initialising plugin ...\r\n", Thread.currentThread().getId(), DF_PLUGIN_NAME)); // get config file CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource(); URI uri = codeSource.getLocation().toURI(); // String path = uri.getSchemeSpecificPart(); // path would contain absolute path including jar file name with extension // String path = FilenameUtils.getPath(uri.getPath()); // path would contain relative path (no leadig '/' and no jar file name String path = FilenameUtils.getPath(uri.getPath()); if (!path.startsWith("/")) { path = String.format("/%s", path); } String baseName = FilenameUtils.getBaseName(uri.getSchemeSpecificPart()); if (null == baseName || baseName.isEmpty()) { baseName = this.getClass().getPackage().getName(); } // get config values configurationFileName = FilenameUtils.concat(path, baseName + ".conf"); JSONParser jsonParser = new JSONParser(); Object object = jsonParser.parse(new FileReader(configurationFileName)); JSONObject jsonObject = (JSONObject) object; String scriptEngine = (String) jsonObject.get(DF_SCRIPT_ENGINE); String scriptPathAndName = (String) jsonObject.get(DF_SCRIPT_PATH_AND_NAME); if (null == scriptPathAndName || scriptPathAndName.isEmpty()) { scriptPathAndName = FilenameUtils.concat(path, (String) jsonObject.get(DF_SCRIPT_NAME)); } Boolean scriptCacheContents = (Boolean) jsonObject.get(DF_SCRIPT_CACHE_CONTENTS); Boolean scriptDisplayOutput = (Boolean) jsonObject.get(DF_SCRIPT_DISPLAY_OUTPUT); String pluginPriority = (String) jsonObject.get(DF_PLUGIN_PRIORITY); Boolean pluginDropMessage = (Boolean) jsonObject.get(DF_PLUGIN_DROP_MESSAGE); Boolean pluginDisabled = (Boolean) jsonObject.get(DF_PLUGIN_DISABLED); // set configuration Map<String, Object> map = new HashMap<>(); map.put(DF_SCRIPT_ENGINE, scriptEngine); map.put(DF_SCRIPT_PATH_AND_NAME, scriptPathAndName); map.put(DF_SCRIPT_DISPLAY_OUTPUT, scriptDisplayOutput); map.put(DF_SCRIPT_CACHE_CONTENTS, scriptCacheContents); map.put(DF_PLUGIN_PRIORITY, pluginPriority); map.put(DF_PLUGIN_DROP_MESSAGE, pluginDropMessage); map.put(DF_PLUGIN_DISABLED, pluginDisabled); initialize(new Configuration(map)); } catch (IOException ex) { LOG.error(String.format("*** [%d] %s: Initialising plugin FAILED. Filter will be disabled.\r\n%s\r\n", Thread.currentThread().getId(), DF_PLUGIN_NAME, ex.getMessage())); LOG.error("*** " + DF_PLUGIN_NAME + "::dfchBizExecScript() - IOException - Filter will be disabled."); ex.printStackTrace(); } catch (Exception ex) { LOG.error(String.format("*** [%d] %s: Initialising plugin FAILED. Filter will be disabled.\r\n", Thread.currentThread().getId(), DF_PLUGIN_NAME)); LOG.error("*** " + DF_PLUGIN_NAME + "::dfchBizExecScript() - Exception - Filter will be disabled."); ex.printStackTrace(); } }
From source file:biz.dfch.j.graylog.plugin.filter.metricsValidation.java
public metricsValidation() throws IOException, URISyntaxException { try {// ww w. j av a2 s . c o m LOG.debug(String.format("[%d] Initialising plugin ...\r\n", Thread.currentThread().getId())); // get config file CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource(); URI uri = codeSource.getLocation().toURI(); // String path = uri.getSchemeSpecificPart(); // path would contain absolute path including jar file name with extension // String path = FilenameUtils.getPath(uri.getPath()); // path would contain relative path (no leading '/' and no jar file name String path = FilenameUtils.getPath(uri.getPath()); if (!path.startsWith("/")) { path = String.format("/%s", path); } String baseName = FilenameUtils.getBaseName(uri.getSchemeSpecificPart()); if (null == baseName || baseName.isEmpty()) { baseName = this.getClass().getPackage().getName(); } // get config values configurationFileName = FilenameUtils.concat(path, baseName + ".conf"); JSONParser jsonParser = new JSONParser(); LOG.info(String.format("Loading configuration file '%s' ...", configurationFileName)); Object object = jsonParser.parse(new FileReader(configurationFileName)); JSONObject jsonObject = (JSONObject) object; String pluginPriority = (String) jsonObject.get(DF_PLUGIN_PRIORITY); Boolean pluginDropMessage = (Boolean) jsonObject.get(DF_PLUGIN_DROP_MESSAGE); Boolean pluginDisabled = (Boolean) jsonObject.get(DF_PLUGIN_DISABLED); // metrics = (HashMap) jsonObject.get("metrics"); // String fieldName = "cpu.average"; // Set<String> keys = metrics.keySet(); // for(String key : keys) // { // Map metric = (Map) metrics.get(key); // LOG.info(String.format("%s [type %s] [range %s .. %s]", key, metric.get("type").toString(), metric.get("minValue").toString(), metric.get("maxValue").toString())); // } // set configuration Map<String, Object> map = new HashMap<>(); map.put(DF_PLUGIN_PRIORITY, pluginPriority); map.put(DF_PLUGIN_DROP_MESSAGE, pluginDropMessage); map.put(DF_PLUGIN_DISABLED, pluginDisabled); //map.put(DF_PLUGIN_METRICS, metrics); initialize(new Configuration(map)); } catch (IOException ex) { LOG.error(String.format("[%d] Initialising plugin FAILED. Filter will be disabled.\r\n%s\r\n", Thread.currentThread().getId(), ex.getMessage())); LOG.error("*** " + DF_PLUGIN_NAME + "::dfchBizExecScript() - IOException - Filter will be disabled."); ex.printStackTrace(); } catch (Exception ex) { LOG.error(String.format("[%d] Initialising plugin FAILED. Filter will be disabled.\r\n", Thread.currentThread().getId())); LOG.error("*** " + DF_PLUGIN_NAME + "::dfchBizExecScript() - Exception - Filter will be disabled."); ex.printStackTrace(); } }
From source file:pl.psnc.synat.wrdz.zmd.download.DownloadManagerBean.java
@Override public String downloadFromUri(URI uri, String relativePath) throws DownloadException, IllegalArgumentException { if (uri == null) { throw new IllegalArgumentException("Cannot download content - given URI is null"); } else if (!uri.isAbsolute()) { throw new IllegalArgumentException("Cannot download content - given URI is not a URL"); }//ww w. j av a 2 s .c o m if (relativePath == null || relativePath.trim().isEmpty()) { throw new IllegalArgumentException("Cannot download content - given path is empty or null"); } String cachedResourcePath = null; if (isLocallyCached(uri)) { return (new File(uri.getSchemeSpecificPart())).getAbsolutePath(); // must be getSchemeSpecificPart() because of mounted network drives } else { try { ConnectionInformation connectionInfo = connectionHelper.getConnectionInformation(uri); DownloadAdapter downloadAdapter = getAdapterForProtocolName(uri.getScheme().toUpperCase(), connectionInfo); cachedResourcePath = downloadAdapter.downloadFile(uri, relativePath); } catch (AmbiguousResultException e) { throw new DownloadException("Could not determine connection information to use", e); } catch (OperationNotSupportedException e) { throw new DownloadException("Cannot download using specified protocol " + uri.getScheme() + ", no compatible adapters present in the system", e); } catch (DownloadAdapterException e) { throw new DownloadException("An error occured while creating the download adapter", e); } } return cachedResourcePath; }
From source file:jasdl.bridge.JASDLOntologyManager.java
/** * Convenience method to (polymorphically) create an entity from resource URI (if known). * TODO: where should this sit?//from ww w . j av a 2s . c o m * @param uri URI of resource to create entity from * @return entity identified by URI * @throws UnknownReferenceException if OWLObject not known */ public OWLEntity toEntity(URI uri) throws JASDLUnknownMappingException { URI ontURI; try { ontURI = new URI(uri.getScheme(), uri.getSchemeSpecificPart(), null); } catch (URISyntaxException e) { throw new JASDLUnknownMappingException("Invalid entity URI " + uri, e); } OWLOntology ontology = getLogicalURIManager().getLeft(ontURI); // clumsy approach, but I can't find any way of achieving this polymorphically (i.e. retrieve an OWLEntity from a URI) using OWL-API OWLEntity entity; if (ontology.containsClassReference(uri)) { entity = getOntologyManager().getOWLDataFactory().getOWLClass(uri); } else if (ontology.containsObjectPropertyReference(uri)) { entity = getOntologyManager().getOWLDataFactory().getOWLObjectProperty(uri); } else if (ontology.containsDataPropertyReference(uri)) { entity = getOntologyManager().getOWLDataFactory().getOWLDataProperty(uri); } else if (ontology.containsIndividualReference(uri)) { entity = getOntologyManager().getOWLDataFactory().getOWLIndividual(uri); } else { throw new JASDLUnknownMappingException("Unknown ontology resource URI: " + uri); } return entity; }
From source file:com.funambol.LDAP.security.LDAPMailUserProvisioningOfficer.java
/** * return an URI from the server, eventually using a default protocol *//*from ww w. jav a 2s . c om*/ protected URI getServerUri(String s, String proto) { URI u = null; String protocol; int port; try { if (s.indexOf(URL_SCHEME_SEPARATOR) < 0) { s = proto + URL_SCHEME_SEPARATOR + s; } u = new URI(s); protocol = (u.getSchemeSpecificPart() != null) ? u.getScheme() : proto; if (u.getPort() == -1) { if (PROTO_IMAP.equals(protocol)) { port = 143; } else if (PROTO_IMAPS.equals(protocol)) { port = 993; } else if (PROTO_SMTP.equals(protocol)) { port = 25; } else if (PROTO_SMTPS.equals(protocol)) { port = 465; } else if (PROTO_POP.equals(protocol)) { port = 110; } else if (PROTO_POPS.equals(protocol)) { port = 995; } else { throw new URISyntaxException(protocol, "Invalid protocol: " + protocol); } // else { // port = -1; // if (log.isDebugEnabled()) { // log.debug("no protocol defined, an error will rise if no default protocol defined in DefaultMailServer.xml"); // } // } } else { port = u.getPort(); } u = new URI(protocol, null, u.getHost(), port, null, null, null); } catch (URISyntaxException e) { log.error("can't parse uri from string: " + s); e.printStackTrace(); } return u; }