@BeforeClass
  public static void setUpClass() throws IOException {

    // Run before the test JVM starts to ensure the dynamic download
    // actually happens during the test run

    PropsUtil.setProps(new PropsImpl());

    String jarName =
        PropsUtil.get(PropsKeys.SETUP_LIFERAY_POOL_PROVIDER_JAR_NAME, new Filter("hikaricp"));

    Path jarPath = Paths.get("lib/portal", jarName);

    if (Files.exists(jarPath)) {
      Path tempFilePath = Files.createTempFile(null, null);

      Files.move(jarPath, tempFilePath, StandardCopyOption.REPLACE_EXISTING);

      URI uri = tempFilePath.toUri();

      URL url = uri.toURL();

      System.setProperty(_HIKARICP_JAR_URL, url.toExternalForm());
    }
  }
  protected String getEditorType(InputRichText inputRichText) {

    String editorType = PropsUtil.get(PropsKeys.EDITOR_WYSIWYG_DEFAULT);
    String editorKey = inputRichText.getEditorKey();

    if (editorKey != null) {
      editorType = PropsUtil.get(editorKey);
    }

    return editorType;
  }
  public static GoogleCredential getGoogleCredential() throws Exception {
    if (_googleCredential != null) {
      return _googleCredential;
    }

    GoogleCredential.Builder builder = new GoogleCredential.Builder();

    builder.setJsonFactory(new JacksonFactory());
    builder.setServiceAccountId(PortletPropsValues.GOOGLE_API_SERVICE_ACCOUNT_ID);

    File file =
        new File(
            PropsUtil.get(PropsKeys.LIFERAY_HOME)
                + PortletPropsValues.GOOGLE_API_SERVICE_ACCOUNT_PRIVATE_KEY_P12_FILE);

    builder.setServiceAccountPrivateKeyFromP12File(file);

    builder.setServiceAccountScopes(
        Arrays.asList(PortletPropsValues.GOOGLE_API_SERVICE_ACCOUNT_SCOPES));
    builder.setServiceAccountUser(PortletPropsValues.GOOGLE_API_SERVICE_ACCOUNT_USER);
    builder.setTransport(new NetHttpTransport());

    _googleCredential = builder.build();

    return _googleCredential;
  }
  private String _getLogin() {
    String login = PrincipalThreadLocal.getName();

    if (Validator.isNull(login) || _isDefaultUser(login)) {
      return PropsUtil.get(PropsKeys.DL_REPOSITORY_GUEST_USERNAME);
    }

    try {
      String authType = getAuthType();

      if (!authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
        User user = userLocalService.getUser(GetterUtil.getLong(login));

        if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
          login = user.getEmailAddress();
        } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
          login = user.getScreenName();
        }
      }
    } catch (PortalException | SystemException e) {
      if (_log.isWarnEnabled()) {
        _log.warn("Unable to get login to connect to external repository " + _extRepository, e);
      }

      login = null;
    }

    return login;
  }
  protected static void initPortalServices() {
    JSONFactoryUtil jsonFactoryUtil = new JSONFactoryUtil();

    jsonFactoryUtil.setJSONFactory(new JSONFactoryImpl());

    JSONIncludesManagerUtil jsonIncludesManagerUtil = new JSONIncludesManagerUtil();

    jsonIncludesManagerUtil.setJSONIncludesManager(new JSONIncludesManagerImpl());

    JSONWebServiceActionsManagerUtil jsonWebServiceActionsManagerUtil =
        new JSONWebServiceActionsManagerUtil();

    jsonWebServiceActionsManagerUtil.setJSONWebServiceActionsManager(
        new JSONWebServiceActionsManagerImpl());

    JSONWebServiceClassVisitorFactoryUtil jsonWebServiceClassVisitorFactoryUtil =
        new JSONWebServiceClassVisitorFactoryUtil();

    jsonWebServiceClassVisitorFactoryUtil.setJSONWebServiceClassVisitorFactory(
        new JSONWebServiceClassVisitorFactoryImpl());

    MethodParametersResolverUtil methodParametersResolverUtil = new MethodParametersResolverUtil();

    methodParametersResolverUtil.setMethodParametersResolver(new MethodParametersResolverImpl());

    PropsUtil.setProps(new PropsImpl());
  }
  @After
  public void tearDown() throws IOException {
    String jarName =
        PropsUtil.get(PropsKeys.SETUP_LIFERAY_POOL_PROVIDER_JAR_NAME, new Filter("hikaricp"));

    Files.deleteIfExists(Paths.get(PropsValues.LIFERAY_LIB_PORTAL_DIR, jarName));
  }
  private void _populateGenericNamesMap(String genericName) {
    String[] extensions =
        PropsUtil.getArray(PropsKeys.DL_FILE_GENERIC_EXTENSIONS, new Filter(genericName));

    for (String extension : extensions) {
      _genericNames.put(extension, genericName);
    }
  }
