Example usage for org.apache.commons.collections ExtendedProperties getStringArray

List of usage examples for org.apache.commons.collections ExtendedProperties getStringArray

Introduction

In this page you can find the example usage for org.apache.commons.collections ExtendedProperties getStringArray.

Prototype

public String[] getStringArray(String key) 

Source Link

Document

Get an array of strings associated with the given configuration key.

Usage

From source file:adalid.commons.velocity.Writer.java

private void writePlatform(WriterContext basicWriterContext, File platformPropertiesFile) {
    logger.info("propertiesFile=" + platformPropertiesFile.getPath());
    try {/* ww  w.j  a v  a 2s. com*/
        VelocityContext platformContext = basicWriterContext.getVelocityContextClone();
        String platform = StringUtils.removeEndIgnoreCase(platformPropertiesFile.getName(), PROPERTIES_SUFFIX);
        platformContext.put(VC_PLATFORM, platform);
        TLB.setProgrammers(basicWriterContext.programmers);
        TLB.setWrapperClasses(basicWriterContext.wrapperClasses);
        putProperties(platformContext, platformPropertiesFile);
        Properties properties = mergeProperties(platformContext, platformPropertiesFile);
        putStrings(platformContext, properties);
        ExtendedProperties mergeExtendedProperties = mergeExtendedProperties(platformContext,
                platformPropertiesFile);
        createDirectories(mergeExtendedProperties);
        deletePreviouslyGeneratedFiles(mergeExtendedProperties);
        WriterContext platformWriterContext = newWriterContext(platformContext);
        File platformsFolder = platformPropertiesFile.getParentFile();
        ExtendedProperties platformExtendedProperties = PropertiesHandler
                .getExtendedProperties(platformPropertiesFile);
        String[] pathnames = platformExtendedProperties.getStringArray(FILE_RESOURCE_LOADER_PATH);
        String[] pathfilters = platformExtendedProperties.getStringArray(FILE_RESOURCE_LOADER_PATH_FILTER);
        Map<String, File> folders = new LinkedHashMap<>();
        if (pathnames == null || pathnames.length == 0) {
        } else {
            for (File folder : bootstrappingPlatformsFolders) {
                folders.putAll(FilUtils.directoriesMap(folder, pathnames, folder));
            }
        }
        if (pathfilters != null && pathfilters.length > 0) {
            String[] keyArray = folders.keySet().toArray(new String[folders.keySet().size()]);
            String slashedFilter, slashedPath;
            for (String pathfilter : pathfilters) {
                slashedFilter = pathfilter.replace(FILE_SEPARATOR, SLASH);
                for (String key : keyArray) {
                    slashedPath = key.replace(FILE_SEPARATOR, SLASH) + SLASH;
                    if (StringUtils.containsIgnoreCase(slashedPath, slashedFilter)) {
                        folders.remove(key);
                        logger.debug(pathfilter + " excludes " + key);
                    }
                }
            }
        }
        File[] templateFiles;
        Properties templateProperties;
        String disabled;
        String disabledMissing;
        String pattern;
        String template;
        String message;
        String platformsFolderPath = platformsFolder.getPath(); // + FILE_SEPARATOR;
        for (File folder : folders.values()) {
            log(_detailLevel, "write",
                    "path=" + StringUtils.removeStart(folder.getPath(), platformsFolderPath));
            templateFiles = folder.listFiles(propertiesFileFilter);
            Arrays.sort(templateFiles);
            for (File templatePropertiesFile : templateFiles) {
                if (reject(templatePropertiesFile, pathfilters)) {
                    continue;
                }
                templateProperties = PropertiesHandler.loadProperties(templatePropertiesFile);
                disabled = templateProperties.getProperty(TP_DISABLED, Boolean.FALSE.toString());
                disabledMissing = templateProperties.getProperty(TP_DISABLED_MISSING);
                templates++;
                if (BitUtils.valueOf(disabled)) {
                    disabledTemplates++;
                    template = StringUtils.removeEndIgnoreCase(templatePropertiesFile.getName(),
                            PROPERTIES_SUFFIX);
                    pattern = "template \"{0}\" ignored, check property \"{1}\" at file \"{2}\"";
                    message = MessageFormat.format(pattern, template, TP_DISABLED, templatePropertiesFile);
                    log(_alertLevel, message);
                    warnings++;
                } else if (missing(disabledMissing)) {
                    disabledTemplates++;
                    template = StringUtils.removeEndIgnoreCase(templatePropertiesFile.getName(),
                            PROPERTIES_SUFFIX);
                    pattern = "template \"{0}\" ignored because {3} is missing, check property \"{1}\" at file \"{2}\"";
                    message = MessageFormat.format(pattern, template, TP_DISABLED_MISSING,
                            templatePropertiesFile, disabledMissing);
                    log(_alertLevel, message);
                    warnings++;
                } else {
                    writeTemplate(platformWriterContext, templatePropertiesFile);
                }
            }
        }
        platforms++;
    } catch (Throwable throwable) {
        error(throwable);
    }
    printSummary();
}

