KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > util > RuleBasedContentFilter


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.util;
14
15 import info.magnolia.cms.core.Content;
16
17 import javax.jcr.RepositoryException;
18
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22
23 /**
24  * @author Sameer Charles
25  * @version $Revision: 6341 $ ($Author: philipp $)
26  */

27 public class RuleBasedContentFilter implements Content.ContentFilter {
28
29     /**
30      * Logger
31      */

32     private static Logger log = LoggerFactory.getLogger(RuleBasedContentFilter.class);
33
34     /**
35      * Rule on which this filter works
36      */

37     private Rule rule;
38
39     /**
40      * @param rule
41      */

42     public RuleBasedContentFilter(Rule rule) {
43         this.rule = rule;
44     }
45
46     /**
47      * Test if this content should be included in a resultant collection
48      * @param content
49      * @return if true this will be a part of collection
50      */

51     public boolean accept(Content content) {
52         String JavaDoc nodeType = "";
53         try {
54             nodeType = content.getNodeTypeName();
55         }
56         catch (RepositoryException re) {
57             if (log.isDebugEnabled()) {
58                 log.debug("failed to retrieve node type : " + re.getMessage(), re);
59             }
60         }
61         return this.rule.isAllowed(nodeType);
62     }
63
64 }
65
Popular Tags