示例#8
0
  /** Inits the. */
  @PostConstruct
  public void init() {
    ThemeDisplay themeDisplay = LiferayFacesContext.getInstance().getThemeDisplay();
    String currentPage = themeDisplay.getLayout().getFriendlyURL();
    if (currentPage.equals("/daten")) {
      metadataType = MetadataEnumType.DATASET.toField();
    } else if (currentPage.equals("/apps")) {
      metadataType = MetadataEnumType.APPLICATION.toField();
    } else if (currentPage.equals("/dokumente")) {
      metadataType = MetadataEnumType.DOCUMENT.toField();
    } else {
      metadataType = "metadata";
    }

    scmBuildnumber = PropsUtil.get("ogdd.buildNumber");
    scmBranch = PropsUtil.get("ogdd.scmBranch");
  }
示例#9
0
  static {
    _allMediaGalleryMimeTypes.addAll(
        SetUtil.fromArray(PropsUtil.getArray(PropsKeys.DL_FILE_ENTRY_PREVIEW_AUDIO_MIME_TYPES)));
    _allMediaGalleryMimeTypes.addAll(
        SetUtil.fromArray(PropsUtil.getArray(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO_MIME_TYPES)));
    _allMediaGalleryMimeTypes.addAll(
        SetUtil.fromArray(PropsUtil.getArray(PropsKeys.DL_FILE_ENTRY_PREVIEW_IMAGE_MIME_TYPES)));

    _allMediaGalleryMimeTypesString = StringUtil.merge(_allMediaGalleryMimeTypes);

    String[] fileIcons = null;

    try {
      fileIcons = PropsUtil.getArray(PropsKeys.DL_FILE_ICONS);
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug(e, e);
      }

      fileIcons = new String[] {StringPool.BLANK};
    }

    for (int i = 0; i < fileIcons.length; i++) {

      // Only process non wildcard extensions

      if (!StringPool.STAR.equals(fileIcons[i])) {

        // Strip starting period

        String extension = fileIcons[i];

        if (extension.length() > 0) {
          extension = extension.substring(1);
        }

        _fileIcons.add(extension);
      }
    }

    String[] genericNames = PropsUtil.getArray(PropsKeys.DL_FILE_GENERIC_NAMES);

    for (String genericName : genericNames) {
      _populateGenericNamesMap(genericName);
    }
  }
  @AfterClass
  public static void tearDownClass() throws Exception {
    String hikaricpJarURL = System.clearProperty(_HIKARICP_JAR_URL);

    if (hikaricpJarURL != null) {
      PropsUtil.setProps(new PropsImpl());

      String jarName =
          PropsUtil.get(PropsKeys.SETUP_LIFERAY_POOL_PROVIDER_JAR_NAME, new Filter("hikaricp"));

      URL url = new URL(hikaricpJarURL);

      Files.move(
          Paths.get(url.toURI()),
          Paths.get("lib/portal", jarName),
          StandardCopyOption.REPLACE_EXISTING);
    }
  }
  private String _getPassword() {
    String login = PrincipalThreadLocal.getName();

    if (Validator.isNull(login) || _isDefaultUser(login)) {
      return PropsUtil.get(PropsKeys.DL_REPOSITORY_GUEST_PASSWORD);
    }

    return PrincipalThreadLocal.getPassword();
  }
  public static String getServletContextName() {
    if (Validator.isNotNull(_servletContextName)) {
      return _servletContextName;
    }

    synchronized (ClpSerializer.class) {
      if (Validator.isNotNull(_servletContextName)) {
        return _servletContextName;
      }

      try {
        ClassLoader classLoader = ClpSerializer.class.getClassLoader();

        Class<?> portletPropsClass = classLoader.loadClass("com.liferay.util.portlet.PortletProps");

        Method getMethod = portletPropsClass.getMethod("get", new Class<?>[] {String.class});

        String portletPropsServletContextName =
            (String)
                getMethod.invoke(
                    null,
                    "com.liferay.portal.content.targeting.rule.score.points-deployment-context");

        if (Validator.isNotNull(portletPropsServletContextName)) {
          _servletContextName = portletPropsServletContextName;
        }
      } catch (Throwable t) {
        if (_log.isInfoEnabled()) {
          _log.info("Unable to locate deployment context from portlet properties");
        }
      }

      if (Validator.isNull(_servletContextName)) {
        try {
          String propsUtilServletContextName =
              PropsUtil.get(
                  "com.liferay.portal.content.targeting.rule.score.points-deployment-context");

          if (Validator.isNotNull(propsUtilServletContextName)) {
            _servletContextName = propsUtilServletContextName;
          }
        } catch (Throwable t) {
          if (_log.isInfoEnabled()) {
            _log.info("Unable to locate deployment context from portal properties");
          }
        }
      }

      if (Validator.isNull(_servletContextName)) {
        _servletContextName = "com.liferay.portal.content.targeting.rule.score.points";
      }

      return _servletContextName;
    }
  }
  protected void indexKeywords(
      long companyId,
      String languageId,
      String propsKey,
      String keywordFieldName,
      String typeFieldValue,
      int maxNGramLength)
      throws Exception {

    String[] dictionaryFileNames = PropsUtil.getArray(propsKey, new Filter(languageId));

    indexKeywords(
        companyId,
        0,
        languageId,
        dictionaryFileNames,
        keywordFieldName,
        typeFieldValue,
        maxNGramLength);

    List<Group> groups = GroupLocalServiceUtil.getLiveGroups();

    for (Group group : groups) {
      String[] groupDictionaryFileNames =
          PropsUtil.getArray(
              PropsKeys.INDEX_SEARCH_SPELL_CHECKER_DICTIONARY,
              new Filter(languageId, String.valueOf(group.getGroupId())));

      if (ArrayUtil.isEmpty(groupDictionaryFileNames)) {
        continue;
      }

      indexKeywords(
          companyId,
          group.getGroupId(),
          languageId,
          dictionaryFileNames,
          keywordFieldName,
          typeFieldValue,
          maxNGramLength);
    }
  }
