Search in sources :

Example 1 with IFileFilter

use of org.pentaho.platform.api.repository2.unified.IFileFilter in project pentaho-platform by pentaho.

the class ActionSequenceJCRHelper method getLocaleString.

protected String getLocaleString(final String key, String baseName, final RepositoryFile baseFile, boolean marchUpParents) {
    String parentPath = FilenameUtils.getFullPathNoEndSeparator(baseFile.getPath());
    RepositoryFile searchDir = repository.getFile(parentPath);
    if (baseFile.isFolder()) {
        searchDir = baseFile;
    }
    try {
        boolean searching = true;
        while (searching) {
            RepositoryFile[] propertyFiles = listFiles(searchDir, new IFileFilter() {

                public boolean accept(RepositoryFile file) {
                    return file.getName().toLowerCase().endsWith(PROPERTIES_SUFFIX);
                }
            });
            RepositoryFile blcv = null;
            RepositoryFile blc = null;
            RepositoryFile bl = null;
            RepositoryFile b = null;
            for (RepositoryFile element : propertyFiles) {
                if (element.getName().equalsIgnoreCase(baseName + '_' + getLocale().getLanguage() + '_' + getLocale().getCountry() + '_' + getLocale().getVariant() + PROPERTIES_SUFFIX)) {
                    blcv = element;
                }
                if (element.getName().equalsIgnoreCase(baseName + '_' + getLocale().getLanguage() + '_' + getLocale().getCountry() + PROPERTIES_SUFFIX)) {
                    blc = element;
                }
                if (element.getName().equalsIgnoreCase(baseName + '_' + getLocale().getLanguage() + PROPERTIES_SUFFIX)) {
                    bl = element;
                }
                if (element.getName().equalsIgnoreCase(baseName + PROPERTIES_SUFFIX)) {
                    b = element;
                }
            }
            String localeText = getLocaleText(key, blcv);
            if (localeText == null) {
                localeText = getLocaleText(key, blc);
                if (localeText == null) {
                    localeText = getLocaleText(key, bl);
                    if (localeText == null) {
                        localeText = getLocaleText(key, b);
                    }
                }
            }
            if (localeText != null) {
                return localeText;
            }
            if (searching && marchUpParents) {
                if (!baseName.equals("messages")) {
                    // $NON-NLS-1$
                    // $NON-NLS-1$
                    baseName = "messages";
                } else {
                    parentPath = FilenameUtils.getFullPathNoEndSeparator(searchDir.getPath());
                    // If the parent path is empty or the same as the parent's parent path (meaning root)
                    if (parentPath == null || parentPath.length() < 1 || parentPath.equals(searchDir.getPath())) {
                        searching = false;
                    } else {
                        searchDir = repository.getFile(parentPath);
                    }
                }
            } else if (!marchUpParents) {
                searching = false;
            }
        }
        return null;
    } catch (Exception e) {
        logger.error(Messages.getInstance().getErrorString("ActionSequenceJCRHelper.ERROR_0007_COULD_NOT_READ_PROPERTIES", baseFile.getPath()), // $NON-NLS-1$
        e);
    }
    return null;
}
Also used : IFileFilter(org.pentaho.platform.api.repository2.unified.IFileFilter) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 IFileFilter (org.pentaho.platform.api.repository2.unified.IFileFilter)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1