Index: xinha-integration/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/WhiteBlackListResolver.java =================================================================== --- xinha-integration/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/WhiteBlackListResolver.java (revision 41312) +++ xinha-integration/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/WhiteBlackListResolver.java (revision 41313) @@ -1,92 +0,0 @@ -/* - * Copyright 2008 Hippo. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.hippoecm.frontend.plugins.xinha.dialog.images; - -import java.util.ArrayList; -import java.util.List; - -public class WhiteBlackListResolver { - - private List initials; - private List whiteList; - private List blackList; - private List allowedList = new ArrayList(); - private boolean useWhiteList; - - - /** - * - * @param initials list with initial items - * @param blackList list with items that should be omitted - * @return The intersection of initials and blacklist - */ - public static List getAllowedList(List initials, List blackList) { - WhiteBlackListResolver whiteBlackListResolver = new WhiteBlackListResolver(); - whiteBlackListResolver.setInitials(initials); - whiteBlackListResolver.setBlackList(blackList); - whiteBlackListResolver.setWhiteList(new ArrayList()); - whiteBlackListResolver.setUseWhiteList(false); - whiteBlackListResolver.resolve(); - return whiteBlackListResolver.getAllowedList(); - } - - /** - * Constructs a list based on the initial item, a blacklist and a whitelist - * - * @param initials list with initial items - * @param blackList list with items that should be omitted - * @param whiteList list with items that should be added - * @return The intersection of initials and whitelist minus the blacklist - */ - public static List getAllowedList(List initials, List blackList, List whiteList) { - WhiteBlackListResolver whiteBlackListResolver = new WhiteBlackListResolver(); - whiteBlackListResolver.setInitials(initials); - whiteBlackListResolver.setBlackList(blackList); - whiteBlackListResolver.setWhiteList(whiteList); - whiteBlackListResolver.setUseWhiteList(true); - whiteBlackListResolver.resolve(); - return whiteBlackListResolver.getAllowedList(); - } - - void resolve() { - allowedList.addAll(initials); - if (useWhiteList) { - allowedList.retainAll(whiteList); - } - allowedList.removeAll(blackList); - } - - void setUseWhiteList(final boolean useWhiteList) { - this.useWhiteList = useWhiteList; - } - - List getAllowedList() { - return allowedList; - } - - void setInitials(final List initials) { - this.initials = initials; - } - - void setWhiteList(final List whiteList) { - this.whiteList = whiteList; - } - - void setBlackList(final List blackList) { - this.blackList = blackList; - } -} Index: xinha-integration/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/ImageBrowserDialog.java =================================================================== --- xinha-integration/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/ImageBrowserDialog.java (revision 41312) +++ xinha-integration/src/main/java/org/hippoecm/frontend/plugins/xinha/dialog/images/ImageBrowserDialog.java (revision 41313) @@ -96,8 +96,6 @@ public final static List ALIGN_OPTIONS = Arrays.asList("top", "middle", "bottom", "left", "right"); private static final String CONFIG_KEY_PREFERRED_RESOURCE_NAMES = "preferred.resource.names"; private static final String GALLERY_TYPE_SELECTOR_ID = "galleryType"; - public static final String BLACKLIST_NAME_TYPES = "blacklist.nameTypes"; - public static final String WHITELIST_NAME_TYPES = "whitelist.nameTypes"; DropDownChoice type; @@ -243,7 +241,7 @@ private void setTypeChoices(final Node imageSetNode) { if (nameTypeMap == null) { - nameTypeMap = new LinkedHashMap(); + nameTypeMap = new LinkedHashMap(); } else { nameTypeMap.clear(); } @@ -262,24 +260,13 @@ } TypeTranslator typeTranslator = new TypeTranslator(new JcrNodeTypeModel(tmpImageSetNode.getPrimaryNodeType())); NodeIterator childNodes = tmpImageSetNode.getNodes(); - List initials = new ArrayList(); while (childNodes.hasNext()) { Node childNode = childNodes.nextNode(); if (childNode.isNodeType("hippogallery:image")) { String childNodeName = childNode.getName(); - initials.add(childNodeName); + sortedEntries.add(new AbstractMap.SimpleEntry(childNodeName, typeTranslator.getPropertyName(childNodeName).getObject())); } } - List allowedChildNodeNames; - if (hasWhiteList()){ - allowedChildNodeNames = WhiteBlackListResolver.getAllowedList(initials,getBlackListNameTypes(),getWhiteListNameTypes()); - } - else{ - allowedChildNodeNames = WhiteBlackListResolver.getAllowedList(initials,getBlackListNameTypes()); - } - for (String childNodeName:allowedChildNodeNames){ - sortedEntries.add(new AbstractMap.SimpleEntry(childNodeName, typeTranslator.getPropertyName(childNodeName).getObject())); - } } catch (RepositoryException repositoryException) { log.error("Error updating the available image variants.", repositoryException); } @@ -294,32 +281,6 @@ } } - - - private List getWhiteListNameTypes(){ - return getListNameTypes(WHITELIST_NAME_TYPES); - } - - private List getBlackListNameTypes(){ - return getListNameTypes(BLACKLIST_NAME_TYPES); - } - - private List getListNameTypes(final String key) { - List result = new ArrayList(); - final String[] stringArray = getPluginConfig().getStringArray(key); - if (stringArray!=null){ - for (String s : stringArray) { - result.add(s); - } - } - return result; - } - - private boolean hasWhiteList() { - return getPluginConfig().getStringArray(WHITELIST_NAME_TYPES)!=null; - } - - @SuppressWarnings("unchecked") private Component createUploadForm() { Form uploadForm = new Form("uploadForm"); @@ -535,13 +496,13 @@ return getChoices().size() > 1; } } - .setNullValid(false) - .add(new AjaxFormComponentUpdatingBehavior("onchange") { - @Override - protected void onUpdate(AjaxRequestTarget target) { - // required because abstract, but all we need is to have galleryType set, which happens underwater. - } - }); + .setNullValid(false) + .add(new AjaxFormComponentUpdatingBehavior("onchange") { + @Override + protected void onUpdate(AjaxRequestTarget target) { + // required because abstract, but all we need is to have galleryType set, which happens underwater. + } + }); } /** Index: xinha-integration/src/test/java/org/hippoecm/frontend/plugins/xinha/dialog/images/WhiteBlackListResolverTest.java =================================================================== --- xinha-integration/src/test/java/org/hippoecm/frontend/plugins/xinha/dialog/images/WhiteBlackListResolverTest.java (revision 41312) +++ xinha-integration/src/test/java/org/hippoecm/frontend/plugins/xinha/dialog/images/WhiteBlackListResolverTest.java (revision 41313) @@ -1,92 +0,0 @@ -/* - * Copyright 2008 Hippo. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.hippoecm.frontend.plugins.xinha.dialog.images; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; - -public class WhiteBlackListResolverTest { - - - - @Test - public void getAllowed_BlackListEmptyWhiteListEmpty_returnInitial(){ - WhiteBlackListResolver whiteBlackListResolver = new WhiteBlackListResolver(); - List initials = new ArrayList(); - initials.add("A"); - initials.add("B"); - initials.add("C"); - initials.add("D"); - List whiteList = new ArrayList(); - List blackList = new ArrayList(); - whiteBlackListResolver.setInitials(initials); - whiteBlackListResolver.setBlackList(blackList); - whiteBlackListResolver.setWhiteList(whiteList); - whiteBlackListResolver.setUseWhiteList(false); - whiteBlackListResolver.resolve(); - final List actual = whiteBlackListResolver.getAllowedList(); - Assert.assertArrayEquals(initials.toArray(),actual.toArray()); - } - - @Test - public void getAllowed_BlackListEmptyWhiteListNotEmpty_returnWhiteListItemIfPresentInInitial(){ - WhiteBlackListResolver whiteBlackListResolver = new WhiteBlackListResolver(); - List initials = new ArrayList(); - initials.add("A"); - initials.add("B"); - initials.add("C"); - initials.add("D"); - List whiteList = new ArrayList(); - whiteList.add("E"); - whiteList.add("A"); - List blackList = new ArrayList(); - whiteBlackListResolver.setInitials(initials); - whiteBlackListResolver.setBlackList(blackList); - whiteBlackListResolver.setWhiteList(whiteList); - whiteBlackListResolver.setUseWhiteList(true); - whiteBlackListResolver.resolve(); - final List actual = whiteBlackListResolver.getAllowedList(); - final List expected = new ArrayList(); - expected.add("A"); - Assert.assertArrayEquals(expected.toArray(),actual.toArray()); - } - - @Test - public void getAllowed_BlackListNotEmpty_WhitelistNotEmpty_returnWhiteListMinusBlackList(){ - WhiteBlackListResolver whiteBlackListResolver = new WhiteBlackListResolver(); - List initials = new ArrayList(); - initials.add("A"); - initials.add("B"); - initials.add("C"); - initials.add("D"); - List whiteList = new ArrayList(); - whiteList.add("E"); - whiteList.add("A"); - List blackList = new ArrayList(); - blackList.add("A"); - whiteBlackListResolver.setInitials(initials); - whiteBlackListResolver.setBlackList(blackList); - whiteBlackListResolver.setWhiteList(whiteList); - whiteBlackListResolver.setUseWhiteList(true); - whiteBlackListResolver.resolve(); - final List actual = whiteBlackListResolver.getAllowedList(); - final List expected = new ArrayList(); - Assert.assertArrayEquals(expected.toArray(),actual.toArray()); - } -}