示例#14
0
  public static boolean isValidMessageFormat(String messageFormat) {
    String editorImpl = PropsUtil.get(BB_CODE_EDITOR_WYSIWYG_IMPL_KEY);

    if (messageFormat.equals("bbcode")
        && !(editorImpl.equals("bbcode") || editorImpl.equals("ckeditor_bbcode"))) {

      return false;
    }

    return true;
  }
/** @author Alexander Chow */
public class JournalArticleConstants {

  public static final String CANONICAL_URL_SEPARATOR = "/-/";

  public static final double DEFAULT_VERSION = 1.0;

  public static final String PORTLET = "portlet";

  public static final String STAND_ALONE = "stand-alone";

  public static final String[] TYPES = PropsUtil.getArray(PropsKeys.JOURNAL_ARTICLE_TYPES);
}
  @After
  public void tearDown() throws Exception {
    _storeFactory.setStore(_CLASS_NAME_DB_STORE);

    _convertProcess.setParameterValues(
        new String[] {_CLASS_NAME_FILE_SYSTEM_STORE, Boolean.TRUE.toString()});

    _convertProcess.convert();

    PropsValues.DL_STORE_IMPL = PropsUtil.get(PropsKeys.DL_STORE_IMPL);

    _storeFactory.setStore(PropsValues.DL_STORE_IMPL);
  }