From source file:adalid.commons.velocity.Writer.java

@SuppressWarnings("unchecked")
private void createDirectories(ExtendedProperties properties) {
    String[] stringArray;//w  w w. ja  va  2 s.c o m
    Set<String> stringPropertyNames = properties.keySet();
    for (String name : stringPropertyNames) {
        switch (name) {
        case DO_CREATE_DIR:
            stringArray = properties.getStringArray(name);
            createDirectories(name, stringArray);
            break;
        }
    }
}

From source file:adalid.commons.velocity.Writer.java

@SuppressWarnings("unchecked")
private void deletePreviouslyGeneratedFiles(ExtendedProperties properties) {
    String[] stringArray;/*from  w  ww  .  j  av  a  2s . c  o m*/
    Set<String> stringPropertyNames = properties.keySet();
    for (String name : stringPropertyNames) {
        switch (name) {
        case DO_CASCADED_DELETE:
            stringArray = properties.getStringArray(name);
            deletePreviouslyGeneratedFiles(name, stringArray, true);
            break;
        case DO_ISOLATED_DELETE:
            stringArray = properties.getStringArray(name);
            deletePreviouslyGeneratedFiles(name, stringArray, false);
            break;
        }
    }
}

From source file:org.apache.roller.weblogger.ui.rendering.velocity.WebappResourceLoader.java

/**
 * This is abstract in the base class, so we need it. <br>
 * NOTE: this expects that the ServletContext has already been placed in the
 * runtime's application attributes under its full class name (i.e.
 * "javax.servlet.ServletContext").//from w  w  w  .ja  v  a2  s . c  om
 * 
 * @param configuration
 *            the {@link ExtendedProperties} associated with this resource
 *            loader.
 */
public void init(ExtendedProperties configuration) {

    if (log.isDebugEnabled())
        log.debug("WebappResourceLoader: initialization starting.");

    // get configured paths
    paths = configuration.getStringArray("path");
    if (paths == null || paths.length == 0) {
        paths = new String[1];
        paths[0] = "/";
    } else {
        // make sure the paths end with a '/'
        for (int i = 0; i < paths.length; i++) {
            if (!paths[i].endsWith("/")) {
                paths[i] += '/';
            }
            if (log.isDebugEnabled())
                log.debug("WebappResourceLoader: added template path - '" + paths[i] + "'");
        }
    }

    // get the ServletContext
    servletContext = RollerContext.getServletContext();

    if (log.isDebugEnabled())
        log.debug("Servlet Context = " + servletContext.getRealPath("/WEB-INF/velocity/"));

    // init the template paths map
    templatePaths = new HashMap<String, String>();

    if (log.isDebugEnabled())
        log.debug("WebappResourceLoader: initialization complete.");
}

From source file:org.apache.velocity.runtime.resource.loader.URLResourceLoader.java

/**
 * @see org.apache.velocity.runtime.resource.loader.ResourceLoader#init(org.apache.commons.collections.ExtendedProperties)
 *//*from   ww  w  .j a va 2 s.  co  m*/
