Return an integer vendor ID from a URI specifying a USB device.

@param uri the USB device URI
@throws DataSourceResourceException If the URI doesn't match the
format usb://vendor_id/device_id
184591
public static int vendorFromUri(URI uri)
            throws DataSourceResourceException {
        try {
            return Integer.parseInt(uri.getAuthority(), 16);
        } catch(NumberFormatException e) {
            throw new DataSourceResourceException(
                "USB device must be of the format " + DEFAULT_USB_DEVICE_URI +
                " -- the given " + uri + " has a bad vendor ID");
        }
    }
1212600
protected Dataset getDatasetOrThrowException(final Uri uri) {
		final Dataset dataset = mMatcher.matchDataset(uri);
		if (dataset == null) {
			throw new IllegalArgumentException("Unsupported URI: " + uri);
		}
		if (dataset instanceof ContextDataset) {
			((ContextDataset)dataset).setContext(getContext());
		}
		return dataset;
	}
630218
public static boolean isLocalResourceUri(@Nullable Uri uri) {
    final String scheme = getSchemeOrNull(uri);
    return LOCAL_RESOURCE_SCHEME.equals(scheme);
  }
255136
public SipURI getRecordRouteURI() {
		if(this.getRecordRoute()) {
			if(this.recordRouteURI == null && this.recordRouteURIString == null) 
				this.recordRouteURIString = DEFAULT_RECORD_ROUTE_URI;
			
			if(recordRouteURIString != null) {
				try {
					recordRouteURI = ((SipURI)proxy.getSipFactoryImpl().createURI(recordRouteURIString));
					recordRouteURIString = null;
				} catch (ServletParseException e) {
					logger.error("A problem occured while setting the target URI while proxying a request " + recordRouteURI, e);
					return null;
				}
			}
			return recordRouteURI;
		}
		
		else throw new IllegalStateException("Record Route not enabled for this ProxyBranch. You must call proxyBranch.setRecordRoute(true) before getting an URI.");
	}
425166
@Override
	@Transactional
	public String getResource(String id)
	{
		final TemplateCall call = templater.template("resource_template");

		final ResourceTemplateEntity entity = resourceProvisionService.getOrCreateTemplate(id);

		if (entity == null)
			throw new RestException(404, "No such resource with id: " + id);

		call.set("entity", entity);
		call.set("nonce", nonceStore.getValue());

		return call.process();
	}
725485
static public String toResourceUri(FacesContext facesContext, Object o)
    {
        if (o == null)
        {
            return null;
        }

        String uri = o.toString();

        // *** EL Coercion problem ***
        // If icon or image attribute was declared with #{resource[]} and that expression
        // evaluates to null (it means ResourceHandler.createResource returns null because 
        // requested resource does not exist)
        // EL implementation turns null into ""
        // see http://www.irian.at/blog/blogid/unifiedElCoercion/#unifiedElCoercion
        if (uri.length() == 0)
        {
            return null;
        }

        // With JSF 2.0 url for resources can be done with EL like #{resource['resourcename']}
        // and such EL after evalution contains context path for the current web application already,
        // -> we dont want call viewHandler.getResourceURL()
        if (uri.contains(ResourceHandler.RESOURCE_IDENTIFIER))
        {
            return uri;
        }

        // Treat two slashes as server-relative
        if (uri.startsWith("//"))
        {
            return uri.substring(1);
        }
        else
        {
            // If the specified path starts with a "/",
            // following method will prefix it with the context path for the current web application,
            // and return the result
            String resourceURL = facesContext.getApplication().getViewHandler()
                    .getResourceURL(facesContext, uri);
            return facesContext.getExternalContext().encodeResourceURL(
                    resourceURL);
        }
    }
674554
private Long transactionId(URI location) {
		return Long.valueOf( location.getPath().substring( location.getPath().lastIndexOf( "/" ) + 1 ) );
	}
346789
protected Supplier<DataSource<IMAGE>> obtainDataSourceSupplier(
      final DraweeController controller, final String controllerId) {
    if (mDataSourceSupplier != null) {
      return mDataSourceSupplier;
    }

    Supplier<DataSource<IMAGE>> supplier = null;

    // final image supplier;
    if (mImageRequest != null) {
      supplier = getDataSourceSupplierForRequest(controller, controllerId, mImageRequest);
    } else if (mMultiImageRequests != null) {
      supplier =
          getFirstAvailableDataSourceSupplier(
              controller, controllerId, mMultiImageRequests, mTryCacheOnlyFirst);
    }

    // increasing-quality supplier; highest-quality supplier goes first
    if (supplier != null && mLowResImageRequest != null) {
      List<Supplier<DataSource<IMAGE>>> suppliers = new ArrayList<>(2);
      suppliers.add(supplier);
      suppliers.add(getDataSourceSupplierForRequest(controller, controllerId, mLowResImageRequest));
      supplier = IncreasingQualityDataSourceSupplier.create(suppliers, false);
    }

    // no image requests; use null data source supplier
    if (supplier == null) {
      supplier = DataSources.getFailedDataSourceSupplier(NO_REQUEST_EXCEPTION);
    }

    return supplier;
  }
