Package org.apache.shindig.gadgets.spec

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


    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, String view)
      throws GadgetException {
    MessageBundle exact = getBundleFor(spec, locale, ignoreCache, container, view);

    // 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, view);
    }

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

    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, view);
    }

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

      injectFeatureLibraries(gadget, head, firstHeadChild);

      // This can be one script block.
      Element mainScriptTag = document.createElement("script");
      GadgetContext context = gadget.getContext();
      MessageBundle bundle = messageBundleFactory.getBundle(
          gadget.getSpec(), context.getLocale(), context.getIgnoreCache(), context.getContainer(), context.getView());
      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

    this.messageBundleFactory = messageBundleFactory;
  }

  public void addSubstitutions(Substitutions substituter, GadgetContext context, GadgetSpec spec)
      throws GadgetException {
    MessageBundle bundle =
        messageBundleFactory.getBundle(spec, context.getLocale(), context.getIgnoreCache(),
                    context.getContainer(), context.getView());
    String dir = bundle.getLanguageDirection();

    boolean rtl = RTL.equals(dir);
    substituter.addSubstitution(Substitutions.Type.BIDI, START_EDGE, rtl ? RIGHT : LEFT);
    substituter.addSubstitution(Substitutions.Type.BIDI, END_EDGE, rtl ? LEFT : RIGHT);
    substituter.addSubstitution(Substitutions.Type.BIDI, DIR, rtl ? RTL : LTR);
View Full Code Here

    this.messageBundleFactory = messageBundleFactory;
  }

  public void addSubstitutions(Substitutions substituter, GadgetContext context, GadgetSpec spec)
          throws GadgetException {
    MessageBundle bundle = messageBundleFactory.getBundle(spec, context.getLocale(),
        context.getIgnoreCache(), context.getContainer(), context.getView());

    substituter.addSubstitutions(Substitutions.Type.MESSAGE, bundle.getMessages());
  }
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(), gadget.getContext().getView());
      MessageELResolver messageELResolver = new MessageELResolver(expressions, bundle);

      int autoUpdateID = 0;
View Full Code Here

  public void getBundle() throws Exception {
    HttpResponse response = new HttpResponse(BASIC_BUNDLE);
    expect(fetcher.fetch(isA(HttpRequest.class))).andReturn(response);
    replay(fetcher);

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

    assertEquals(MSG_0_VALUE, bundle.getMessages().get(MSG_0_NAME));
    assertEquals(MSG_1_VALUE, bundle.getMessages().get(MSG_1_NAME));
    assertEquals(MSG_2_VALUE, bundle.getMessages().get(MSG_2_NAME));
  }
View Full Code Here

  public void getBundleFromCache() throws Exception {
    HttpResponse response = new HttpResponse(BASIC_BUNDLE);
    expect(fetcher.fetch(isA(HttpRequest.class))).andReturn(response).once();
    replay(fetcher);

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

    assertSame("Different objects returned out of the cache", bundle0, bundle1);
  }
View Full Code Here

    assertSame("Different objects returned out of the cache", bundle0, bundle1);
  }

  @Test
  public void getParentBundle() throws Exception {
    MessageBundle bundle = bundleFactory.getBundle(gadgetSpec, PARENT_LOCALE, true);

    assertEquals(MSG_0_ALT_VALUE, bundle.getMessages().get(MSG_0_NAME));
    assertEquals(MSG_1_VALUE, bundle.getMessages().get(MSG_1_NAME));
    assertEquals(MSG_2_VALUE, bundle.getMessages().get(MSG_2_NAME));
  }
View Full Code Here

    assertEquals(MSG_2_VALUE, bundle.getMessages().get(MSG_2_NAME));
  }

  @Test
  public void getAllAllBundle() throws Exception {
    MessageBundle bundle = bundleFactory.getBundle(gadgetSpec, new Locale("all", "ALL"), true);
    assertEquals(MSG_0_VALUE, bundle.getMessages().get(MSG_0_NAME));
  }
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.