Skip to content

Commit

Permalink
Include UI class @javascript and @Stylesheet in bootstrap html (#9045)
Browse files Browse the repository at this point in the history
Change-Id: I9d4243fa6f91ba5bc3449d0a3ec24f209e6360e6
  • Loading branch information
Legioth authored and Artur- committed Jan 12, 2015
1 parent 2bc4f17 commit e20f6fd
Show file tree
Hide file tree
Showing 15 changed files with 398 additions and 125 deletions.
Empty file.
11 changes: 3 additions & 8 deletions client/src/com/vaadin/client/ApplicationConfiguration.java
Expand Up @@ -276,8 +276,7 @@ public final native String getUrl()
* <code>false</code> if the path info goes after the service URL
*/
public boolean useServiceUrlPathParam() {
return getJsoConfiguration(id).getConfigBoolean(
ApplicationConstants.SERVICE_URL_PATH_AS_PARAMETER) == Boolean.TRUE;
return getServiceUrlParameterName() != null;
}

/**
Expand All @@ -289,12 +288,8 @@ public boolean useServiceUrlPathParam() {
* @return The parameter name, by default <code>v-resourcePath</code>
*/
public String getServiceUrlParameterName() {
String prefix = getJsoConfiguration(id).getConfigString(
ApplicationConstants.SERVICE_URL_PARAMETER_NAMESPACE);
if (prefix == null) {
prefix = "";
}
return prefix + ApplicationConstants.V_RESOURCE_PATH;
return getJsoConfiguration(id).getConfigString(
ApplicationConstants.SERVICE_URL_PARAMETER_NAME);
}

public String getRootPanelId() {
Expand Down
128 changes: 37 additions & 91 deletions client/src/com/vaadin/client/ApplicationConnection.java
Expand Up @@ -99,12 +99,14 @@
import com.vaadin.shared.AbstractComponentState;
import com.vaadin.shared.ApplicationConstants;
import com.vaadin.shared.JsonConstants;
import com.vaadin.shared.VaadinUriResolver;
import com.vaadin.shared.Version;
import com.vaadin.shared.communication.LegacyChangeVariablesInvocation;
import com.vaadin.shared.communication.MethodInvocation;
import com.vaadin.shared.communication.SharedState;
import com.vaadin.shared.ui.ui.UIConstants;
import com.vaadin.shared.ui.ui.UIState.PushConfigurationState;
import com.vaadin.shared.util.SharedUtil;

/**
* This is the client side communication "engine", managing client-server
Expand Down Expand Up @@ -472,6 +474,33 @@ public interface ApplicationStoppedHandler extends EventHandler {

private boolean tooltipInitialized = false;

private final VaadinUriResolver uriResolver = new VaadinUriResolver() {
@Override
protected String getVaadinDirUrl() {
return getConfiguration().getVaadinDirUrl();
}

@Override
protected String getServiceUrlParameterName() {
return getConfiguration().getServiceUrlParameterName();
}

@Override
protected String getServiceUrl() {
return getConfiguration().getServiceUrl();
}

@Override
protected String getThemeUri() {
return ApplicationConnection.this.getThemeUri();
}

@Override
protected String encodeQueryStringParameterValue(String queryString) {
return URL.encodeQueryString(queryString);
}
};

public static class MultiStepDuration extends Duration {
private int previousStep = elapsedMillis();

Expand Down Expand Up @@ -823,10 +852,10 @@ protected void makeUidlRequest(final JSONArray reqInvocations,
+ ApplicationConstants.UIDL_PATH + '/');

if (extraParams != null && extraParams.length() > 0) {
uri = addGetParameters(uri, extraParams);
uri = SharedUtil.addGetParameters(uri, extraParams);
}
uri = addGetParameters(uri, UIConstants.UI_ID_PARAMETER + "="
+ configuration.getUIId());
uri = SharedUtil.addGetParameters(uri, UIConstants.UI_ID_PARAMETER
+ "=" + configuration.getUIId());

doUidlRequest(uri, payload);

Expand Down Expand Up @@ -3185,67 +3214,7 @@ public Icon getIcon(String uri) {
* @return translated URI ready for browser
*/
public String translateVaadinUri(String uidlUri) {
if (uidlUri == null) {
return null;
}
if (uidlUri.startsWith("theme://")) {
final String themeUri = getThemeUri();
if (themeUri == null) {
VConsole.error("Theme not set: ThemeResource will not be found. ("
+ uidlUri + ")");
}
uidlUri = themeUri + uidlUri.substring(7);
}

if (uidlUri.startsWith(ApplicationConstants.PUBLISHED_PROTOCOL_PREFIX)) {
// getAppUri *should* always end with /
// substring *should* always start with / (published:///foo.bar
// without published://)
uidlUri = ApplicationConstants.APP_PROTOCOL_PREFIX
+ ApplicationConstants.PUBLISHED_FILE_PATH
+ uidlUri
.substring(ApplicationConstants.PUBLISHED_PROTOCOL_PREFIX
.length());
// Let translation of app:// urls take care of the rest
}
if (uidlUri.startsWith(ApplicationConstants.APP_PROTOCOL_PREFIX)) {
String relativeUrl = uidlUri
.substring(ApplicationConstants.APP_PROTOCOL_PREFIX
.length());
ApplicationConfiguration conf = getConfiguration();
String serviceUrl = conf.getServiceUrl();
if (conf.useServiceUrlPathParam()) {
// Should put path in v-resourcePath parameter and append query
// params to base portlet url
String[] parts = relativeUrl.split("\\?", 2);
String path = parts[0];

// If there's a "?" followed by something, append it as a query
// string to the base URL
if (parts.length > 1) {
String appUrlParams = parts[1];
serviceUrl = addGetParameters(serviceUrl, appUrlParams);
}
if (!path.startsWith("/")) {
path = '/' + path;
}
String pathParam = conf.getServiceUrlParameterName() + "="
+ URL.encodeQueryString(path);
serviceUrl = addGetParameters(serviceUrl, pathParam);
uidlUri = serviceUrl;
} else {
uidlUri = serviceUrl + relativeUrl;
}
}
if (uidlUri.startsWith(ApplicationConstants.VAADIN_PROTOCOL_PREFIX)) {
final String vaadinUri = configuration.getVaadinDirUrl();
String relativeUrl = uidlUri
.substring(ApplicationConstants.VAADIN_PROTOCOL_PREFIX
.length());
uidlUri = vaadinUri + relativeUrl;
}

return uidlUri;
return uriResolver.resolveVaadinUri(uidlUri);
}

/**
Expand Down Expand Up @@ -3362,35 +3331,12 @@ public boolean hasEventListeners(ComponentConnector paintable,
* One or more parameters in the format "a=b" or "c=d&e=f". An
* empty string is allowed but will not modify the url.
* @return The modified URI with the get parameters in extraParams added.
* @deprecated Use {@link SharedUtil#addGetParameters(String,String)}
* instead
*/
@Deprecated
public static String addGetParameters(String uri, String extraParams) {
if (extraParams == null || extraParams.length() == 0) {
return uri;
}
// RFC 3986: The query component is indicated by the first question
// mark ("?") character and terminated by a number sign ("#") character
// or by the end of the URI.
String fragment = null;
int hashPosition = uri.indexOf('#');
if (hashPosition != -1) {
// Fragment including "#"
fragment = uri.substring(hashPosition);
// The full uri before the fragment
uri = uri.substring(0, hashPosition);
}

if (uri.contains("?")) {
uri += "&";
} else {
uri += "?";
}
uri += extraParams;

if (fragment != null) {
uri += fragment;
}

return uri;
return SharedUtil.addGetParameters(uri, extraParams);
}

ConnectorMap getConnectorMap() {
Expand Down
Expand Up @@ -35,6 +35,7 @@
import com.vaadin.shared.communication.PushConstants;
import com.vaadin.shared.ui.ui.UIConstants;
import com.vaadin.shared.ui.ui.UIState.PushConfigurationState;
import com.vaadin.shared.util.SharedUtil;

/**
* The default {@link PushConnection} implementation that uses Atmosphere for
Expand Down Expand Up @@ -185,7 +186,7 @@ private void connect() {
}

// uri is needed to identify the right connection when closing
uri = ApplicationConnection.addGetParameters(baseUrl, extraParams);
uri = SharedUtil.addGetParameters(baseUrl, extraParams);

VConsole.log("Establishing push connection");
socket = doConnect(uri, getConfig());
Expand Down
3 changes: 2 additions & 1 deletion client/src/com/vaadin/client/communication/Heartbeat.java
Expand Up @@ -28,6 +28,7 @@
import com.vaadin.client.ApplicationConnection.ConnectionStatusEvent;
import com.vaadin.shared.ApplicationConstants;
import com.vaadin.shared.ui.ui.UIConstants;
import com.vaadin.shared.util.SharedUtil;

/**
* Handles sending of heartbeats to the server and reacting to the response
Expand Down Expand Up @@ -63,7 +64,7 @@ public void init(ApplicationConnection applicationConnection) {

setInterval(connection.getConfiguration().getHeartbeatInterval());

uri = ApplicationConnection.addGetParameters(connection
uri = SharedUtil.addGetParameters(connection
.translateVaadinUri(ApplicationConstants.APP_PROTOCOL_PREFIX
+ ApplicationConstants.HEARTBEAT_PATH + '/'),
UIConstants.UI_ID_PARAMETER + "="
Expand Down
Expand Up @@ -23,12 +23,12 @@
import com.google.gwt.http.client.URL;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ServerConnector;
import com.vaadin.server.BrowserWindowOpener;
import com.vaadin.shared.ui.BrowserWindowOpenerState;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.util.SharedUtil;

/**
* Client-side code for {@link BrowserWindowOpener}
Expand Down Expand Up @@ -81,8 +81,7 @@ private String addParametersAndFragment(String url) {
}
}

url = ApplicationConnection
.addGetParameters(url, params.toString());
url = SharedUtil.addGetParameters(url, params.toString());
}

if (getState().uriFragment != null) {
Expand Down
Expand Up @@ -4,6 +4,8 @@

import org.junit.Test;

import com.vaadin.shared.util.SharedUtil;

public class ApplicationConnectionURLGenerationTest {

private static final String[] URIS = new String[] {
Expand Down Expand Up @@ -51,23 +53,23 @@ public void testParameterAdding() {
for (int i = 0; i < URIS.length; i++) {
// Adding nothing
assertEquals(URIS[i],
ApplicationConnection.addGetParameters(URIS[i], ""));
SharedUtil.addGetParameters(URIS[i], ""));

// Adding a=b&c=d
assertEquals(URIS_WITH_ABCD_PARAM[i],
ApplicationConnection.addGetParameters(URIS[i], "a=b&c=d"));
SharedUtil.addGetParameters(URIS[i], "a=b&c=d"));

// Fragments
if (URIS_WITH_ABCD_PARAM_AND_FRAGMENT[i].length() > 0) {
assertEquals(
URIS_WITH_ABCD_PARAM_AND_FRAGMENT[i],
ApplicationConnection.addGetParameters(URIS[i]
SharedUtil.addGetParameters(URIS[i]
+ "#fragment", "a=b&c=d"));

// Empty fragment
assertEquals(URIS_WITH_ABCD_PARAM_AND_FRAGMENT[i].replace(
"#fragment", "#"),
ApplicationConnection.addGetParameters(URIS[i] + "#",
SharedUtil.addGetParameters(URIS[i] + "#",
"a=b&c=d"));
}
}
Expand Down

0 comments on commit e20f6fd

Please sign in to comment.