@@ -6,6 +6,9 @@ package com.vaadin.terminal; | |||
import java.io.Serializable; | |||
import javax.portlet.PortletContext; | |||
import javax.servlet.ServletContext; | |||
/** | |||
* Provide deployment specific settings that are required outside terminal | |||
* specific code. | |||
@@ -83,4 +86,19 @@ public interface DeploymentConfiguration extends Serializable { | |||
* @return the class loader to use, or <code>null</code> | |||
*/ | |||
public ClassLoader getClassLoader(); | |||
/** | |||
* Returns the MIME type of the specified file, or null if the MIME type is | |||
* not known. The MIME type is determined by the configuration of the | |||
* container, and may be specified in a deployment descriptor. Common MIME | |||
* types are "text/html" and "image/gif". | |||
* | |||
* @param resourceName | |||
* a String specifying the name of a file | |||
* @return a String specifying the file's MIME type | |||
* | |||
* @see ServletContext#getMimeType(String) | |||
* @see PortletContext#getMimeType(String) | |||
*/ | |||
public String getMimeType(String resourceName); | |||
} |
@@ -2295,6 +2295,15 @@ public class ApplicationConnection { | |||
} | |||
uidlUri = themeUri + uidlUri.substring(7); | |||
} | |||
if (uidlUri.startsWith(CONNECTOR_PROTOCOL_PREFIX)) { | |||
// getAppUri *should* always end with / | |||
// substring *should* always start with / (connector:///foo.bar | |||
// without connector://) | |||
uidlUri = "app://" + CONNECTOR_RESOURCE_PREFIX | |||
+ uidlUri.substring(CONNECTOR_PROTOCOL_PREFIX.length()); | |||
// Let translation of app:// urls take care of the rest | |||
} | |||
if (uidlUri.startsWith("app://")) { | |||
String relativeUrl = uidlUri.substring(6); | |||
if (getConfiguration().usePortletURLs()) { | |||
@@ -2318,12 +2327,6 @@ public class ApplicationConnection { | |||
} else { | |||
uidlUri = getAppUri() + relativeUrl; | |||
} | |||
} else if (uidlUri.startsWith(CONNECTOR_PROTOCOL_PREFIX)) { | |||
// getAppUri *should* always end with / | |||
// substring *should* always start with / (connector:///foo.bar | |||
// without connector://) | |||
uidlUri = getAppUri() + CONNECTOR_RESOURCE_PREFIX | |||
+ uidlUri.substring(CONNECTOR_PROTOCOL_PREFIX.length()); | |||
} | |||
return uidlUri; | |||
} |
@@ -298,6 +298,11 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet | |||
// #8574) | |||
return null; | |||
} | |||
@Override | |||
public String getMimeType(String resourceName) { | |||
return getPortletContext().getMimeType(resourceName); | |||
} | |||
}; | |||
@Override | |||
@@ -434,7 +439,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet | |||
} | |||
protected enum RequestType { | |||
FILE_UPLOAD, UIDL, RENDER, STATIC_FILE, APPLICATION_RESOURCE, DUMMY, EVENT, ACTION, UNKNOWN, BROWSER_DETAILS; | |||
FILE_UPLOAD, UIDL, RENDER, STATIC_FILE, APPLICATION_RESOURCE, DUMMY, EVENT, ACTION, UNKNOWN, BROWSER_DETAILS, CONNECTOR_RESOURCE; | |||
} | |||
protected RequestType getRequestType(WrappedPortletRequest wrappedRequest) { | |||
@@ -449,6 +454,9 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet | |||
return RequestType.BROWSER_DETAILS; | |||
} else if (ServletPortletHelper.isFileUploadRequest(wrappedRequest)) { | |||
return RequestType.FILE_UPLOAD; | |||
} else if (ServletPortletHelper | |||
.isConnectorResourceRequest(wrappedRequest)) { | |||
return RequestType.CONNECTOR_RESOURCE; | |||
} else if (ServletPortletHelper | |||
.isApplicationResourceRequest(wrappedRequest)) { | |||
return RequestType.APPLICATION_RESOURCE; | |||
@@ -546,6 +554,12 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet | |||
PortletCommunicationManager applicationManager = applicationContext | |||
.getApplicationManager(application); | |||
if (requestType == RequestType.CONNECTOR_RESOURCE) { | |||
applicationManager.serveConnectorResource(wrappedRequest, | |||
wrappedResponse); | |||
return; | |||
} | |||
/* Update browser information from request */ | |||
applicationContext.getBrowser().updateRequestDetails( | |||
wrappedRequest); |
@@ -139,6 +139,11 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements | |||
throw new RuntimeException(e); | |||
} | |||
} | |||
@Override | |||
public String getMimeType(String resourceName) { | |||
return getServletContext().getMimeType(resourceName); | |||
} | |||
}; | |||
/** | |||
@@ -402,17 +407,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements | |||
.getApplicationManager(application, this); | |||
if (requestType == RequestType.CONNECTOR_RESOURCE) { | |||
String pathInfo = getRequestPathInfo(request); | |||
// + 2 to also remove beginning and ending slashes | |||
String resourceName = pathInfo | |||
.substring(ApplicationConnection.CONNECTOR_RESOURCE_PREFIX | |||
.length() + 2); | |||
final String mimetype = getServletContext().getMimeType( | |||
resourceName); | |||
applicationManager.serveConnectorResource(resourceName, | |||
request, response, mimetype); | |||
applicationManager.serveConnectorResource(request, response); | |||
return; | |||
} | |||
@@ -2471,15 +2471,23 @@ public abstract class AbstractCommunicationManager implements Serializable { | |||
* including a {@link JavaScript} or {@link StyleSheet} annotation on a | |||
* Connector class. | |||
* | |||
* @param resourceName | |||
* @param request | |||
* @param response | |||
* @param mimetype | |||
* | |||
* @throws IOException | |||
*/ | |||
public void serveConnectorResource(String resourceName, | |||
WrappedRequest request, WrappedResponse response, String mimetype) | |||
throws IOException { | |||
public void serveConnectorResource(WrappedRequest request, | |||
WrappedResponse response) throws IOException { | |||
String pathInfo = request.getRequestPathInfo(); | |||
// + 2 to also remove beginning and ending slashes | |||
String resourceName = pathInfo | |||
.substring(ApplicationConnection.CONNECTOR_RESOURCE_PREFIX | |||
.length() + 2); | |||
final String mimetype = response.getDeploymentConfiguration() | |||
.getMimeType(resourceName); | |||
// Security check: avoid accidentally serving from the root of the | |||
// classpath instead of relative to the context class | |||
if (resourceName.startsWith("/")) { |
@@ -19,6 +19,7 @@ import javax.portlet.ResourceResponse; | |||
import javax.portlet.WindowState; | |||
import com.vaadin.Application; | |||
import com.vaadin.annotations.StyleSheet; | |||
import com.vaadin.terminal.ExternalResource; | |||
import com.vaadin.terminal.gwt.client.ui.label.ContentMode; | |||
import com.vaadin.terminal.gwt.server.PortletApplicationContext2; | |||
@@ -38,7 +39,12 @@ import com.vaadin.ui.Upload.Receiver; | |||
*/ | |||
public class JSR286PortletApplication extends Application.LegacyApplication { | |||
LegacyWindow main = new LegacyWindow(); | |||
@StyleSheet("PortletConnectorResource.css") | |||
public final class LegacyWindowWithStylesheet extends LegacyWindow { | |||
} | |||
LegacyWindow main = new LegacyWindowWithStylesheet(); | |||
TextField tf = new TextField("Some value"); | |||
Label userInfo = new Label(); | |||
Link portletEdit = new Link(); | |||
@@ -56,6 +62,7 @@ public class JSR286PortletApplication extends Application.LegacyApplication { | |||
Embedded specialNameResourceTest = new Embedded( | |||
"Test ApplicationResources with special names", | |||
new SpecialNameResource(this)); | |||
specialNameResourceTest.addStyleName("hugeBorder"); | |||
main.addComponent(specialNameResourceTest); | |||
userInfo.setCaption("User info"); |
@@ -0,0 +1,3 @@ | |||
.hugeBorder { | |||
border: 10px solid green; | |||
} |