Example usage for com.liferay.portal.util PropsValues DL_NAME_BLACKLIST

List of usage examples for com.liferay.portal.util PropsValues DL_NAME_BLACKLIST

Introduction

In this page you can find the example usage for com.liferay.portal.util PropsValues DL_NAME_BLACKLIST.

Prototype

String[] DL_NAME_BLACKLIST

To view the source code for com.liferay.portal.util PropsValues DL_NAME_BLACKLIST.

Click Source Link

Usage

From source file:com.liferay.document.library.internal.util.DLValidatorImpl.java

License:Open Source License

@Override
public boolean isValidName(String name) {
    if (Validator.isNull(name)) {
        return false;
    }//from   ww  w .  j a va2 s. c o m

    for (String blacklistChar : PropsValues.DL_CHAR_BLACKLIST) {
        if (name.contains(blacklistChar)) {
            return false;
        }
    }

    for (String blacklistLastChar : PropsValues.DL_CHAR_LAST_BLACKLIST) {
        if (blacklistLastChar.startsWith(UnicodeFormatter.UNICODE_PREFIX)) {
            blacklistLastChar = UnicodeFormatter.parseString(blacklistLastChar);
        }

        if (name.endsWith(blacklistLastChar)) {
            return false;
        }
    }

    String nameWithoutExtension = FileUtil.stripExtension(name);

    for (String blacklistName : PropsValues.DL_NAME_BLACKLIST) {
        if (StringUtil.equalsIgnoreCase(nameWithoutExtension, blacklistName)) {

            return false;
        }
    }

    return true;
}

From source file:com.liferay.document.library.internal.util.DLValidatorImpl.java

License:Open Source License

protected String replaceDLNameBlacklist(String title) {
    String extension = FileUtil.getExtension(title);
    String nameWithoutExtension = FileUtil.stripExtension(title);

    for (String blacklistName : PropsValues.DL_NAME_BLACKLIST) {
        if (StringUtil.equalsIgnoreCase(nameWithoutExtension, blacklistName)) {

            if (Validator.isNull(extension)) {
                return nameWithoutExtension + StringPool.UNDERLINE;
            }//from   ww w .  j  a v a 2  s .c om

            return StringBundler.concat(nameWithoutExtension, StringPool.UNDERLINE, StringPool.PERIOD,
                    extension);
        }
    }

    return title;
}

From source file:com.liferay.document.library.util.test.DLDirectoryNameAndFileNameTest.java

License:Open Source License

@Test
public void testFixNameBlacklist() throws Exception {
    for (String blacklistName : PropsValues.DL_NAME_BLACKLIST) {
        String name = blacklistName;

        Assert.assertEquals(blacklistName + StringPool.UNDERLINE, DLValidatorUtil.fixName(name));

        name = blacklistName + ".txt";

        Assert.assertEquals(blacklistName + StringPool.UNDERLINE + ".txt", DLValidatorUtil.fixName(name));

        name = blacklistName + StringUtil.randomString(10);

        Assert.assertEquals(name, DLValidatorUtil.fixName(name));

        name = blacklistName + StringUtil.randomString(10) + " .txt";

        Assert.assertEquals(name, DLValidatorUtil.fixName(name));
    }//from   ww  w .ja  v  a  2 s  . c o  m
}

From source file:com.liferay.document.library.util.test.DLDirectoryNameAndFileNameTest.java

License:Open Source License

@Test
public void testIsValidNameBlacklist() throws Exception {
    for (String blacklistName : PropsValues.DL_NAME_BLACKLIST) {
        String name = blacklistName;

        Assert.assertFalse(name, DLValidatorUtil.isValidName(name));

        name = blacklistName + ".txt";

        Assert.assertFalse(name, DLValidatorUtil.isValidName(name));

        name = blacklistName + StringUtil.randomString(10);

        Assert.assertTrue(name, DLValidatorUtil.isValidName(name));

        name = blacklistName + StringUtil.randomString(10) + " .txt";

        Assert.assertTrue(name, DLValidatorUtil.isValidName(name));
    }//from   www  .  j a  va2 s  .co m
}