Package org.apache.shindig.gadgets.spec

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


    if (nodes.isEmpty()) {
      return mutated;
    }
   
    Uri contentBase = gadget.getSpec().getUrl();
    View view = gadget.getCurrentView();
    if (view != null && view.getHref() != null) {
      contentBase = view.getHref();
    }
   
    Element head = (Element)DomUtil.getFirstNamedChildNode(
        nodes.get(0).getOwnerDocument().getDocumentElement(), "head");
    for (Node node : nodes) {
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

    this.httpCache = httpCache;
    this.pipelineExecutor = pipelineExecutor;
  }

  public String render(Gadget gadget) throws RenderingException, GadgetException {
    View view = gadget.getCurrentView();
    Uri href = view.getHref();
    Preconditions.checkArgument(href != null, "Gadget does not have href for the current view");

    GadgetContext context = gadget.getContext();
    String path = context.getParameter(PATH_PARAM);
    if (path != null) {
      try {
        Uri relative = Uri.parse(path);
        if (!relative.isAbsolute()) {
          href = href.resolve(relative);
        }
      } catch (IllegalArgumentException e) {
        // TODO: Spec does not say what to do for an invalid relative path.
        // Just ignoring for now.
      }
    }

    UriBuilder uri = new UriBuilder(href);
    uri.addQueryParameter("lang", context.getLocale().getLanguage());
    uri.addQueryParameter("country", context.getLocale().getCountry());

    OAuthArguments oauthArgs = new OAuthArguments(view);
    oauthArgs.setProxiedContentRequest(true);

    HttpRequest request = new HttpRequest(uri.toUri())
        .setIgnoreCache(context.getIgnoreCache())
        .setOAuthArguments(oauthArgs)
        .setAuthType(view.getAuthType())
        .setSecurityToken(context.getToken())
        .setContainer(context.getContainer())
        .setGadget(gadget.getSpec().getUrl());
    setUserAgent(request, context);
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

    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);
      }
      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().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

      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

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.