Get resource with media inline data (nt:file node).
@param mediaRequest Media reference
@return Resource or null if not present
339472
private Resource getMediaInlineResource(MediaRequest mediaRequest) {
    Resource resource = mediaRequest.getResource();
    if (resource == null) {
      return null;
    }

    // check if resource itself is a nt:file node
    if (JcrBinary.isNtFileOrResource(resource)) {
      return resource;
    }

    // check if child node exists which is a nt:file node
    String refProperty = StringUtils.defaultString(mediaRequest.getRefProperty(), mediaHandlerConfig.getMediaInlineNodeName());
    Resource mediaInlineResource = resource.getChild(refProperty);
    if (JcrBinary.isNtFileOrResource(mediaInlineResource)) {
      return mediaInlineResource;
    }

    // not found
    return null;
  }
591429
@Override
    public Object getRequestContents() {
        MediaUriType mediaUriType = new MediaUriType();
        mediaUriType.setUri(getProxyData().getServiceUri().toString()
                + this.secondaryEntityUri.toString());
        JAXBElement<MediaUriType> mediaUriTypeElement = new JAXBElement<MediaUriType>(
                new QName(Constants.ODATA_DATA_NS, "uri"), MediaUriType.class,
                mediaUriType);
        Document document = documentBuilder.newDocument();
        document.setXmlStandalone(true);
        try {
            marshaller.marshal(mediaUriTypeElement, document);
        } catch (JAXBException e) {
            throw new RuntimeException(e);
        }
        return document;
    }
519421
public InputStream getResourceAsStream(String fileName) {
		InputStream retval = super.getResourceAsStream(fileName);

		if (retval == null) {
			//String className = this.convertFileNameToClassName(fileName);
			//Object location = classResourceLocations.get(className);
			Object location = this.mixedResourceLocations.get(fileName);
			if (location == null) {
				return null;
			}

			byte[] data;
			try {
				data = getData(fileName, location);
			} catch (IOException ioe) {
				return null;
			}
			if (data == null) {
				return null;
			}
			return new ByteArrayInputStream(data);

		}
		return retval;
	}
1145800
@SuppressWarnings("null")
  protected final @Nullable Integer getMediaRotation(@NotNull MediaRequest mediaRequest,
      @NotNull MediaHandlerConfig mediaHandlerConfig) {
    if (mediaRequest.getResource() != null) {
      String rotationProperty = getMediaRotationProperty(mediaRequest, mediaHandlerConfig);
      String stringValue = mediaRequest.getResource().getValueMap().get(rotationProperty, String.class);
      if (StringUtils.isNotEmpty(stringValue)) {
        int rotationValue = NumberUtils.toInt(stringValue);
        if (TransformedRenditionHandler.isValidRotation(rotationValue)) {
          return rotationValue;
        }
      }
    }
    return null;
  }
