Package org.apache.shindig.gadgets.spec

Examples of org.apache.shindig.gadgets.spec.View


      if (exception != null) {
        throw exception;
      }
      try {
        GadgetSpec spec = new GadgetSpec(SPEC_URL, GADGET);
        View view = spec.getView(context.getView());
        return new Gadget()
            .setContext(context)
            .setSpec(spec)
            .setCurrentView(view);
      } catch (GadgetException e) {
View Full Code Here


  }

  private Gadget makeHrefGadget(String authz) throws Exception {
    Gadget gadget = makeGadget("");
    String doc = "<Content href='" + PROXIED_HTML_HREF + "' authz='" + authz + "'/>";
    View view = new View("proxied", Arrays.asList(XmlUtil.parse(doc)), SPEC_URL);
    gadget.setCurrentView(view);
    return gadget;
  }
View Full Code Here

        throw exception;
      }

      try {
        GadgetSpec spec = new GadgetSpec(Uri.parse("#"), gadgets.get(context.getUrl()));
        View view = spec.getView(context.getView());
        return new Gadget()
            .setContext(context)
            .setSpec(spec)
            .setCurrentView(view);
      } catch (GadgetException e) {
View Full Code Here

  public void baseElementInsertedWhenContentIsProxied() throws Exception {
    Gadget gadget = makeDefaultGadget();

    String viewUrl = "http://example.org/view.html";
    String xml = "<Content href='" + viewUrl + "'/>";
    View fakeView = new View("foo", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
    gadget.setCurrentView(fakeView);

    expect(config.get(ContainerConfig.DEFAULT_CONTAINER, INSERT_BASE_ELEMENT_KEY))
        .andReturn("true");
View Full Code Here

  public void baseElementInsertedWhenContentIsProxied() throws Exception {
    Gadget gadget = makeDefaultGadget();

    String viewUrl = "http://example.org/view.html";
    String xml = "<Content href='" + viewUrl + "'/>";
    View fakeView = new View("foo", Arrays.asList(XmlUtil.parse(xml)), SPEC_URL);
    gadget.setCurrentView(fakeView);

    config.data.put(INSERT_BASE_ELEMENT_KEY, true);

    String rewritten = rewrite(gadget, BODY_CONTENT);
View Full Code Here

  protected void injectBaseTag(Gadget gadget, Node headTag) {
    GadgetContext context = gadget.getContext();
    if (containerConfig.getBool(context.getContainer(), INSERT_BASE_ELEMENT_KEY)) {
      Uri base = gadget.getSpec().getUrl();
      View view = gadget.getCurrentView();
      if (view != null && view.getHref() != null) {
        base = view.getHref();
      }
      Element baseTag = headTag.getOwnerDocument().createElement("base");
      baseTag.setAttribute("href", base.toString());
      headTag.insertBefore(baseTag, headTag.getFirstChild());
    }
View Full Code Here

  /**
   * Attempts to extract the "current" view for the given gadget.
   */
  private View getView(GadgetContext context, GadgetSpec spec) {
    String viewName = context.getView();
    View view = spec.getView(viewName);
    if (view == null) {
      String container = context.getContainer();
      String property = "${Cur['gadgets.features'].views['" + viewName + "'].aliases}";
      for (Object alias : containerConfig.getList(container, property)) {
        viewName = alias.toString();
View Full Code Here

@Singleton
public class XhrwrapperConfigContributor implements ConfigContributor {
  /** {@inheritDoc} */
  public void contribute(Map<String,Object> config, Gadget gadget) {
    Map<String, String> xhrWrapperConfig = Maps.newHashMapWithExpectedSize(2);
    View view = gadget.getCurrentView();
    Uri contentsUri = view.getHref();
    xhrWrapperConfig.put("contentUrl", contentsUri == null ? "" : contentsUri.toString());
    if (AuthType.OAUTH.equals(view.getAuthType())) {
      addOAuthConfig(xhrWrapperConfig, view);
    } else if (AuthType.SIGNED.equals(view.getAuthType())) {
      xhrWrapperConfig.put("authorization", "signed");
    }
    config.put("shindig.xhrwrapper", xhrWrapperConfig);
  }
View Full Code Here

   * @return The rendered gadget content
   * @throws RenderingException if any issues arise that prevent rendering.
   */
  public String render(Gadget gadget) throws RenderingException {
    try {
      View view = gadget.getCurrentView();

      // We always execute these preloads, they have nothing to do with the cache output.
      Collection<PreloadedData> preloads = preloader.preload(gadget);
      gadget.setPreloads(preloads);

      String content;

      if (view.getHref() == null) {
        content = getViewContent(gadget, view);
      } else {
        content = proxyRenderer.render(gadget);
      }

View Full Code Here

    this.tplSignal = tplSignal;
  }
 
  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);
      }

      // 3. Set host/authority and protocol/schema.
      Uri gadgetUri = Uri.parse(host);
      if (StringUtils.isBlank(gadgetUri.getScheme())) {
        uri.setAuthority(host);
        uri.setScheme(getScheme(gadget, container));
      } else {
        uri.setAuthority(gadgetUri.getAuthority());
        uri.setScheme(gadgetUri.getScheme());
      }     

      // 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().values()) {
      String name = up.getName();
      String data = prefs.getPref(name);
      if (data == null) {
        data = up.getDefaultValue();
      }
     
      boolean upInFragment = !view.needsUserPrefSubstitution();
      addParam(uri, UriCommon.USER_PREF_PREFIX + up.getName(), data, useTpl, upInFragment);
    }

    if (versioner != null) {
      // Added on the query string, obviously not templated.
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.spec.View

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.