List of usage examples for java.net URI getSchemeSpecificPart
public String getSchemeSpecificPart()
From source file:at.gv.egiz.bku.slcommands.impl.cms.Signature.java
protected AlgorithmID getAlgorithmID(String uri) throws URISyntaxException { String oid = null;/*w w w. j a v a2 s . co m*/ URI urn = new URI(uri); String scheme = urn.getScheme(); if ("URN".equalsIgnoreCase(scheme)) { String schemeSpecificPart = urn.getSchemeSpecificPart().toLowerCase(); if (schemeSpecificPart.startsWith("oid:")) { oid = schemeSpecificPart.substring(4, schemeSpecificPart.length()); } } return new AlgorithmID(new ObjectID(oid)); }
From source file:org.sakaiproject.metaobj.shared.control.XmlControllerBase.java
public ModelAndView processFileAttachments(Map request, Map session, ElementBean currentBean, Errors errors) { String fieldName = (String) request.get("childPath"); String fieldLabel = (String) request.get("childFieldLabel"); if (fieldLabel == null) { fieldLabel = fieldName;/*from w w w. j a v a 2s. com*/ } session.put(FILE_ATTACHMENTS_FIELD, fieldName); String title = rl.getString("attachment_file_helper_title_single"); String instructionKey = "attachment_file_helper_instructions_single"; int limit = 0; //ToolSession toolSession = getSessionManager().getCurrentToolSession(); List attachmentRefs = new ArrayList(); session.put(FilePickerHelper.FILE_PICKER_MAX_ATTACHMENTS, FilePickerHelper.CARDINALITY_SINGLE); if (List.class.isAssignableFrom(currentBean.getType(fieldName))) { LimitedList currentIds = (LimitedList) currentBean.get(fieldName); attachmentRefs.addAll(convertToRefList(currentIds)); session.put(FilePickerHelper.FILE_PICKER_MAX_ATTACHMENTS, currentIds.getUpperLimit()); title = rl.getString("attachment_file_helper_title_multiple"); if (currentIds.getUpperLimit() == Integer.MAX_VALUE) { instructionKey = "attachment_file_helper_instructions_multiple_unlim"; } else { limit = currentIds.getUpperLimit(); instructionKey = "attachment_file_helper_instructions_multiple"; } } else if (currentBean.get(fieldName) != null) { URI value = (URI) currentBean.get(fieldName); attachmentRefs.add(convertToRef(value.getSchemeSpecificPart())); } session.put(FilePickerHelper.FILE_PICKER_TITLE_TEXT, title); session.put(FilePickerHelper.FILE_PICKER_INSTRUCTION_TEXT, rl.getFormattedMessage(instructionKey, new Object[] { fieldLabel, limit })); session.put(FilePickerHelper.FILE_PICKER_ATTACHMENTS, attachmentRefs); //session.put(FilePickerHelper.START_HELPER, "true"); return new ModelAndView("fileHelper"); }
From source file:dk.netarkivet.common.distribute.arcrepository.ARCLookup.java
/** Look up a given URI and return the contents as an InputStream. * The uri is first checked using url-decoding (e.g. "," in the argument * is converted to "%2C"). If this returns no match, the method then * searches for a non-url-decoded match. If neither returns a match * the method returns null.// w ww . j a v a 2 s. com * * If the tryToLookupUriAsFtp field is set to true, we will try exchanging * the schema with ftp, whenever we can't lookup the uri with the original * schema. * * @param uri The URI to find in the archive. If the URI does not * match any entries in the archive, null is returned. * @return An InputStream Containing all the data in the entry, or * null if the entry was not found * @throws IOFailure If the ARC file was found in the Lucene index but not * in the bit archive, or if some other failure happened while finding * the file. */ public ResultStream lookup(URI uri) { ArgumentNotValid.checkNotNull(uri, "uri"); boolean containsHeader = true; // the URI.getSchemeSpecificPart() carries out the url-decoding ARCKey key = luceneLookup(uri.getScheme() + ":" + uri.getSchemeSpecificPart()); if (key == null) { // the URI.getRawSchemeSpecificPart() returns the uri in non-decoded form key = luceneLookup(uri.getScheme() + ":" + uri.getRawSchemeSpecificPart()); } if (key == null && tryToLookupUriAsFtp) { log.debug( "Url not found with the schema '" + uri.getScheme() + ". Now trying with 'ftp' as the schema"); final String ftpSchema = "ftp"; key = luceneLookup(ftpSchema + ":" + uri.getSchemeSpecificPart()); if (key == null) { key = luceneLookup(ftpSchema + ":" + uri.getRawSchemeSpecificPart()); if (key != null) { // Remember, that the found ftp-records don't have any HTTP // Header containsHeader = false; } } else { // Remember, that the found ftp-record don't have any HTTP // Header containsHeader = false; } } if (key == null) { return null; // key not found } else { final BitarchiveRecord bitarchiveRecord = arcRepositoryClient.get(key.getFile().getName(), key.getOffset()); if (bitarchiveRecord == null) { String message = "ARC file '" + key.getFile().getName() + "' mentioned in index file was not found by" + " arc repository. This may mean we have a" + " timeout, or that the index is wrong; or" + " it may mean we have lost a record in" + " the bitarchives."; log.debug(message); throw new IOFailure(message); } return new ResultStream(bitarchiveRecord.getData(), containsHeader); } }
From source file:com.kloudtek.kloudmake.service.filestore.FileStore.java
public synchronized DataFile create(@NotNull String uri) throws IOException, TemplateException { URI u = URI.create(uri); if (isEmpty(u.getScheme())) { throw new IllegalArgumentException("Invalid uri " + uri); }//from ww w. ja v a2 s .c om if (u.getScheme().equals("libfile")) { return new LocalDataFile(u.getSchemeSpecificPart()); } else { return null; } }
From source file:org.wso2.carbon.identity.webfinger.builders.DefaultWebFingerRequestBuilder.java
@Override public WebFingerRequest buildRequest(HttpServletRequest request) throws WebFingerEndpointException { WebFingerRequest webFingerRequest = new WebFingerRequest(); List<String> parameters = Collections.list(request.getParameterNames()); if (parameters.size() != 2 || !parameters.contains(WebFingerConstants.REL) || !parameters.contains(WebFingerConstants.RESOURCE)) { throw new WebFingerEndpointException(WebFingerConstants.ERROR_CODE_INVALID_REQUEST, "Bad Web " + "Finger request."); }//from ww w. ja v a 2 s .c o m webFingerRequest.setServletRequest(request); String resource = request.getParameter(WebFingerConstants.RESOURCE); webFingerRequest.setRel(request.getParameter(WebFingerConstants.REL)); webFingerRequest.setResource(resource); if (StringUtils.isBlank(resource)) { log.warn("Can't normalize null or empty URI: " + resource); throw new WebFingerEndpointException(WebFingerConstants.ERROR_CODE_INVALID_RESOURCE, "Null or empty URI."); } else { URI resourceURI = URI.create(resource); if (StringUtils.isBlank(resourceURI.getScheme())) { throw new WebFingerEndpointException("Scheme of the resource cannot be empty"); } String userInfo; if (WebFingerConstants.ACCT_SCHEME.equals(resourceURI.getScheme())) { //acct scheme userInfo = resourceURI.getSchemeSpecificPart(); userInfo = userInfo.substring(0, userInfo.lastIndexOf('@')); } else { //https scheme userInfo = resourceURI.getUserInfo(); webFingerRequest.setScheme(resourceURI.getScheme()); webFingerRequest.setHost(resourceURI.getHost()); webFingerRequest.setPort(resourceURI.getPort()); webFingerRequest.setPath(resourceURI.getPath()); webFingerRequest.setQuery(resourceURI.getQuery()); } String tenant; if (StringUtils.isNotBlank(userInfo)) { try { userInfo = URLDecoder.decode(userInfo, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new WebFingerEndpointException("Cannot decode the userinfo"); } tenant = MultitenantUtils.getTenantDomain(userInfo); webFingerRequest.setUserInfo(resourceURI.getUserInfo()); } else { tenant = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME; } validateTenant(tenant); webFingerRequest.setTenant(tenant); } return webFingerRequest; }
From source file:org.apache.servicemix.jms.JmsComponent.java
protected Endpoint getResolvedEPR(ServiceEndpoint ep) throws Exception { // We receive an exchange for an EPR that has not been used yet. // Register a provider endpoint and restart processing. JmsEndpoint jmsEp = new JmsEndpoint(true); jmsEp.setServiceUnit(new DefaultServiceUnit(component)); jmsEp.setService(ep.getServiceName()); jmsEp.setEndpoint(ep.getEndpointName()); jmsEp.setRole(MessageExchange.Role.PROVIDER); URI uri = new URI(ep.getEndpointName()); Map map = URISupport.parseQuery(uri.getQuery()); if (IntrospectionSupport.setProperties(jmsEp, map, "jms.")) { uri = URISupport.createRemainingURI(uri, map); }/* w ww . ja v a2 s .c o m*/ if (uri.getPath() != null) { String path = uri.getSchemeSpecificPart(); while (path.startsWith("/")) { path = path.substring(1); } if (path.startsWith(AbstractJmsProcessor.STYLE_QUEUE + "/")) { jmsEp.setDestinationStyle(AbstractJmsProcessor.STYLE_QUEUE); jmsEp.setJmsProviderDestinationName(path.substring(AbstractJmsProcessor.STYLE_QUEUE.length() + 1)); } else if (path.startsWith(AbstractJmsProcessor.STYLE_TOPIC + "/")) { jmsEp.setDestinationStyle(AbstractJmsProcessor.STYLE_TOPIC); jmsEp.setJmsProviderDestinationName(path.substring(AbstractJmsProcessor.STYLE_TOPIC.length() + 1)); } } return jmsEp; }
From source file:leap.webunit.client.THttpRequestImpl.java
protected String buildRequestUrl() { String url = null;/*from ww w. j a v a 2 s . c om*/ if (Strings.isEmpty(uri)) { url = tclient.getBaseUrl(); } else if (uri.indexOf("://") > 0) { url = uri; } else if (Strings.startsWith(uri, "/")) { url = tclient.getBaseUrl() + uri; } else { url = tclient.getBaseUrl() + "/" + uri; } if (!queryString.isEmpty()) { url = Urls.appendQueryString(url, queryString.build()); } URI uri = URI.create(url); String path = uri.getPath(); if (!"".equals(path)) { for (String contextPath : tclient.getContextPaths()) { if (path.equals(contextPath)) { url = uri.getScheme() + ":" + uri.getSchemeSpecificPart() + "/"; if (null != uri.getQuery()) { url = url + "?" + uri.getRawQuery(); } break; } } } return url; }
From source file:com.twitter.hraven.etl.JobFilePartitioner.java
/** * Input is a regular directory (non-hdfs). Process files accordingly. * //from w w w .ja v a 2 s.c o m * @param inputURI * @throws IOException */ private void processPlainFileSources(URI inputURI) throws IOException { LOG.info("Scheme specific part is: " + inputURI.getSchemeSpecificPart()); File inputFile = new File(inputURI.getSchemeSpecificPart()); // Check if input is a directory if (!inputFile.isDirectory()) { throw new IOException("Input is not a regular directory: " + input); } File[] files = inputFile.listFiles(); int processedCount = 0; try { for (File f : files) { // Process only files, not (sub)directories. if (f.isFile()) { processPlainFile(hdfs, f, outputPath, skipExisting); processedCount++; // Print something each 100 files to show progress. if ((processedCount % 1000) == 0) { LOG.info("Processed " + processedCount + " files."); } } } } finally { LOG.info("Processed " + processedCount + " files."); } }
From source file:org.codice.ddf.catalog.content.impl.FileSystemStorageProviderTest.java
private void assertUpdateRequest(UpdateStorageRequest updateRequest) throws Exception { UpdateStorageResponse updateResponse = provider.update(updateRequest); List<ContentItem> items = updateResponse.getUpdatedContentItems(); ContentItem item = items.get(0);// ww w.ja v a2s .c o m String id = item.getId(); LOGGER.debug("Item retrieved: {}", item); assertEquals(id, item.getId()); assertEquals(NITF_MIME_TYPE, item.getMimeTypeRawData()); URI uri = new URI(item.getUri()); 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 + FileSystemStorageProvider.DEFAULT_TMP + File.separator + updateRequest.getId() + 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); String updatedFileContents = IOUtils.toString(item.getInputStream()); assertEquals("Updated NITF", updatedFileContents); provider.commit(updateRequest); assertReadRequest(new URI(updateRequest.getContentItems().get(0).getUri()), NITF_MIME_TYPE); }
From source file:org.apache.fop.layoutmgr.ExternalDocumentLayoutManager.java
/** {@inheritDoc} */ public void activateLayout() { initialize();/*from w ww . j a v a 2s . c o m*/ FOUserAgent userAgent = pageSeq.getUserAgent(); ImageManager imageManager = userAgent.getFactory().getImageManager(); String uri = URISpecification.getURL(getExternalDocument().getSrc()); Integer firstPageIndex = ImageUtil.getPageIndexFromURI(uri); boolean hasPageIndex = (firstPageIndex != null); try { ImageInfo info = imageManager.getImageInfo(uri, userAgent.getImageSessionContext()); Object moreImages = info.getCustomObjects().get(ImageInfo.HAS_MORE_IMAGES); boolean hasMoreImages = moreImages != null && !Boolean.FALSE.equals(moreImages); Dimension intrinsicSize = info.getSize().getDimensionMpt(); ImageLayout layout = new ImageLayout(getExternalDocument(), this, intrinsicSize); PageSequence pageSequence = new PageSequence(null); transferExtensions(pageSequence); areaTreeHandler.getAreaTreeModel().startPageSequence(pageSequence); if (log.isDebugEnabled()) { log.debug("Starting layout"); } makePageForImage(info, layout); if (!hasPageIndex && hasMoreImages) { if (log.isTraceEnabled()) { log.trace("Starting multi-page processing..."); } URI originalURI; try { originalURI = new URI(URISpecification.escapeURI(uri)); int pageIndex = 1; while (hasMoreImages) { URI tempURI = new URI(originalURI.getScheme(), originalURI.getSchemeSpecificPart(), "page=" + Integer.toString(pageIndex + 1)); if (log.isTraceEnabled()) { log.trace("Subimage: " + tempURI.toASCIIString()); } ImageInfo subinfo = imageManager.getImageInfo(tempURI.toASCIIString(), userAgent.getImageSessionContext()); moreImages = subinfo.getCustomObjects().get(ImageInfo.HAS_MORE_IMAGES); hasMoreImages = moreImages != null && !Boolean.FALSE.equals(moreImages); intrinsicSize = subinfo.getSize().getDimensionMpt(); layout = new ImageLayout(getExternalDocument(), this, intrinsicSize); makePageForImage(subinfo, layout); pageIndex++; } } catch (URISyntaxException e) { getResourceEventProducer().uriError(this, uri, e, getExternalDocument().getLocator()); } } } catch (FileNotFoundException fnfe) { getResourceEventProducer().imageNotFound(this, uri, fnfe, getExternalDocument().getLocator()); } catch (IOException ioe) { getResourceEventProducer().imageIOError(this, uri, ioe, getExternalDocument().getLocator()); } catch (ImageException ie) { getResourceEventProducer().imageError(this, uri, ie, getExternalDocument().getLocator()); } }