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

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

Introduction

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

Prototype

String[] DL_CHAR_BLACKLIST

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

Click Source Link

Usage

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

License:Open Source License

@Override
public String fixName(String name) {
    if (Validator.isNull(name)) {
        return StringPool.UNDERLINE;
    }//from w  w  w  . ja v a 2s  . c  om

    for (String blacklistChar : PropsValues.DL_CHAR_BLACKLIST) {
        name = StringUtil.replace(name, blacklistChar, StringPool.UNDERLINE);
    }

    name = replaceDLCharLastBlacklist(name);

    return replaceDLNameBlacklist(name);
}

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  v a 2 s.  com

    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.util.test.DLDirectoryNameAndFileNameTest.java

License:Open Source License

@Test(expected = FileNameException.class)
public void testAddFileEntry() throws Exception {
    String name = StringUtil.randomString(20) + PropsValues.DL_CHAR_BLACKLIST[0];

    addFileEntry(name);//from   w w w  . j a  va2  s .c o  m
}

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

License:Open Source License

@Test(expected = FolderNameException.class)
public void testAddFolder() throws Exception {
    String name = StringUtil.randomString(20) + PropsValues.DL_CHAR_BLACKLIST[0];

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(),
            TestPropsValues.getUserId());

    DLAppServiceUtil.addFolder(_group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, name,
            RandomTestUtil.randomString(), serviceContext);
}

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

License:Open Source License

@Test
public void testFixNameRandom() throws Exception {
    for (String blacklistChar : PropsValues.DL_CHAR_BLACKLIST) {
        StringBuilder sb = new StringBuilder(4);

        sb.append(StringUtil.randomString(10));
        sb.append(blacklistChar);//  w  w  w . j  ava2 s  . co  m
        sb.append(StringUtil.randomString(10));

        String name = sb.toString();

        Assert.assertEquals(name.replace(blacklistChar, StringPool.UNDERLINE),
                DLValidatorUtil.fixName(sb.toString()));

        sb.append(".txt");

        Assert.assertEquals(sb.toString().replace(blacklistChar, StringPool.UNDERLINE),
                DLValidatorUtil.fixName(sb.toString()));
    }
}

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

License:Open Source License

@Test
public void testIsValidNameRandom() throws Exception {
    for (int i = 0; i < 100; i++) {
        String name = StringUtil.randomString(20);

        Assert.assertTrue(name, DLValidatorUtil.isValidName(name));
    }//w w w .  j  av a 2  s .  c om

    for (String blacklistChar : PropsValues.DL_CHAR_BLACKLIST) {
        StringBuilder sb = new StringBuilder(4);

        sb.append(StringUtil.randomString(10));
        sb.append(blacklistChar);
        sb.append(StringUtil.randomString(10));

        Assert.assertFalse(sb.toString(), DLValidatorUtil.isValidName(sb.toString()));

        sb.append(".txt");

        Assert.assertFalse(sb.toString(), DLValidatorUtil.isValidName(sb.toString()));
    }
}

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

License:Open Source License

@Test(expected = FileNameException.class)
public void testUpdateFileEntry() throws Exception {
    FileEntry fileEntry = addFileEntry(StringUtil.randomString(20));

    String name = StringUtil.randomString(20) + PropsValues.DL_CHAR_BLACKLIST[0];

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(),
            TestPropsValues.getUserId());

    DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), name, ContentTypes.TEXT_PLAIN, name,
            StringPool.BLANK, StringPool.BLANK, false,
            RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE), serviceContext);
}

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

License:Open Source License

@Test(expected = FolderNameException.class)
public void testUpdateFolder() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(),
            TestPropsValues.getUserId());

    Folder folder = DLAppServiceUtil.addFolder(_group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext);

    String name = StringUtil.randomString(20) + PropsValues.DL_CHAR_BLACKLIST[0];

    DLAppServiceUtil.updateFolder(folder.getFolderId(), name, StringPool.BLANK,
            ServiceContextTestUtil.getServiceContext(_group.getGroupId()));
}