Пример #1
0
  public static com.liferay.opensocial.model.Gadget getGadget(PortletPreferences portletPreferences)
      throws Exception {

    String url = portletPreferences.getValue("url", StringPool.BLANK);

    if (Validator.isNull(url)) {
      return null;
    }

    com.liferay.opensocial.model.Gadget gadget = new GadgetImpl();

    GadgetSpec gadgetSpec = null;

    try {
      gadgetSpec = ShindigUtil.getGadgetSpec(url);
    } catch (Exception e) {
      throw new GadgetURLException(e);
    }

    ModulePrefs modulePrefs = gadgetSpec.getModulePrefs();

    gadget.setName(modulePrefs.getTitle());
    gadget.setUrl(url);

    return gadget;
  }
Пример #2
0
  @Override
  protected Gadget getGadget(RenderRequest renderRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PortletConfig portletConfig = getPortletConfig();

    return ShindigUtil.getGadget(portletConfig.getPortletName(), themeDisplay.getCompanyId());
  }
  @Override
  protected Gadget getGadget(PortletConfig portletConfig, PortletRequest portletRequest)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String portletResource = ParamUtil.getString(portletRequest, "portletResource");

    return ShindigUtil.getGadget(portletResource, themeDisplay.getCompanyId());
  }
Пример #4
0
  @Override
  protected void overrideConfiguration(
      GadgetSpec gadgetSpec, Portlet portlet, PortletDisplay portletDisplay) throws Exception {

    String urlConfiguration = portletDisplay.getURLConfiguration();

    if (ShindigUtil.hasUserPrefs(gadgetSpec)) {
      portlet.setConfigurationActionClass(ConfigurationActionImpl.class.getName());

      urlConfiguration = urlConfiguration.replaceAll("edit_permissions", "edit_configuration");
    } else {
      portlet.setConfigurationActionClass(null);

      urlConfiguration = urlConfiguration.replaceAll("edit_configuration", "edit_permissions");
    }

    portletDisplay.setURLConfiguration(urlConfiguration);
  }
  public ConsumerInfo getConsumerKeyAndSecret(
      SecurityToken securityToken, String serviceName, OAuthServiceProvider oAuthServiceProvider)
      throws GadgetException {

    OAuthConsumer oAuthConsumer = getOAuthConsumer(securityToken, serviceName);

    if (oAuthConsumer == null) {
      throw new GadgetException(
          GadgetException.Code.INTERNAL_SERVER_ERROR,
          "No key for gadget " + securityToken.getAppUrl() + " and service " + serviceName);
    }

    net.oauth.OAuthConsumer netOAuthConsumer = null;

    String keyType = oAuthConsumer.getKeyType();

    if (keyType.equals(OAuthConsumerConstants.KEY_TYPE_RSA_PRIVATE)) {
      netOAuthConsumer =
          new net.oauth.OAuthConsumer(
              null, oAuthConsumer.getConsumerKey(), null, oAuthServiceProvider);

      netOAuthConsumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.RSA_SHA1);
      netOAuthConsumer.setProperty(RSA_SHA1.PRIVATE_KEY, oAuthConsumer.getConsumerSecret());
    } else {
      netOAuthConsumer =
          new net.oauth.OAuthConsumer(
              null,
              oAuthConsumer.getConsumerKey(),
              oAuthConsumer.getConsumerSecret(),
              oAuthServiceProvider);

      netOAuthConsumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
    }

    String keyName = oAuthConsumer.getKeyName();

    String callbackURL = _callbackURL.replace("%host%", ShindigUtil.getHost());

    return new ConsumerInfo(netOAuthConsumer, keyName, callbackURL);
  }