Search in sources :

Example 1 with DynamicProperties

use of org.codelibs.core.misc.DynamicProperties in project fess by codelibs.

the class ThumbnailGenerator method process.

private static int process(final Options options) {
    final DynamicProperties systemProperties = ComponentUtil.getSystemProperties();
    if (StringUtil.isNotBlank(options.propertiesPath)) {
        systemProperties.reload(options.propertiesPath);
    } else {
        try {
            final File propFile = ComponentUtil.getSystemHelper().createTempFile("thumbnail_", ".properties");
            if (propFile.delete() && logger.isDebugEnabled()) {
                logger.debug("Deleted a temp file: {}", propFile.getAbsolutePath());
            }
            systemProperties.reload(propFile.getAbsolutePath());
            propFile.deleteOnExit();
        } catch (final Exception e) {
            logger.warn("Failed to create system properties file.", e);
        }
    }
    int totalCount = 0;
    int count = 1;
    final ExecutorService executorService = Executors.newFixedThreadPool(options.numOfThreads);
    try {
        while (count != 0) {
            count = ComponentUtil.getThumbnailManager().generate(executorService, options.cleanup);
            totalCount += count;
        }
        executorService.shutdown();
        executorService.awaitTermination(60, TimeUnit.SECONDS);
    } catch (final InterruptedException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Interrupted.", e);
        }
    } finally {
        executorService.shutdownNow();
    }
    return totalCount;
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) DynamicProperties(org.codelibs.core.misc.DynamicProperties) File(java.io.File) ContainerNotAvailableException(org.codelibs.fess.exception.ContainerNotAvailableException) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 2 with DynamicProperties

use of org.codelibs.core.misc.DynamicProperties in project fess by codelibs.

the class QueryHelperTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    queryHelper = new QueryHelper() {

        protected QueryParser getQueryParser() {
            ExtendableQueryParser queryParser = new ExtendableQueryParser(Constants.DEFAULT_FIELD, new WhitespaceAnalyzer());
            queryParser.setAllowLeadingWildcard(true);
            queryParser.setDefaultOperator(QueryParser.Operator.AND);
            return queryParser;
        }
    };
    File file = File.createTempFile("test", ".properties");
    file.deleteOnExit();
    FileUtil.writeBytes(file.getAbsolutePath(), "ldap.security.principal=%s@fess.codelibs.local".getBytes("UTF-8"));
    DynamicProperties systemProps = new DynamicProperties(file);
    ComponentUtil.register(systemProps, "systemProperties");
    ComponentUtil.register(new SystemHelper(), "systemHelper");
    ComponentUtil.register(new VirtualHostHelper(), "virtualHostHelper");
    ComponentUtil.register(new KeyMatchHelper(), "keyMatchHelper");
    inject(queryHelper);
    queryHelper.init();
}
Also used : WhitespaceAnalyzer(org.apache.lucene.analysis.core.WhitespaceAnalyzer) ExtendableQueryParser(org.apache.lucene.queryparser.ext.ExtendableQueryParser) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) DynamicProperties(org.codelibs.core.misc.DynamicProperties) File(java.io.File) ExtendableQueryParser(org.apache.lucene.queryparser.ext.ExtendableQueryParser)

Example 3 with DynamicProperties

use of org.codelibs.core.misc.DynamicProperties in project fess by codelibs.

the class ViewHelperTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    propertiesFile = File.createTempFile("test", ".properties");
    FileUtil.writeBytes(propertiesFile.getAbsolutePath(), new byte[0]);
    propertiesFile.deleteOnExit();
    DynamicProperties systemProps = new DynamicProperties(propertiesFile);
    ComponentUtil.register(systemProps, "systemProperties");
    userAgentHelper = new UserAgentHelper();
    ComponentUtil.register(userAgentHelper, "userAgentHelper");
    pathMappingHelper = new PathMappingHelper();
    pathMappingHelper.init();
    ComponentUtil.register(pathMappingHelper, "pathMappingHelper");
    FileTypeHelper fileTypeHelper = new FileTypeHelper();
    ComponentUtil.register(fileTypeHelper, "fileTypeHelper");
    FacetInfo facetInfo = new FacetInfo();
    ComponentUtil.register(facetInfo, "facetInfo");
    viewHelper = new ViewHelper();
    viewHelper.init();
}
Also used : FacetInfo(org.codelibs.fess.entity.FacetInfo) DynamicProperties(org.codelibs.core.misc.DynamicProperties)

