public Uri makeRenderingUri(Gadget gadget) {
UriBuilder uri;
View view = gadget.getCurrentView();
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());
} 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 host;
if (usingLockedDomain(gadget, container)) {
host = ldGen.getLockedDomainPrefix(gadget.getSpec().getUrl()) +
getReqVal(container, LOCKED_DOMAIN_SUFFIX_KEY);
} else {
host = getReqVal(container, UNLOCKED_DOMAIN_KEY);
}
uri.setAuthority(host);
// 3. Set protocol/schema.
uri.setScheme(getScheme(gadget, container));
// 4. 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);
// Add all UserPrefs
UserPrefs prefs = context.getUserPrefs();
for (UserPref up : gadget.getSpec().getUserPrefs()) {
String name = up.getName();
String data = prefs.getPref(name);
if (data == null) {
data = up.getDefaultValue();