Package org.apache.shindig.gadgets.spec

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


      }
    });

    time.set(System.currentTimeMillis());

    MessageBundle bundle0 = bundleFactory.getBundle(gadgetSpec, LOCALE, false);

    time.set(time.get() + MAX_AGE + 1);

    MessageBundle bundle1 = bundleFactory.getBundle(gadgetSpec, LOCALE, false);

    verify(fetcher);

    assertSame("Did not respond from cache when refresh failed.", bundle0, bundle1);
  }
View Full Code Here


    expect(fetcher.fetch(isA(HttpRequest.class)))
        .andReturn(badResponse).once();
    replay(fetcher);

    MessageBundle bundle = bundleFactory.getBundle(gadgetSpec, LOCALE, false);

    verify(fetcher);

    assertEquals(0, bundle.getMessages().size());
  }
View Full Code Here

   * Substitutes all hangman variables into the gadget spec.
   *
   * @return A new GadgetSpec, with all fields substituted as needed.
   */
  public GadgetSpec substitute(GadgetContext context, GadgetSpec spec) throws GadgetException {
    MessageBundle bundle =
        messageBundleFactory.getBundle(spec, context.getLocale(), context.getIgnoreCache());
    String dir = bundle.getLanguageDirection();

    Substitutions substituter = new Substitutions();
    substituter.addSubstitutions(Substitutions.Type.MESSAGE, bundle.getMessages());
    BidiSubstituter.addSubstitutions(substituter, dir);
    substituter.addSubstitution(Substitutions.Type.MODULE, "ID",
        Integer.toString(context.getModuleId()));
    UserPrefSubstituter.addSubstitutions(substituter, spec, context.getUserPrefs());

View Full Code Here

    }

    String key = spec.getUrl().toString() + '.' + locale.toString();
    CachedObject<MessageBundle> cached = cache.getElement(key);

    MessageBundle bundle;
    if (cached == null || cached.isExpired) {
      try {
        bundle = getNestedBundle(spec, locale, ignoreCache);
      } catch (GadgetException e) {
        // Enforce negative caching.
View Full Code Here

    return bundle;
  }

  private MessageBundle getNestedBundle(GadgetSpec spec, Locale locale, boolean ignoreCache)
      throws GadgetException {
    MessageBundle parent = getParentBundle(spec, locale, ignoreCache);
    MessageBundle child = null;
    LocaleSpec localeSpec = spec.getModulePrefs().getLocale(locale);
    if (localeSpec == null) {
      return parent == null ? MessageBundle.EMPTY : parent;
    }
    Uri messages = localeSpec.getMessages();
    if (messages == null || messages.toString().length() == 0) {
      child = localeSpec.getMessageBundle();
    } else {
      child = fetchBundle(localeSpec, ignoreCache);
    }
    return new MessageBundle(parent, child);
  }
View Full Code Here

      throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT,
          "Unable to retrieve message bundle xml. HTTP error " +
          response.getHttpStatusCode());
    }

    MessageBundle bundle  = new MessageBundle(locale, response.getResponseAsString());
    return bundle;
  }
