public void updateBlocked(long companyId, long userId, List<String> blocked) {

    String home = PropsUtil.get(PropsKeys.MAIL_HOOK_CYRUS_HOME);

    File file = new File(home + "/" + userId + ".procmail.blocked");

    if ((blocked == null) || (blocked.size() == 0)) {
      file.delete();

      return;
    }

    StringBundler sb = new StringBundler(blocked.size() * 9);

    for (int i = 0; i < blocked.size(); i++) {
      String emailAddress = blocked.get(i);

      sb.append("\n");
      sb.append(":0\n");
      sb.append("* ^From.*");
      sb.append(emailAddress);
      sb.append("\n");
      sb.append("{\n");
      sb.append(":0\n");
      sb.append("/dev/null\n");
      sb.append("}\n");
    }

    try {
      FileUtil.write(file, sb.toString());
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
예제 #2
0
  protected int getRangeSize(String name) {
    if (name.equals(_NAME)) {
      return PropsValues.COUNTER_INCREMENT;
    }

    String incrementType = null;

    int pos = name.indexOf(CharPool.POUND);

    if (pos != -1) {
      incrementType = name.substring(0, pos);
    } else {
      incrementType = name;
    }

    Integer rangeSize = _rangeSizeMap.get(incrementType);

    if (rangeSize == null) {
      rangeSize =
          GetterUtil.getInteger(
              PropsUtil.get(PropsKeys.COUNTER_INCREMENT_PREFIX + incrementType),
              PropsValues.COUNTER_INCREMENT);

      _rangeSizeMap.put(incrementType, rangeSize);
    }

    return rangeSize.intValue();
  }
  public void addUser(
      long companyId,
      long userId,
      String password,
      String firstName,
      String middleName,
      String lastName,
      String emailAddress) {

    try {
      CyrusServiceUtil.addUser(userId, emailAddress, password);

      // Expect

      String addUserCmd = PropsUtil.get(PropsKeys.MAIL_HOOK_CYRUS_ADD_USER);

      addUserCmd = StringUtil.replace(addUserCmd, "%1%", String.valueOf(userId));

      Runtime rt = Runtime.getRuntime();

      Process p = rt.exec(addUserCmd);

      ProcessUtil.close(p);
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
예제 #4
0
  @Override
  public void init(FilterConfig filterConfig) {
    super.init(filterConfig);

    _basicAuthEnabled = GetterUtil.getBoolean(filterConfig.getInitParameter("basic_auth"));
    _digestAuthEnabled = GetterUtil.getBoolean(filterConfig.getInitParameter("digest_auth"));

    String propertyPrefix = filterConfig.getInitParameter("portal_property_prefix");

    String[] hostsAllowed = null;

    if (Validator.isNull(propertyPrefix)) {
      hostsAllowed = StringUtil.split(filterConfig.getInitParameter("hosts.allowed"));
      _httpsRequired = GetterUtil.getBoolean(filterConfig.getInitParameter("https.required"));
    } else {
      hostsAllowed = PropsUtil.getArray(propertyPrefix + "hosts.allowed");
      _httpsRequired = GetterUtil.getBoolean(PropsUtil.get(propertyPrefix + "https.required"));
    }

    for (String hostAllowed : hostsAllowed) {
      _hostsAllowed.add(hostAllowed);
    }

    _usePermissionChecker =
        GetterUtil.getBoolean(filterConfig.getInitParameter("use_permission_checker"));
  }
  protected void verifyObsoletePortalProperty(String key) throws Exception {
    String value = PropsUtil.get(key);

    if (value != null) {
      _log.error("Portal property \"" + key + "\" is obsolete");
    }
  }
  public void deleteUser(long companyId, long userId) {
    try {
      CyrusServiceUtil.deleteUser(userId);

      // Expect

      String deleteUserCmd = PropsUtil.get(PropsKeys.MAIL_HOOK_CYRUS_DELETE_USER);

      deleteUserCmd = StringUtil.replace(deleteUserCmd, "%1%", String.valueOf(userId));

      Runtime rt = Runtime.getRuntime();

      Process p = rt.exec(deleteUserCmd);

      ProcessUtil.close(p);

      // Procmail

      String home = PropsUtil.get(PropsKeys.MAIL_HOOK_CYRUS_HOME);

      File file = new File(home + "/" + userId + ".procmail.blocked");

      if (file.exists()) {
        file.delete();
      }

      file = new File(home + "/" + userId + ".procmail.forward");

      if (file.exists()) {
        file.delete();
      }

      file = new File(home + "/" + userId + ".vacation");

      if (file.exists()) {
        file.delete();
      }

      file = new File(home + "/" + userId + ".vacation.cache");

      if (file.exists()) {
        file.delete();
      }
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
  public HostConfiguration getHostConfiguration(String location) throws IOException {

    if (_log.isDebugEnabled()) {
      _log.debug("Location is " + location);
    }

    HostConfiguration hostConfiguration = new HostConfiguration();

    hostConfiguration.setHost(new URI(location, false));

    if (isProxyHost(hostConfiguration.getHost())) {
      hostConfiguration.setProxy(_PROXY_HOST, _PROXY_PORT);
    }

    HttpConnectionManager httpConnectionManager = _httpClient.getHttpConnectionManager();

    HttpConnectionManagerParams httpConnectionManagerParams = httpConnectionManager.getParams();

    int defaultMaxConnectionsPerHost =
        httpConnectionManagerParams.getMaxConnectionsPerHost(hostConfiguration);

    int maxConnectionsPerHost =
        GetterUtil.getInteger(
            PropsUtil.get(
                HttpImpl.class.getName() + ".max.connections.per.host",
                new Filter(hostConfiguration.getHost())));

    if ((maxConnectionsPerHost > 0) && (maxConnectionsPerHost != defaultMaxConnectionsPerHost)) {

      httpConnectionManagerParams.setMaxConnectionsPerHost(
          hostConfiguration, maxConnectionsPerHost);
    }

    int timeout =
        GetterUtil.getInteger(
            PropsUtil.get(
                HttpImpl.class.getName() + ".timeout", new Filter(hostConfiguration.getHost())));

    if (timeout > 0) {
      HostParams hostParams = hostConfiguration.getParams();

      hostParams.setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, timeout);
      hostParams.setIntParameter(HttpConnectionParams.SO_TIMEOUT, timeout);
    }

    return hostConfiguration;
  }
  public void addForward(
      long companyId,
      long userId,
      List<Filter> filters,
      List<String> emailAddresses,
      boolean leaveCopy) {

    try {
      if (emailAddresses != null) {
        String home = PropsUtil.get(PropsKeys.MAIL_HOOK_CYRUS_HOME);

        File file = new File(home + "/" + userId + ".procmail.forward");

        if ((filters.size() > 0) || (emailAddresses.size() > 0) || (leaveCopy)) {

          StringBundler sb = new StringBundler();

          for (int i = 0; i < filters.size(); i++) {
            Filter filter = filters.get(i);

            sb.append(":0\n");
            sb.append("* ^(From|Cc|To).*");
            sb.append(filter.getEmailAddress());
            sb.append("\n");
            sb.append("| $DELIVER -e -a $USER -m user.$USER.");
            sb.append(filter.getFolder());
            sb.append("\n\n");
          }

          if (leaveCopy) {
            sb.append(":0 c\n");
            sb.append("| $DELIVER -e -a $USER -m user.$USER\n\n");
          }

          if (emailAddresses.size() > 0) {
            sb.append(":0\n");
            sb.append("!");

            for (String emailAddress : emailAddresses) {
              sb.append(" ");
              sb.append(emailAddress);
            }
          }

          String content = sb.toString();

          while (content.endsWith("\n")) {
            content = content.substring(0, content.length() - 1);
          }

          FileUtil.write(file, content);
        } else {
          file.delete();
        }
      }
    } catch (Exception e) {
      _log.error(e, e);
    }
  }
  protected void verifyRenamedPortalProperty(String oldKey, String newKey) throws Exception {

    String value = PropsUtil.get(oldKey);

    if (value != null) {
      _log.error("Portal property \"" + oldKey + "\" was renamed to \"" + newKey + "\"");
    }
  }
예제 #10
0
  public static String getEmailPageAddedBody(PortletPreferences preferences) {
    String emailPageAddedBody = preferences.getValue("emailPageAddedBody", StringPool.BLANK);

    if (Validator.isNotNull(emailPageAddedBody)) {
      return emailPageAddedBody;
    } else {
      return ContentUtil.get(PropsUtil.get(PropsKeys.WIKI_EMAIL_PAGE_ADDED_BODY));
    }
  }
예제 #11
0
  public static boolean getEmailPageAddedEnabled(PortletPreferences preferences) {

    String emailPageAddedEnabled = preferences.getValue("emailPageAddedEnabled", StringPool.BLANK);

    if (Validator.isNotNull(emailPageAddedEnabled)) {
      return GetterUtil.getBoolean(emailPageAddedEnabled);
    } else {
      return GetterUtil.getBoolean(PropsUtil.get(PropsKeys.WIKI_EMAIL_PAGE_ADDED_ENABLED));
    }
  }
예제 #12
0
  public static String getEmailPageUpdatedSignature(PortletPreferences preferences) {

    String emailPageUpdatedSignature =
        preferences.getValue("emailPageUpdatedSignature", StringPool.BLANK);

    if (Validator.isNotNull(emailPageUpdatedSignature)) {
      return emailPageUpdatedSignature;
    } else {
      return ContentUtil.get(PropsUtil.get(PropsKeys.WIKI_EMAIL_PAGE_UPDATED_SIGNATURE));
    }
  }
예제 #13
0
  public static boolean getEmailEntryUpdatedEnabled(PortletPreferences preferences) {

    String emailEntryUpdatedEnabled =
        preferences.getValue("emailEntryUpdatedEnabled", StringPool.BLANK);

    if (Validator.isNotNull(emailEntryUpdatedEnabled)) {
      return GetterUtil.getBoolean(emailEntryUpdatedEnabled);
    } else {
      return GetterUtil.getBoolean(PropsUtil.get(PropsKeys.BOOKMARKS_EMAIL_ENTRY_UPDATED_ENABLED));
    }
  }
예제 #14
0
  public static String getEmailEventReminderSubject(PortletPreferences preferences) {

    String emailEventReminderSubject =
        preferences.getValue("emailEventReminderSubject", StringPool.BLANK);

    if (Validator.isNotNull(emailEventReminderSubject)) {
      return emailEventReminderSubject;
    } else {
      return ContentUtil.get(PropsUtil.get(PropsKeys.CALENDAR_EMAIL_EVENT_REMINDER_SUBJECT));
    }
  }
예제 #15
0
  public static boolean getEmailEventReminderEnabled(PortletPreferences preferences) {

    String emailEventReminderEnabled =
        preferences.getValue("emailEventReminderEnabled", StringPool.BLANK);

    if (Validator.isNotNull(emailEventReminderEnabled)) {
      return GetterUtil.getBoolean(emailEventReminderEnabled);
    } else {
      return GetterUtil.getBoolean(PropsUtil.get(PropsKeys.CALENDAR_EMAIL_EVENT_REMINDER_ENABLED));
    }
  }
예제 #16
0
  public static String getEmailPageUpdatedSubjectPrefix(PortletPreferences preferences) {

    String emailPageUpdatedSubject =
        preferences.getValue("emailPageUpdatedSubjectPrefix", StringPool.BLANK);

    if (Validator.isNotNull(emailPageUpdatedSubject)) {
      return emailPageUpdatedSubject;
    } else {
      return ContentUtil.get(PropsUtil.get(PropsKeys.WIKI_EMAIL_PAGE_UPDATED_SUBJECT_PREFIX));
    }
  }
예제 #17
0
  private static void _enableTransactions() throws Exception {
    if (_log.isDebugEnabled()) {
      _log.debug("Enable transactions");
    }

    PropsValues.SPRING_HIBERNATE_SESSION_DELEGATED =
        GetterUtil.getBoolean(PropsUtil.get(PropsKeys.SPRING_HIBERNATE_SESSION_DELEGATED));

    Field field = ReflectionUtil.getDeclaredField(ServiceBeanAopCacheManager.class, "_annotations");

    field.set(null, new ConcurrentHashMap<MethodInvocation, Annotation[]>());
  }
예제 #18
0
  private String _readConfigurationFile(String propertyName, String format) throws IOException {

    ClassLoader classLoader = getClass().getClassLoader();

    String configurationFile = PropsUtil.get(propertyName, new Filter(format));

    if (Validator.isNotNull(configurationFile)) {
      return HttpUtil.URLtoString(classLoader.getResource(configurationFile));
    } else {
      return StringPool.BLANK;
    }
  }
예제 #19
0
  protected void upgradeRatingsEntry(long classNameId) throws Exception {
    String className = PortalUtil.getClassName(classNameId);

    if (ArrayUtil.contains(PropsValues.RATINGS_UPGRADE_THUMBS_CLASS_NAMES, className)) {

      upgradeRatingsEntryThumbs(classNameId);
    } else {
      int defaultRatingsStarsNormalizationFactor =
          GetterUtil.getInteger(
              PropsUtil.get(
                  PropsKeys.RATINGS_UPGRADE_STARS_NORMALIZATION_FACTOR, new Filter("default")),
              5);

      int ratingsStarsNormalizationFactor =
          GetterUtil.getInteger(
              PropsUtil.get(
                  PropsKeys.RATINGS_UPGRADE_STARS_NORMALIZATION_FACTOR, new Filter(className)),
              defaultRatingsStarsNormalizationFactor);

      upgradeRatingsEntryStars(classNameId, ratingsStarsNormalizationFactor);
    }
  }
예제 #20
0
  public Transformer(String errorTemplatePropertyKey, boolean restricted) {
    Set<String> langTypes = TemplateManagerUtil.getSupportedLanguageTypes(errorTemplatePropertyKey);

    for (String langType : langTypes) {
      String errorTemplateId = PropsUtil.get(errorTemplatePropertyKey, new Filter(langType));

      if (Validator.isNotNull(errorTemplateId)) {
        _errorTemplateIds.put(langType, errorTemplateId);
      }
    }

    _restricted = restricted;
  }
  @Override
  public void execute() throws BuildException {
    ClassLoader antClassLoader = getClass().getClassLoader();

    Thread currentThread = Thread.currentThread();

    ClassLoader contextClassLoader = currentThread.getContextClassLoader();

    try {
      currentThread.setContextClassLoader(antClassLoader);

      getProject().setUserProperty(_result, PropsUtil.get(_key));
    } finally {
      currentThread.setContextClassLoader(contextClassLoader);
    }
  }
예제 #22
0
  public void store() throws IOException, ValidatorException {
    if (GetterUtil.getBoolean(PropsUtil.get(PropsUtil.TCK_URL))) {

      // Be strict to pass the TCK

      if (_action) {
        _prefs.store();
      } else {
        throw new IllegalStateException("Preferences cannot be stored inside a render call");
      }
    } else {

      // Relax so that poorly written portlets can still work

      _prefs.store();
    }
  }
예제 #23
0
  public static Map<Locale, String> getEmailEntryAddedBodyMap(PortletPreferences preferences) {

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

    Locale defaultLocale = LocaleUtil.getDefault();

    String defaultValue = map.get(defaultLocale);

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

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

    return map;
  }
예제 #24
0
  public static Map<Locale, String> getEmailEntryUpdatedSubjectMap(PortletPreferences preferences) {

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

    Locale defaultLocale = LocaleUtil.getDefault();

    String defaultValue = map.get(defaultLocale);

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

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

    return map;
  }
예제 #25
0
  private WikiEngine _getEngine(String format) throws WikiFormatException {
    WikiEngine engine = _engines.get(format);

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

    synchronized (_engines) {
      engine = _engines.get(format);

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

      try {
        String engineClass = PropsUtil.get(PropsKeys.WIKI_FORMATS_ENGINE, new Filter(format));

        if (engineClass == null) {
          throw new WikiFormatException(format);
        }

        if (!InstancePool.contains(engineClass)) {
          engine = (WikiEngine) InstancePool.get(engineClass);

          engine.setMainConfiguration(
              _readConfigurationFile(PropsKeys.WIKI_FORMATS_CONFIGURATION_MAIN, format));

          engine.setInterWikiConfiguration(
              _readConfigurationFile(PropsKeys.WIKI_FORMATS_CONFIGURATION_INTERWIKI, format));
        } else {
          engine = (WikiEngine) InstancePool.get(engineClass);
        }

        _engines.put(format, engine);

        return engine;
      } catch (Exception e) {
        throw new WikiFormatException(e);
      }
    }
  }
  public void afterPropertiesSet() {
    String[] listenerClassNames =
        StringUtil.split(
            GetterUtil.getString(
                com.liferay.portal.util.PropsUtil.get(
                    "value.object.listener.com.sgs.portlet.pmllevelsend.model.PmlEdmLevelSend")));

    if (listenerClassNames.length > 0) {
      try {
        List<ModelListener> listeners = new ArrayList<ModelListener>();

        for (String listenerClassName : listenerClassNames) {
          listeners.add((ModelListener) Class.forName(listenerClassName).newInstance());
        }

        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
      } catch (Exception e) {
        _log.error(e);
      }
    }
  }
  /** Initializes the ticket persistence. */
  public void afterPropertiesSet() {
    String[] listenerClassNames =
        StringUtil.split(
            GetterUtil.getString(
                com.liferay.portal.util.PropsUtil.get(
                    "value.object.listener.com.liferay.portal.model.Ticket")));

    if (listenerClassNames.length > 0) {
      try {
        List<ModelListener<Ticket>> listenersList = new ArrayList<ModelListener<Ticket>>();

        for (String listenerClassName : listenerClassNames) {
          listenersList.add((ModelListener<Ticket>) InstanceFactory.newInstance(listenerClassName));
        }

        listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
      } catch (Exception e) {
        _log.error(e);
      }
    }
  }
  public static String getGlobalSearchPath() throws Exception {
    PortletPreferences preferences = PrefsPropsUtil.getPreferences();

    String globalSearchPath = preferences.getValue(PropsKeys.IMAGEMAGICK_GLOBAL_SEARCH_PATH, null);

    if (Validator.isNotNull(globalSearchPath)) {
      return globalSearchPath;
    }

    String filterName = null;

    if (OSDetector.isApple()) {
      filterName = "apple";
    } else if (OSDetector.isWindows()) {
      filterName = "windows";
    } else {
      filterName = "unix";
    }

    return PropsUtil.get(PropsKeys.IMAGEMAGICK_GLOBAL_SEARCH_PATH, new Filter(filterName));
  }
예제 #29
0
/**
 * <a href="WikiPage.java.html"><b><i>View Source</i></b></a>
 *
 * @author Brian Wing Shun Chan
 * @version $Revision: 1.13 $
 */
public class WikiPage extends WikiPageModel {

  public static final String FRONT_PAGE = PropsUtil.get(PropsUtil.WIKI_FRONT_PAGE_NAME);

  public static final double DEFAULT_VERSION = 1.0;

  public static final String CLASSIC_WIKI_FORMAT = "classic_wiki";

  public static final String HTML_FORMAT = "html";

  public static final String PLAIN_TEXT_FORMAT = "plain_text";

  public static final String DEFAULT_FORMAT = CLASSIC_WIKI_FORMAT;

  public static final String[] FORMATS =
      new String[] {CLASSIC_WIKI_FORMAT, HTML_FORMAT, PLAIN_TEXT_FORMAT};

  public WikiPage() {
    super();
  }

  public WikiPage(WikiPagePK pk) {
    super(pk);
  }

  public WikiPage(
      String nodeId,
      String title,
      double version,
      String companyId,
      String userId,
      String userName,
      Date createDate,
      String content,
      String format,
      boolean head) {

    super(nodeId, title, version, companyId, userId, userName, createDate, content, format, head);
  }
}
  public void afterPropertiesSet() {
    String configurationPath = PropsUtil.get(_configPropertyKey);

    if (Validator.isNull(configurationPath)) {
      configurationPath = _DEFAULT_CLUSTERED_EHCACHE_CONFIG_FILE;
    }

    boolean usingDefault = configurationPath.equals(_DEFAULT_CLUSTERED_EHCACHE_CONFIG_FILE);

    Configuration configuration =
        EhcacheConfigurationUtil.getConfiguration(configurationPath, _clusterAware, usingDefault);

    _cacheManager = new CacheManager(configuration);

    FailSafeTimer failSafeTimer = _cacheManager.getTimer();

    failSafeTimer.cancel();

    try {
      Field cacheManagerTimerField =
          ReflectionUtil.getDeclaredField(CacheManager.class, "cacheManagerTimer");

      cacheManagerTimerField.set(_cacheManager, null);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    if (PropsValues.EHCACHE_PORTAL_CACHE_MANAGER_JMX_ENABLED) {
      _managementService =
          new ManagementService(
              _cacheManager,
              _mBeanServer,
              _registerCacheManager,
              _registerCaches,
              _registerCacheConfigurations,
              _registerCacheStatistics);

      _managementService.init();
    }
  }