4057
public String formatKey(URI uri) throws URISyntaxException
	{
		if (uri == null) {
			throw new URISyntaxException("","URI specified is null");
		}
		return formatKey(uri.getHost(), uri.getPort());
	}
493644
private StreamSource getSource(String pURI)
            throws IOException, MalformedURLException {
        if (pURI != null && pURI.indexOf("://") < 0) {
            // If local, get as stream
            return new StreamSource(getResourceAsStream(pURI));
        }

        // ...else, create from URI string
        return new StreamSource(pURI);
    }
1325673
private DataSource getDataSource(ComponentHelper cmp, Resource resource) {
    try {
      /*
       * by default the path is read from request "path" parameter
       * here we overwrite it via a synthetic resource because the path may be overwritten by validation logic
       * to ensure the path is not beyond the configured root path
       */
      ValueMap overwriteProperties = new ValueMapDecorator(ImmutableMap.<String, Object>of("path", resource.getPath()));
      Resource dataSourceResourceWrapper = GraniteUiSyntheticResource.wrapMerge(request.getResource(), overwriteProperties);
      return cmp.getItemDataSource(dataSourceResourceWrapper);
    }
    catch (ServletException | IOException ex) {
      throw new RuntimeException("Unable to get data source.", ex);
    }
  }
595849
public static boolean isQualifiedResourceUri(@Nullable Uri uri) {
    final String scheme = getSchemeOrNull(uri);
    return QUALIFIED_RESOURCE_SCHEME.equals(scheme);
  }
435612
@Override
    public String getResourceId() {
        Preconditions.checkArgument(
                this.urlType == UrlType.RESOURCE,
                "UrlType must be %s but was %s",
                UrlType.RESOURCE,
                this.urlType);
        return this.resourceId;
    }
998075
private IDataSource getDataSource(HttpServletRequest request) throws DataSourceNotFoundException {
        String contextPath = request.getContextPath();
        String requestURI = request.getRequestURI();

        String path = contextPath == null
                ? requestURI
                : requestURI.substring(contextPath.length());

        if (path.equals("/") || path.isEmpty()) {
            final String baseURL = FragmentRequestParserBase.extractBaseURL(request, config);
            return new IndexDataSource(baseURL, dataSources);
        }

        String dataSourceName = path.substring(1);
        IDataSource dataSource = dataSources.get(dataSourceName);
        if (dataSource == null) {
            throw new DataSourceNotFoundException(dataSourceName);
        }
        return dataSource;
    }
1066976
@Nonnull
    public List<Resource> getResourcesById(long resourceId) {
        // An Android Resource id is a 32-bit integer. It comprises
        // an 8-bit Package id [bits 24-31]
        // an 8-bit Type id [bits 16-23]
        // a 16-bit Entry index [bits 0-15]


        short packageId = (short) (resourceId >> 24 & 0xff);
        short typeId = (short) ((resourceId >> 16) & 0xff);
        int entryIndex = (int) (resourceId & 0xffff);
        ResourcePackage resourcePackage = this.getPackage(packageId);
        if (resourcePackage == null) {
            return Collections.emptyList();
        }
        TypeSpec typeSpec = resourcePackage.getTypeSpec(typeId);
        List<Type> types = resourcePackage.getTypes(typeId);
        if (typeSpec == null || types == null) {
            return Collections.emptyList();
        }
        if (!typeSpec.exists(entryIndex)) {
            return Collections.emptyList();
        }

        // read from type resource
        List<Resource> result = new ArrayList<>();
        for (Type type : types) {
            ResourceEntry resourceEntry = type.getResourceEntry(entryIndex);
            if (resourceEntry == null) {
                continue;
            }
            ResourceValue currentResourceValue = resourceEntry.getValue();
            if (currentResourceValue == null) {
                continue;
            }

            // cyclic reference detect
            if (currentResourceValue instanceof ResourceValue.ReferenceResourceValue) {
                if (resourceId == ((ResourceValue.ReferenceResourceValue) currentResourceValue)
                        .getReferenceResourceId()) {
                    continue;
                }
            }

            result.add(new Resource(typeSpec, type, resourceEntry));
        }
        return result;
    }
891526
public static boolean validateResource(URI uri) {
        return uri != null && uri.getPort() != -1 && uri.getHost() != null;
    }
329040
public static SeLionDataProvider getDataProvider(DataResource resource)
            throws IOException {
        logger.entering(resource);

        if(resource == null) {
            return null;
        }

        switch (resource.getType().toUpperCase()) {
        case "XML":
            return new XmlDataProviderImpl((XmlDataSource) resource);
        case "JSON":
            return new JsonDataProviderImpl(resource);
        case "YAML":
        case "YML":
            return new YamlDataProviderImpl(resource);
        case "XLSX":
        case "XLS":
            return new ExcelDataProviderImpl(resource);
        default:
            return null;
        }
     }