return buildUri(view, gadget);
}
protected Uri buildUri(View view, Gadget gadget) {
UriBuilder uri;
GadgetContext context = gadget.getContext();
String container = context.getContainer();
if (View.ContentType.URL.equals(view.getType())) {
// A. type=url. Initializes all except standard parameters.
uri = new UriBuilder(view.getHref());
addExtrasForTypeUrl(uri, gadget);
} else {
// B. Others, aka. type=html and html_sanitized.
uri = new UriBuilder();
// 1. Set base path.
uri.setPath(getReqVal(container, IFRAME_BASE_PATH_KEY));
// 2. Set host/authority.
String ldDomain;
try {
ldDomain = ldService.getLockedDomainForGadget(gadget, container);
} catch (GadgetException e) {
throw new RuntimeException(e);
}
String host = "//" +
(ldDomain == null ? getReqVal(container, UNLOCKED_DOMAIN_KEY) : ldDomain);
Uri gadgetUri = Uri.parse(host);
if (gadgetUri.getAuthority() == null
&& gadgetUri.getScheme() == null
&& gadgetUri.getPath().equals(host)) {
// This is for backwards compatibility with unlocked domains like
// "unlockeddomain.com"
gadgetUri = Uri.parse("//" + host);
}
// 3. Set the scheme.
if (StringUtils.isBlank(gadgetUri.getScheme())) {
uri.setScheme(getScheme(gadget, container));
} else {
uri.setScheme(gadgetUri.getScheme());
}
// 4. Set the authority.
uri.setAuthority(gadgetUri.getAuthority());
// 5. Add the URL.
uri.addQueryParameter(Param.URL.getKey(), context.getUrl().toString());
}
// Add container, whose input derived other components of the URI.
uri.addQueryParameter(Param.CONTAINER.getKey(), container);
// Add remaining non-url standard parameters, in templated or filled form.
boolean useTpl = tplSignal != null ? tplSignal.useTemplates() : DEFAULT_USE_TEMPLATES;
addParam(uri, Param.VIEW.getKey(), view.getName(), useTpl, false);
addParam(uri, Param.LANG.getKey(), context.getLocale().getLanguage(), useTpl, false);
addParam(uri, Param.COUNTRY.getKey(), context.getLocale().getCountry(), useTpl, false);
addParam(uri, Param.DEBUG.getKey(), context.getDebug() ? "1" : "0", useTpl, false);
addParam(uri, Param.NO_CACHE.getKey(), context.getIgnoreCache() ? "1" : "0", useTpl, false);
addParam(uri, Param.SANITIZE.getKey(), context.getSanitize() ? "1" : "0", useTpl, false);
if (context.getCajoled()) {
addParam(uri, Param.CAJOLE.getKey(), "1", useTpl, false);
}
// Add all UserPrefs
UserPrefs prefs = context.getUserPrefs();
for (UserPref up : gadget.getSpec().getUserPrefs().values()) {
String name = up.getName();
String data = prefs.getPref(name);
if (data == null) {
data = up.getDefaultValue();