641008
public ContentEncodedResource getResource(final Resource resource, final HttpServerExchange exchange) throws IOException {
        final String path = resource.getPath();
        Path file = resource.getFilePath();
        if (file == null) {
            return null;
        }
        if (minResourceSize > 0 && resource.getContentLength() < minResourceSize ||
                maxResourceSize > 0 && resource.getContentLength() > maxResourceSize ||
                !(encodingAllowed == null || encodingAllowed.resolve(exchange))) {
            return null;
        }
        AllowedContentEncodings encodings = contentEncodingRepository.getContentEncodings(exchange);
        if (encodings == null || encodings.isNoEncodingsAllowed()) {
            return null;
        }
        EncodingMapping encoding = encodings.getEncoding();
        if (encoding == null || encoding.getName().equals(ContentEncodingRepository.IDENTITY)) {
            return null;
        }
        String newPath = path + ".undertow.encoding." + encoding.getName();
        Resource preCompressed = encoded.getResource(newPath);
        if (preCompressed != null) {
            return new ContentEncodedResource(preCompressed, encoding.getName());
        }
        final LockKey key = new LockKey(path, encoding.getName());
        if (fileLocks.putIfAbsent(key, this) != null) {
            //another thread is already compressing
            //we don't do anything fancy here, just return and serve non-compressed content
            return null;
        }
        FileChannel targetFileChannel = null;
        FileChannel sourceFileChannel = null;
        try {
            //double check, the compressing thread could have finished just before we acquired the lock
            preCompressed = encoded.getResource(newPath);
            if (preCompressed != null) {
                return new ContentEncodedResource(preCompressed, encoding.getName());
            }

            final Path finalTarget = encodedResourcesRoot.resolve(newPath);
            final Path tempTarget = encodedResourcesRoot.resolve(newPath);

            //horrible hack to work around XNIO issue
            OutputStream tmp = Files.newOutputStream(tempTarget);
            try {
                tmp.close();
            } finally {
                IoUtils.safeClose(tmp);
            }

            targetFileChannel = FileChannel.open(tempTarget, StandardOpenOption.READ, StandardOpenOption.WRITE);
            sourceFileChannel = FileChannel.open(file, StandardOpenOption.READ);

            StreamSinkConduit conduit = encoding.getEncoding().getResponseWrapper().wrap(new ImmediateConduitFactory<StreamSinkConduit>(new FileConduitTarget(targetFileChannel, exchange)), exchange);
            final ConduitStreamSinkChannel targetChannel = new ConduitStreamSinkChannel(null, conduit);
            long transferred = sourceFileChannel.transferTo(0, resource.getContentLength(), targetChannel);
            targetChannel.shutdownWrites();
            org.xnio.channels.Channels.flushBlocking(targetChannel);
            if (transferred != resource.getContentLength()) {
                UndertowLogger.REQUEST_LOGGER.failedToWritePreCachedFile();
            }
            Files.move(tempTarget, finalTarget);
            encoded.invalidate(newPath);
            final Resource encodedResource = encoded.getResource(newPath);
            return new ContentEncodedResource(encodedResource, encoding.getName());
        } finally {
            IoUtils.safeClose(targetFileChannel);
            IoUtils.safeClose(sourceFileChannel);
            fileLocks.remove(key);
        }
    }
599795
private String buildDownloadMediaUrl() {
    String resourcePath = this.resource.getPath();

    // if parent resource is a nt:file resource, use this one as path for scaled image
    Resource parentResource = this.resource.getParent();
    if (JcrBinary.isNtFile(parentResource)) {
      resourcePath = parentResource.getPath();
    }

    // URL to render scaled image via {@link InlineRenditionServlet}
    String path = resourcePath + "." + MediaFileServlet.SELECTOR
        + "." + MediaFileServlet.SELECTOR_DOWNLOAD
        + "." + MediaFileServlet.EXTENSION + "/" + getFileName();

    // build externalized URL
    UrlHandler urlHandler = AdaptTo.notNull(this.adaptable, UrlHandler.class);
    return urlHandler.get(path).urlMode(this.mediaArgs.getUrlMode()).buildExternalResourceUrl(this.resource);
  }
789432
public static @Nullable Resource getContentResource(@NotNull HttpServletRequest request) {

    String contentPath = getContentPath(request);

    if (StringUtils.isNotEmpty(contentPath)) {
      SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;
      return slingRequest.getResourceResolver().getResource(contentPath);
    }
    return null;
  }
849681
public MediaQueryList parseMedia(final String media) throws IOException {
        try (InputSource source = new InputSource(new StringReader(media))) {
            final HandlerBase handler = new HandlerBase();
            parser_.setDocumentHandler(handler);
            if (parser_ instanceof AbstractCSSParser) {
                return ((AbstractCSSParser) parser_).parseMedia(source);
            }
            return null;
        }
    }
