123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- /*
- * Copyright 2000-2018 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
- package com.vaadin.server;
-
- import java.net.URL;
-
- import com.vaadin.util.FileTypeResolver;
-
- /**
- * <code>ExternalResource</code> implements source for resources fetched from
- * location specified by URL:s. The resources are fetched directly by the client
- * terminal and are not fetched through the terminal adapter.
- *
- * @author Vaadin Ltd.
- * @since 3.0
- */
- @SuppressWarnings("serial")
- public class ExternalResource implements Resource {
-
- /**
- * Url of the download.
- */
- private String sourceURL = null;
-
- /**
- * MIME Type for the resource
- */
- private String mimeType = null;
-
- /**
- * Creates a new download component for downloading directly from given URL.
- *
- * @param sourceURL
- * the source URL.
- */
- public ExternalResource(URL sourceURL) {
- if (sourceURL == null) {
- throw new RuntimeException("Source must be non-null");
- }
-
- this.sourceURL = sourceURL.toString();
- }
-
- /**
- * Creates a new download component for downloading directly from given URL.
- *
- * @param sourceURL
- * the source URL.
- * @param mimeType
- * the MIME Type
- */
- public ExternalResource(URL sourceURL, String mimeType) {
- this(sourceURL);
- this.mimeType = mimeType;
- }
-
- /**
- * Creates a new download component for downloading directly from given URL.
- *
- * @param sourceURL
- * the source URL.
- */
- public ExternalResource(String sourceURL) {
- if (sourceURL == null) {
- throw new RuntimeException("Source must be non-null");
- }
-
- this.sourceURL = sourceURL;
- }
-
- /**
- * Creates a new download component for downloading directly from given URL.
- *
- * @param sourceURL
- * the source URL.
- * @param mimeType
- * the MIME Type
- */
- public ExternalResource(String sourceURL, String mimeType) {
- this(sourceURL);
- this.mimeType = mimeType;
- }
-
- /**
- * Gets the URL of the external resource.
- *
- * @return the URL of the external resource.
- */
- public String getURL() {
- return sourceURL;
- }
-
- /**
- * Gets the MIME type of the resource.
- *
- * @see com.vaadin.server.Resource#getMIMEType()
- */
- @Override
- public String getMIMEType() {
- if (mimeType == null) {
- mimeType = FileTypeResolver.getMIMEType(getURL());
- }
- return mimeType;
- }
-
- /**
- * Sets the MIME type of the resource.
- */
- public void setMIMEType(String mimeType) {
- this.mimeType = mimeType;
- }
- }
|