public void init(ExtendedProperties configuration) {
    Logger.debug(this, "URLResourceLoader : initialization starting.");

    roots = configuration.getStringArray("root");
    if (Logger.isDebugEnabled(this.getClass())) {
        for (int i = 0; i < roots.length; i++) {
            Logger.debug(this, "URLResourceLoader : adding root '" + roots[i] + "'");
        }
    }

    timeout = configuration.getInt("timeout", -1);
    if (timeout > 0) {
        try {
            Class[] types = new Class[] { Integer.TYPE };
            Method conn = URLConnection.class.getMethod("setConnectTimeout", types);
            Method read = URLConnection.class.getMethod("setReadTimeout", types);
            timeoutMethods = new Method[] { conn, read };
            Logger.debug(this, "URLResourceLoader : timeout set to " + timeout);
        } catch (NoSuchMethodException nsme) {
            Logger.debug(this, "URLResourceLoader : Java 1.5+ is required to customize timeout!", nsme);
            timeout = -1;
        }
    }

    // init the template paths map
    templateRoots = new HashMap();

    Logger.debug(this, "URLResourceLoader : initialization complete.");
}

From source file:org.apache.velocity.tools.config.PropertiesFactoryConfiguration.java

protected void readToolboxes(ExtendedProperties factory) {
    String[] scopes = factory.getStringArray("toolbox");
    for (String scope : scopes) {
        ToolboxConfiguration toolbox = new ToolboxConfiguration();
        toolbox.setScope(scope);/*from w w w .  ja  v  a 2  s  .  c  om*/
        addToolbox(toolbox);

        ExtendedProperties toolboxProps = factory.subset(scope);
        readTools(toolboxProps, toolbox);
        readProperties(toolboxProps, toolbox);
    }
}

From source file:org.apache.velocity.tools.view.servlet.WebappLoader.java

/**
 *  This is abstract in the base class, so we need it.
 *  <br>// w  w  w. java 2 s  . c  o  m
 *  NOTE: this expects that the ServletContext has already
 *        been placed in the runtime's application attributes
 *        under its full class name (i.e. "javax.servlet.ServletContext").
 *
 * @param configuration the {@link ExtendedProperties} associated with
 *        this resource loader.
 */
public void init(ExtendedProperties configuration) {
    rsvc.info("WebappLoader : initialization starting.");

    /* get configured paths */
    paths = configuration.getStringArray("path");
    if (paths == null || paths.length == 0) {
        paths = new String[1];
        paths[0] = "/";
    } else {
        /* make sure the paths end with a '/' */
        for (int i = 0; i < paths.length; i++) {
            if (!paths[i].endsWith("/")) {
                paths[i] += '/';
            }
            rsvc.info("WebappLoader : added template path - '" + paths[i] + "'");
        }
    }

    /* get the ServletContext */
    Object obj = rsvc.getApplicationAttribute(ServletContext.class.getName());
    if (obj instanceof ServletContext) {
        servletContext = (ServletContext) obj;
    } else {
        rsvc.error("WebappLoader : unable to retrieve ServletContext");
    }

    /* init the template paths map */
    templatePaths = new HashMap();

    rsvc.info("WebappLoader : initialization complete.");
}

From source file:org.apache.velocity.tools.view.WebappResourceLoader.java

/**
 *  This is abstract in the base class, so we need it.
 *  <br>/*w w  w  .  j a v  a  2s . com*/
 *  NOTE: this expects that the ServletContext has already
 *        been placed in the runtime's application attributes
 *        under its full class name (i.e. "javax.servlet.ServletContext").
 *
 * @param configuration the {@link ExtendedProperties} associated with
 *        this resource loader.
 */
