Package org.apache.shindig.gadgets.spec

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


    expect(pipeline.execute(isA(HttpRequest.class))).andReturn(countryResponse);
    HttpResponse allAllResponse = new HttpResponse(ALL_ALL_BUNDLE);
    expect(pipeline.execute(isA(HttpRequest.class))).andReturn(allAllResponse);

    replay(pipeline);
    MessageBundle bundle = bundleFactory.getBundle(externalSpec, COUNTRY_LOCALE, true, ContainerConfig.DEFAULT_CONTAINER);
    verify(pipeline);

    assertEquals("true", bundle.getMessages().get("country"));
    assertEquals("true", bundle.getMessages().get("all"));
    assertEquals(MSG_0_COUNTRY_VALUE, bundle.getMessages().get(MSG_0_NAME));
  }
View Full Code Here


  public void getAllAllExternal() throws Exception {
    HttpResponse allAllResponse = new HttpResponse(ALL_ALL_BUNDLE);
    expect(pipeline.execute(isA(HttpRequest.class))).andReturn(allAllResponse);

    replay(pipeline);
    MessageBundle bundle = bundleFactory.getBundle(externalSpec, new Locale("all", "ALL"), true, ContainerConfig.DEFAULT_CONTAINER);
    verify(pipeline);

    assertEquals("true", bundle.getMessages().get("all"));
    assertEquals(MSG_0_ALL_VALUE, bundle.getMessages().get(MSG_0_NAME));
  }
View Full Code Here

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

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

    verify(pipeline);

    assertEquals(bundle0.getMessages().get(MSG_0_NAME), bundle1.getMessages().get(MSG_0_NAME));
  }
View Full Code Here

      }
    });

    time.set(System.currentTimeMillis());

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

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

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

    verify(pipeline);

    assertEquals(bundle0.getMessages().get(MSG_0_NAME), bundle1.getMessages().get(MSG_0_NAME));
  }
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

   * Injects message bundles into the gadget output.
   * @throws GadgetException If we are unable to retrieve the message bundle.
   */
  private void injectMessageBundles(Gadget gadget, Node scriptTag) throws GadgetException {
    GadgetContext context = gadget.getContext();
    MessageBundle bundle = messageBundleFactory.getBundle(
        gadget.getSpec(), context.getLocale(), context.getIgnoreCache());

    String msgs = bundle.toJSONString();

    Text text = scriptTag.getOwnerDocument().createTextNode("gadgets.Prefs.setMessages_(");
    text.appendData(msgs);
    text.appendData(");");
    scriptTag.appendChild(text);
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");

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

      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

  public void getExactBundle() throws Exception {
    HttpResponse response = new HttpResponse(BASIC_BUNDLE);
    expect(pipeline.execute(isA(HttpRequest.class))).andReturn(response);
    replay(pipeline);

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

    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));
    assertEquals(MSG_3_VALUE, bundle.getMessages().get(MSG_3_NAME));
  }
View Full Code Here

    assertEquals(MSG_3_VALUE, bundle.getMessages().get(MSG_3_NAME));
  }

  @Test
  public void getLangBundle() throws Exception {
    MessageBundle bundle = bundleFactory.getBundle(gadgetSpec, LANG_LOCALE, true, ContainerConfig.DEFAULT_CONTAINER, null);

    assertEquals(MSG_0_LANG_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));
    assertNull(bundle.getMessages().get(MSG_3_NAME));
  }
View Full Code Here

    assertNull(bundle.getMessages().get(MSG_3_NAME));
  }

  @Test
  public void getCountryBundle() throws Exception {
    MessageBundle bundle = bundleFactory.getBundle(gadgetSpec, COUNTRY_LOCALE, true, ContainerConfig.DEFAULT_CONTAINER, null);

    assertEquals(MSG_0_COUNTRY_VALUE, bundle.getMessages().get(MSG_0_NAME));
    assertNull(bundle.getMessages().get(MSG_1_NAME));
    assertNull(bundle.getMessages().get(MSG_2_NAME));
    assertEquals(MSG_3_VALUE, bundle.getMessages().get(MSG_3_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.