/src/main/java/org/andya/confluence/utils/page/source/RequiredLabelFilter.java
Java | 64 lines | 29 code | 8 blank | 27 comment | 4 complexity | 33c180de8b58708a5cf8a3b263250ee8 MD5 | raw file
- /*
- * Copyright (c) 2006, 2007 Andy Armstrong, Kelsey Grant and other contributors.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * The names of contributors may not
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
- package org.andya.confluence.utils.page.source;
-
- import java.util.List;
-
- import com.atlassian.confluence.labels.Label;
- import com.atlassian.confluence.pages.Page;
- import com.atlassian.renderer.v2.macro.MacroException;
- import org.andya.confluence.utils.page.PageSearchContext;
-
- public class RequiredLabelFilter extends FilterPageSource {
-
- private final String[] requiredLabels;
-
- public RequiredLabelFilter(String[] requiredLabels, PageSource child, PageSearchContext context) throws MacroException {
- super(child);
- this.requiredLabels = requiredLabels;
- }
-
- protected boolean include(Page p, PageSearchContext context) {
- List<Label> labels = p.getLabels();
-
- for (int i = 0; i < requiredLabels.length; i++) {
- String requiredLabel = requiredLabels[i];
- boolean found = false;
- for (Label label : labels) {
- if(label.getName().equals(requiredLabel)) {
- found = true;
- }
- }
- if(!found) {
- return false;
- }
- }
- return true;
- }
- }