View Full Code Here

      return;
    }

    try {
      GadgetContext context = gadget.getContext();
      MessageBundle bundle = messageBundleFactory.getBundle(gadget.getSpec(), context.getLocale(),
              context.getIgnoreCache(), context.getContainer(), context.getView());

      MessageELResolver messageELResolver = new MessageELResolver(expressions, bundle);

      this.elContext = expressions.newELContext(messageELResolver,
              new GadgetELResolver(gadget.getContext()));
      this.elContext.putContext(GadgetContext.class, elContext);
      Document document = mutableContent.getDocument();
      processChildNodes(document);
      Element head = (Element) DomUtil.getFirstNamedChildNode(document.getDocumentElement(), "head");

      Element title = document.createElement("title");
      ModulePrefs mps = gadget.getSpec().getModulePrefs();
      String titleValue = "default title";
      if (mps != null && mps.getTitle() != null && !mps.getTitle().isEmpty()){
        titleValue = mps.getTitle();
      }
      title.appendChild(title.getOwnerDocument().createTextNode(titleValue));

      // Insert new content before any of the existing children of the head element
      Node firstHeadChild = head.getFirstChild();

      head.insertBefore(title, firstHeadChild);

      Element injectedStyle = document.createElement("style");
      injectedStyle.setAttribute("type", "text/css");
      head.insertBefore(injectedStyle, firstHeadChild);

      // Inject default scrolling to the body
      this.injectDefaultScrolling(injectedStyle);

      // Only inject default styles if no doctype was specified.
      if (document.getDoctype() == null) {
        injectedStyle.appendChild(injectedStyle.getOwnerDocument().
            createTextNode(DEFAULT_CSS));
      }
      // Override & insert DocType if Gadget is written for OpenSocial 2.0 or greater,
      // if quirksmode is not set
      if(gadget.getSpecificationVersion().isEqualOrGreaterThan("2.0.0")
          && !gadget.useQuirksMode()){
        String container = gadget.getContext().getContainer();
        String doctype_qname = defaultDoctypeQName;
        String doctype_sysid = defaultDoctypeSysId;
        String doctype_pubid = defaultDoctypePubId;
        String value = containerConfig.getString(container, REWRITE_DOCTYPE_QNAME);
        if(value != null){
          doctype_qname = value;
        }
        value = containerConfig.getString(container, REWRITE_DOCTYPE_SYSID);
        if(value != null){
          doctype_sysid = value;
        }
        value = containerConfig.getString(container, REWRITE_DOCTYPE_PUBID);
        if(value != null){
          doctype_pubid = value;
        }
        //Don't inject DOCTYPE if QName is null
        if(doctype_qname != null){
          DocumentType docTypeNode = document.getImplementation()
              .createDocumentType(doctype_qname, doctype_pubid, doctype_sysid);
          if(document.getDoctype() != null){
            document.removeChild(document.getDoctype());
          }
          document.insertBefore(docTypeNode, document.getFirstChild());
        }
      }

      Element html= (Element)document.getElementsByTagName("html").item(0);
      if(html != null){
        Locale locale = gadget.getContext().getLocale();
        if (locale != null) {
          String locStr = locale.toString();
          String locValue = locStr.replace("_", "-");
          html.setAttribute("lang", locValue);
          html.setAttribute("xml:lang", locValue);
        }
      }

      injectBaseTag(gadget, head);
      injectGadgetBeacon(gadget, head, firstHeadChild);
      injectFeatureLibraries(gadget, head, firstHeadChild);

      // This can be one script block.
      Element mainScriptTag = document.createElement("script");
      injectMessageBundles(bundle, mainScriptTag);
      injectDefaultPrefs(gadget, mainScriptTag);
      injectPreloads(gadget, mainScriptTag);

      // We need to inject our script before any developer scripts.
      head.insertBefore(mainScriptTag, firstHeadChild);

      Element body = (Element)DomUtil.getFirstNamedChildNode(document.getDocumentElement(), "body");

      body.setAttribute("dir", bundle.getLanguageDirection());

      // With Caja enabled, onloads are triggered by features/caja/taming.js
      if (!gadget.requiresCaja()) {
        injectOnLoadHandlers(body);
      }
View Full Code Here

    return cacheProvider.createCache(CACHE_NAME);
  }

  @Override
  protected MessageBundle parse(String content, Query query) throws GadgetException {
    return new MessageBundle(((LocaleQuery) query).locale, content);
  }
View Full Code Here

    return new MessageBundle(((LocaleQuery) query).locale, content);
  }

  public MessageBundle getBundle(GadgetSpec spec, Locale locale, boolean ignoreCache, String container)
      throws GadgetException {
    MessageBundle exact = getBundleFor(spec, locale, ignoreCache, container);

    // We don't want to fetch the same bundle multiple times, so we verify that the exact match
    // has not already been fetched.
    MessageBundle lang, country, all;

    boolean isAllLanguage = locale.getLanguage().equalsIgnoreCase("all");
    boolean isAllCountry = locale.getCountry().equalsIgnoreCase("ALL");

    if (isAllCountry) {
      lang = MessageBundle.EMPTY;
    } else {
      lang = getBundleFor(spec, new Locale(locale.getLanguage(), "ALL"), ignoreCache, container);
    }

    if (isAllLanguage) {
      country = MessageBundle.EMPTY;
    } else {
      country = getBundleFor(spec, new Locale("all", locale.getCountry()), ignoreCache, container);
    }

    if (isAllCountry || isAllLanguage) {
      // If either of these is true, we already picked up both anyway.
      all = MessageBundle.EMPTY;
    } else {
      all = getBundleFor(spec, ALL_ALL, ignoreCache, container);
    }

    return new MessageBundle(all, country, lang, exact);
  }
View Full Code Here

    }
   
    if (!templates.isEmpty()) {
      Gadget gadget = templateContext.getGadget();
     
      MessageBundle bundle = messageBundleFactory.getBundle(gadget.getSpec(),
          gadget.getContext().getLocale(), gadget.getContext().getIgnoreCache(), gadget.getContext().getContainer());
      MessageELResolver messageELResolver = new MessageELResolver(expressions, bundle);
 
      int autoUpdateID = 0;
      for (Element template : templates) {
View Full Code Here

TOP

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

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.