Package org.apache.shindig.gadgets.spec

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


  protected Gadget mockGadget(String targetUrl, boolean isTypeUrl, String currentViewStr, String lang,
      String country, boolean isDebug, boolean ignoreCache, boolean sanitize, boolean cajoled,
      Map<String, String> specPrefs, Map<String, String> inPrefs, boolean needsPrefSubst, List<String> features) {
    View currentView = createMock(View.class);
    View secondView = createMock(View.class);
    ModulePrefs modulePrefs = createMock(ModulePrefs.class);
    GadgetSpec spec = createMock(GadgetSpec.class);
    GadgetContext context = createMock(GadgetContext.class);
    Gadget gadget = createMock(Gadget.class);

    // Base URL/view.
    Uri targetUri = Uri.parse(targetUrl);
    if (isTypeUrl) {
      expect(currentView.getType()).andReturn(ContentType.URL).anyTimes();
      expect(currentView.getHref()).andReturn(targetUri).anyTimes();
      expect(secondView.getType()).andReturn(ContentType.HTML).anyTimes();
      expect(spec.getUrl()).andReturn(targetUri).anyTimes();
    } else {
      expect(currentView.getType()).andReturn(ContentType.HTML).anyTimes();
      expect(spec.getUrl()).andReturn(targetUri).anyTimes();
      expect(secondView.getType()).andReturn(ContentType.URL).anyTimes();
      expect(secondView.getHref()).andReturn(targetUri).anyTimes();
    }
    expect(currentView.getName()).andReturn(currentViewStr).anyTimes();
    expect(secondView.getName()).andReturn(ANOTHER_VIEW).anyTimes();

    // Basic context info
    Locale locale = new Locale(lang, country);
    expect(context.getUrl()).andReturn(SPEC_URI).anyTimes();
    expect(context.getContainer()).andReturn(CONTAINER).anyTimes();
    expect(context.getLocale()).andReturn(locale).anyTimes();
    expect(context.getDebug()).andReturn(isDebug).anyTimes();
    expect(context.getIgnoreCache()).andReturn(ignoreCache).anyTimes();
    expect(context.getToken()).andReturn(null).anyTimes();
    expect(context.getSanitize()).andReturn(sanitize).anyTimes();
    expect(context.getCajoled()).andReturn(cajoled).anyTimes();

    // All Features (doesn't distinguish between transitive and not)
    expect(gadget.getAllFeatures()).andReturn(features).anyTimes();
    Map<String, Feature> featureMap = Maps.newLinkedHashMap();
    for (String feature : features) {
      featureMap.put(feature, null);
    }
    expect(gadget.getViewFeatures()).andReturn(featureMap).anyTimes();
    expect(modulePrefs.getFeatures()).andReturn(featureMap).anyTimes();

    // User prefs
    Map<String, UserPref> specPrefMap = Maps.newLinkedHashMap();
    for (Map.Entry<String, String> specPref : specPrefs.entrySet()) {
      UserPref up = createMock(UserPref.class);
View Full Code Here


        Gadget gadget = processor.process(context);
        GadgetSpec spec = gadget.getSpec();

        JSONObject gadgetJson = new JSONObject();

        ModulePrefs prefs = spec.getModulePrefs();

        // TODO: modularize response fields based on requested items.
        JSONObject views = new JSONObject();
        for (View view : spec.getViews().values()) {
          views.put(view.getName(), new JSONObject()
               // .put("content", view.getContent())
               .put("type", view.getType().toString().toLowerCase())
               .put("quirks", view.getQuirks())
               .put("preferredHeight", view.getPreferredHeight())
               .put("preferredWidth", view.getPreferredWidth()));
        }

        // Features.
        Set<String> feats = prefs.getFeatures().keySet();
        String[] features = feats.toArray(new String[feats.size()]);

        // Links
        JSONObject links = new JSONObject();
        for (LinkSpec link : prefs.getLinks().values()) {
          links.put(link.getRel(), link.getHref());
        }

        JSONObject userPrefs = new JSONObject();

        // User pref specs
        for (UserPref pref : spec.getUserPrefs()) {
          JSONObject up = new JSONObject()
              .put("displayName", pref.getDisplayName())
              .put("type", pref.getDataType().toString().toLowerCase())
              .put("default", pref.getDefaultValue())
              .put("enumValues", pref.getEnumValues())
              .put("orderedEnumValues", getOrderedEnums(pref));
          userPrefs.put(pref.getName(), up);
        }

        // TODO: This should probably just copy all data from
        // ModulePrefs.getAttributes(), but names have to be converted to
        // camel case.
        gadgetJson.put("iframeUrl", urlGenerator.getIframeUrl(gadget))
                  .put("url",context.getUrl().toString())
                  .put("moduleId", context.getModuleId())
                  .put("title", prefs.getTitle())
                  .put("titleUrl", prefs.getTitleUrl().toString())
                  .put("views", views)
                  .put("features", features)
                  .put("userPrefs", userPrefs)
                  .put("links", links)

                  // extended meta data
                  .put("directoryTitle", prefs.getDirectoryTitle())
                  .put("thumbnail", prefs.getThumbnail().toString())
                  .put("screenshot", prefs.getScreenshot().toString())
                  .put("author", prefs.getAuthor())
                  .put("authorEmail", prefs.getAuthorEmail())
                  .put("authorAffiliation", prefs.getAuthorAffiliation())
                  .put("authorLocation", prefs.getAuthorLocation())
                  .put("authorPhoto", prefs.getAuthorPhoto())
                  .put("authorAboutme", prefs.getAuthorAboutme())
                  .put("authorQuote", prefs.getAuthorQuote())
                  .put("authorLink", prefs.getAuthorLink())
                  .put("categories", prefs.getCategories())
                  .put("screenshot", prefs.getScreenshot().toString())
                  .put("height", prefs.getHeight())
                  .put("width", prefs.getWidth())
                  .put("showStats", prefs.getShowStats())
                  .put("showInDirectory", prefs.getShowInDirectory())
                  .put("singleton", prefs.getSingleton())
                  .put("scaling", prefs.getScaling())
                  .put("scrolling", prefs.getScrolling());
        return gadgetJson;
      } catch (ProcessingException e) {
        throw new RpcException(context, e);
      } catch (JSONException e) {
        // Shouldn't be possible
View Full Code Here

      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();
View Full Code Here


  /** {@inheritDoc} */
  public void contribute(Map<String, Object> config, Gadget gadget) {
    // Add gadgets.util support. This is calculated dynamically based on request inputs.
    ModulePrefs prefs = gadget.getSpec().getModulePrefs();
    Collection<Feature> features = prefs.getFeatures().values();
    Map<String, Map<String, Object>> featureMap = Maps.newHashMapWithExpectedSize(features.size());
    Set<String> allFeatureNames = registry.getAllFeatureNames();

    for (Feature feature : features) {
      // Skip unregistered features
View Full Code Here

   
    protected JSONObject getGadgetJson(Gadget gadget, GadgetSpec spec)
        throws JSONException {
        JSONObject gadgetJson = new JSONObject();

        ModulePrefs prefs = spec.getModulePrefs();

        // TODO: modularize response fields based on requested items.
        JSONObject views = new JSONObject();
        for (View view : spec.getViews().values()) {
          JSONObject jv = new JSONObject()
               // .put("content", view.getContent())
               .put("type", view.getType().toString())
               .put("quirks", view.getQuirks())
               .put("preferredHeight", view.getPreferredHeight())
               .put("preferredWidth", view.getPreferredWidth());
          Map<String, String> vattrs = view.getAttributes();
          if (!vattrs.isEmpty()){
            JSONObject ja = new JSONObject(vattrs);
            jv.put("attributes", ja);
          }
          views.put(view.getName(), jv);
        }

        // Features.
        Set<String> feats = prefs.getFeatures().keySet();
        String[] features = feats.toArray(new String[feats.size()]);
       
        // Feature details
        // The following renders an object containing feature details, of the form
        //   { <featureName>*: { "required": <boolean>, "parameters": { <paramName>*: <string> } } }
        JSONObject featureDetailList = new JSONObject();
        for (Feature featureSpec : prefs.getFeatures().values()) {
          JSONObject featureDetail = new JSONObject();
          featureDetail.put("required", featureSpec.getRequired());
          JSONObject featureParameters = new JSONObject();
          featureDetail.put("parameters", featureParameters);
          Multimap<String, String> featureParams = featureSpec.getParams();
          for (String paramName : featureParams.keySet()) {
            featureParameters.put(paramName, featureParams.get(paramName));
          }
          featureDetailList.put(featureSpec.getName(), featureDetail);
        }
       
        // Links
        JSONObject links = new JSONObject();
        for (LinkSpec link : prefs.getLinks().values()) {
          links.put(link.getRel(), link.getHref());
        }

        JSONObject userPrefs = new JSONObject();

        // User pref specs
        for (UserPref pref : spec.getUserPrefs().values()) {
          JSONObject up = new JSONObject()
              .put("displayName", pref.getDisplayName())
              .put("type", pref.getDataType().toString().toLowerCase())
              .put("default", pref.getDefaultValue())
              .put("enumValues", pref.getEnumValues())
              .put("orderedEnumValues", getOrderedEnums(pref));
          userPrefs.put(pref.getName(), up);
        }

        // TODO: This should probably just copy all data from
        // ModulePrefs.getAttributes(), but names have to be converted to
        // camel case.
        gadgetJson.put("iframeUrl", iframeUriManager.makeRenderingUri(gadget).toString())
                  .put("url",context.getUrl().toString())
                  .put("moduleId", context.getModuleId())
                  .put("title", prefs.getTitle())
                  .put("titleUrl", prefs.getTitleUrl().toString())
                  .put("views", views)
                  .put("features", features)
                  .put("featureDetails", featureDetailList)
                  .put("userPrefs", userPrefs)
                  .put("links", links)

                  // extended meta data
                  .put("directoryTitle", prefs.getDirectoryTitle())
                  .put("thumbnail", prefs.getThumbnail().toString())
                  .put("screenshot", prefs.getScreenshot().toString())
                  .put("author", prefs.getAuthor())
                  .put("authorEmail", prefs.getAuthorEmail())
                  .put("authorAffiliation", prefs.getAuthorAffiliation())
                  .put("authorLocation", prefs.getAuthorLocation())
                  .put("authorPhoto", prefs.getAuthorPhoto())
                  .put("authorAboutme", prefs.getAuthorAboutme())
                  .put("authorQuote", prefs.getAuthorQuote())
                  .put("authorLink", prefs.getAuthorLink())
                  .put("categories", prefs.getCategories())
                  .put("screenshot", prefs.getScreenshot().toString())
                  .put("height", prefs.getHeight())
                  .put("width", prefs.getWidth())
                  .put("showStats", prefs.getShowStats())
                  .put("showInDirectory", prefs.getShowInDirectory())
                  .put("singleton", prefs.getSingleton())
                  .put("scaling", prefs.getScaling())
                  .put("scrolling", prefs.getScrolling());
        return gadgetJson;
    }
View Full Code Here

      //
      GadgetData data = def.getData();
      if (data instanceof LocalGadgetData)
      {
         GadgetSpec spec = new GadgetSpec(Uri.parse("http://www.gatein.org"), source.getTextContent());
         ModulePrefs prefs = spec.getModulePrefs();

         //
         String description = prefs.getDescription();
         String thumbnail = prefs.getThumbnail().toString();
         String title = getGadgetTitle(prefs, gadget.getName());
         String referenceURL = prefs.getTitleUrl().toString();

         // Update state from XML
         def.setDescription(description);
         def.setThumbnail(thumbnail); // Do something better than that
         def.setTitle(title);
View Full Code Here

      // Get the definition
      GadgetDefinition def = getDefinition();

      // Get the related content
      GadgetSpec spec = new GadgetSpec(Uri.parse("http://www.gatein.org"), gadgetXML);
      ModulePrefs prefs = spec.getModulePrefs();
      byte[] bytes = gadgetXML.getBytes();
      String encoding = EncodingDetector.detect(new ByteArrayInputStream(bytes));

      // Update def
      def.setDescription(prefs.getDescription());
      def.setThumbnail(prefs.getThumbnail().toString()); // Do something better than that
      def.setTitle(prefs.getTitle());
      def.setReferenceURL(prefs.getTitleUrl().toString());

      // Update content
      NTFile content = getGadgetContent();
      content.setContentResource(new Resource(GADGET_MIME_TYPE, encoding, bytes));
   }
View Full Code Here

        String encoding = EncodingDetector.detect(new ByteArrayInputStream(bytes));
        String gadget = new String(bytes, encoding);
        String gadgetURL = getGadgetURL();
        GadgetSpec spec = new GadgetSpec(Uri.parse(gadgetURL), gadget);
        ModulePrefs prefs = spec.getModulePrefs();
        processMetadata(prefs, def);
    }
View Full Code Here

TOP

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

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.