Package org.apache.shindig.gadgets.spec

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


    return mockContext;
  }

  private GadgetSpec mockGadgetSpec(List<Feature> allFeatures, String gadgetUrl) {
    GadgetSpec mockSpec = control.createMock(GadgetSpec.class);
    ModulePrefs mockPrefs = mockModulePrefs(allFeatures);
    EasyMock.expect(mockSpec.getUrl()).andReturn(Uri.parse(gadgetUrl)).anyTimes();
    EasyMock.expect(mockSpec.getModulePrefs()).andReturn(mockPrefs).anyTimes();
    return mockSpec;
  }
View Full Code Here


    EasyMock.expect(mockSpec.getModulePrefs()).andReturn(mockPrefs).anyTimes();
    return mockSpec;
  }

  private ModulePrefs mockModulePrefs(List<Feature> features) {
    ModulePrefs mockPrefs = control.createMock(ModulePrefs.class);
    EasyMock.expect(mockPrefs.getAllFeatures()).andReturn(features).anyTimes();
    return mockPrefs;
  }
View Full Code Here

        }
        config = new JSONObject(features, properties);
      }

      // Add gadgets.util support. This is calculated dynamically based on request inputs.
      ModulePrefs prefs = gadget.getSpec().getModulePrefs();
      JSONObject featureMap = new JSONObject();

      for (Feature feature : prefs.getFeatures().values()) {
        featureMap.put(feature.getName(), feature.getParams());
      }
      config.put("core.util", featureMap);

      // Add authentication token config
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

                String gadgetName = def.getName();
                LocalGadgetData localData = (LocalGadgetData) data;
                Resource resource = localData.getResources().getFile(localData.getFileName()).getContentResource();
                String content = new String(resource.getData(), resource.getEncoding());
                GadgetSpec gadgetSpec = new GadgetSpec(Uri.parse(getGadgetURL(gadgetName)), content);
                ModulePrefs prefs = gadgetSpec.getModulePrefs();

                String title = prefs.getDirectoryTitle();
                if (title == null || title.trim().length() < 1) {
                    title = prefs.getTitle();
                }
                if (title == null || title.trim().length() < 1) {
                    title = gadgetName;
                }
                gadget.setName(def.getName());
                gadget.setDescription(prefs.getDescription());
                gadget.setLocal(true);
                gadget.setTitle(title);
                gadget.setReferenceUrl(prefs.getTitleUrl().toString());
                gadget.setThumbnail(prefs.getThumbnail().toString());
                gadget.setUrl(getJCRGadgetURL(localData));
            } catch (Exception ex) {
                log.error("Error while loading the content of local gadget " + def.getName(), ex);
            }
        } else {
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();

        // detect the encoding declared in the XML source
        // note that we do not need to detect the encoding of gadgetXML because
        // it is a String and not a stream
        String encoding = new XMLDeclarationParser(gadgetXML).parse().get(XMLDeclarationParser.ENCODING);
        if (encoding == null || !Charset.isSupported(encoding)) {
            throw new UnsupportedEncodingException(encoding);
        }
        // get the bytes in the declared encoding
        byte[] bytes = gadgetXML.getBytes(encoding);

        // 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 gadget = new String(bytes, encoding);

      //
      String gadgetURL = getGadgetURL();
      GadgetSpec spec = new GadgetSpec(Uri.parse(gadgetURL), gadget);
      ModulePrefs prefs = spec.getModulePrefs();

      //
      GadgetDefinition def = registry.addGadget(name);

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

      //
      log.info("Importing gadget name=" + name + " description=" + description + " thumbnail=" + thumbnail + " title=" +
               thumbnail + " title=" + title);
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

    return mockContext;
  }

  private GadgetSpec mockGadgetSpec(List<Feature> allFeatures, String gadgetUrl) {
    GadgetSpec mockSpec = control.createMock(GadgetSpec.class);
    ModulePrefs mockPrefs = mockModulePrefs(allFeatures);
    EasyMock.expect(mockSpec.getUrl()).andReturn(Uri.parse(gadgetUrl)).anyTimes();
    EasyMock.expect(mockSpec.getModulePrefs()).andReturn(mockPrefs).anyTimes();
    return mockSpec;
  }
View Full Code Here

    EasyMock.expect(mockSpec.getModulePrefs()).andReturn(mockPrefs).anyTimes();
    return mockSpec;
  }

  private ModulePrefs mockModulePrefs(List<Feature> features) {
    ModulePrefs mockPrefs = control.createMock(ModulePrefs.class);
    EasyMock.expect(mockPrefs.getAllFeatures()).andReturn(features).anyTimes();
    return mockPrefs;
  }
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.