예제 #1
0
  protected void checkResourceBundles(
      BundleContext bundleContext,
      ClassLoader classLoader,
      com.liferay.portal.model.Portlet portletModel,
      ServiceRegistrations serviceRegistrations) {

    if (Validator.isBlank(portletModel.getResourceBundle())) {
      return;
    }

    for (Locale locale : LanguageUtil.getAvailableLocales()) {
      ResourceBundle resourceBundle =
          ResourceBundleUtil.getBundle(portletModel.getResourceBundle(), locale, classLoader);

      Dictionary<String, Object> properties = new HashMapDictionary<>();

      properties.put("javax.portlet.name", portletModel.getPortletId());
      properties.put("language.id", LocaleUtil.toLanguageId(locale));

      ServiceRegistration<ResourceBundle> serviceRegistration =
          bundleContext.registerService(ResourceBundle.class, resourceBundle, properties);

      serviceRegistrations.addServiceRegistration(serviceRegistration);
    }
  }
예제 #2
0
  @Activate
  protected void activate(Map<String, Object> properties) {
    _fileSystemStoreConfiguration =
        Configurable.createConfigurable(FileSystemStoreConfiguration.class, properties);

    if (Validator.isBlank(_fileSystemStoreConfiguration.rootDir())) {
      throw new IllegalArgumentException(
          "File system root directory is not set", new FileSystemStoreRootDirException());
    }

    validate();

    initializeRootDir();
  }
예제 #3
0
  @Override
  protected Summary doGetSummary(
      Document document, Locale locale, String snippet, PortletURL portletURL) {

    Locale snippetLocale = getSnippetLocale(document, locale);

    String prefix = Field.SNIPPET + StringPool.UNDERLINE;

    String title = document.get(snippetLocale, prefix + Field.TITLE, Field.TITLE);

    String content =
        document.get(snippetLocale, prefix + Field.DESCRIPTION, prefix + Field.CONTENT);

    if (Validator.isBlank(content)) {
      content = document.get(locale, Field.DESCRIPTION, Field.CONTENT);

      if (Validator.isBlank(content)) {
        content = document.get(Field.DESCRIPTION, Field.CONTENT);
      }
    }

    if (content.length() > 200) {
      content = StringUtil.shorten(content, 200);
    }

    String groupId = document.get(Field.GROUP_ID);
    String articleId = document.get("articleId");
    String version = document.get(Field.VERSION);

    portletURL.setParameter("struts_action", "/journal/edit_article");
    portletURL.setParameter("groupId", groupId);
    portletURL.setParameter("articleId", articleId);
    portletURL.setParameter("version", version);

    return new Summary(snippetLocale, title, content, portletURL);
  }
  protected void initPermissions(
      long companyId, long powerUserRoleId, String rootPortletId, long userPersonalSiteGroupId)
      throws PortalException {

    String primaryKey = String.valueOf(userPersonalSiteGroupId);

    if (_resourcePermissionLocalService.getResourcePermissionsCount(
            companyId, rootPortletId, ResourceConstants.SCOPE_GROUP, primaryKey)
        == 0) {

      List<String> portletActionIds = ResourceActionsUtil.getPortletResourceActions(rootPortletId);

      _resourcePermissionLocalService.setResourcePermissions(
          companyId,
          rootPortletId,
          ResourceConstants.SCOPE_GROUP,
          String.valueOf(userPersonalSiteGroupId),
          powerUserRoleId,
          portletActionIds.toArray(new String[0]));
    }

    String modelName = ResourceActionsUtil.getPortletRootModelResource(rootPortletId);

    if (Validator.isBlank(modelName)) {
      return;
    }

    if (_resourcePermissionLocalService.getResourcePermissionsCount(
            companyId, modelName, ResourceConstants.SCOPE_GROUP, primaryKey)
        == 0) {

      List<String> modelActionIds = ResourceActionsUtil.getModelResourceActions(modelName);

      _resourcePermissionLocalService.setResourcePermissions(
          companyId,
          modelName,
          ResourceConstants.SCOPE_GROUP,
          String.valueOf(userPersonalSiteGroupId),
          powerUserRoleId,
          modelActionIds.toArray(new String[0]));
    }
  }
예제 #5
0
  protected void getFileNames(List<String> fileNames, String dirName, String path) {

    String[] pathDirNames = FileUtil.listDirs(path);

    if (ArrayUtil.isNotEmpty(pathDirNames)) {
      for (String pathDirName : pathDirNames) {
        String subdirName = null;

        if (Validator.isBlank(dirName)) {
          subdirName = pathDirName;
        } else {
          subdirName = dirName + StringPool.SLASH + pathDirName;
        }

        getFileNames(fileNames, subdirName, path + StringPool.SLASH + pathDirName);
      }
    } else if (new File(path).isDirectory()) {
      fileNames.add(dirName);
    }
  }
 public void saveName(ActionRequest actionRequest, ActionResponse actionResponse)
     throws IOException, PortletException {
   _log.debug("saveName started");
   final String name =
       ParamUtil.get(actionRequest, MyHelloWorldMVCUtil.REQUEST_PARAM_NAME, StringPool.BLANK);
   final PortletPreferences portletPreferences = actionRequest.getPreferences();
   if (Validator.isBlank(name)) {
     _log.error("Name is blank. You must introduce valid value for name parameter.");
   } else {
     portletPreferences.setValue(MyHelloWorldMVCUtil.PORTLET_PREFERENCES_PARAM_NAME, name);
     _log.info(
         "saving new value ("
             + name
             + ") of "
             + MyHelloWorldMVCUtil.PORTLET_PREFERENCES_PARAM_NAME
             + " on portletPreferences");
     portletPreferences.store();
   }
   // Una vez que terminas la lógica de saveName forward a la vista
   actionResponse.setPortletMode(PortletMode.VIEW);
 }