示例#17
0
  public static String getMessageFormat(PortletPreferences preferences) {
    String messageFormat = preferences.getValue("messageFormat", MBMessageConstants.DEFAULT_FORMAT);

    String editorImpl = PropsUtil.get(BB_CODE_EDITOR_WYSIWYG_IMPL_KEY);

    if (messageFormat.equals("bbcode")
        && !(editorImpl.equals("bbcode") || editorImpl.equals("ckeditor_bbcode"))) {

      messageFormat = "html";
    }

    return messageFormat;
  }
  private Map<String, String> _getPrivateField(String privateFieldName) {
    Map<String, String> privateField = new HashMap<String, String>();

    String dataType =
        PropsUtil.get(
            PropsKeys.DYNAMIC_DATA_MAPPING_STRUCTURE_PRIVATE_FIELD_DATATYPE,
            new Filter(privateFieldName));

    privateField.put("dataType", dataType);

    privateField.put("name", privateFieldName);
    privateField.put("private", Boolean.TRUE.toString());

    String repeatable =
        PropsUtil.get(
            PropsKeys.DYNAMIC_DATA_MAPPING_STRUCTURE_PRIVATE_FIELD_REPEATABLE,
            new Filter(privateFieldName));

    privateField.put("repeatable", repeatable);

    return privateField;
  }
  protected Properties getPortalProperties(String settingsId) {
    Properties portalProperties = _propertiesMap.get(settingsId);

    if (portalProperties != null) {
      return portalProperties;
    }

    portalProperties = PropsUtil.getProperties();

    _propertiesMap.put(settingsId, portalProperties);

    return portalProperties;
  }
/** @author Eudaldo Alonso */
public class LayoutCommonTag extends IncludeTag {

  @Override
  protected void cleanUp() {
    _includeStaticPortlets = false;
    _includeWebServerDisplayNode = false;
  }

  @Override
  protected String getPage() {
    return _PAGE;
  }

  @Override
  protected boolean isCleanUpSetAttributes() {
    return _CLEAN_UP_SET_ATTRIBUTES;
  }

  @Override
  protected void setAttributes(HttpServletRequest request) {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    if (!themeDisplay.isFacebook()
        && !themeDisplay.isStateExclusive()
        && !themeDisplay.isStatePopUp()
        && !themeDisplay.isWidget()) {

      _includeStaticPortlets = true;
    }

    request.setAttribute("liferay-ui:layout-common:includeStaticPortlets", _includeStaticPortlets);

    if (_WEB_SERVER_DISPLAY_NODE && !themeDisplay.isStatePopUp()) {
      _includeWebServerDisplayNode = true;
    }

    request.setAttribute(
        "liferay-ui:layout-common:includeWebServerDisplayNode", _includeWebServerDisplayNode);
  }

  private static final boolean _CLEAN_UP_SET_ATTRIBUTES = true;

  private static final String _PAGE = "/html/taglib/ui/layout_common/page.jsp";

  private static final boolean _WEB_SERVER_DISPLAY_NODE =
      GetterUtil.getBoolean(PropsUtil.get(PropsKeys.WEB_SERVER_DISPLAY_NODE));

  private boolean _includeStaticPortlets;
  private boolean _includeWebServerDisplayNode;
}
示例#21
0
  /**
   * Upload CSV or XML file.
   *
   * @param csvXmlFile the file
   * @return the url
   * @throws Exception
   */
  public static String uploadToDocmentLibrary(UploadedFile file) throws Exception {
    LiferayFacesContext lfc = LiferayFacesContext.getInstance();
    ThemeDisplay themeDisplay = lfc.getThemeDisplay();

    // upload file to local liferay storage
    DLFileEntry fileEntry =
        FileUtils.uploadFileToFolder(file, PropsUtil.get("image.folder.id"), themeDisplay);

    return themeDisplay.getPortalURL()
        + "/c/document_library/get_file?uuid="
        + fileEntry.getUuid()
        + "&groupId="
        + themeDisplay.getScopeGroupId();
  }
  @BeforeClass
  public static void setUpClass() throws Exception {
    PortalUtil portalUtil = new PortalUtil();

    portalUtil.setPortal(new PortalImpl());

    PropsUtil.setProps(new PropsImpl());

    ThreadLocalDistributor threadLocalDistributor = new ThreadLocalDistributor();

    threadLocalDistributor.setThreadLocalSources(
        Arrays.asList(new KeyValuePair(SPIAgentResponseTest.class.getName(), "_threadLocal")));

    threadLocalDistributor.afterPropertiesSet();
  }
  public String getSocialBookmarksDisplayStyle() {
    if (_socialBookmarksDisplayStyle == null) {
      _socialBookmarksDisplayStyle =
          _portletPreferences.getValue("socialBookmarksDisplayStyle", null);

      if (Validator.isNull(_socialBookmarksDisplayStyle)) {
        String[] socialBookmarksDisplayStyles =
            PropsUtil.getArray(PropsKeys.SOCIAL_BOOKMARK_DISPLAY_STYLES);

        _socialBookmarksDisplayStyle = socialBookmarksDisplayStyles[0];
      }
    }

    return _socialBookmarksDisplayStyle;
  }
  protected void initializeRootDir() {
    String path = getRootDirName();

    _rootDir = new File(path);

    if (!_rootDir.isAbsolute()) {
      _rootDir = new File(PropsUtil.get(PropsKeys.LIFERAY_HOME), path);
    }

    try {
      FileUtil.mkdirs(_rootDir);
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    }
  }
  @Before
  public void setUp() {
    PropsUtil.setProps(new PropsImpl());

    _portlet =
        new PortletImpl() {

          @Override
          public String getContextName() {
            return _SERVLET_CONTEXT_NAME;
          }
        };

    _mockHttpServletRequest.setAttribute(WebKeys.SPI_AGENT_PORTLET, _portlet);
  }