public void init(ExtendedProperties configuration) {
    log.trace("WebappResourceLoader: initialization starting.");

    /* get configured paths */
    paths = configuration.getStringArray("path");
    if (paths == null || paths.length == 0) {
        paths = new String[1];
        paths[0] = "/";
    } else {
        /* make sure the paths end with a '/' */
        for (int i = 0; i < paths.length; i++) {
            if (!paths[i].endsWith("/")) {
                paths[i] += '/';
            }
            log.info("WebappResourceLoader: added template path - '" + paths[i] + "'");
        }
    }

    /* get the ServletContext */
    Object obj = rsvc.getApplicationAttribute(ServletContext.class.getName());
    if (obj instanceof ServletContext) {
        servletContext = (ServletContext) obj;
    } else {
        log.error("WebappResourceLoader: unable to retrieve ServletContext");
    }

    /* init the template paths map */
    templatePaths = new HashMap();

    log.trace("WebappResourceLoader: initialization complete.");
}

From source file:org.kalypso.metadoc.configuration.ConfigurationUtils.java

/**
 * Add the value to the given property. If the property is already defined, it adds the value only if it is not
 * already existing in the list of values for that property.
 *//*from  ww w . j a  v  a  2  s. co  m*/
public static void addPropertyDistinct(final ExtendedProperties conf, final String property,
        final String value) {
    if (conf == null || value == null || property == null)
        return;

    final String[] array = conf.getStringArray(property);
    if (array == null || !Arrays.asList(array).contains(value))
        conf.addProperty(property, value);
}

From source file:org.opencms.frontend.templateone.form.CmsFieldFactory.java

/**
 * Default constructor.<p>/*w ww  . j a va 2  s .  c  om*/
 */
private CmsFieldFactory() {

    super();

    m_registeredFieldTypes = new HashMap();

    // register all the standard OpenCms field types
    registerFieldType(CmsCheckboxField.getStaticType(), CmsCheckboxField.class.getName());
    registerFieldType(CmsEmailField.getStaticType(), CmsEmailField.class.getName());
    registerFieldType(CmsFileUploadField.getStaticType(), CmsFileUploadField.class.getName());
    registerFieldType(CmsHiddenField.getStaticType(), CmsHiddenField.class.getName());
    registerFieldType(CmsRadioButtonField.getStaticType(), CmsRadioButtonField.class.getName());
    registerFieldType(CmsSelectionField.getStaticType(), CmsSelectionField.class.getName());
    registerFieldType(CmsTextField.getStaticType(), CmsTextField.class.getName());
    registerFieldType(CmsTextareaField.getStaticType(), CmsTextareaField.class.getName());
    registerFieldType(CmsEmptyField.getStaticType(), CmsEmptyField.class.getName());
    registerFieldType(CmsPrivacyField.getStaticType(), CmsPrivacyField.class.getName());

    File propertyFile = null;
    try {

        // register all custom field types declared in a property file.
        // since custom fields are optional, the property file doesn't have to exist necessarily in the file system.
        // this file should contain a mapping of field type names to a Java classes separated by a colo ":", e.g.:
        // FIELDS=<fieldtype>:<java class>,...,<fieldtype>:<java class>

        propertyFile = new File(CUSTOM_FORM_FIELD_PROPERTIES);
        if (propertyFile.exists()) {

            ExtendedProperties fieldProperties = new ExtendedProperties();
            fieldProperties.load(new FileInputStream(propertyFile));

            Iterator i = fieldProperties.keySet().iterator();
            while (i.hasNext()) {

                String key = (String) i.next();
                if (!"FIELDS".equalsIgnoreCase(key)) {
                    continue;
                }

                String[] values = fieldProperties.getStringArray(key);
                if ((values == null) || (values.length == 0)) {
                    continue;
                }

                for (int j = 0, n = values.length; j < n; j++) {

                    String field = values[j];
                    int index = field.indexOf(":");
                    if (index == -1) {
                        continue;
                    }

                    String fieldType = field.substring(0, index);
                    String fieldClass = field.substring(index + 1, field.length());
                    registerFieldType(fieldType, fieldClass);
                }
            }
        }
    } catch (IOException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(Messages.get().getBundle().key(Messages.LOG_ERR_READING_CUSTOM_FORM_FIELD_PROPERTIES_1,
                    propertyFile == null ? CUSTOM_FORM_FIELD_PROPERTIES : propertyFile.getAbsolutePath()), e);
        }
    }
}