320262
@Override
  public RenditionMetadata getRendition(MediaArgs mediaArgs) {

    // get list of file extensions requested
    String[] requestedFileExtensions = getRequestedFileExtensions(mediaArgs);

    // if the array is null file extensions constraints are applied, but do not match to each other
    // - no rendition can fulfill these constraints
    if (requestedFileExtensions == null) {
      return null;
    }

    // check if a specific media size is requested
    boolean isSizeMatchingRequest = isSizeMatchingRequest(mediaArgs, requestedFileExtensions);

    // get rendition candidates matching for file extensions
    Set<RenditionMetadata> candidates = getRendtionsMatchingFileExtensions(requestedFileExtensions, mediaArgs);

    // if request does not contain any size restrictions return original image or first by filename matching rendition
    if (!isSizeMatchingRequest) {
      return getOriginalOrFirstRendition(candidates);
    }

    // original rendition is a image - check for matching rendition or build virtual one
    RenditionMetadata exactMatchRendition = getExactMatchRendition(candidates, mediaArgs);
    if (exactMatchRendition != null) {
      return exactMatchRendition;
    }

    // get rendition virtual rendition downscaled from existing one
    RenditionMetadata virtualRendition = getVirtualRendition(candidates, mediaArgs);
    if (virtualRendition != null) {
      return virtualRendition;
    }

    // no match found
    return null;
  }
82139
@SuppressWarnings("null")
  protected final @Nullable CropDimension getMediaCropDimension(@NotNull MediaRequest mediaRequest,
      @Nullable MediaHandlerConfig mediaHandlerConfig) {
    if (mediaRequest.getResource() != null) {
      String cropProperty = getMediaCropProperty(mediaRequest, mediaHandlerConfig);
      String cropString = mediaRequest.getResource().getValueMap().get(cropProperty, String.class);
      if (StringUtils.isNotEmpty(cropString)) {
        try {
          return CropDimension.fromCropString(cropString);
        }
        catch (IllegalArgumentException ex) {
          // ignore
        }
      }
    }
    return null;
  }
27823
public boolean mediaIsVideo () {
        String contentType = this.getContentType();
        return contentType != null && this.media != null && contentType.startsWith("video");
    }
588073
public static File getRequestFile(final PutObjectRequest putObjectRequest) {
        if (putObjectRequest.getFile() != null) return putObjectRequest.getFile();
        return null;
    }
710893
public MultipartResourceRequest resolveMultipart(final ResourceRequest request) throws MultipartException {
        Assert.notNull(request, "Request must not be null");
        if (this.resolveLazily) {
            return new DefaultMultipartResourceRequest(request) {
                @Override
                protected void initializeMultipart() {
                    MultipartParsingResult parsingResult = parseRequest(request);
                    setMultipartFiles(parsingResult.getMultipartFiles());
                    setMultipartParameters(parsingResult.getMultipartParameters());
                    setMultipartParameterContentTypes(parsingResult.getMultipartParameterContentTypes());
                }
            };
        } else {
            MultipartParsingResult parsingResult = parseRequest(request);
            return new DefaultMultipartResourceRequest(request, parsingResult.getMultipartFiles(),
                    parsingResult.getMultipartParameters(), parsingResult.getMultipartParameterContentTypes());
        }
    }
687511
protected HtmlElement<?> getImageElement(Media media) {
    Image img = new Image();

    // Alternative text
    Asset asset = media.getAsset();
    String altText = null;
    if (asset != null) {
      altText = asset.getAltText();
    }
    if (StringUtils.isNotEmpty(altText)) {
      img.setAlt(altText);
    }

    return img;
  }
868621
private static Media getMediaDpi(Media media)
    {
        Check.notNull(media);

        final DpiType current = dpi;
        if (current == null || current == DpiType.MDPI)
        {
            return media;
        }
        return getClosestDpi(current, media);
    }
918125
protected final @Nullable MediaFormat getFirstMediaFormatWithRatio(@NotNull Media media) {
    MediaFormat[] mediaFormats = media.getMediaRequest().getMediaArgs().getMediaFormats();
    if (mediaFormats != null) {
      for (MediaFormat mediaFormat : mediaFormats) {
        if (mediaFormat.hasRatio()) {
          return mediaFormat;
        }
      }
    }
    return null;
  }
699215
public static Node getJcrNode(final FedoraResource resource) {
        if (resource instanceof FedoraResourceImpl) {
            return ((FedoraResourceImpl)resource).getNode();
        }
        throw new IllegalArgumentException("FedoraResource is of the wrong type");
    }