示例#26
0
  public int getMaxAge(Group group) throws PortalException, SystemException {
    if (group.isLayout()) {
      group = group.getParentGroup();
    }

    int trashEntriesMaxAge =
        PrefsPropsUtil.getInteger(
            group.getCompanyId(),
            PropsKeys.TRASH_ENTRIES_MAX_AGE,
            GetterUtil.getInteger(PropsUtil.get(PropsKeys.TRASH_ENTRIES_MAX_AGE)));

    UnicodeProperties typeSettingsProperties = group.getTypeSettingsProperties();

    return GetterUtil.getInteger(
        typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAge);
  }
  protected File getLogFile() {
    File logFile = null;

    if (ServerDetector.isJBoss()) {
      File logDirectory = new File(System.getProperty("jboss.server.log.dir"));

      logFile = new File(logDirectory, "server.log");
    } else {
      logFile =
          new File(
              PropsUtil.get(PropsKeys.LIFERAY_HOME)
                  + "/logs/liferay."
                  + getLiferayDateString()
                  + ".log");
    }

    return logFile;
  }
示例#28
0
  @Override
  public Map<Locale, String> getEmailFileEntryUpdatedBodyMap(PortletPreferences preferences) {

    Map<Locale, String> map =
        LocalizationUtil.getLocalizationMap(preferences, "emailFileEntryUpdatedBody");

    Locale defaultLocale = LocaleUtil.getSiteDefault();

    String defaultValue = map.get(defaultLocale);

    if (Validator.isNotNull(defaultValue)) {
      return map;
    }

    map.put(
        defaultLocale, ContentUtil.get(PropsUtil.get(PropsKeys.DL_EMAIL_FILE_ENTRY_UPDATED_BODY)));

    return map;
  }
  @Override
  public Map<Locale, String> getEmailAssetEntryAddedSubjectMap(PortletPreferences preferences) {

    Map<Locale, String> map =
        LocalizationUtil.getLocalizationMap(preferences, "emailAssetEntryAddedSubject");

    Locale defaultLocale = LocaleUtil.getDefault();

    String defaultValue = map.get(defaultLocale);

    if (Validator.isNotNull(defaultValue)) {
      return map;
    }

    map.put(
        defaultLocale,
        ContentUtil.get(PropsUtil.get(PropsKeys.ASSET_PUBLISHER_EMAIL_ASSET_ENTRY_ADDED_SUBJECT)));

    return map;
  }
  public static String getLogin(boolean encodeLogin) throws Exception {
    String login = null;

    String authType = GetterUtil.getString(PropsUtil.get(PropsKeys.COMPANY_SECURITY_AUTH_TYPE));

    User user = TestPropsValues.getUser();

    if (authType.equals(CompanyConstants.AUTH_TYPE_EA)) {
      login = user.getEmailAddress();

      if (encodeLogin) {
        login = HttpUtil.encodeURL(login);
      }
    } else if (authType.equals(CompanyConstants.AUTH_TYPE_SN)) {
      login = user.getScreenName();
    } else if (authType.equals(CompanyConstants.AUTH_TYPE_ID)) {
      login = Long.toString(TestPropsValues.getUserId());
    }

    return login;
  }