Example 4 with DynamicProperties

use of org.codelibs.core.misc.DynamicProperties in project fess by codelibs.

the class ViewHelper method updateFileProtocol.

protected String updateFileProtocol(String url) {
    final int pos = url.indexOf(':', 5);
    final boolean isLocalFile = pos > 0 && pos < 12;
    final UserAgentType ua = ComponentUtil.getUserAgentHelper().getUserAgentType();
    final DynamicProperties systemProperties = ComponentUtil.getSystemProperties();
    switch(ua) {
        case IE:
            if (isLocalFile) {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.winlocal.ie", "file://"));
            } else {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.ie", "file://"));
            }
            break;
        case FIREFOX:
            if (isLocalFile) {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.winlocal.firefox", "file://"));
            } else {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.firefox", "file://///"));
            }
            break;
        case CHROME:
            if (isLocalFile) {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.winlocal.chrome", "file://"));
            } else {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.chrome", "file://"));
            }
            break;
        case SAFARI:
            if (isLocalFile) {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.winlocal.safari", "file://"));
            } else {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.safari", "file:////"));
            }
            break;
        case OPERA:
            if (isLocalFile) {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.winlocal.opera", "file://"));
            } else {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.opera", "file://"));
            }
            break;
        default:
            if (isLocalFile) {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.winlocal.other", "file://"));
            } else {
                url = url.replaceFirst("file:/+", systemProperties.getProperty("file.protocol.other", "file://"));
            }
            break;
    }
    return url;
}
Also used : DynamicProperties(org.codelibs.core.misc.DynamicProperties) UserAgentType(org.codelibs.fess.helper.UserAgentHelper.UserAgentType)

Example 5 with DynamicProperties

use of org.codelibs.core.misc.DynamicProperties in project fess by codelibs.

the class AdminSysteminfoAction method getBugReportItems.

public static List<Map<String, String>> getBugReportItems() {
    final List<Map<String, String>> itemList = new ArrayList<>();
    for (final String label : bugReportLabels) {
        itemList.add(createPropItem(label));
    }
    final DynamicProperties systemProperties = ComponentUtil.getSystemProperties();
    for (final Map.Entry<Object, Object> entry : systemProperties.entrySet()) {
        if (isBugReportTarget(entry.getKey())) {
            itemList.add(createItem(entry.getKey(), entry.getValue()));
        }
    }
    return itemList;
}
Also used : ArrayList(java.util.ArrayList) DynamicProperties(org.codelibs.core.misc.DynamicProperties) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DynamicProperties (org.codelibs.core.misc.DynamicProperties)12 File (java.io.File)7 HashMap (java.util.HashMap)5 Map (java.util.Map)4 ContainerNotAvailableException (org.codelibs.fess.exception.ContainerNotAvailableException)4 CmdLineException (org.kohsuke.args4j.CmdLineException)4 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 InterruptedRuntimeException (org.codelibs.core.exception.InterruptedRuntimeException)2 CrawlingInfoHelper (org.codelibs.fess.helper.CrawlingInfoHelper)2 SettingsBuilder (com.onelogin.saml2.settings.SettingsBuilder)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 ManagementFactory (java.lang.management.ManagementFactory)1 LocalDateTime (java.time.LocalDateTime)1 Collections (java.util.Collections)1 List (java.util.List)1 Queue (java.util.Queue)1